Search in sources :

Example 96 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.

the class ExecuteBuildingBlockBuilder method buildExecuteBuildingBlockList.

protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows, List<Resource> originalResourceList, String requestId, String apiVersion, String resourceId, String requestAction, String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean replaceVnf) {
    List<Resource> resourceList = getOnlyRootResourceList(originalResourceList);
    List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
    boolean ascendingOrder = requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGN_INSTANCE) || requestAction.equals(ACTIVATE_INSTANCE);
    ExecutionPlan plan = ExecutionPlan.build(resourceList, ascendingOrder);
    logger.info("Orchestration Flows");
    for (OrchestrationFlow orchFlow : orchFlows) {
        String flowDetails = new ToStringBuilder(this).append("id", orchFlow.getId()).append("action", orchFlow.getAction()).append("sequenceNumber", orchFlow.getSequenceNumber()).append("flowName", orchFlow.getFlowName()).append("flowVersion", orchFlow.getFlowVersion()).append("bpmnAction", orchFlow.getBpmnAction()).append("bpmnScope", orchFlow.getBpmnScope()).toString();
        logger.info("Flow: " + flowDetails);
        buildExecuteBuildingBlockListPlan(orchFlow, plan, requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, replaceVnf);
    }
    plan.flushBlocksFromCache(flowsToExecute);
    return flowsToExecute;
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArrayList(java.util.ArrayList) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow)

Example 97 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.

the class WorkflowActionBBFailure method updateRequestStatusToFailed.

