Search in sources :

Example 66 with ExecuteBuildingBlock

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

the class WorkflowActionBBTasksTest method rollbackExecutionPathTest.

@Test
public void rollbackExecutionPathTest() {
    execution.setVariable("handlingCode", "Rollback");
    execution.setVariable("isRollback", false);
    execution.setVariable("requestAction", EMPTY_STRING);
    execution.setVariable("resourceName", EMPTY_STRING);
    List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
    BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
    ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
    flowsToExecute.add(ebb1);
    BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
    ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
    flowsToExecute.add(ebb2);
    BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
    ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
    flowsToExecute.add(ebb3);
    execution.setVariable("flowsToExecute", flowsToExecute);
    execution.setVariable("gCurrentSequence", 3);
    doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
    workflowActionBBTasks.rollbackExecutionPath(execution);
    List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
    assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
    assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
    assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
    assertEquals(0, execution.getVariable("gCurrentSequence"));
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ArrayList(java.util.ArrayList) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ArrayList(java.util.ArrayList) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 67 with ExecuteBuildingBlock

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

the class BBInputSetupUtils method loadOriginalFlowExecutionPath.

public List<ExecuteBuildingBlock> loadOriginalFlowExecutionPath(String requestId) {
    if (requestId != null) {
        InfraActiveRequests request = loadInfraActiveRequestById(requestId);
        if (request.getOriginalRequestId() != null) {
            RequestProcessingData requestProcessingData = this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName(request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS);
            try {
                ObjectMapper om = new ObjectMapper();
                TypeFactory typeFactory = om.getTypeFactory();
                om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
                return om.readValue(requestProcessingData.getValue(), typeFactory.constructCollectionType(List.class, ExecuteBuildingBlock.class));
            } catch (Exception e) {
                logger.error(DATA_LOAD_ERROR, e);
                throw new RuntimeException("Error Loading Original Request Data", e);
            }
        } else {
            throw new RuntimeException("Original Request Id is null for record: " + requestId);
        }
    } else {
        throw new RuntimeException("Null Request Id Passed in");
    }
}
Also used : RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ArrayList(java.util.ArrayList) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NoServiceInstanceFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException) MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 68 with ExecuteBuildingBlock

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

the class BBInputSetupUtils method persistFlowExecutionPath.

