use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionBBTasks method rollbackExecutionPath.
/**
* Rollback will only handle Create/Activate/Assign Macro flows. Execute layer will rollback the flow its currently
* working on.
*/
public void rollbackExecutionPath(DelegateExecution execution) {
final String action = (String) execution.getVariable(BBConstants.G_ACTION);
final String resourceName = (String) execution.getVariable("resourceName");
if ((boolean) execution.getVariable("isRollback")) {
workflowAction.buildAndThrowException(execution, "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
}
List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
List<ExecuteBuildingBlock> flowsToExecuteChangeBBs = flowsToExecute.stream().filter(buildingBlock -> buildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")).collect(Collectors.toList());
List<ExecuteBuildingBlock> rollbackFlows = new ArrayList<>();
int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
int listSize = flowsToExecute.size();
List<BuildingBlockRollback> bbRollbackList = catalogDbClient.getBuildingBlockRollbackEntries();
for (int i = listSize - 1; i >= 0; i--) {
if (i > currentSequence - 1) {
flowsToExecute.remove(i);
} else {
// filter bbRollbackList for bbrollback, and check if action exists, then filter by action
BuildingBlock bb = flowsToExecute.get(i).getBuildingBlock();
String flowName = bb.getBpmnFlowName();
String scope = Objects.toString(bb.getBpmnScope(), "");
String bbAction = Objects.toString(bb.getBpmnAction(), "");
ExecuteBuildingBlock currentBB = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
List<BuildingBlockRollback> filteredList = bbRollbackList.stream().filter(k -> k.getBuildingBlockName().equals((flowName))).collect(Collectors.toList());
Optional<BuildingBlockRollback> matchedBBRollback = "".equals(bbAction) ? filteredList.stream().findFirst() : filteredList.stream().filter(k -> bbAction.equals(k.getAction())).findFirst();
if (matchedBBRollback.isPresent()) {
final BuildingBlockRollback buildingBlockRollbackItem = matchedBBRollback.get();
String rollbackFlow = buildingBlockRollbackItem.getRollbackBuildingBlockName();
flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(rollbackFlow);
// if we have an action, search the filtered list for the bbrollback that matches the given action.
if (null != buildingBlockRollbackItem.getRollbackAction()) {
logger.info("Setting rollback_action {} for BB: {} action: {}", buildingBlockRollbackItem.getRollbackAction(), buildingBlockRollbackItem.getBuildingBlockName(), buildingBlockRollbackItem.getAction());
flowsToExecute.get(i).getBuildingBlock().setBpmnAction(buildingBlockRollbackItem.getRollbackAction());
}
rollbackFlows.add(flowsToExecute.get(i));
}
}
}
String handlingCode = (String) execution.getVariable(HANDLINGCODE);
List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows);
if (ROLLBACK_TO_ASSIGNED.equals(handlingCode) || ROLLBACKTOCREATED.equals(handlingCode) || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)) {
for (ExecuteBuildingBlock rollbackFlow : rollbackFlows) {
if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(UNASSIGN) && !rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION)) {
rollbackFlowsFiltered.remove(rollbackFlow);
} else if (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(DELETE) && ((!rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION) && (ROLLBACKTOCREATED.equals(handlingCode) || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode))) || (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains(FABRIC_CONFIGURATION) && ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode)))) {
rollbackFlowsFiltered.remove(rollbackFlow);
}
}
}
List<ExecuteBuildingBlock> rollbackFlowsFilteredNonChangeBBs = new ArrayList<>();
if (action.equals(REPLACEINSTANCE) && resourceName.equals(VFMODULE)) {
for (ExecuteBuildingBlock executeBuildingBlock : rollbackFlowsFiltered) {
if (!executeBuildingBlock.getBuildingBlock().getBpmnFlowName().startsWith("Change")) {
rollbackFlowsFilteredNonChangeBBs.add(executeBuildingBlock);
}
}
rollbackFlowsFiltered.clear();
rollbackFlowsFiltered.addAll(flowsToExecuteChangeBBs);
rollbackFlowsFiltered.addAll(rollbackFlowsFilteredNonChangeBBs);
}
logger.info("List of BuildingBlocks to execute for rollback");
rollbackFlowsFiltered.forEach(item -> {
logger.info(item.getBuildingBlock().getBpmnFlowName());
});
workflowActionBBFailure.updateRequestErrorStatusMessage(execution);
execution.setVariable("isRollbackNeeded", !rollbackFlows.isEmpty());
execution.setVariable("flowsToExecute", rollbackFlowsFiltered);
execution.setVariable(HANDLINGCODE, "PreformingRollback");
execution.setVariable("isRollback", true);
execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, 0);
execution.setVariable(RETRY_COUNT, 0);
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListServiceMacroUnassignTest.
@Test
public void selectExecutionListServiceMacroUnassignTest() throws Exception {
String gAction = "unassignInstance";
String resource = "Service";
String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON);
initExecution(gAction, bpmnRequest, false);
execution.setVariable("requestUri", "v6/serviceInstances/123");
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
List<OrchestrationFlow> orchFlows = createFlowList("UnassignVfModuleBB", "UnassignVolumeGroupBB", "UnassignVnfBB", "UnassignNetworkBB", "UnassignServiceInstanceBB");
northBoundRequest.setOrchestrationFlowList(orchFlows);
ServiceInstance serviceInstanceAAI = new ServiceInstance();
serviceInstanceAAI.setServiceInstanceId("aaisi123");
org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf();
vnf.setVnfId("vnfId123");
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = buildVfModule();
vnf.getVfModules().add(vfModule);
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = buildVfModule();
vnf.getVfModules().add(vfModule2);
org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = new org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup();
volumeGroup.setVolumeGroupId("vg123");
vnf.getVolumeGroups().add(volumeGroup);
serviceInstanceMSO.getVnfs().add(vnf);
VfModule aaiVfModule = new VfModule();
aaiVfModule.setIsBaseVfModule(false);
doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any());
doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
doReturn(Mockito.mock(GenericVnf.class)).when(bbSetupUtils).getAAIGenericVnf(any());
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "UnassignVfModuleBB", "UnassignVfModuleBB", "UnassignVolumeGroupBB", "UnassignVnfBB", "UnassignServiceInstanceBB");
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method getConfigBuildingBlocksNullConfigurationTest.
@Test
public void getConfigBuildingBlocksNullConfigurationTest() throws Exception {
String gAction = "deleteInstance";
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
WorkflowType resourceType = WorkflowType.VFMODULE;
execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
execution.setVariable("requestAction", gAction);
String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json")));
execution.setVariable("bpmnRequest", bpmnRequest);
execution.setVariable("vnfId", "1234");
execution.setVariable("vfModuleId", "vfModuleId1234");
execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
RequestDetails requestDetails = sIRequest.getRequestDetails();
String requestAction = "deleteInstance";
String requestId = "9c944122-d161-4280-8594-48c06a9d96d5";
boolean aLaCarte = true;
String apiVersion = "7";
String vnfType = "vnfType";
String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0";
String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e";
Resource resourceKey = new Resource(resourceType, key, aLaCarte, null);
WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution);
List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "UnassignVfModuleBB", "DeleteFabricConfigurationBB");
ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion).setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution);
org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
vnf.setVnfId("vnf0");
vnf.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf);
org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
vfModule.setModelCustomizationId("modelCustomizationId");
/* this is a test case where configuration for vnfc is null */
org.onap.aai.domain.yang.Configuration config1 = null;
org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration();
config2.setConfigurationId("config2");
List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc();
vnfc1.setVnfcName("zauk53avetd02svm001");
org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc();
vnfc2.setVnfcName("zauk53avetd02tvm001");
vnfcs.add(vnfc1);
vnfcs.add(vnfc2);
when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule);
doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), eq(org.onap.aai.domain.yang.Vnfc.class), eq(Types.VNFC));
doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1), eq(org.onap.aai.domain.yang.Configuration.class), eq(Types.CONFIGURATION));
doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2), eq(org.onap.aai.domain.yang.Configuration.class), eq(Types.CONFIGURATION));
List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj);
assertFalse(results.isEmpty());
assertEquals(1, results.size());
assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId());
assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName());
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListServiceMacroDeleteTest.
@Test
public void selectExecutionListServiceMacroDeleteTest() throws Exception {
String gAction = "deleteInstance";
String resource = "Service";
String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON);
initExecution(gAction, bpmnRequest, false);
execution.setVariable("requestUri", "v6/serviceInstances/123");
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVolumeGroupBB", "DeleteVolumeGroupBB", "DeactivateVnfBB", "DeactivatePnfBB", "DeactivateNetworkBB", "DeleteNetworkBB", "DeleteNetworkCollectionBB", "DeactivateServiceInstanceBB", "UnassignVfModuleBB", "UnassignVolumeGroupBB", "UnassignVnfBB", "UnassignNetworkBB", "UnassignServiceInstanceBB");
northBoundRequest.setOrchestrationFlowList(orchFlows);
ServiceInstance serviceInstanceAAI = new ServiceInstance();
serviceInstanceAAI.setServiceInstanceId("aaisi123");
org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf();
org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf();
vnf.setVnfId("vnfId123");
pnf.setPnfId("pnfId123");
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = buildVfModule();
vnf.getVfModules().add(vfModule);
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = buildVfModule();
vnf.getVfModules().add(vfModule2);
org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = new org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup();
volumeGroup.setVolumeGroupId("vg123");
vnf.getVolumeGroups().add(volumeGroup);
serviceInstanceMSO.getVnfs().add(vnf);
serviceInstanceMSO.getPnfs().add(pnf);
VfModule aaiVfModule = new VfModule();
aaiVfModule.setIsBaseVfModule(false);
doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any());
doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
doReturn(Mockito.mock(GenericVnf.class)).when(bbSetupUtils).getAAIGenericVnf(any());
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVolumeGroupBB", "DeleteVolumeGroupBB", "DeactivateVnfBB", "DeactivatePnfBB", "DeactivateServiceInstanceBB", "UnassignVfModuleBB", "UnassignVfModuleBB", "UnassignVolumeGroupBB", "UnassignVnfBB", "UnassignServiceInstanceBB");
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListALaCarteVfModuleRebuildVolumeGroupReplaceRetainAssignmentsTest.
@Test
public void selectExecutionListALaCarteVfModuleRebuildVolumeGroupReplaceRetainAssignmentsTest() throws Exception {
String gAction = "replaceInstanceRetainAssignments";
String resource = "VfModule";
String bpmnRequest = readBpmnRequestFromFile(VF_MODULE_REPLACE_REBUILD_VOLUME_GROUPS_JSON);
initExecution(gAction, bpmnRequest, true);
execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules/1234");
execution.setVariable("vnfId", "b80b16a5-f80d-4ffa-91c8-bd47c7438a3d");
execution.setVariable("vfModuleId", "1234");
VolumeGroup volumeGroup = new VolumeGroup();
volumeGroup.setVolumeGroupId("volumeGroupId");
doReturn(Optional.of(volumeGroup)).when(bbSetupUtils).getRelatedVolumeGroupFromVfModule("b80b16a5-f80d-4ffa-91c8-bd47c7438a3d", "1234");
VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment());
org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule();
vfModule.setVolumeHeatTemplate(new HeatTemplate());
vfModuleCustomization.setVfModule(vfModule);
when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("9a6d01fd-19a7-490a-9800-460830a12e0b")).thenReturn(vfModuleCustomization);
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
northBoundRequest.setOrchestrationFlowList(replaceRetainAssignmentsVfModuleOrchFlows);
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "DeactivateVfModuleBB", "DeleteVfModuleATTBB", "DeactivateVolumeGroupBB", "DeleteVolumeGroupBB", "UnassignVolumeGroupBB", "AssignVolumeGroupBB", "ChangeModelVfModuleBB", "CreateVolumeGroupBB", "ActivateVolumeGroupBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ChangeModelVnfBB", "ChangeModelServiceInstanceBB");
}
Aggregations