package org.onap.so.bpmn.infrastructure.workflow.tasks;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Arrays;
+import java.util.Collections;
+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;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
-import org.onap.so.client.namingservice.NamingRequestObject;
+import org.onap.so.db.catalog.beans.BuildingBlockRollback;
import org.onap.so.db.catalog.beans.ConfigurationResource;
import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.RelatedInstance;
+import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestDetails;
import org.springframework.core.env.Environment;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isA;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
public class WorkflowActionBBTasksTest extends BaseTaskTest {
@Mock
private DelegateExecution mockExecution;
+ @Before
+ public void initCatalogDBRollbackTable() {
+ when(catalogDbClient.getBuildingBlockRollbackEntries()).thenReturn(getRollbackBuildingBlockList());
+ }
+
@Before
public void before() throws Exception {
execution = new DelegateExecutionFake();
workflowActionBBTasks.selectBB(execution);
boolean success = (boolean) execution.getVariable("completed");
int currentSequence = (int) execution.getVariable("gCurrentSequence");
- assertTrue(success);
+ assertFalse(success);
assertEquals(1, currentSequence);
}
}
@Test
- public void postProcessingExecuteBBActivateVfModuleTest() throws CloneNotSupportedException {
+ public void rollbackExecutionRollbackControllerExecutionBBTest() {
+ execution.setVariable("isRollback", false);
+ execution.setVariable("handlingCode", "Rollback");
+ execution.setVariable("requestAction", EMPTY_STRING);
+ execution.setVariable("resourceName", EMPTY_STRING);
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
+ ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
+ flowsToExecute.add(ebb1);
+
+ BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
+ ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
+ flowsToExecute.add(ebb2);
+ BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignVnfBB");
+ ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
+ flowsToExecute.add(ebb3);
+
+ BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
+ ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
+ flowsToExecute.add(ebb4);
+
+ BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ControllerExecutionBB");
+ buildingBlock5.setBpmnScope("vnf");
+ buildingBlock5.setBpmnAction("config-assign");
+ ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
+ flowsToExecute.add(ebb5);
+
+ BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
+ ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
+ flowsToExecute.add(ebb6);
+
+ execution.setVariable("flowsToExecute", flowsToExecute);
+ execution.setVariable("gCurrentSequence", 5);
+
+ workflowActionBBTasks.rollbackExecutionPath(execution);
+ List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
+ BuildingBlock bb = ebbs.get(0).getBuildingBlock();
+ assertEquals("ControllerExecutionBB", bb.getBpmnFlowName());
+ assertEquals("vnf", bb.getBpmnScope());
+ assertEquals("config-unassign", bb.getBpmnAction());
+ assertEquals(0, execution.getVariable("gCurrentSequence"));
+ assertEquals(5, ebbs.size());
+ }
+
+ @Test
+ public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("1");
+ workflowResourceIds.setVnfId("1");
+
+ BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+ ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
+ ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
+ ebbActivateVfModule.setResourceId("1");
+
+ ServiceInstance service = new ServiceInstance();
+ service.setServiceInstanceName("name");
+ service.setModelVersionId("1");
+ doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("name");
+ vnf.setModelCustomizationId("1");
+ doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name");
+ vfModule.setModelCustomizationId("1");
+ doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
+ vnfc.setModelInvariantId("1");
+ vnfc.setVnfcName("name");
+ vnfc.setModelCustomizationId("2");
+ vnfcs.add(vnfc);
+ doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
+
+ CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
+ ConfigurationResource configuration = new ConfigurationResource();
+ configuration.setToscaNodeType("FabricConfiguration");
+ configuration.setModelUUID("1");
+ vfModuleCustomization.setConfigurationResource(configuration);
+
+ doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
+
+ prepareDelegateExecution();
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ flowsToExecute.add(ebbActivateVfModule);
+
+ execution.setVariable("requestAction", "createInstance");
+ execution.setVariable("completed", true);
+
+ ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
+ ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
+ ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
+ workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
+ verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
+ bbCaptor.capture(), listCaptor.capture());
+ assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
+ assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
+ assertEquals("2",
+ ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
+ .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
+ .getCvnfcCustomizationUUID());
+ assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
+ .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
+ }
+
+ @Test
+ public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
+ throws CloneNotSupportedException {
+ RequestDetails reqDetails = new RequestDetails();
+ RelatedInstanceList[] list = new RelatedInstanceList[2];
+ RelatedInstanceList vnfList = new RelatedInstanceList();
+ RelatedInstanceList serviceList = new RelatedInstanceList();
+ list[0] = vnfList;
+ list[1] = serviceList;
+ RelatedInstance vnfInstance = new RelatedInstance();
+ RelatedInstance serviceInstance = new RelatedInstance();
+ ModelInfo vnfModelInfo = new ModelInfo();
+ vnfModelInfo.setModelType(ModelType.vnf);
+ vnfModelInfo.setModelCustomizationId("1");
+ ModelInfo serviceModelInfo = new ModelInfo();
+ serviceModelInfo.setModelType(ModelType.service);
+ serviceModelInfo.setModelVersionId("1");
+ vnfInstance.setModelInfo(vnfModelInfo);
+ serviceInstance.setModelInfo(serviceModelInfo);
+ reqDetails.setRelatedInstanceList(list);
+ vnfList.setRelatedInstance(vnfInstance);
+ serviceList.setRelatedInstance(serviceInstance);
+ ModelInfo vfModuleInfo = new ModelInfo();
+ vfModuleInfo.setModelCustomizationId("1");
+ reqDetails.setModelInfo(vfModuleInfo);
BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
ebbActivateVfModule.setResourceId("1");
ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
- ebbActivateVfModule.setConfigurationResourceKeys(configurationResourceKeys);
+ ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
+ ebbActivateVfModule.setRequestDetails(reqDetails);
ServiceInstance service = new ServiceInstance();
service.setServiceInstanceName("name");
ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
- workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbAddFabric, flowsToExecute);
+
+ execution.setVariable("requestAction", "replaceInstance");
+ execution.setVariable("completed", true);
+ workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
bbCaptor.capture(), listCaptor.capture());
assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
- assertEquals(null,
+ assertEquals("2",
((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
- .getVariable("flowsToExecute")).get(0)).getConfigurationResourceKeys()
+ .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
.getCvnfcCustomizationUUID());
+ }
+ @Test
+ public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
+ throws CloneNotSupportedException {
- execution.setVariable("requestAction", "replaceInstance");
- flowsToExecute = new ArrayList<>();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("1");
+ workflowResourceIds.setVnfId("1");
+
+ BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+ ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
+ ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
+ ebbActivateVfModule.setResourceId("1");
+
+ ServiceInstance service = new ServiceInstance();
+ service.setServiceInstanceName("name");
+ service.setModelVersionId("1");
+ doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("name");
+ vnf.setModelCustomizationId("1");
+ doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name");
+ vfModule.setModelCustomizationId("1");
+ doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
+ vnfc.setModelInvariantId("1");
+ vnfc.setVnfcName("name");
+ vnfc.setModelCustomizationId("2");
+ vnfcs.add(vnfc);
+ doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
+
+ CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
+ ConfigurationResource configuration = new ConfigurationResource();
+ configuration.setToscaNodeType("FabricConfiguration");
+ configuration.setModelUUID("1");
+ vfModuleCustomization.setConfigurationResource(configuration);
+
+ doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
+
+ prepareDelegateExecution();
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
flowsToExecute.add(ebbActivateVfModule);
+
+ ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
+ ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
+ ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
+
+ execution.setVariable("requestAction", "replaceInstance");
+ execution.setVariable("completed", true);
+
workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
- verify(workflowActionBBTasks, times(2)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
+ verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
bbCaptor.capture(), listCaptor.capture());
- assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
- assertEquals(1, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
- assertEquals("2",
- ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
- .getVariable("flowsToExecute")).get(0)).getConfigurationResourceKeys()
- .getCvnfcCustomizationUUID());
+ assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
}
+
+
@Test
public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
execution.setVariable("homing", false);
execution.setVariable("calledHoming", false);
}
+
+ private List<BuildingBlockRollback> getRollbackBuildingBlockList() {
+ List<BuildingBlockRollback> rollbackBBList = Collections.unmodifiableList(Arrays.asList(
+ new BuildingBlockRollback(1, "ActivateNetworkBB", null, "DeactivateNetworkBB", null),
+ new BuildingBlockRollback(2, "ActivatePnfBB", null, "DeactivatePnfBB", null),
+ new BuildingBlockRollback(3, "ActivateServiceInstanceBB", null, "DeactivateServiceInstanceBB", null),
+ new BuildingBlockRollback(4, "ActivateVfModuleBB", null, "DeactivateVfModuleBB", null),
+ new BuildingBlockRollback(5, "ActivateVnfBB", null, "DeactivateVnfBB", null),
+ new BuildingBlockRollback(6, "ActivateVolumeGroupBB", null, "DeactivateVolumeGroupBB", null),
+ new BuildingBlockRollback(7, "AssignNetworkBB", null, "UnassignNetworkBB", null),
+ new BuildingBlockRollback(8, "AssignServiceInstanceBB", null, "UnassignServiceInstanceBB", null),
+ new BuildingBlockRollback(9, "AssignVfModuleBB", null, "UnassignVfModuleBB", null),
+ new BuildingBlockRollback(10, "AssignVnfBB", null, "UnassignVnfBB", null),
+ new BuildingBlockRollback(11, "AssignVolumeGroupBB", null, "UnassignVolumeGroupBB", null),
+ new BuildingBlockRollback(12, "ControllerExecutionBB", "config-assign", "ControllerExecutionBB",
+ "config-unassign"),
+ new BuildingBlockRollback(13, "ControllerExecutionBB", "config-deploy", "ControllerExecutionBB",
+ "config-undeploy"),
+ new BuildingBlockRollback(14, "ControllerExecutionBB", "service-config-deploy", "ControllerExecutionBB",
+ "service-config-undeploy"),
+ new BuildingBlockRollback(15, "CreateNetworkBB", null, "DeleteNetworkBB", null),
+ new BuildingBlockRollback(16, "CreateNetworkCollectionBB", null, "DeleteNetworkCollectionBB", null),
+ new BuildingBlockRollback(17, "CreateVfModuleBB", null, "DeleteVfModuleBB", null),
+ new BuildingBlockRollback(18, "CreateVolumeGroupBB", null, "DeleteVolumeGroupBB", null),
+ new BuildingBlockRollback(19, "VNFSetInMaintFlagActivity", null, "VNFUnsetInMaintFlagActivity", null),
+ new BuildingBlockRollback(20, "VNFSetClosedLoopDisabledFlagActivity", null,
+ "VNFUnsetClosedLoopDisabledFlagActivity", null),
+ new BuildingBlockRollback(21, "VNFLockActivity", null, "VNFUnlockActivity", null),
+ new BuildingBlockRollback(22, "VNFStopActivity", null, "VNFStartActivity", null),
+ new BuildingBlockRollback(23, "VNFQuiesceTrafficActivity", null, "VNFResumeTrafficActivity", null),
+ new BuildingBlockRollback(24, "EtsiVnfInstantiateBB", null, "EtsiVnfDeleteBB", null),
+ // AddFabricConfigurationBB this does not seem to be present as a bpmn in Guilin
+ new BuildingBlockRollback(25, "AddFabricConfigurationBB", null, "DeleteFabricConfigurationBB", null)));
+ return rollbackBBList;
+ }
+
}