Search in sources :

Example 21 with WorkflowException

use of org.onap.so.bpmn.core.WorkflowException in project so by onap.

the class ManualHandlingTasks method setFalloutTaskVariables.

public void setFalloutTaskVariables(DelegateTask task) {
    DelegateExecution execution = task.getExecution();
    try {
        logger.debug("Setting fallout task variables:");
        String taskId = task.getId();
        logger.debug("taskId is: " + taskId);
        String type = TASK_TYPE_FALLOUT;
        BuildingBlockExecution gBuildingBlockExecution = (BuildingBlockExecution) execution.getVariable(G_BUILDING_BLOCK_EXECUTION);
        WorkflowException workflowException = (WorkflowException) execution.getVariable(WORKFLOW_EXCEPTION);
        String nfRole = (String) execution.getVariable(RAINY_DAY_VNF_TYPE);
        logger.debug(TASK_VARIABLE_NFROLE + ": " + nfRole);
        String subscriptionServiceType = (String) execution.getVariable(RAINY_DAY_SERVICE_TYPE);
        logger.debug(TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE + ": " + subscriptionServiceType);
        String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
        logger.debug(TASK_VARIABLE_ORIGINAL_REQUEST_ID + ": " + originalRequestId);
        String originalRequestorId = gBuildingBlockExecution.getGeneralBuildingBlock().getRequestContext().getRequestorId();
        logger.debug(TASK_VARIABLE_ORIGINAL_REQUESTOR_ID + ": " + originalRequestorId);
        String description = "Manual user task to handle a failure of a BB execution";
        logger.debug(TASK_VARIABLE_DESCRIPTION + ": " + description);
        String taskTimeout = (String) gBuildingBlockExecution.getVariable(TASK_TIMEOUT);
        String timeout = Date.from((new Date()).toInstant().plus(Duration.parse(taskTimeout))).toGMTString();
        logger.debug(TASK_VARIABLE_TIMEOUT + ": " + timeout);
        String errorSource = ASTERISK;
        if (workflowException != null && workflowException.getExtSystemErrorSource() != null) {
            errorSource = workflowException.getExtSystemErrorSource().toString();
        }
        logger.debug(TASK_VARIABLE_ERROR_SOURCE + ": " + errorSource);
        String errorCode = ASTERISK;
        if (workflowException != null) {
            errorCode = workflowException.getErrorCode() + "";
        }
        logger.debug(TASK_VARIABLE_ERROR_CODE + ": " + errorCode);
        String errorMessage = ASTERISK;
        if (workflowException != null) {
            errorMessage = workflowException.getErrorMessage();
        }
        logger.debug(TASK_VARIABLE_ERROR_MESSAGE + ": " + errorMessage);
        String buildingBlockName = gBuildingBlockExecution.getFlowToBeCalled();
        logger.debug(TASK_VARIABLE_BUILDING_BLOCK_NAME + ": " + buildingBlockName);
        String buildingBlockStep = ASTERISK;
        if (workflowException != null) {
            buildingBlockStep = workflowException.getWorkStep();
        }
        execution.setVariable(WORKSTEP, buildingBlockStep);
        logger.debug(TASK_VARIABLE_BUILDING_BLOCK_STEP + ": " + buildingBlockStep);
        String validResponses = this.environment.getProperty(validResponsesPath);
        logger.debug(TASK_VARIABLE_VALID_RESPONSES + ": " + validResponses);
        Map<String, String> taskVariables = new HashMap<>();
        taskVariables.put(TASK_VARIABLE_TYPE, type);
        taskVariables.put(TASK_VARIABLE_NFROLE, nfRole);
        taskVariables.put(TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE, subscriptionServiceType);
        taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUEST_ID, originalRequestId);
        taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUESTOR_ID, originalRequestorId);
        taskVariables.put(TASK_VARIABLE_ERROR_SOURCE, errorSource);
        taskVariables.put(TASK_VARIABLE_ERROR_CODE, errorCode);
        taskVariables.put(TASK_VARIABLE_ERROR_MESSAGE, errorMessage);
        taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_NAME, buildingBlockName);
        taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_STEP, buildingBlockStep);
        taskVariables.put(TASK_VARIABLE_VALID_RESPONSES, validResponses);
        taskVariables.put(TASK_VARIABLE_TIMEOUT, timeout);
        taskVariables.put(TASK_VARIABLE_DESCRIPTION, description);
        TaskService taskService = execution.getProcessEngineServices().getTaskService();
        taskService.setVariablesLocal(taskId, taskVariables);
        logger.debug("successfully created fallout task: " + taskId);
    } catch (BpmnError e) {
        logger.debug(BPMN_EXCEPTION + e.getMessage());
        throw e;
    } catch (Exception ex) {
        String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
        logger.debug(msg);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
    }
}
Also used : BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) HashMap(java.util.HashMap) TaskService(org.camunda.bpm.engine.TaskService) WorkflowException(org.onap.so.bpmn.core.WorkflowException) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Date(java.util.Date) WorkflowException(org.onap.so.bpmn.core.WorkflowException) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 22 with WorkflowException

