Search in sources :

Example 21 with DelegateExecutionImpl

use of org.onap.so.bpmn.common.DelegateExecutionImpl in project so by onap.

the class ExceptionBuilder method processAuditException.

public void processAuditException(DelegateExecutionImpl execution, boolean flowShouldContinue) {
    logger.debug("Processing Audit Results");
    String auditListString = execution.getVariable("auditInventoryResult");
    String processKey = getProcessKey(execution.getDelegateExecution());
    if (auditListString != null) {
        StringBuilder errorMessage = new StringBuilder();
        try {
            ExtractPojosForBB extractPojosForBB = getExtractPojosForBB();
            VfModule module = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
            String cloudRegionId = execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId();
            GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
            AAIObjectAuditList auditList = objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
            errorMessage = errorMessage.append(auditList.getAuditType() + " VF-Module " + module.getVfModuleId() + " failed due to incomplete AAI vserver inventory population after stack " + auditList.getHeatStackName() + " was successfully " + auditList.getAuditType() + "d in cloud region " + cloudRegionId + ". MSO Audit indicates that the following was not " + auditList.getAuditType() + "d in AAI: ");
            Stream<AAIObjectAudit> vServerLInterfaceAuditStream = auditList.getAuditList().stream().filter(auditObject -> auditObject.getAaiObjectType().equals(Types.VSERVER.typeName()) || auditObject.getAaiObjectType().equals(Types.L_INTERFACE.typeName()));
            List<AAIObjectAudit> filteredAuditStream = vServerLInterfaceAuditStream.filter(a -> !a.isDoesObjectExist()).collect(Collectors.toList());
            for (AAIObjectAudit object : filteredAuditStream) {
                if (object.getAaiObjectType().equals(Types.L_INTERFACE.typeName())) {
                    LInterface li = objectMapper.getMapper().convertValue(object.getAaiObject(), LInterface.class);
                    errorMessage = errorMessage.append(Types.L_INTERFACE.typeName() + " " + li.getInterfaceId() + ", ");
                } else {
                    Vserver vs = objectMapper.getMapper().convertValue(object.getAaiObject(), Vserver.class);
                    errorMessage = errorMessage.append(Types.VSERVER.typeName() + " " + vs.getVserverId() + ", ");
                }
            }
            if (errorMessage.length() > 0) {
                errorMessage.setLength(errorMessage.length() - 2);
                errorMessage = errorMessage.append(".");
            }
        } catch (IOException | BBObjectNotFoundException e) {
            errorMessage = errorMessage.append("process objects in AAI. ");
            logger.error("Exception occurred in processAuditException", e);
        }
        if (flowShouldContinue) {
            execution.setVariable("StatusMessage", errorMessage.toString());
        } else {
            WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString(), ONAPComponents.SO);
            execution.setVariable("WorkflowException", exception);
            execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString());
            logger.info("Outgoing WorkflowException is {}", exception);
            logger.info("Throwing AAIInventoryFailure");
            throw new BpmnError("AAIInventoryFailure");
        }
    } else {
        String errorMessage = "Unable to process audit results due to auditInventoryResult being null";
        WorkflowException exception = new WorkflowException(processKey, 400, errorMessage, ONAPComponents.SO);
        execution.setVariable("WorkflowException", exception);
        execution.setVariable("WorkflowExceptionErrorMessage", errorMessage);
        logger.info("Outgoing WorkflowException is {}", exception);
        logger.info("Throwing AAIInventoryFailure");
        throw new BpmnError("AAIInventoryFailure");
    }
}
Also used : ONAPComponents(org.onap.logging.filter.base.ONAPComponents) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) LoggerFactory(org.slf4j.LoggerFactory) WorkflowException(org.onap.so.bpmn.core.WorkflowException) BpmnError(org.camunda.bpm.engine.delegate.BpmnError) MessageEnum(org.onap.so.logger.MessageEnum) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) LInterface(org.onap.aai.domain.yang.LInterface) ExtractPojosForBB(org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB) ErrorCode(org.onap.logging.filter.base.ErrorCode) Logger(org.slf4j.Logger) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ONAPComponentsList(org.onap.logging.filter.base.ONAPComponentsList) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Vserver(org.onap.aai.domain.yang.Vserver) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) LoggingAnchor(org.onap.so.logger.LoggingAnchor) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) Components(org.onap.so.utils.Components) Vserver(org.onap.aai.domain.yang.Vserver) WorkflowException(org.onap.so.bpmn.core.WorkflowException) IOException(java.io.IOException) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) ExtractPojosForBB(org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB) LInterface(org.onap.aai.domain.yang.LInterface) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 22 with DelegateExecutionImpl

use of org.onap.so.bpmn.common.DelegateExecutionImpl in project so by onap.

the class ExtractPojosForBBTest method before.

