diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
4 files changed, 123 insertions, 99 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java new file mode 100644 index 0000000000..7e6eb2a23d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java @@ -0,0 +1,116 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.Optional; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowActionBBFailure { + + private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBFailure.class); + @Autowired + private RequestsDbClient requestDbclient; + @Autowired + private WorkflowAction workflowAction; + + protected void updateRequestErrorStatusMessage(DelegateExecution execution) { + try { + String requestId = (String) execution.getVariable("mso-request-id"); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + String errorMsg = ""; + Optional<String> errorMsgOp = retrieveErrorMessage(execution); + if(errorMsgOp.isPresent()){ + errorMsg = errorMsgOp.get(); + }else{ + errorMsg = "Failed to determine error message"; + } + request.setStatusMessage(errorMsg); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + logger.error("Failed to update Request db with the status message after retry or rollback has been initialized.",e); + } + } + + 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"); + + 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); + }else if(isRollbackFailure){ + 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); + }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); + } + request.setProgress(Long.valueOf(100)); + request.setRequestStatus("FAILED"); + request.setLastModifiedBy("CamundaBPMN"); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + workflowAction.buildAndThrowException(execution, "Error Updating Request Database", e); + } + } + + private Optional<String> retrieveErrorMessage (DelegateExecution execution){ + String errorMsg = ""; + try { + WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); + if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ + errorMsg = exception.getErrorMessage(); + } + if(errorMsg == null || errorMsg.equals("")){ + errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); + } + return Optional.of(errorMsg); + } catch (Exception ex) { + logger.error("Failed to extract workflow exception from execution.",ex); + } + return Optional.of(errorMsg); + } + + public void updateRequestStatusToFailedWithRollback(DelegateExecution execution) { + execution.setVariable("isRollbackComplete", true); + updateRequestStatusToFailed(execution); + } + + public void abortCallErrorHandling(DelegateExecution execution) { + String msg = "Flow has failed. Rainy day handler has decided to abort the process."; + logger.error(msg); + throw new BpmnError(msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 7670e0245d..d9125e4104 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -57,6 +58,8 @@ public class WorkflowActionBBTasks { private RequestsDbClient requestDbclient; @Autowired private WorkflowAction workflowAction; + @Autowired + private WorkflowActionBBFailure workflowActionBBFailure; public void selectBB(DelegateExecution execution) { List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution @@ -207,7 +210,7 @@ public class WorkflowActionBBTasks { String retryDuration = (String) execution.getVariable("RetryDuration"); int retryCount = (int) execution.getVariable(RETRY_COUNT); if (handlingCode.equals("Retry")){ - updateRequestErrorStatusMessage(execution); + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); try{ InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); request.setRetryStatusMessage("Retry " + retryCount+1 + "/5 will be started in " + retryDuration); @@ -267,7 +270,7 @@ public class WorkflowActionBBTasks { } } - updateRequestErrorStatusMessage(execution); + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); if (rollbackFlows.isEmpty()) execution.setVariable("isRollbackNeeded", false); @@ -282,99 +285,4 @@ public class WorkflowActionBBTasks { workflowAction.buildAndThrowException(execution, "Rollback has already been called. Cannot rollback a request that is currently in the rollback state."); } } - - protected void updateRequestErrorStatusMessage(DelegateExecution execution) { - try { - String requestId = (String) execution.getVariable(G_REQUEST_ID); - InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); - String errorMsg = retrieveErrorMessage(execution); - if(errorMsg == null || errorMsg.equals("")){ - errorMsg = "Failed to determine error message"; - } - request.setStatusMessage(errorMsg); - logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); - requestDbclient.updateInfraActiveRequests(request); - } catch (Exception e) { - logger.error("Failed to update Request db with the status message after retry or rollback has been initialized.",e); - } - } - - public void abortCallErrorHandling(DelegateExecution execution) { - String msg = "Flow has failed. Rainy day handler has decided to abort the process."; - logger.error(msg); - throw new BpmnError(msg); - } - - public void updateRequestStatusToFailed(DelegateExecution execution) { - try { - String requestId = (String) execution.getVariable(G_REQUEST_ID); - InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); - String errorMsg = null; - String rollbackErrorMsg = null; - Boolean rollbackCompleted = (Boolean) execution.getVariable("isRollbackComplete"); - Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback"); - - if(rollbackCompleted==null) - rollbackCompleted = false; - - if(isRollbackFailure==null) - isRollbackFailure = false; - - if(rollbackCompleted){ - rollbackErrorMsg = "Rollback has been completed successfully."; - request.setRollbackStatusMessage(rollbackErrorMsg); - logger.debug("Updating RequestDB to failed: Rollback has been completed successfully"); - }else{ - if(isRollbackFailure){ - rollbackErrorMsg = retrieveErrorMessage(execution); - if(rollbackErrorMsg == null || rollbackErrorMsg.equals("")){ - rollbackErrorMsg = "Failed to determine rollback error message."; - } - request.setRollbackStatusMessage(rollbackErrorMsg); - logger.debug("Updating RequestDB to failed: rollbackErrorMsg = " + rollbackErrorMsg); - }else{ - errorMsg = retrieveErrorMessage(execution); - if(errorMsg == null || errorMsg.equals("")){ - errorMsg = "Failed to determine error message"; - } - request.setStatusMessage(errorMsg); - logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); - } - } - request.setProgress(Long.valueOf(100)); - request.setRequestStatus("FAILED"); - request.setLastModifiedBy("CamundaBPMN"); - requestDbclient.updateInfraActiveRequests(request); - } catch (Exception e) { - workflowAction.buildAndThrowException(execution, "Error Updating Request Database", e); - } - } - - private String retrieveErrorMessage (DelegateExecution execution){ - String errorMsg = ""; - try { - WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); - if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ - errorMsg = exception.getErrorMessage(); - } - } catch (Exception ex) { - //log error and attempt to extact WorkflowExceptionMessage - logger.error("Failed to extract workflow exception from execution.",ex); - } - - if (errorMsg == null){ - try { - errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); - } catch (Exception ex) { - logger.error("Failed to extract workflow exception message from WorkflowException",ex); - errorMsg = "Unexpected Error in BPMN."; - } - } - return errorMsg; - } - - public void updateRequestStatusToFailedWithRollback(DelegateExecution execution) { - execution.setVariable("isRollbackComplete", true); - updateRequestStatusToFailed(execution); - } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java index 46b18f5e32..16d5e8e1db 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java @@ -124,7 +124,7 @@ public class AAINetworkResources { AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); AAIResourceUri networkURI = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, l3network.getNetworkId()); - injectionHelper.getAaiClient().connect(cloudRegionURI, networkURI); + injectionHelper.getAaiClient().connect(networkURI,cloudRegionURI); } public void connectNetworkToNetworkCollectionInstanceGroup(L3Network l3network, InstanceGroup instanceGroup) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java index 6717c1c6bc..a9a52bd115 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java @@ -115,7 +115,7 @@ public class AAIVnfResources { AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()); - injectionHelper.getAaiClient().connect(cloudRegionURI, vnfURI); + injectionHelper.getAaiClient().connect(vnfURI,cloudRegionURI); } public void connectVnfToTenant(GenericVnf vnf, CloudRegion cloudRegion) { |