Search in sources :

Example 91 with ExecuteBuildingBlock

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

the class WorkflowAction method createBuildingBlocksForOrchFlows.

private void createBuildingBlocksForOrchFlows(DelegateExecution execution, ServiceInstancesRequest sIRequest, String requestId, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, String requestAction, String resourceId, List<ExecuteBuildingBlock> flowsToExecute, String vnfType, List<OrchestrationFlow> orchFlows, String apiVersion, Resource resourceKey, ReplaceInstanceRelatedInformation replaceInfo) throws Exception {
    for (OrchestrationFlow orchFlow : orchFlows) {
        if (orchFlow.getFlowName().contains(CONFIGURATION)) {
            List<OrchestrationFlow> configOrchFlows = new ArrayList<>();
            configOrchFlows.add(orchFlow);
            addConfigBuildingBlocksToFlowsToExecuteList(execution, sIRequest, requestId, workflowResourceIds, requestDetails, requestAction, resourceId, flowsToExecute, vnfType, apiVersion, resourceKey, replaceInfo, configOrchFlows);
        } else {
            ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds, requestDetails, false, null, null, false, replaceInfo);
            flowsToExecute.add(ebb);
        }
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArrayList(java.util.ArrayList) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow)

Example 92 with ExecuteBuildingBlock

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

the class WorkflowActionBBTasks method postProcessingExecuteBBActivateVfModule.

protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb, List<ExecuteBuildingBlock> flowsToExecute) {
    try {
        String requestAction = (String) execution.getVariable(BBConstants.G_ACTION);
        String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
        String vnfId = ebb.getWorkflowResourceIds().getVnfId();
        String vfModuleId = ebb.getResourceId();
        ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
        String serviceModelUUID = "";
        String vnfCustomizationUUID = "";
        String vfModuleCustomizationUUID = "";
        if (requestAction.equalsIgnoreCase("replaceInstance") || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments")) {
            for (RelatedInstanceList relatedInstList : ebb.getRequestDetails().getRelatedInstanceList()) {
                RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
                if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
                    vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
                }
                if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
                    serviceModelUUID = relatedInstance.getModelInfo().getModelVersionId();
                }
            }
            vfModuleCustomizationUUID = ebb.getRequestDetails().getModelInfo().getModelCustomizationId();
        } else {
            serviceModelUUID = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
            vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
            vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
        }
        List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
        logger.debug("Vnfc Size: {}", vnfcs.size());
        for (Vnfc vnfc : vnfcs) {
            String modelCustomizationId = vnfc.getModelCustomizationId();
            logger.debug("Processing Vnfc: {}", modelCustomizationId);
            CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
            if (fabricConfig != null && fabricConfig.getConfigurationResource() != null && fabricConfig.getConfigurationResource().getToscaNodeType() != null && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
                String configurationId = getConfigurationId(vnfc);
                ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
                configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
                configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
                configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
                configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
                ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb, configurationId, configurationResourceKeys);
                flowsToExecute.add(addConfigBB);
                flowsToExecute.stream().forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}", executeBB.getBuildingBlock().getBpmnFlowName()));
                execution.setVariable("flowsToExecute", flowsToExecute);
                execution.setVariable(COMPLETED, false);
            } else {
                logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
            }
        }
    } catch (EntityNotFoundException e) {
        logger.debug("Will not be running Fabric Config Building Blocks", e);
    } catch (Exception e) {
        String errorMessage = "Error occurred in post processing of Vf Module create";
        execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
        execution.setVariable("WorkflowActionErrorMessage", errorMessage);
        logger.error(errorMessage, e);
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) EntityNotFoundException(javax.persistence.EntityNotFoundException) Vnfc(org.onap.aai.domain.yang.Vnfc) EntityNotFoundException(javax.persistence.EntityNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 93 with ExecuteBuildingBlock

use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock 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.");
    }
}
Also used : ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) BBConstants(org.onap.so.bpmn.common.BBConstants) VolumeGroup(org.onap.aai.domain.yang.VolumeGroup) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) Configuration(org.onap.aaiclient.client.aai.entities.Configuration) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) VfModule(org.onap.aai.domain.yang.VfModule) Vnfc(org.onap.aai.domain.yang.Vnfc) ArrayList(java.util.ArrayList) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) RequestsDbListenerRunner(org.onap.so.bpmn.common.listener.db.RequestsDbListenerRunner) FlowManipulatorListenerRunner(org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) EntityNotFoundException(javax.persistence.EntityNotFoundException) InstanceGroup(org.onap.aai.domain.yang.InstanceGroup) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) L3Network(org.onap.aai.domain.yang.L3Network) GenericVnf(org.onap.aai.domain.yang.GenericVnf) BBInputSetupUtils(org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils) RequestsDbClient(org.onap.so.db.request.client.RequestsDbClient) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) Logger(org.slf4j.Logger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) Timestamp(java.sql.Timestamp) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CatalogDbClient(org.onap.so.db.catalog.client.CatalogDbClient) WorkflowContextHolder(org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) Component(org.springframework.stereotype.Component) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) Environment(org.springframework.core.env.Environment) ModelType(org.onap.so.serviceinstancebeans.ModelType) Optional(java.util.Optional) WorkflowCallbackResponse(org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList)