@Before
public void before() {
    execution = new DelegateExecutionImpl(new ExecutionImpl());
    execution.setVariable("testProcessKey", "AAICreateTasksTests");
    gBBInput = new GeneralBuildingBlock();
    execution.setVariable("gBBInput", gBBInput);
    lookupKeyMap = new HashMap<>();
    execution.setVariable("lookupKeyMap", lookupKeyMap);
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) Before(org.junit.Before)

Example 23 with DelegateExecutionImpl

use of org.onap.so.bpmn.common.DelegateExecutionImpl in project so by onap.

the class BuildingBlockTestDataSetup method buildingBlockTestDataSetupBefore.

@Before
public void buildingBlockTestDataSetupBefore() {
    collectionCounter = 0;
    configurationCounter = 0;
    customerCounter = 0;
    genericVnfCounter = 0;
    instanceGroupCounter = 0;
    l3NetworkCounter = 0;
    owningEntityCounter = 0;
    pnfCounter = 0;
    projectCounter = 0;
    serviceInstanceCounter = 0;
    serviceProxyCounter = 0;
    serviceSubscriptionCounter = 0;
    vfModuleCounter = 0;
    volumeGroupCounter = 0;
    vpnBindingCounter = 0;
    vpnBondingLinkCounter = 0;
    execution = new DelegateExecutionImpl(new ExecutionImpl());
    execution.setVariable("testProcessKey", "testProcessKeyValue");
    gBBInput = new GeneralBuildingBlock();
    execution.setVariable("gBBInput", gBBInput);
    lookupKeyMap = new HashMap<ResourceKey, String>();
    execution.setVariable("lookupKeyMap", lookupKeyMap);
    ExecutionImpl mockExecutionImpl = mock(ExecutionImpl.class);
    doReturn("test").when(mockExecutionImpl).getProcessInstanceId();
    ExecutionImpl executionImpl = new ExecutionImpl();
    executionImpl.setProcessInstance(mockExecutionImpl);
    delegateExecution = (DelegateExecution) executionImpl;
    delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) Before(org.junit.Before)

Example 24 with DelegateExecutionImpl

use of org.onap.so.bpmn.common.DelegateExecutionImpl in project so by onap.

the class WorkflowActionBBTasks method updateRequestStatusToComplete.

public void updateRequestStatusToComplete(DelegateExecution execution) {
    try {
        final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
        InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
        final String action = (String) execution.getVariable(BBConstants.G_ACTION);
        final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE);
        final String resourceName = (String) execution.getVariable("resourceName");
        String statusMessage = (String) execution.getVariable("StatusMessage");
        String macroAction;
        if (statusMessage == null) {
            if (aLaCarte) {
                macroAction = "ALaCarte-" + resourceName + "-" + action + " request was executed correctly.";
            } else {
                macroAction = "Macro-" + resourceName + "-" + action + " request was executed correctly.";
            }
        } else {
            macroAction = statusMessage;
        }
        execution.setVariable("finalStatusMessage", macroAction);
        Timestamp endTime = new Timestamp(System.currentTimeMillis());
        request.setEndTime(endTime);
        request.setFlowStatus("Successfully completed all Building Blocks");
        request.setStatusMessage(macroAction);
        request.setProgress(100L);
        request.setRequestStatus("COMPLETE");
        request.setLastModifiedBy("CamundaBPMN");
        requestsDbListener.post(request, new DelegateExecutionImpl(execution));
        requestDbclient.updateInfraActiveRequests(request);
    } catch (Exception ex) {
        workflowAction.buildAndThrowException(execution, "Error Updating Request Database", ex);
    }
}
Also used : DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Timestamp(java.sql.Timestamp) EntityNotFoundException(javax.persistence.EntityNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 25 with DelegateExecutionImpl

use of org.onap.so.bpmn.common.DelegateExecutionImpl in project so by onap.

the class RegisterForPnfReadyEventTest method init.

@Before
public void init() {
    delegateExecution = prepareExecution();
    dmaapClientTest = new DmaapClientTestImpl();
    exceptionBuilderMock = mock(ExceptionBuilder.class);
    extractPojosForBBMock = mock(ExtractPojosForBB.class);
    buildingBlockExecution = new DelegateExecutionImpl(new HashMap<>());
    when(delegateExecution.getVariable("gBuildingBlockExecution")).thenReturn(buildingBlockExecution);
}
Also used : HashMap(java.util.HashMap) ExtractPojosForBB(org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) Before(org.junit.Before)

Aggregations

DelegateExecutionImpl (org.onap.so.bpmn.common.DelegateExecutionImpl)29 DelegateExecutionFake (org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake)17 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)11 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)9 Before (org.junit.Before)9 Test (org.junit.Test)9 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)8 ExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl)6 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)6 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)2 WorkflowException (org.onap.so.bpmn.core.WorkflowException)2 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)2 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)2 ExtractPojosForBB (org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB)2