X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-tasks%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fworkflow%2Ftasks%2FWorkflowActionBBTasks.java;h=d9125e41044337fc0eabf4e1968818a67e95d859;hb=9e416c4a70bcfa7be773169b3dbbb2edfe92d3fc;hp=9e4b01eea5db1c6bce136aace878be1eae96fdf5;hpb=aefc4022be976a64b2dca05316c05a91a102bbfd;p=so.git diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 9e4b01eea5..d9125e4104 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -50,12 +51,15 @@ public class WorkflowActionBBTasks { private static final String G_REQUEST_ID = "mso-request-id"; private static final String G_ALACARTE = "aLaCarte"; private static final String G_ACTION = "requestAction"; + private static final String RETRY_COUNT = "retryCount"; private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class); @Autowired private RequestsDbClient requestDbclient; @Autowired private WorkflowAction workflowAction; + @Autowired + private WorkflowActionBBFailure workflowActionBBFailure; public void selectBB(DelegateExecution execution) { List flowsToExecute = (List) execution @@ -108,7 +112,7 @@ public class WorkflowActionBBTasks { String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(), nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs); Long percentProgress = this.getPercentProgress(completedBBs, totalBBs); - request.setStatusMessage(statusMessage); + request.setFlowStatus(statusMessage); request.setProgress(percentProgress); request.setLastModifiedBy("CamundaBPMN"); return request; @@ -200,34 +204,29 @@ public class WorkflowActionBBTasks { execution.setVariable("mso-service-instance-id", resourceId); } - public void setupFalloutHandler(DelegateExecution execution) { - final String requestId = (String) execution.getVariable(G_REQUEST_ID); - final String action = (String) execution.getVariable(G_ACTION); - final String resourceId = (String) execution.getVariable("resourceId"); - String exceptionMsg = ""; - if (execution.getVariable("WorkflowActionErrorMessage") != null) { - exceptionMsg = (String) execution.getVariable("WorkflowActionErrorMessage"); - } else { - exceptionMsg = "Error in WorkflowAction"; - } - execution.setVariable("mso-service-instance-id", resourceId); - execution.setVariable("mso-request-id", requestId); - String falloutRequest = "" - + requestId + "" + action - + "VID" - + exceptionMsg - + "7000"; - execution.setVariable("falloutRequest", falloutRequest); - } - public void checkRetryStatus(DelegateExecution execution) { - if (execution.getVariable("handlingCode") == "Retry") { - int currSequence = (int) execution.getVariable("gCurrentSequence"); - currSequence--; - execution.setVariable("gCurrentSequence", currSequence); - int currRetryCount = (int) execution.getVariable("retryCount"); - currRetryCount++; - execution.setVariable("retryCount", currRetryCount); + String handlingCode = (String) execution.getVariable("handlingCode"); + String requestId = (String) execution.getVariable(G_REQUEST_ID); + String retryDuration = (String) execution.getVariable("RetryDuration"); + int retryCount = (int) execution.getVariable(RETRY_COUNT); + if (handlingCode.equals("Retry")){ + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); + try{ + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + request.setRetryStatusMessage("Retry " + retryCount+1 + "/5 will be started in " + retryDuration); + requestDbclient.updateInfraActiveRequests(request); + } catch(Exception ex){ + logger.warn("Failed to update Request Db Infra Active Requests with Retry Status",ex); + } + if(retryCount<5){ + int currSequence = (int) execution.getVariable("gCurrentSequence"); + execution.setVariable("gCurrentSequence", currSequence-1); + execution.setVariable(RETRY_COUNT, retryCount + 1); + }else{ + workflowAction.buildAndThrowException(execution, "Exceeded maximum retries. Ending flow with status Abort"); + } + }else{ + execution.setVariable(RETRY_COUNT, 0); } } @@ -236,69 +235,54 @@ public class WorkflowActionBBTasks { * layer will rollback the flow its currently working on. */ public void rollbackExecutionPath(DelegateExecution execution) { - List flowsToExecute = (List) execution - .getVariable("flowsToExecute"); - List rollbackFlows = new ArrayList(); - int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE) - 1; - for (int i = flowsToExecute.size() - 1; i >= 0; i--) { - if (i >= currentSequence) { - flowsToExecute.remove(i); - } else { - ExecuteBuildingBlock ebb = flowsToExecute.get(i); - BuildingBlock bb = flowsToExecute.get(i).getBuildingBlock(); - String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName(); - if (flowName.contains("Assign")) { - flowName = "Unassign" + flowName.substring(7, flowName.length()); - } else if (flowName.contains("Create")) { - flowName = "Delete" + flowName.substring(6, flowName.length()); - } else if (flowName.contains("Activate")) { - flowName = "Deactivate" + flowName.substring(8, flowName.length()); + if(!(boolean)execution.getVariable("isRollback")){ + List flowsToExecute = (List) execution + .getVariable("flowsToExecute"); + List rollbackFlows = new ArrayList(); + int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE); + int listSize = flowsToExecute.size(); + for (int i = listSize - 1; i >= 0; i--) { + if (i > currentSequence - 1) { + flowsToExecute.remove(i); + } else { + String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName(); + if (flowName.contains("Assign")) { + flowName = "Unassign" + flowName.substring(6, flowName.length()); + } else if (flowName.contains("Create")) { + flowName = "Delete" + flowName.substring(6, flowName.length()); + } else if (flowName.contains("Activate")) { + flowName = "Deactivate" + flowName.substring(8, flowName.length()); + }else{ + continue; + } + flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName); + rollbackFlows.add(flowsToExecute.get(i)); } - flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName); - rollbackFlows.add(flowsToExecute.get(i)); - } - } - if (rollbackFlows.isEmpty()) - execution.setVariable("isRollbackNeeded", false); - else - execution.setVariable("isRollbackNeeded", true); - - execution.setVariable("flowsToExecute", rollbackFlows); - execution.setVariable("handlingCode", "PreformingRollback"); - } - - public void abortCallErrorHandling(DelegateExecution execution) { - String msg = "Flow has failed. Rainy day handler has decided to abort the process."; - logger.error(msg); - throw new BpmnError(msg); - } - - public void updateRequestStatusToFailed(DelegateExecution execution) { - try { - String requestId = (String) execution.getVariable(G_REQUEST_ID); - InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); - String errorMsg = null; - try { - WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); - request.setStatusMessage(exception.getErrorMessage()); - } catch (Exception ex) { - //log error and attempt to extact WorkflowExceptionMessage - logger.error("Failed to extract workflow exception from execution.",ex); } - if (errorMsg == null){ - try { - errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); - request.setStatusMessage(errorMsg); - } catch (Exception ex) { - logger.error("Failed to extract workflow exception message from WorkflowException",ex); - request.setStatusMessage("Unexpected Error in BPMN"); + + int flowSize = rollbackFlows.size(); + String handlingCode = (String) execution.getVariable("handlingCode"); + if(handlingCode.equals("RollbackToAssigned")){ + for(int i = 0; i