Skip to content

Commit

Permalink
Updated cmdline input variables to be just one JSON variable (#24)
Browse files Browse the repository at this point in the history
* Updated cmdline input variables to be just one JSON variable

* added a TODO

* Fixed some bugs and added input field verification

* No longer needed

Co-authored-by: James Wood <[email protected]>
  • Loading branch information
jamesfwood and James Wood authored Mar 2, 2021
1 parent aea0963 commit 746c0e1
Show file tree
Hide file tree
Showing 11 changed files with 2,982 additions and 819 deletions.
1 change: 0 additions & 1 deletion create_server_dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ cp ${INSTALL_DIR}/refresh_cws_token.sh ${CWS}
cp ${INSTALL_DIR}/deploy_proc_def.sh ${CWS}
cp ${INSTALL_DIR}/launch_ls.sh ${CWS}
cp ${INSTALL_DIR}/launch_es.sh ${CWS}
cp -R ${INSTALL_DIR}/external_tasks ${CWS}

print 'Copying Modeller scripts and libraries...'
cp -R ${INSTALL_DIR}/modeler ${CWS}
Expand Down
6 changes: 5 additions & 1 deletion cws-engine-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-spring</artifactId>
</dependency>


<dependency>
<groupId>org.camunda.spin</groupId>
<artifactId>camunda-spin-dataformat-all</artifactId>
</dependency>
<!-- Spring MVC framework -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jpl.cws.engine;

public class CmdLineInputFields {

public String command = null;
public String workingDir = null;
public String successfulValues = null;
public String exitCodeEvents = null;
public boolean throwOnFailures;
public boolean throwOnTruncatedVariable;
public long timeout = 0; // in seconds
public int retries = 0;
public int retryDelay = 0; // in milliseconds
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import javax.jms.Session;

import com.google.gson.Gson;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.HtmlEmail;
import org.camunda.bpm.application.PostDeploy;
import org.camunda.bpm.application.PreUndeploy;
import org.camunda.bpm.application.ProcessApplication;
import org.camunda.bpm.application.impl.ServletProcessApplication;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
Expand All @@ -26,10 +26,11 @@
import org.camunda.bpm.engine.impl.context.CoreExecutionContext;
import org.camunda.bpm.engine.impl.core.instance.CoreExecution;
import org.camunda.bpm.engine.impl.el.ExpressionManager;
import org.camunda.bpm.engine.spring.application.SpringProcessApplication;
import org.camunda.bpm.engine.spring.application.SpringServletProcessApplication;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaField;
import org.camunda.spin.plugin.variable.SpinValues;
import org.camunda.spin.plugin.variable.value.JsonValue;
import org.slf4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -364,7 +365,9 @@ public void notify(final DelegateExecution execution) throws Exception {
final String activityId = execution.getCurrentActivityId();

String fieldName = null;


CmdLineInputFields cmdFields = new CmdLineInputFields();

try {
log.debug("Service Task with External Task's ExecutionId = " + execution.getId());
log.debug("Service task current ActivityId = " + execution.getCurrentActivityId());
Expand All @@ -376,64 +379,63 @@ public void notify(final DelegateExecution execution) throws Exception {
ExpressionManager expressionManager = Context
.getProcessEngineConfiguration()
.getExpressionManager();

fieldName = "cmdLine";
String command = getFieldValue(fieldName, fields, expressionManager, execution);
cmdFields.command = getFieldValue(fieldName, fields, expressionManager, execution);

fieldName = "workingDir";
String workingDir = getFieldValue(fieldName, fields, expressionManager, execution);
cmdFields.workingDir = getFieldValue(fieldName, fields, expressionManager, execution);

if (workingDir == null) {
workingDir = System.getProperty("user.home");
if (cmdFields.workingDir == null) {
cmdFields.workingDir = System.getProperty("user.home");
}

fieldName = "successExitValues";
String successExitValues = getFieldValue(fieldName, fields, expressionManager, execution);

cmdFields.successfulValues = getFieldValue(fieldName, fields, expressionManager, execution).replaceAll("\\s+", "");

// Verify field format
for (String successCode : cmdFields.successfulValues.split(",")) {
Integer.parseInt(successCode);
}

fieldName = "exitCodeEvents";
String exitCodeEvents = getFieldValue(fieldName, fields, expressionManager, execution).replaceAll("\\s+", "");

fieldName = "throwOnFailures";
String throwOnFailures = getFieldValue(fieldName, fields, expressionManager, execution);

fieldName = "throwOnTruncatedVariable";
String throwOnTruncatedVariable = getFieldValue(fieldName, fields, expressionManager, execution);

fieldName = "timeout";
String timeout = getFieldValue(fieldName, fields, expressionManager, execution);

fieldName = "retries";
String retries = getFieldValue(fieldName, fields, expressionManager, execution);

fieldName = "retryDelay";
String retryDelay = getFieldValue(fieldName, fields, expressionManager, execution);
cmdFields.exitCodeEvents = getFieldValue(fieldName, fields, expressionManager, execution).replaceAll("\\s+", "");

// Verify field format
String[] exitCodeMapArray = cmdFields.exitCodeEvents.split(",");
for (String exitCodeMap : exitCodeMapArray) {

String[] keyVal = exitCodeMap.split("=");
if (keyVal.length != 2) {
throw new Exception("Bad format: " + exitCodeMap);
}
Integer.parseInt(keyVal[0]);
}

execution.setVariable(activityId + "_cwsCommand", command);
execution.setVariable(activityId + "_cwsWorkingDir", workingDir);
execution.setVariable(activityId + "_cwsSuccessExitValues", successExitValues);
execution.setVariable(activityId + "_cwsExitCodeEvents", exitCodeEvents);

fieldName = "throwOnFailures";
execution.setVariable(activityId + "_cwsThrowOnFailures", Boolean.parseBoolean(throwOnFailures));
cmdFields.throwOnFailures = Boolean.parseBoolean(getFieldValue(fieldName, fields, expressionManager, execution));

fieldName = "throwOnTruncatedVariable";
execution.setVariable(activityId + "_cwsThrowOnTruncatedVariable", Boolean.parseBoolean(throwOnTruncatedVariable));
cmdFields.throwOnTruncatedVariable = Boolean.parseBoolean(getFieldValue(fieldName, fields, expressionManager, execution));

fieldName = "timeout";
execution.setVariable(activityId + "_cwsTimeout", Long.parseLong(timeout));
cmdFields.timeout = Long.parseLong(getFieldValue(fieldName, fields, expressionManager, execution));

fieldName = "retries";
execution.setVariable(activityId + "_cwsRetries", Integer.parseInt(retries));
cmdFields.retries = Integer.parseInt(getFieldValue(fieldName, fields, expressionManager, execution));

fieldName = "retryDelay";
execution.setVariable(activityId + "_cwsRetryDelay", Integer.parseInt(retryDelay));
cmdFields.retryDelay = Integer.parseInt(getFieldValue(fieldName, fields, expressionManager, execution));

JsonValue jsonValue = SpinValues.jsonValue(new Gson().toJson(cmdFields)).create();
execution.setVariable(activityId + "_input", jsonValue);
}
catch (Throwable t) {
log.error("Error parsing cmdLine fields", t);

String msg = "Error parsing field '" + fieldName + "': " + t.getMessage();
execution.setVariable(activityId + "_cwsError", msg);

execution.setVariable(activityId + "_errorMsg", msg);
}
finally {

Expand Down
Loading

0 comments on commit 746c0e1

Please sign in to comment.