add work step option for failures 06/113506/4
authorKuleshov, Elena <evn@att.com>
Sat, 3 Oct 2020 15:17:14 +0000 (11:17 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Wed, 7 Oct 2020 18:15:26 +0000 (14:15 -0400)
Introduce new Policy and workStep to handle failures
Reapply changes using correct camunda modeler version.

Issue-ID: SO-3287
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I7e0a36305322c255f6678529f0a27c023fd983ef

bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayTest.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java
bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java

index 4206596..3b84b15 100644 (file)
@@ -213,7 +213,8 @@ public class ExecuteBuildingBlockRainyDay {
                     String targetState = "";
                     if ("RollbackToAssigned".equalsIgnoreCase(handlingCode)) {
                         targetState = Status.ROLLED_BACK_TO_ASSIGNED.toString();
-                    } else if ("RollbackToCreated".equalsIgnoreCase(handlingCode)) {
+                    } else if ("RollbackToCreated".equalsIgnoreCase(handlingCode)
+                            || "RollbackToCreatedNoConfiguration".equalsIgnoreCase(handlingCode)) {
                         targetState = Status.ROLLED_BACK_TO_CREATED.toString();
                     } else {
                         targetState = Status.ROLLED_BACK.toString();
index 843cca0..43db279 100644 (file)
@@ -232,6 +232,20 @@ public class ExceptionBuilder {
         throw new BpmnError("MSOWorkflowException");
     }
 
+    public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, String errorMessage,
+            ONAPComponentsList extSystemErrorSource, String workStep) {
+        String processKey = getProcessKey(execution);
+        logger.info("Building a WorkflowException for Subflow");
+
+        WorkflowException exception =
+                new WorkflowException(processKey, errorCode, errorMessage, workStep, extSystemErrorSource);
+        execution.setVariable("WorkflowException", exception);
+        execution.setVariable("WorkflowExceptionErrorMessage", errorMessage);
+        logger.info("Outgoing WorkflowException is {}", exception);
+        logger.info("Throwing MSOWorkflowException");
+        throw new BpmnError("MSOWorkflowException");
+    }
+
     public WorkflowException buildWorkflowException(DelegateExecution execution, int errorCode, String errorMessage,
             ONAPComponentsList extSystemErrorSource) {
         String processKey = getProcessKey(execution);
index ee47b51..b34d9dc 100644 (file)
@@ -259,6 +259,35 @@ public class ExecuteBuildingBlockRainyDayTest extends BaseTest {
         assertEquals(Status.ROLLED_BACK_TO_CREATED.toString(), delegateExecution.getVariable("rollbackTargetState"));
     }
 
+    @Test
+    public void queryRainyDayTableRollbackToCreatedNoConfiguration() throws Exception {
+        customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
+        serviceInstance.getModelInfoServiceInstance().setServiceType("st1");
+        vnf.setVnfType("vnft1");
+        BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
+        ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock);
+        delegateExecution.setVariable("buildingBlock", executeBuildingBlock);
+        delegateExecution.setVariable("aLaCarte", true);
+        delegateExecution.setVariable("suppressRollback", false);
+        delegateExecution.setVariable("WorkflowExceptionCode", "7000");
+        RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus();
+        rainyDayHandlerStatus.setErrorCode("7000");
+        rainyDayHandlerStatus.setFlowName("AddFabricConfigurationBB");
+        rainyDayHandlerStatus.setServiceType("st1");
+        rainyDayHandlerStatus.setVnfType("vnft1");
+        rainyDayHandlerStatus.setPolicy("RollbackToCreatedNoConfiguration");
+        rainyDayHandlerStatus.setWorkStep(ASTERISK);
+        rainyDayHandlerStatus.setSecondaryPolicy("Abort");
+
+        doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AddFabricConfigurationBB",
+                "st1", "vnft1", "7000", "*", "errorMessage", "*");
+
+        executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true);
+
+        assertEquals("RollbackToCreatedNoConfiguration", delegateExecution.getVariable("handlingCode"));
+        assertEquals(Status.ROLLED_BACK_TO_CREATED.toString(), delegateExecution.getVariable("rollbackTargetState"));
+    }
+
 
     @Test
     public void suppressRollbackTest() throws Exception {
index 5baafbb..b7e4dd9 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.so.client.exception;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
@@ -39,6 +40,7 @@ import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.core.WorkflowException;
 import org.onap.logging.filter.base.ONAPComponents;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -95,4 +97,17 @@ public class ExceptionBuilderUnitTest {
         thrown.expect(BpmnError.class);
         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), ONAPComponents.SDNC);
     }