Example 94 with ExecuteBuildingBlock

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

the class WorkflowActionBBTasks method getUpdatedRequest.

protected InfraActiveRequests getUpdatedRequest(DelegateExecution execution, int currentSequence) {
    List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
    String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
    InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
    ExecuteBuildingBlock completedBB = flowsToExecute.get(currentSequence - 2);
    ExecuteBuildingBlock nextBB = flowsToExecute.get(currentSequence - 1);
    int completedBBs = currentSequence - 1;
    int totalBBs = flowsToExecute.size();
    int remainingBBs = totalBBs - completedBBs;
    String statusMessage = this.getStatusMessage(completedBB.getBuildingBlock().getBpmnFlowName(), nextBB.getBuildingBlock().getBpmnFlowName(), completedBBs, remainingBBs);
    Long percentProgress = this.getPercentProgress(completedBBs, totalBBs);
    request.setFlowStatus(statusMessage);
    request.setProgress(percentProgress);
    request.setLastModifiedBy("CamundaBPMN");
    return request;
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArrayList(java.util.ArrayList) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests)

Example 95 with ExecuteBuildingBlock

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

the class ExecuteBuildingBlockBuilder method buildExecuteBuildingBlock.

protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, Resource resource, String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isVirtualLink, String virtualLinkKey, String vnfcName, boolean isConfiguration, ReplaceInstanceRelatedInformation replaceInfo) {
    BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName(orchFlow.getFlowName()).setMsoId(UUID.randomUUID().toString()).setIsVirtualLink(isVirtualLink).setVirtualLinkKey(virtualLinkKey).setKey(Optional.ofNullable(resource).map(Resource::getResourceId).orElse(""));
    Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(buildingBlock::setBpmnAction);
    Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(buildingBlock::setBpmnScope);
    String oldVolumeGroupName = "";
    if (replaceInfo != null) {
        oldVolumeGroupName = replaceInfo.getOldVolumeGroupName();
    }
    if (resource != null && (orchFlow.getFlowName().contains(VOLUMEGROUP) && (requestAction.equalsIgnoreCase(REPLACEINSTANCE) || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)))) {
        logger.debug("Setting resourceId to volume group id for volume group flow on replace");
        resourceId = workflowResourceIds.getVolumeGroupId();
    }
    ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setApiVersion(apiVersion).setaLaCarte(aLaCarte).setRequestAction(requestAction).setResourceId(resourceId).setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds).setRequestId(requestId).setBuildingBlock(buildingBlock).setRequestDetails(requestDetails).setOldVolumeGroupName(oldVolumeGroupName);
    if (resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))) {
        ConfigurationResourceKeys configurationResourceKeys = getConfigurationResourceKeys(resource, vnfcName);
        executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
    }
    return executeBuildingBlock;
}
Also used : BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys)

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