public void updateRequestStatusToFailed(DelegateExecution execution) {
    try {
        String requestId = (String) execution.getVariable("mso-request-id");
        InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
        String rollbackErrorMsg = "";
        String errorMsg = "";
        Boolean rollbackCompletedSuccessfully = (Boolean) execution.getVariable("isRollbackComplete");
        Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback");
        ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
        if (rollbackCompletedSuccessfully == null)
            rollbackCompletedSuccessfully = false;
        if (isRollbackFailure == null)
            isRollbackFailure = false;
        if (rollbackCompletedSuccessfully) {
            rollbackErrorMsg = "Rollback has been completed successfully.";
            request.setRollbackStatusMessage(rollbackErrorMsg);
            execution.setVariable("RollbackErrorMessage", rollbackErrorMsg);
            String rollbackTargetState = (String) execution.getVariable(ROLLBACK_TARGET_STATE);
            request.setRequestStatus(rollbackTargetState);
        } else if (isRollbackFailure) {
            if (ebb != null && ebb.getBuildingBlock() != null && ebb.getBuildingBlock().getBpmnFlowName() != null) {
                String flowName = ebb.getBuildingBlock().getBpmnFlowName();
                if (DEACTIVATE_FABRIC_CONFIGURATION_FLOW.equalsIgnoreCase(flowName) || UNASSIGN_FABRIC_CONFIGURATION_FLOW.equalsIgnoreCase(flowName) || DELETE_FABRIC_CONFIGURATION_FLOW.equalsIgnoreCase(flowName)) {
                    String statusMessage = String.format("%s Warning: The vf-module is active but configuration was not removed completely for one or more VMs.", request.getStatusMessage());
                    request.setStatusMessage(statusMessage);
                }
            }
            Optional<String> rollbackErrorMsgOp = retrieveErrorMessage(execution);
            if (rollbackErrorMsgOp.isPresent()) {
                rollbackErrorMsg = rollbackErrorMsgOp.get();
            } else {
                rollbackErrorMsg = "Failed to determine rollback error message.";
            }
            request.setRollbackStatusMessage(rollbackErrorMsg);
            execution.setVariable("RollbackErrorMessage", rollbackErrorMsg);
            request.setRequestStatus(Status.FAILED.toString());
        } else {
            Optional<String> errorMsgOp = retrieveErrorMessage(execution);
            if (errorMsgOp.isPresent()) {
                errorMsg = errorMsgOp.get();
            } else {
                errorMsg = "Failed to determine error message";
            }
            request.setStatusMessage(errorMsg);
            execution.setVariable("ErrorMessage", errorMsg);
            String handlingCode = (String) execution.getVariable("handlingCode");
            if ("Abort".equalsIgnoreCase(handlingCode)) {
                request.setRequestStatus(Status.ABORTED.toString());
            } else {
                request.setRequestStatus(Status.FAILED.toString());
            }
        }
        if (ebb != null && ebb.getBuildingBlock() != null) {
            String flowStatus = "";
            if (rollbackCompletedSuccessfully) {
                flowStatus = "All Rollback flows have completed successfully";
            } else {
                flowStatus = ebb.getBuildingBlock().getBpmnFlowName() + " has failed.";
            }
            request.setFlowStatus(flowStatus);
            execution.setVariable("flowStatus", flowStatus);
        }
        request.setProgress(Long.valueOf(100));
        request.setLastModifiedBy("CamundaBPMN");
        request.setEndTime(new Timestamp(System.currentTimeMillis()));
        requestDbclient.updateInfraActiveRequests(request);
    } catch (Exception e) {
        workflowAction.buildAndThrowException(execution, "Error Updating Request Database", e);
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) Optional(java.util.Optional) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Timestamp(java.sql.Timestamp) WorkflowException(org.onap.so.bpmn.core.WorkflowException)

Example 98 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.

the class WorkflowActionTest method selectExecutionListNetworkCollectionMacroCreate.

@Ignore
@Test
public void selectExecutionListNetworkCollectionMacroCreate() throws Exception {
    String gAction = "createInstance";
    String resource = "NetworkCollection";
    String bpmnRequest = readBpmnRequestFromFile(MACRO_CREATE_NETWORK_COLLECTION_JSON);
    initExecution(gAction, bpmnRequest, false);
    execution.setVariable("requestUri", "v6/serviceInstances/123/networkCollections/123");
    NorthBoundRequest northBoundRequest = new NorthBoundRequest();
    List<OrchestrationFlow> orchFlows = createFlowList("CreateNetworkCollectionBB", "AssignNetworkBB", "CreateNetworkBB", "ActivateNetworkBB", "ActivateNetworkCollectionBB");
    northBoundRequest.setOrchestrationFlowList(orchFlows);
    Service service = new Service();
    CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization();
    CollectionResource collectionResource = new CollectionResource();
    collectionResource.setToscaNodeType("Data NetworkCollection Data");
    collectionResourceCustomization.setCollectionResource(collectionResource);
    service.getCollectionResourceCustomizations().add(collectionResourceCustomization);
    when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
    when(catalogDbClient.getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a")).thenReturn(service);
    workflowAction.selectExecutionList(execution);
    List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
    assertEqualsBulkFlowName(ebbs, "CreateNetworkCollectionBB", "AssignNetworkBB", "CreateNetworkBB", "ActivateNetworkBB", "AssignNetworkBB", "CreateNetworkBB", "ActivateNetworkBB", "ActivateNetworkCollectionBB");
}
Also used : CollectionResource(org.onap.so.db.catalog.beans.CollectionResource) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) Service(org.onap.so.db.catalog.beans.Service) CollectionResourceCustomization(org.onap.so.db.catalog.beans.CollectionResourceCustomization) NetworkCollectionResourceCustomization(org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) Ignore(org.junit.Ignore) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 99 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock 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");
}
Also used : HeatEnvironment(org.onap.so.db.catalog.beans.HeatEnvironment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) VfModule(org.onap.aai.domain.yang.VfModule) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) VolumeGroup(org.onap.aai.domain.yang.VolumeGroup) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 100 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock 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");
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) GenericVnf(org.onap.aai.domain.yang.GenericVnf) ArrayList(java.util.ArrayList) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) VfModule(org.onap.aai.domain.yang.VfModule) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) VfModule(org.onap.aai.domain.yang.VfModule) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Aggregations

ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)147 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)86 List (java.util.List)65 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)63 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)61 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)49 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)45 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)45 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)41 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)40 NorthBoundRequest (org.onap.so.db.catalog.beans.macro.NorthBoundRequest)40 File (java.io.File)38 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)38 RelationshipList (org.onap.aai.domain.yang.RelationshipList)38 OrchestrationFlow (org.onap.so.db.catalog.beans.macro.OrchestrationFlow)37 Service (org.onap.so.db.catalog.beans.Service)35 HashMap (java.util.HashMap)27 VfModule (org.onap.aai.domain.yang.VfModule)25 RelatedInstanceList (org.onap.so.serviceinstancebeans.RelatedInstanceList)24