use of org.onap.so.bpmn.core.WorkflowException in project so by onap.

the class ExecuteActivity method execute.

@Override
public void execute(DelegateExecution execution) throws Exception {
    final String requestId = (String) execution.getVariable(G_REQUEST_ID);
    WorkflowException workflowException;
    String handlingCode;
    try {
        Boolean workflowSyncAckSent = (Boolean) execution.getVariable(WORKFLOW_SYNC_ACK_SENT);
        if (workflowSyncAckSent == null || workflowSyncAckSent == false) {
            workflowActionBBTasks.sendSyncAck(execution);
            execution.setVariable(WORKFLOW_SYNC_ACK_SENT, Boolean.TRUE);
        }
        final String implementationString = execution.getBpmnModelElementInstance().getAttributeValue(SERVICE_TASK_IMPLEMENTATION_ATTRIBUTE);
        logger.debug("activity implementation String: {}", implementationString);
        if (!implementationString.startsWith(ACTIVITY_PREFIX)) {
            buildAndThrowException(execution, "Implementation attribute has a wrong format");
        }
        String activityName = implementationString.replaceFirst(ACTIVITY_PREFIX, "");
        logger.info("activityName is: {}", activityName);
        BuildingBlock buildingBlock = buildBuildingBlock(activityName);
        ExecuteBuildingBlock executeBuildingBlock = buildExecuteBuildingBlock(execution, requestId, buildingBlock);
        Map<String, Object> variables = new HashMap<>();
        if (execution.getVariables() != null) {
            execution.getVariables().forEach((key, value) -> {
                if (value instanceof Serializable) {
                    variables.put(key, value);
                }
            });
        }
        variables.put(BUILDING_BLOCK, executeBuildingBlock);
        variables.put(G_REQUEST_ID, requestId);
        variables.put(RETRY_COUNT, 1);
        variables.put(A_LA_CARTE, true);
        variables.put(SUPPRESS_ROLLBACK, true);
        ProcessInstanceWithVariables buildingBlockResult = runtimeService.createProcessInstanceByKey(EXECUTE_BUILDING_BLOCK).setVariables(variables).executeWithVariablesInReturn();
        VariableMap variableMap = buildingBlockResult.getVariables();
        workflowException = (WorkflowException) variableMap.get(WORKFLOW_EXCEPTION);
        if (workflowException != null) {
            logger.error("Workflow exception is: {}", workflowException.getErrorMessage());
        }
        handlingCode = (String) variableMap.get(HANDLING_CODE);
        logger.debug("Handling code: " + handlingCode);
        execution.setVariable(WORKFLOW_EXCEPTION, workflowException);
    } catch (Exception e) {
        logger.error("BPMN exception on activity execution: " + e.getMessage());
        workflowException = new WorkflowException(EXECUTE_BUILDING_BLOCK, 7000, e.getMessage());
        handlingCode = ABORT_HANDLING_CODE;
    }
    if (workflowException != null && handlingCode != null && handlingCode.equals(ABORT_HANDLING_CODE)) {
        logger.debug("Aborting execution of the custom workflow");
        buildAndThrowException(execution, workflowException.getErrorMessage());
    }
}
Also used : Serializable(java.io.Serializable) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) HashMap(java.util.HashMap) VariableMap(org.camunda.bpm.engine.variable.VariableMap) WorkflowException(org.onap.so.bpmn.core.WorkflowException) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) WorkflowException(org.onap.so.bpmn.core.WorkflowException) IOException(java.io.IOException)