+
+    @Test
+    public void buildAndThrowWorkflowExceptionWithWorkStepTest() {
+        doReturn("Process key").when(exceptionBuilder).getProcessKey(execution);
+
+        try {
+            exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), ONAPComponents.SDNC,
+                    "WORKSTEP");
+        } catch (BpmnError e) {
+        }
+        WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
+        assertEquals("WORKSTEP", workflowException.getWorkStep());
+    }
 }
index f2e0ce2..5fd9701 100644 (file)
@@ -95,7 +95,7 @@
       </bpmn:serviceTask>
     </bpmn:subProcess>
     <bpmn:sequenceFlow id="SequenceFlow_0v588sm" name="Rollback = true" sourceRef="ExclusiveGateway_Finished" targetRef="Task_RollbackExecutionPath">
-      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${execution.getVariable("handlingCode")=="Rollback"||execution.getVariable("handlingCode")=="RollbackToAssigned"||execution.getVariable("handlingCode")=="RollbackToCreated"}</bpmn:conditionExpression>
+      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${execution.getVariable("handlingCode")=="Rollback"||execution.getVariable("handlingCode")=="RollbackToAssigned"||execution.getVariable("handlingCode")=="RollbackToCreated"||execution.getVariable("handlingCode")=="RollbackToCreatedNoConfiguration"}</bpmn:conditionExpression>
     </bpmn:sequenceFlow>
     <bpmn:sequenceFlow id="SequenceFlow_1atzsgn" sourceRef="Task_RollbackExecutionPath" targetRef="Task_SelectBB">
       <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${execution.getVariable("isRollbackNeeded")==true}</bpmn:conditionExpression>
index 5425b2a..f0898ac 100644 (file)
@@ -75,6 +75,7 @@ public class WorkflowActionBBTasks {
     private static final String COMPLETED = "completed";
     private static final String HANDLINGCODE = "handlingCode";
     private static final String ROLLBACKTOCREATED = "RollbackToCreated";
+    private static final String ROLLBACKTOCREATEDNOCONFIGURATION = "RollbackToCreatedNoConfiguration";
     private static final String REPLACEINSTANCE = "replaceInstance";
     private static final String VFMODULE = "VfModule";
     protected String maxRetries = "mso.rainyDay.maxRetries";
@@ -334,14 +335,19 @@ public class WorkflowActionBBTasks {
 
             String handlingCode = (String) execution.getVariable(HANDLINGCODE);
             List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows);
-            if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)) {
+            if ("RollbackToAssigned".equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode)
+                    || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) {
                 for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) {
                     if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Unassign")
                             && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")) {
                         rollbackFlowsFiltered.remove(rollbackFlow);
                     } else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("Delete")
-                            && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")
-                            && ROLLBACKTOCREATED.equals(handlingCode)) {
+                            && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration")
+                                    && (ROLLBACKTOCREATED.equals(handlingCode)
+                                            || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))
+                                    || (rollbackFlow.getBuildingBlock().getBpmnFlowName()
+                                            .contains("FabricConfiguration")
+                                            && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) {
                         rollbackFlowsFiltered.remove(rollbackFlow);
                     }
                 }
index a7ee89f..3290bb3 100644 (file)
@@ -435,6 +435,40 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
 
     }
 
+    @Test
+    public void rollbackExecutionRollbackToCreatedNoConfigurationWithFabricTest() {
+        execution.setVariable("isRollback", false);
+        execution.setVariable("handlingCode", "RollbackToCreatedNoConfiguration");
+        execution.setVariable("requestAction", EMPTY_STRING);
+        execution.setVariable("resourceName", EMPTY_STRING);
+        List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+
+        BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
+        ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
+        flowsToExecute.add(ebb1);
+
+        BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
+        ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
+        flowsToExecute.add(ebb2);
+
+        BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+        ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
+        flowsToExecute.add(ebb3);
+
+        BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
+        ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
+        flowsToExecute.add(ebb4);
+
+        execution.setVariable("flowsToExecute", flowsToExecute);
+        execution.setVariable("gCurrentSequence", 4);
+
+        workflowActionBBTasks.rollbackExecutionPath(execution);
+        List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
+        assertEquals(0, execution.getVariable("gCurrentSequence"));
+        assertEquals(1, ebbs.size());
+        assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
+    }
+
     @Test
     public void rollbackExecutionRollbackToCreatedTest() {
         execution.setVariable("isRollback", false);