public void persistFlowExecutionPath(String requestId, List<ExecuteBuildingBlock> flowsToExecute) {
    if (requestId != null) {
        List<String> flows = new ArrayList<>();
        ObjectMapper om = new ObjectMapper();
        try {
            for (ExecuteBuildingBlock ebb : flowsToExecute) {
                flows.add(om.writeValueAsString(ebb));
            }
        } catch (JsonProcessingException e) {
            logger.error(DATA_PARSE_ERROR, e);
        }
        this.requestsDbClient.persistProcessingData(flows.toString(), requestId);
    } else {
        logger.debug(REQUEST_ERROR);
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 69 with ExecuteBuildingBlock

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

the class ExecuteBuildingBlockRainyDay method queryRainyDayTable.

public void queryRainyDayTable(DelegateExecution execution, boolean primaryPolicy) {
    try {
        ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
        String bbName = ebb.getBuildingBlock().getBpmnFlowName();
        GeneralBuildingBlock gBBInput = (GeneralBuildingBlock) execution.getVariable("gBBInput");
        String requestId = (String) execution.getVariable("mso-request-id");
        Map<ResourceKey, String> lookupKeyMap = (Map<ResourceKey, String>) execution.getVariable("lookupKeyMap");
        String serviceType = ASTERISK;
        boolean aLaCarte = (boolean) execution.getVariable("aLaCarte");
        boolean suppressRollback = (boolean) execution.getVariable("suppressRollback");
        WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
        if (workflowException != null) {
            execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage());
        } else {
            logger.debug("WorkflowException is null, unable to set WorkflowExceptionErrorMessage");
        }
        String handlingCode = "";
        if (suppressRollback) {
            handlingCode = "Abort";
        } else {
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceType();
                }
                if (serviceType == null || serviceType.isEmpty()) {
                    serviceType = ASTERISK;
                }
            } catch (Exception ex) {
                // keep default serviceType value
                logger.error("Exception in serviceType retrieval", ex);
            }
            execution.setVariable(RAINY_DAY_SERVICE_TYPE, serviceType);
            String vnfType = ASTERISK;
            String vnfName = ASTERISK;
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    for (GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
                        if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
                            vnfType = vnf.getVnfType();
                            vnfName = vnf.getVnfName();
                        }
                    }
                } else {
                    for (GenericVnf vnf : gBBInput.getServiceInstance().getVnfs()) {
                        if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
                            vnfType = vnf.getVnfType();
                            vnfName = vnf.getVnfName();
                        }
                    }
                }
            } catch (Exception ex) {
                // keep default vnfType value
                logger.error("Exception in vnfType retrieval", ex);
            }
            execution.setVariable(RAINY_DAY_VNF_TYPE, vnfType);
            execution.setVariable(RAINY_DAY_VNF_NAME, vnfName);
            String errorCode = ASTERISK;
            if (workflowException != null) {
                errorCode = "" + workflowException.getErrorCode();
            } else {
                logger.debug("WorkflowException is null, unable to get error code");
            }
            try {
                errorCode = "" + (String) execution.getVariable("WorkflowExceptionCode");
            } catch (Exception ex) {
                // keep default errorCode value
                logger.error("Exception in errorCode retrieval", ex);
            }
            String workStep = ASTERISK;
            try {
                workStep = workflowException.getWorkStep();
            } catch (Exception ex) {
                // keep default workStep value
                logger.error("Exception in workStep retrieval", ex);
            }
            String errorMessage = ASTERISK;
            try {
                errorMessage = workflowException.getErrorMessage();
            } catch (Exception ex) {
                // keep default workStep value
                logger.error("Exception in errorMessage retrieval", ex);
            }
            String serviceRole = ASTERISK;
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    serviceRole = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceRole();
                }
                if (serviceRole == null || serviceRole.isEmpty()) {
                    serviceRole = ASTERISK;
                }
            } catch (Exception ex) {
            // keep default serviceRole value
            }
            RainyDayHandlerStatus rainyDayHandlerStatus;
            rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatus(bbName, serviceType, vnfType, errorCode, workStep, errorMessage, serviceRole);
            if (rainyDayHandlerStatus == null) {
                handlingCode = "Abort";
            } else {
                if (primaryPolicy) {
                    handlingCode = rainyDayHandlerStatus.getPolicy();
                } else {
                    handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
                }
            }
            if (!primaryPolicy) {
                try {
                    InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
                    request.setRetryStatusMessage("Retries have been exhausted.");
                    requestDbclient.updateInfraActiveRequests(request);
                } catch (Exception ex) {
                    logger.error("Failed to update Request Db Infra Active Requests with Retry Status", ex);
                }
            }
            if ("RollbackToAssigned".equals(handlingCode) && !aLaCarte) {
                handlingCode = "Rollback";
            }
            if (handlingCode.startsWith("Rollback")) {
                String targetState = "";
                if ("RollbackToAssigned".equalsIgnoreCase(handlingCode)) {
                    targetState = Status.ROLLED_BACK_TO_ASSIGNED.toString();
                } else if ("RollbackToCreated".equalsIgnoreCase(handlingCode) || "RollbackToCreatedNoConfiguration".equalsIgnoreCase(handlingCode)) {
                    targetState = Status.ROLLED_BACK_TO_CREATED.toString();
                } else {
                    targetState = Status.ROLLED_BACK.toString();
                }
                execution.setVariable(ROLLBACK_TARGET_STATE, targetState);
                logger.debug("Rollback target state is: {}", targetState);
            }
        }
        logger.debug("RainyDayHandler Status Code is: {}", handlingCode);
        execution.setVariable(HANDLING_CODE, handlingCode);
    } catch (Exception e) {
        String code = this.environment.getProperty(defaultCode);
        logger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = {}", code, e);
        execution.setVariable(HANDLING_CODE, code);
    }
    try {
        int envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
        execution.setVariable("maxRetries", envMaxRetries);
    } catch (Exception ex) {
        logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
        execution.setVariable("maxRetries", 5);
    }
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) WorkflowException(org.onap.so.bpmn.core.WorkflowException) RainyDayHandlerStatus(org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) WorkflowException(org.onap.so.bpmn.core.WorkflowException) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) Map(java.util.Map)

Example 70 with ExecuteBuildingBlock

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

the class GeneratePayloadForCds method buildCdsPropertiesBean.

/**
 * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module
 * and service.
 *
 * @param execution - A building block execution object.
 * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
 * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
 */
public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution) throws PayloadGenerationException {
    ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
    BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
    final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
    final String scope = buildingBlock.getBpmnScope();
    final String action = buildingBlock.getBpmnAction();
    CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
    requestProvider.setExecutionObject(execution);
    final String requestPayload = requestProvider.buildRequestPayload(action).orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
    return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE);
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

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