Example 23 with WorkflowException

use of org.onap.so.bpmn.core.WorkflowException in project so by onap.

the class BuildingBlockValidatorRunnerTest method testValidate.

@Test
public void testValidate() {
    BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
    execution.setVariable("testProcessKey", "1234");
    try {
        runner.preValidate("test", execution);
        fail("exception not thrown");
    } catch (BpmnError e) {
        WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
        assertEquals("Failed Validations:\norg.onap.so.bpmn.common.listener.validation.MyPreValidatorTwo: my-error-two\norg.onap.so.bpmn.common.listener.validation.MyPreValidatorOne: my-error-one", workflowException.getErrorMessage());
    }
    runner.preValidate("test2", mock(BuildingBlockExecution.class));
}
Also used : BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) WorkflowException(org.onap.so.bpmn.core.WorkflowException) DelegateExecutionFake(org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake) BpmnError(org.camunda.bpm.engine.delegate.BpmnError) Test(org.junit.Test)

Example 24 with WorkflowException

use of org.onap.so.bpmn.core.WorkflowException in project so by onap.

the class SdncNetworkTopologyOperationTask method saveOutput.

private void saveOutput(DelegateExecution execution, RpcNetworkTopologyOperationOutputEntity output) throws RouteException {
    logger.info("SdncNetworkTopologyOperationTask.saveOutput begin!");
    String responseCode = output.getOutput().getResponseCode();
    if (!"200".equals(responseCode)) {
        String processKey = getProcessKey(execution);
        int errorCode = Integer.parseInt(responseCode);
        String errorMessage = output.getOutput().getResponseMessage();
        WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
        execution.setVariable("SDNCA_SuccessIndicator", workflowException);
        updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), "100", errorMessage);
        logger.info("exception: SdncNetworkTopologyOperationTask.saveOutput fail!");
        throw new RouteException();
    }
    logger.info("SdncNetworkTopologyOperationTask.saveOutput end!");
}
Also used : RouteException(org.onap.msb.sdk.discovery.common.RouteException) WorkflowException(org.onap.so.bpmn.core.WorkflowException)

Example 25 with WorkflowException

use of org.onap.so.bpmn.core.WorkflowException in project so by onap.

the class SdncServiceTopologyOperationTask method saveOutput.

private void saveOutput(DelegateExecution execution, RpcServiceTopologyOperationOutputEntity output) throws Exception {
    logger.info("SdncServiceTopologyOperationTask.saveOutput begin!");
    String responseCode = output.getOutput().getResponseCode();
    if (!"200".equals(responseCode)) {
        String processKey = getProcessKey(execution);
        int errorCode = Integer.parseInt(responseCode);
        String errorMessage = output.getOutput().getResponseMessage();
        WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
        execution.setVariable("SDNCA_SuccessIndicator", workflowException);
        updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), null, errorMessage);
        logger.info("exception: SdncServiceTopologyOperationTask.saveOutput fail!");
        throw new RouteException();
    }
    logger.info("SdncServiceTopologyOperationTask.saveOutput end!");
}
Also used : RouteException(org.onap.msb.sdk.discovery.common.RouteException) WorkflowException(org.onap.so.bpmn.core.WorkflowException)

Aggregations

WorkflowException (org.onap.so.bpmn.core.WorkflowException)75 Test (org.junit.Test)61 HashMap (java.util.HashMap)49 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)45 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)9 AllottedResource (org.onap.so.bpmn.core.domain.AllottedResource)8 HomingSolution (org.onap.so.bpmn.core.domain.HomingSolution)8 NetworkResource (org.onap.so.bpmn.core.domain.NetworkResource)8 Resource (org.onap.so.bpmn.core.domain.Resource)8 ServiceDecomposition (org.onap.so.bpmn.core.domain.ServiceDecomposition)8 VnfResource (org.onap.so.bpmn.core.domain.VnfResource)8 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)7 Timestamp (java.sql.Timestamp)4 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)4 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)4 DelegateExecutionFake (org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake)3 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)3 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)3