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")) {
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();
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.startsWith("Assign")) {
flowName = flowName.replaceFirst("Assign", "Unassign");
} else if (flowName.startsWith("Create")) {
flowName = flowName.replaceFirst("Create", "Delete");
} else if (flowName.startsWith("Activate")) {
flowName = flowName.replaceFirst("Activate", "Deactivate");
} else if (flowName.startsWith("Add")) {
flowName = flowName.replaceFirst("Add", "Delete");
} else if (flowName.startsWith("VNF")) {
if (flowName.startsWith("VNFSet")) {
flowName = flowName.replaceFirst("VNFSet", "VNFUnset");
} else if (flowName.startsWith("VNFLock")) {
flowName = flowName.replaceFirst("VNFLock", "VNFUnlock");
} else if (flowName.startsWith("VNFStop")) {
flowName = flowName.replaceFirst("VNFStop", "VNFStart");
} else if (flowName.startsWith("VNFQuiesce")) {
flowName = flowName.replaceFirst("VNFQuiesce", "VNFResume");
} else {
continue;
}
} else {
continue;
}
flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName);
rollbackFlows.add(flowsToExecute.get(i));
}
}
String handlingCode = (String) execution.getVariable(HANDLINGCODE);
List<ExecuteBuildingBlock> rollbackFlowsFiltered = new ArrayList<>(rollbackFlows);
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) || ROLLBACKTOCREATEDNOCONFIGURATION.equals(handlingCode))) || (rollbackFlow.getBuildingBlock().getBpmnFlowName().contains("FabricConfiguration") && 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);
}
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);
} else {
workflowAction.buildAndThrowException(execution, "Rollback has already been called. Cannot rollback a request that is currently in the rollback state.");
}
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class ProcessVnfc method doExecute.
@Override
public void doExecute(TestContext context) {
final Logger logger = LoggerFactory.getLogger(ProcessVnfc.class);
try {
logger.debug("running ProcessVnfc scenario");
logger.debug("requestAction: {}", context.getVariable("requestAction"));
logger.debug("serviceAction: {}", context.getVariable("serviceAction"));
logger.debug("cloudOwner: {}", context.getVariable("cloudOwner"));
logger.debug("cloundRegion: {}", context.getVariable("cloudRegion"));
logger.debug("tenant: {}", context.getVariable("tenant"));
logger.debug("vfModuleId: {}", context.getVariable("vfModuleId"));
logger.debug("vnfId: {}", context.getVariable("vnfId"));
AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
if (context.getVariable("requestAction").equals("CreateVfModuleInstance") && context.getVariable("serviceAction").equals("assign")) {
AAIResourceUri vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(VNF_SERVER_1_NAME));
Vnfc vnfc = new Vnfc();
vnfc.setVnfcName(VNF_SERVER_1_NAME);
vnfc.setNfcNamingCode("oamfw");
vnfc.setNfcFunction("EPC-OAM-FIREWALL");
vnfc.setProvStatus("PREPROV");
vnfc.setOrchestrationStatus("Active");
vnfc.setInMaint(false);
vnfc.setIsClosedLoopDisabled(false);
vnfc.setModelInvariantId("b214d2e9-73d9-49d7-b7c4-a9ae7f06e244");
vnfc.setModelVersionId("9e314c37-2258-4572-a399-c0dd7d5f1aec");
vnfc.setModelCustomizationId("2bd95cd4-d7ff-4af0-985d-2adea0339921");
AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(context.getVariable("vnfId")).vfModule(context.getVariable("vfModuleId")));
if (aaiResourceClient.exists(vnfcURI)) {
Optional<VfModule> vfModule = aaiResourceClient.get(vfModuleURI).asBean(VfModule.class);
if (vfModule.isPresent() && vfModule.get().getVfModuleName().contains("macro")) {
String vnfcName = VNF_SERVER_1_NAME + vfModule.get().getVfModuleName().substring(vfModule.get().getVfModuleName().length() - 1);
vnfc.setVnfcName(vnfcName);
vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfcName));
} else {
logger.debug("cleaning up VNFC");
aaiResourceClient.delete(vnfcURI);
}
}
logger.debug("creating new VNFC");
aaiResourceClient.create(vnfcURI, vnfc);
logger.debug("creating VNFC edge to vf module");
aaiResourceClient.connect(vfModuleURI, vnfcURI);
}
} catch (Exception e) {
logger.debug("Exception in ProcessVnfc.doExecute", e);
}
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListALaCarteVfModuleKeepVolumeGroupReplaceRetainAssignmentsTest.
@Test
public void selectExecutionListALaCarteVfModuleKeepVolumeGroupReplaceRetainAssignmentsTest() throws Exception {
String gAction = "replaceInstanceRetainAssignments";
String resource = "VfModule";
String bpmnRequest = readBpmnRequestFromFile(VF_MODULE_CREATE_WITH_FABRIC_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", "ChangeModelVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ChangeModelVnfBB", "ChangeModelServiceInstanceBB");
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListALaCarteVfModuleNoFabricDeleteTest.
@Test
public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception {
String gAction = "deleteInstance";
String resource = "VfModule";
String bpmnRequest = readBpmnRequestFromFile(VF_MODULE_CREATE_WITH_FABRIC_JSON);
initExecution(gAction, bpmnRequest, true);
execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "UnassignVfModuleBB", "DeleteFabricConfigurationBB");
northBoundRequest.setOrchestrationFlowList(orchFlows);
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
vnf.setVnfId("vnf0");
vnf.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIGenericVnf(anyObject())).thenReturn(vnf);
org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
vfModule.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIVfModule(anyObject(), anyObject())).thenReturn(vfModule);
List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(anyObject(), anyObject(), anyObject(), anyObject());
SPY_workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "DeactivateVfModuleBB", "DeleteVfModuleBB", "UnassignVfModuleBB");
}
use of org.onap.aai.domain.yang.VfModule in project so by onap.
the class WorkflowActionTest method selectExecutionListVnfMacroRecreateTest.
@Test
public void selectExecutionListVnfMacroRecreateTest() throws Exception {
String gAction = "recreateInstance";
String resource = "Vnf";
String bpmnRequest = readBpmnRequestFromFile(MACRO_VNF_MACRO_REPLACE_JSON);
initExecution(gAction, bpmnRequest, false);
execution.setVariable("requestUri", "v7/serviceInstances/123/vnfs/1234/recreate");
execution.setVariable("serviceInstanceId", "123");
execution.setVariable("vnfId", "1234");
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
List<OrchestrationFlow> orchFlows = createFlowList("AAICheckVnfInMaintBB", "AAISetVnfInMaintBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVnfBB", "CreateVfModuleBB", "ActivateVfModuleBB", "AssignFabricConfigurationBB", "ActivateFabricConfigurationBB", "ActivateVnfBB", "SDNOVnfHealthCheckBB", "AAIUnsetVnfInMaintBB");
northBoundRequest.setOrchestrationFlowList(orchFlows);
ServiceInstance serviceInstanceAAI = new ServiceInstance();
serviceInstanceAAI.setServiceInstanceId("123");
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("1234");
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
vfModule.setVfModuleId("vfModule1");
vnf.getVfModules().add(vfModule);
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
vfModule2.setVfModuleId("vfModule2");
vnf.getVfModules().add(vfModule2);
serviceInstanceMSO.getVnfs().add(vnf);
org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule();
aaiVfModule.setIsBaseVfModule(false);
doReturn(aaiVfModule).when(bbSetupUtils).getAAIVfModule(any(), any());
doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(bbSetupUtils).getAAIGenericVnf(vnf.getVnfId());
doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "cloud-owner")).thenReturn(northBoundRequest);
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AAICheckVnfInMaintBB", "AAISetVnfInMaintBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVnfBB", "CreateVfModuleBB", "ActivateVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ActivateVnfBB", "SDNOVnfHealthCheckBB", "AAIUnsetVnfInMaintBB");
}
Aggregations