Skip to content

Commit

Permalink
Accept a list of server in the BPMN list
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-yves-monnet committed Oct 3, 2023
1 parent f01e429 commit 096a531
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 227 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.camunda.community.automator</groupId>
<artifactId>process-execution-automator</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2</version>

<properties>
<java.version>17</java.version>
Expand All @@ -17,7 +17,7 @@

<junit.jupiter.version>5.9.1</junit.jupiter.version>
<opensagres.version>2.0.3</opensagres.version>
<spring.boot.version>3.1.3</spring.boot.version>
<spring.boot.version>3.1.4</spring.boot.version>
</properties>


Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/camunda/automator/AutomatorAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.camunda.automator.bpmnengine.BpmnEngine;
import org.camunda.automator.bpmnengine.BpmnEngineFactory;
import org.camunda.automator.configuration.ConfigurationBpmEngine;
import org.camunda.automator.configuration.BpmnEngineList;
import org.camunda.automator.definition.Scenario;
import org.camunda.automator.engine.AutomatorException;
import org.camunda.automator.engine.RunParameters;
Expand Down Expand Up @@ -72,7 +72,7 @@ public Scenario loadFromInputStream(InputStream scenarioInputStream, String orig
* @param engineConfiguration different engine configuration
* @return the engine, null if no engine exist, an exception if the connection is not possible
*/
public BpmnEngine getBpmnEngineFromScenario(Scenario scenario, ConfigurationBpmEngine engineConfiguration)
public BpmnEngine getBpmnEngineFromScenario(Scenario scenario, BpmnEngineList engineConfiguration)
throws AutomatorException {
try {

Expand Down Expand Up @@ -124,9 +124,8 @@ public RunResult executeScenario(BpmnEngine bpmnEngine, RunParameters runParamet
/* Deploy a process in the server */
/* ******************************************************************** */

public BpmnEngine getBpmnEngine(ConfigurationBpmEngine engineConfiguration,
ConfigurationBpmEngine.BpmnServerDefinition serverDefinition)
throws AutomatorException {
public BpmnEngine getBpmnEngine(BpmnEngineList engineConfiguration,
BpmnEngineList.BpmnServerDefinition serverDefinition) throws AutomatorException {

return BpmnEngineFactory.getInstance().getEngineFromConfiguration(engineConfiguration, serverDefinition);
}
Expand Down
95 changes: 52 additions & 43 deletions src/main/java/org/camunda/automator/AutomatorCLI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.camunda.automator;

import org.camunda.automator.bpmnengine.BpmnEngine;
import org.camunda.automator.configuration.ConfigurationBpmEngine;
import org.camunda.automator.configuration.BpmnEngineList;
import org.camunda.automator.definition.Scenario;
import org.camunda.automator.engine.AutomatorException;
import org.camunda.automator.engine.RunParameters;
import org.camunda.automator.engine.RunResult;
import org.slf4j.Logger;
Expand All @@ -27,7 +28,7 @@ public class AutomatorCLI implements CommandLineRunner {
@Autowired
AutomatorAPI automatorAPI;
@Autowired
ConfigurationBpmEngine engineConfiguration;
BpmnEngineList engineConfiguration;

public static void main(String[] args) {
isRunningCLI = true;
Expand Down Expand Up @@ -59,37 +60,37 @@ public static void main(String[] args) {
/* ******************************************************************** */

private static void printUsage() {
System.out.println("Usage: <option> <action> <parameter>");
System.out.println(" -s, --server <serverName>");
System.out.println(" Which server to use in the configuration");
System.out.println(" -e, --engine ConnectionUrlString");
System.out.println(" CAMUNDA7;<URL>");
System.out.println(" CAMUNDA8;CLOUD;<region>;<clusterId>;<clientIs>;<clientSecret>");
System.out.println(" CAMUNDA8;LOCAL;<gateway>;<plaintext>");
System.out.println(" -l, --level <DEBUG|COMPLETE|MONITORING|MAIN|NOTHING>");
System.out.println(" Define the level of log (MONITORING is the default)");
System.out.println(" -n, --numberofexecution <number>");
System.out.println(" override the number of execution for the scenario");
System.out.println(" -d, --deploy <TRUE|FALSE>");
System.out.println(" Allow deployment of process is defined in the scenario (default is TRUE)");

System.out.println(" -x, --execute");
System.out.println(" execute the scenario");
System.out.println(" -v, --verification");
System.out.println(" verify the scenario");
System.out.println(" -f, --fullreport");
System.out.println(" Full report");

System.out.println();
System.out.println("ACTIONS: ");
System.out.println(" run <scenarioFile>");
System.out.println(" execute one scenario");
System.out.println(" recursive <folder>");
System.out.println(" all *.json in the folder and sub-folder are monitored and executed");
logOutLn("Usage: <option> <action> <parameter>");
logOutLn(" -s, --server <serverName>");
logOutLn(" Which server to use in the configuration");
logOutLn(" -e, --engine ConnectionUrlString");
logOutLn(" CAMUNDA7;<URL>");
logOutLn(" CAMUNDA8;CLOUD;<region>;<clusterId>;<clientIs>;<clientSecret>");
logOutLn(" CAMUNDA8;LOCAL;<gateway>;<plaintext>");
logOutLn(" -l, --level <DEBUG|COMPLETE|MONITORING|MAIN|NOTHING>");
logOutLn(" Define the level of log (MONITORING is the default)");
logOutLn(" -n, --numberofexecution <number>");
logOutLn(" override the number of execution for the scenario");
logOutLn(" -d, --deploy <TRUE|FALSE>");
logOutLn(" Allow deployment of process is defined in the scenario (default is TRUE)");

logOutLn(" -x, --execute");
logOutLn(" execute the scenario");
logOutLn(" -v, --verification");
logOutLn(" verify the scenario");
logOutLn(" -f, --fullreport");
logOutLn(" Full report");

logOutLn("");
logOutLn("ACTIONS: ");
logOutLn(" run <scenarioFile>");
logOutLn(" execute one scenario");
logOutLn(" recursive <folder>");
logOutLn(" all *.json in the folder and sub-folder are monitored and executed");

}

private static ConfigurationBpmEngine decodeConfiguration(String propertiesFileName) throws Exception {
private static BpmnEngineList decodeConfiguration(String propertiesFileName) throws Exception {
throw new Exception("Not yet implemented");
}

Expand Down Expand Up @@ -123,27 +124,27 @@ public void run(String[] args) {
return;
} else if ("-s".equals(args[i]) || "--server".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : -c <ServerName>");
throw new AutomatorException("Bad usage : -c <ServerName>");
serverName = args[i + 1];
i++;
} else if ("-e".equals(args[i]) || "--engine".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : -e <ConnectionUrlString>");
throw new AutomatorException("Bad usage : -e <ConnectionUrlString>");
engineConfiguration = decodeConfiguration(args[i + 1]);
i++;
} else if ("-l".equals(args[i]) || "--level".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : -l <DEBUG|MONITORING|MAIN|NOTHING>");
throw new AutomatorException("Bad usage : -l <DEBUG|MONITORING|MAIN|NOTHING>");
runParameters.setLogLevel(RunParameters.LOGLEVEL.valueOf(args[i + 1]));
i++;
} else if ("-n".equals(args[i]) || "--numberofexecution".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : n <numberofexecution>");
throw new AutomatorException("Bad usage : n <numberofexecution>");
overrideNumberOfExecution = Integer.parseInt(args[i + 1]);
i++;
} else if ("-d".equals(args[i]) || "--deploy".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : -d TRUE|FALSE");
throw new AutomatorException("Bad usage : -d TRUE|FALSE");
runParameters.setDeploymentProcess("TRUE".equalsIgnoreCase(args[i + 1]));
i++;
} else if ("-x".equals(args[i]) || "--execute".equals(args[i])) {
Expand All @@ -154,46 +155,46 @@ public void run(String[] args) {
runParameters.setFullDetailsSynthesis(true);
} else if ("run".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : run <scenarioFile>");
throw new AutomatorException("Bad usage : run <scenarioFile>");
action = ACTION.RUN;
scenarioFile = new File(args[i + 1]);
i++;
} else if ("recursive".equals(args[i])) {
if (args.length < i + 1)
throw new Exception("Bad usage : recursive <folder>");
throw new AutomatorException("Bad usage : recursive <folder>");
action = ACTION.RECURSIVE;
folderRecursive = new File(args[i + 1]);
i++;
} else {
printUsage();
throw new Exception("Bad usage : unknown parameters [" + args[i] + "]");
throw new AutomatorException("Bad usage : unknown parameters [" + args[i] + "]");
}
i++;
}

if (action == null) {
throw new Exception("Bad usage : missing action (" + ACTION.RUN + ")");
throw new AutomatorException("Bad usage : missing action (" + ACTION.RUN + ")");
}
if (!runParameters.isExecution() && !runParameters.isVerification()) {
runParameters.setExecution(true); // default
}

// get the correct server configuration
ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = null;
BpmnEngineList.BpmnServerDefinition serverDefinition = null;
if (serverName != null) {
serverDefinition = engineConfiguration.getByServerName(serverName);

if (serverDefinition == null) {
throw new Exception("Check configuration: name[" + serverName
throw new AutomatorException("Check configuration: name[" + serverName
+ "] does not exist in the list of servers in application.yaml file");
}
} else {
List<ConfigurationBpmEngine.BpmnServerDefinition> listServers = engineConfiguration.getListServers();
List<BpmnEngineList.BpmnServerDefinition> listServers = engineConfiguration.getListServers();

serverDefinition = listServers.isEmpty() ? null : listServers.get(0);
}
if (serverDefinition == null) {
throw new Exception(
throw new AutomatorException(
"Check configuration: configuration to access a Camunda server is missing in application.yaml");
}

Expand Down Expand Up @@ -230,4 +231,12 @@ public void run(String[] args) {
}

public enum ACTION {RUN, RECURSIVE, VERIFY, RUNVERIFY, RECURSIVVERIFY}

/**
* To reduce the number of warning
* @param message message to log out
*/
private static void logOutLn(String message) {
System.out.println(message);
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/camunda/automator/bpmnengine/BpmnEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.camunda.operate.search.DateFilter;
import io.camunda.zeebe.client.api.worker.JobWorker;
import org.camunda.automator.configuration.ConfigurationBpmEngine;
import org.camunda.automator.configuration.BpmnEngineList;
import org.camunda.automator.definition.ScenarioDeployment;
import org.camunda.automator.definition.ScenarioStep;
import org.camunda.automator.engine.AutomatorException;
Expand Down Expand Up @@ -30,7 +30,7 @@ public interface BpmnEngine {
/**
* Engine is ready. If not, a connection() method must be call
*
* @return
* @return true if the engine is ready
*/
boolean isReady();

Expand Down Expand Up @@ -83,7 +83,7 @@ List<String> searchUserTasksByProcessInstance(String processInstanceId, String u
* @param userTaskId userTaskId
* @param maxResult maxResult returned
* @return list of TaskId
* @throws AutomatorException
* @throws AutomatorException in case of error
*/
List<String> searchUserTasks(String userTaskId, int maxResult) throws AutomatorException;

Expand All @@ -108,7 +108,7 @@ List<String> searchUserTasksByProcessInstance(String processInstanceId, String u
* @param lockTime lock time for the job
* @param jobHandler C7: must implement ExternalTaskHandler. C8: must implement JobHandler
* @param backoffSupplier backOffStrategy
* @return
* @return list of Service Task
*/
RegisteredTask registerServiceTask(String workerId,
String topic,
Expand Down Expand Up @@ -207,7 +207,7 @@ long countNumberOfProcessInstancesEnded(String processId, DateFilter startDate,
/* */
/* ******************************************************************** */

ConfigurationBpmEngine.CamundaEngine getTypeCamundaEngine();
BpmnEngineList.CamundaEngine getTypeCamundaEngine();


/* ******************************************************************** */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
package org.camunda.automator.bpmnengine;

import org.camunda.automator.configuration.ConfigurationBpmEngine;
import org.camunda.automator.configuration.BpmnEngineList;

/**
* Generate BpmnEngineConfiguration for different servers
*/
public class BpmnEngineConfigurationInstance {

public static ConfigurationBpmEngine getZeebeSaas(String zeebeGatewayAddress, String zeebeSecurityPlainText) {
ConfigurationBpmEngine bpmEngineConfiguration = new ConfigurationBpmEngine();
public static BpmnEngineList getZeebeSaas(String zeebeGatewayAddress, String zeebeSecurityPlainText) {
BpmnEngineList bpmEngineConfiguration = new BpmnEngineList();

ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = new ConfigurationBpmEngine.BpmnServerDefinition();
serverDefinition.serverType = ConfigurationBpmEngine.CamundaEngine.CAMUNDA_8;
BpmnEngineList.BpmnServerDefinition serverDefinition = new BpmnEngineList.BpmnServerDefinition();
serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_8;
serverDefinition.zeebeGatewayAddress = zeebeGatewayAddress;
serverDefinition.zeebeSecurityPlainText = zeebeSecurityPlainText;

bpmEngineConfiguration.addExplicitServer(serverDefinition);
return bpmEngineConfiguration;
}

public static ConfigurationBpmEngine getCamunda7(String serverUrl) {
ConfigurationBpmEngine bpmEngineConfiguration = new ConfigurationBpmEngine();
public static BpmnEngineList getCamunda7(String serverUrl) {
BpmnEngineList bpmEngineConfiguration = new BpmnEngineList();

ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = new ConfigurationBpmEngine.BpmnServerDefinition();
serverDefinition.serverType = ConfigurationBpmEngine.CamundaEngine.CAMUNDA_7;
BpmnEngineList.BpmnServerDefinition serverDefinition = new BpmnEngineList.BpmnServerDefinition();
serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_7;
serverDefinition.camunda7ServerUrl = serverUrl;

bpmEngineConfiguration.addExplicitServer(serverDefinition);

return bpmEngineConfiguration;
}

public static ConfigurationBpmEngine getCamunda8(String zeebeGatewayAddress) {
ConfigurationBpmEngine bpmEngineConfiguration = new ConfigurationBpmEngine();
public static BpmnEngineList getCamunda8(String zeebeGatewayAddress) {
BpmnEngineList bpmEngineConfiguration = new BpmnEngineList();

ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = new ConfigurationBpmEngine.BpmnServerDefinition();
serverDefinition.serverType = ConfigurationBpmEngine.CamundaEngine.CAMUNDA_8;
BpmnEngineList.BpmnServerDefinition serverDefinition = new BpmnEngineList.BpmnServerDefinition();
serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_8;
serverDefinition.zeebeGatewayAddress = zeebeGatewayAddress;

bpmEngineConfiguration.addExplicitServer(serverDefinition);

return bpmEngineConfiguration;
}

public static ConfigurationBpmEngine getCamundaSaas8(String zeebeCloudRegister,
String zeebeCloudRegion,
String zeebeCloudClusterId,
String zeebeCloudClientId) {
ConfigurationBpmEngine bpmEngineConfiguration = new ConfigurationBpmEngine();
public static BpmnEngineList getCamundaSaas8(String zeebeCloudRegister,
String zeebeCloudRegion,
String zeebeCloudClusterId,
String zeebeCloudClientId) {
BpmnEngineList bpmEngineConfiguration = new BpmnEngineList();

ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = new ConfigurationBpmEngine.BpmnServerDefinition();
serverDefinition.serverType = ConfigurationBpmEngine.CamundaEngine.CAMUNDA_8;
BpmnEngineList.BpmnServerDefinition serverDefinition = new BpmnEngineList.BpmnServerDefinition();
serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_8;
serverDefinition.zeebeCloudRegister = zeebeCloudRegister;
serverDefinition.zeebeCloudRegion = zeebeCloudRegion;
serverDefinition.zeebeCloudClusterId = zeebeCloudClusterId;
Expand All @@ -61,11 +61,11 @@ public static ConfigurationBpmEngine getCamundaSaas8(String zeebeCloudRegister,
return bpmEngineConfiguration;
}

public static ConfigurationBpmEngine getDummy() {
ConfigurationBpmEngine bpmEngineConfiguration = new ConfigurationBpmEngine();
public static BpmnEngineList getDummy() {
BpmnEngineList bpmEngineConfiguration = new BpmnEngineList();

ConfigurationBpmEngine.BpmnServerDefinition serverDefinition = new ConfigurationBpmEngine.BpmnServerDefinition();
serverDefinition.serverType = ConfigurationBpmEngine.CamundaEngine.DUMMY;
BpmnEngineList.BpmnServerDefinition serverDefinition = new BpmnEngineList.BpmnServerDefinition();
serverDefinition.serverType = BpmnEngineList.CamundaEngine.DUMMY;

bpmEngineConfiguration.addExplicitServer(serverDefinition);

Expand Down
Loading

0 comments on commit 096a531

Please sign in to comment.