Skip to content

Commit

Permalink
feat(agama): deploy flows from .gama files (#3250)
Browse files Browse the repository at this point in the history
* feat: add timer for deployment/undeployment of ADS projects #3052

* feat: add data object class for an ADS deployment #3052

* chore: remove TODOs #3052
  • Loading branch information
jgomer2001 authored Dec 7, 2022
1 parent 8f72ea6 commit df14f8a
Show file tree
Hide file tree
Showing 8 changed files with 765 additions and 1 deletion.
555 changes: 555 additions & 0 deletions jans-auth-server/agama/engine/src/main/java/io/jans/ads/Deployer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.jans.ads.timer;

import io.jans.ads.Deployer;
import io.jans.agama.engine.misc.FlowUtils;
import io.jans.service.cdi.async.Asynchronous;
import io.jans.service.cdi.event.Scheduled;
import io.jans.service.timer.event.TimerEvent;
import io.jans.service.timer.schedule.TimerSchedule;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Event;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;

import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;

@ApplicationScoped
public class DeployerTimer {

@Inject
private Deployer deployer;

@Inject
private Logger logger;

@Inject
private Event<TimerEvent> timerEvent;

@Inject
private FlowUtils futils;

private AtomicBoolean isActive;

private static final int DELAY = 5 + (int) (10 * Math.random()); //seconds
private static final int INTERVAL = 30; // seconds

public void initTimer() {

logger.info("Initializing Agama transpilation Timer");
isActive = new AtomicBoolean(false);
timerEvent.fire(new TimerEvent(new TimerSchedule(DELAY, INTERVAL),
new DeploymentEvent(), Scheduled.Literal.INSTANCE));

}

@Asynchronous
public void run(@Observes @Scheduled DeploymentEvent event) {

if (!futils.serviceEnabled()) return;

if (isActive.get()) return;

if (!isActive.compareAndSet(false, true)) return;

try {
deployer.process();
logger.debug("ADS deployer timer has run.");
} catch (Exception e) {
logger.error("An error occurred while running ADS deployer timer", e);
} finally {
isActive.set(false);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.jans.ads.timer;

public class DeploymentEvent { }
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public Flow getFlow(String flowName, boolean full) throws IOException {

if (fls.isEmpty()) {
logger.warn("Flow '{}' does not exist!", flowName);
return null;
}

return fls.get(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jans.agama.engine.service;

import io.jans.ads.timer.DeployerTimer;
import io.jans.agama.timer.FlowRunsCleaner;
import io.jans.agama.timer.Transpilation;
import io.jans.service.cdi.event.ApplicationInitialized;
Expand All @@ -17,12 +18,16 @@ public class AppInitializer {

@Inject
private FlowRunsCleaner fcleaner;

@Inject
private DeployerTimer deployerTimer;

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

trTimer.initTimer();
fcleaner.initTimer();
deployerTimer.initTimer();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.jans.ads.model;

import io.jans.orm.annotation.AttributeName;
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.JsonObject;
import io.jans.orm.annotation.ObjectClass;
import io.jans.orm.model.base.Entry;

import java.util.Date;

@DataEntry
@ObjectClass(value = "adsPrjDeployment")
public class Deployment extends Entry {

public static final String ASSETS_ATTR = "adsPrjAssets";

@AttributeName(name = "jansId")
private String id;

@AttributeName(name = "jansStartDate")
private Date createdAt;

@AttributeName(name = "jansActive")
private boolean taskActive;

@AttributeName(name = "jansEndDate")
private Date finishedAt;

@AttributeName(name = Deployment.ASSETS_ATTR)
private String assets;

@JsonObject
@AttributeName(name = "adsPrjDeplDetails")
private DeploymentDetails details;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public boolean isTaskActive() {
return taskActive;
}

public void setTaskActive(boolean taskActive) {
this.taskActive = taskActive;
}

public Date getFinishedAt() {
return finishedAt;
}

public void setFinishedAt(Date finishedAt) {
this.finishedAt = finishedAt;
}

public String getAssets() {
return assets;
}

public void setAssets(String assets) {
this.assets = assets;
}

public DeploymentDetails getDetails() {
return details;
}

public void setDetails(DeploymentDetails details) {
this.details = details;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.jans.ads.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.List;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class DeploymentDetails {

private String projectName;
private List<String> folders;
private Map<String, String> flowsError;
private String error;

public String getProjectName() {
return projectName;
}

public void setProjectName(String projectName) {
this.projectName = projectName;
}

public List<String> getFolders() {
return folders;
}

public void setFolders(List<String> folders) {
this.folders = folders;
}

public String getError() {
return error;
}

public void setError(String error) {
this.error = error;
}

public Map<String, String> getFlowsError() {
return flowsError;
}

public void setFlowsError(Map<String, String> flowsError) {
this.flowsError = flowsError;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.quartz.scheduler.instanceName=Jans AuthScheduler
org.quartz.threadPool.threadCount=6
org.quartz.threadPool.threadCount=8
org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore
org.quartz.scheduler.skipUpdateCheck=true

0 comments on commit df14f8a

Please sign in to comment.