aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElena Kuleshov <evn@att.com>2019-08-08 17:35:56 -0400
committerElena Kuleshov <evn@att.com>2019-08-08 17:38:56 -0400
commit6610812cea9c569b762b568648ded37d72603de1 (patch)
treeef74dc3f89fe195f3da1073315b25cc51f495478
parentf9c6fa669c914aaee3dee13f747c077ed6c17302 (diff)
Terminate workflow on Abort handling code
Throw WorkflowException to terminate the custom workflow when Abort handling code is returned, add constant names for variables Issue-ID: SO-2171 Signed-off-by: Kuleshov, Elena <evn@att.com> Change-Id: I29a5ede2503f42ff28486318e0239eb6beeb4271
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java53
1 files changed, 38 insertions, 15 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java
index a436f7b5c2..9340609ffc 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java
@@ -59,9 +59,18 @@ public class ExecuteActivity implements JavaDelegate {
private static final String VNF_ID = "vnfId";
private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
private static final String WORKFLOW_SYNC_ACK_SENT = "workflowSyncAckSent";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String EXECUTE_BUILDING_BLOCK = "ExecuteBuildingBlock";
+ private static final String RETRY_COUNT = "retryCount";
+ private static final String A_LA_CARTE = "aLaCarte";
+ private static final String SUPPRESS_ROLLBACK = "suppressRollback";
+ private static final String WORKFLOW_EXCEPTION = "WorkflowException";
+ private static final String HANDLING_CODE = "handlingCode";
+ private static final String ABORT_HANDLING_CODE = "Abort";
private static final String SERVICE_TASK_IMPLEMENTATION_ATTRIBUTE = "implementation";
private static final String ACTIVITY_PREFIX = "activity:";
+ private static final String EXECUTE_ACTIVITY_ERROR_MESSAGE = "ExecuteActivityErrorMessage";
private ObjectMapper mapper = new ObjectMapper();
@@ -75,7 +84,8 @@ public class ExecuteActivity implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
final String requestId = (String) execution.getVariable(G_REQUEST_ID);
-
+ WorkflowException workflowException = null;
+ String handlingCode = null;
try {
Boolean workflowSyncAckSent = (Boolean) execution.getVariable(WORKFLOW_SYNC_ACK_SENT);
if (workflowSyncAckSent == null || workflowSyncAckSent == false) {
@@ -95,31 +105,44 @@ public class ExecuteActivity implements JavaDelegate {
ExecuteBuildingBlock executeBuildingBlock = buildExecuteBuildingBlock(execution, requestId, buildingBlock);
Map<String, Object> variables = new HashMap<>();
- variables.put("buildingBlock", executeBuildingBlock);
- variables.put(G_REQUEST_ID, requestId);
- variables.put("retryCount", 1);
- variables.put("aLaCarte", true);
- variables.put("suppressRollback", true);
- execution.getVariables().forEach((key, value) -> {
- if (value instanceof Serializable) {
- variables.put(key, (Serializable) value);
- }
- });
+ if (execution.getVariables() != null) {
+ execution.getVariables().forEach((key, value) -> {
+ if (value instanceof Serializable) {
+ variables.put(key, (Serializable) value);
+ }
+ });
+ }
+
+ variables.put(BUILDING_BLOCK, executeBuildingBlock);
+ variables.put(G_REQUEST_ID, requestId);
+ variables.put(RETRY_COUNT, 1);
+ variables.put(A_LA_CARTE, true);
+ variables.put(SUPPRESS_ROLLBACK, true);
ProcessInstanceWithVariables buildingBlockResult =
- runtimeService.createProcessInstanceByKey("ExecuteBuildingBlock").setVariables(variables)
+ runtimeService.createProcessInstanceByKey(EXECUTE_BUILDING_BLOCK).setVariables(variables)
.executeWithVariablesInReturn();
VariableMap variableMap = buildingBlockResult.getVariables();
- WorkflowException workflowException = (WorkflowException) variableMap.get("WorklfowException");
+ workflowException = (WorkflowException) variableMap.get(WORKFLOW_EXCEPTION);
if (workflowException != null) {
logger.error("Workflow exception is: {}", workflowException.getErrorMessage());
}
- execution.setVariable("WorkflowException", workflowException);
+
+ handlingCode = (String) variableMap.get(HANDLING_CODE);
+ logger.debug("Handling code: " + handlingCode);
+
+ execution.setVariable(WORKFLOW_EXCEPTION, workflowException);
} catch (Exception e) {
buildAndThrowException(execution, e.getMessage());
}
+
+ if (workflowException != null && handlingCode != null && handlingCode.equals(ABORT_HANDLING_CODE)) {
+ logger.debug("Aborting execution of the custom workflow");
+ buildAndThrowException(execution, workflowException.getErrorMessage());
+ }
+
}
protected BuildingBlock buildBuildingBlock(String activityName) {
@@ -161,7 +184,7 @@ public class ExecuteActivity implements JavaDelegate {
protected void buildAndThrowException(DelegateExecution execution, String msg) {
logger.error(msg);
- execution.setVariable("ExecuteActuvityErrorMessage", msg);
+ execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg);
exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
}
}