Skip to content

Commit df14f8a

Browse files
authored
feat(agama): deploy flows from .gama files (#3250)
* feat: add timer for deployment/undeployment of ADS projects #3052 * feat: add data object class for an ADS deployment #3052 * chore: remove TODOs #3052
1 parent 8f72ea6 commit df14f8a

File tree

8 files changed

+765
-1
lines changed

8 files changed

+765
-1
lines changed

jans-auth-server/agama/engine/src/main/java/io/jans/ads/Deployer.java

+555
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.jans.ads.timer;
2+
3+
import io.jans.ads.Deployer;
4+
import io.jans.agama.engine.misc.FlowUtils;
5+
import io.jans.service.cdi.async.Asynchronous;
6+
import io.jans.service.cdi.event.Scheduled;
7+
import io.jans.service.timer.event.TimerEvent;
8+
import io.jans.service.timer.schedule.TimerSchedule;
9+
10+
import jakarta.enterprise.context.ApplicationScoped;
11+
import jakarta.enterprise.event.Event;
12+
import jakarta.enterprise.event.Observes;
13+
import jakarta.inject.Inject;
14+
15+
import java.util.concurrent.atomic.AtomicBoolean;
16+
17+
import org.slf4j.Logger;
18+
19+
@ApplicationScoped
20+
public class DeployerTimer {
21+
22+
@Inject
23+
private Deployer deployer;
24+
25+
@Inject
26+
private Logger logger;
27+
28+
@Inject
29+
private Event<TimerEvent> timerEvent;
30+
31+
@Inject
32+
private FlowUtils futils;
33+
34+
private AtomicBoolean isActive;
35+
36+
private static final int DELAY = 5 + (int) (10 * Math.random()); //seconds
37+
private static final int INTERVAL = 30; // seconds
38+
39+
public void initTimer() {
40+
41+
logger.info("Initializing Agama transpilation Timer");
42+
isActive = new AtomicBoolean(false);
43+
timerEvent.fire(new TimerEvent(new TimerSchedule(DELAY, INTERVAL),
44+
new DeploymentEvent(), Scheduled.Literal.INSTANCE));
45+
46+
}
47+
48+
@Asynchronous
49+
public void run(@Observes @Scheduled DeploymentEvent event) {
50+
51+
if (!futils.serviceEnabled()) return;
52+
53+
if (isActive.get()) return;
54+
55+
if (!isActive.compareAndSet(false, true)) return;
56+
57+
try {
58+
deployer.process();
59+
logger.debug("ADS deployer timer has run.");
60+
} catch (Exception e) {
61+
logger.error("An error occurred while running ADS deployer timer", e);
62+
} finally {
63+
isActive.set(false);
64+
}
65+
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.jans.ads.timer;
2+
3+
public class DeploymentEvent { }

jans-auth-server/agama/engine/src/main/java/io/jans/agama/engine/service/AgamaPersistenceService.java

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public Flow getFlow(String flowName, boolean full) throws IOException {
139139

140140
if (fls.isEmpty()) {
141141
logger.warn("Flow '{}' does not exist!", flowName);
142+
return null;
142143
}
143144

144145
return fls.get(0);

jans-auth-server/agama/engine/src/main/java/io/jans/agama/engine/service/AppInitializer.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.jans.agama.engine.service;
22

3+
import io.jans.ads.timer.DeployerTimer;
34
import io.jans.agama.timer.FlowRunsCleaner;
45
import io.jans.agama.timer.Transpilation;
56
import io.jans.service.cdi.event.ApplicationInitialized;
@@ -17,12 +18,16 @@ public class AppInitializer {
1718

1819
@Inject
1920
private FlowRunsCleaner fcleaner;
21+
22+
@Inject
23+
private DeployerTimer deployerTimer;
2024

2125
public void run(@Observes @ApplicationInitialized(ApplicationScoped.class)
2226
ApplicationInitializedEvent event) {
2327

2428
trTimer.initTimer();
2529
fcleaner.initTimer();
30+
deployerTimer.initTimer();
2631

2732
}
2833

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.jans.ads.model;
2+
3+
import io.jans.orm.annotation.AttributeName;
4+
import io.jans.orm.annotation.DataEntry;
5+
import io.jans.orm.annotation.JsonObject;
6+
import io.jans.orm.annotation.ObjectClass;
7+
import io.jans.orm.model.base.Entry;
8+
9+
import java.util.Date;
10+
11+
@DataEntry
12+
@ObjectClass(value = "adsPrjDeployment")
13+
public class Deployment extends Entry {
14+
15+
public static final String ASSETS_ATTR = "adsPrjAssets";
16+
17+
@AttributeName(name = "jansId")
18+
private String id;
19+
20+
@AttributeName(name = "jansStartDate")
21+
private Date createdAt;
22+
23+
@AttributeName(name = "jansActive")
24+
private boolean taskActive;
25+
26+
@AttributeName(name = "jansEndDate")
27+
private Date finishedAt;
28+
29+
@AttributeName(name = Deployment.ASSETS_ATTR)
30+
private String assets;
31+
32+
@JsonObject
33+
@AttributeName(name = "adsPrjDeplDetails")
34+
private DeploymentDetails details;
35+
36+
public String getId() {
37+
return id;
38+
}
39+
40+
public void setId(String id) {
41+
this.id = id;
42+
}
43+
44+
public Date getCreatedAt() {
45+
return createdAt;
46+
}
47+
48+
public void setCreatedAt(Date createdAt) {
49+
this.createdAt = createdAt;
50+
}
51+
52+
public boolean isTaskActive() {
53+
return taskActive;
54+
}
55+
56+
public void setTaskActive(boolean taskActive) {
57+
this.taskActive = taskActive;
58+
}
59+
60+
public Date getFinishedAt() {
61+
return finishedAt;
62+
}
63+
64+
public void setFinishedAt(Date finishedAt) {
65+
this.finishedAt = finishedAt;
66+
}
67+
68+
public String getAssets() {
69+
return assets;
70+
}
71+
72+
public void setAssets(String assets) {
73+
this.assets = assets;
74+
}
75+
76+
public DeploymentDetails getDetails() {
77+
return details;
78+
}
79+
80+
public void setDetails(DeploymentDetails details) {
81+
this.details = details;
82+
}
83+
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.jans.ads.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class DeploymentDetails {
10+
11+
private String projectName;
12+
private List<String> folders;
13+
private Map<String, String> flowsError;
14+
private String error;
15+
16+
public String getProjectName() {
17+
return projectName;
18+
}
19+
20+
public void setProjectName(String projectName) {
21+
this.projectName = projectName;
22+
}
23+
24+
public List<String> getFolders() {
25+
return folders;
26+
}
27+
28+
public void setFolders(List<String> folders) {
29+
this.folders = folders;
30+
}
31+
32+
public String getError() {
33+
return error;
34+
}
35+
36+
public void setError(String error) {
37+
this.error = error;
38+
}
39+
40+
public Map<String, String> getFlowsError() {
41+
return flowsError;
42+
}
43+
44+
public void setFlowsError(Map<String, String> flowsError) {
45+
this.flowsError = flowsError;
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.quartz.scheduler.instanceName=Jans AuthScheduler
2-
org.quartz.threadPool.threadCount=6
2+
org.quartz.threadPool.threadCount=8
33
org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore
44
org.quartz.scheduler.skipUpdateCheck=true

0 commit comments

Comments
 (0)