From 0e2cda138f35ee6a7a8a54c29a6c4edf07d51745 Mon Sep 17 00:00:00 2001 From: "Plummer, Brittany" Date: Fri, 5 Jul 2019 10:23:16 -0400 Subject: update bpmn to save extsystemerrorsource Added ext error source to workflow exception Updated all lines that create this exception with source Added unit tests and updated existing ones Change-Id: Id9b3b1e6e24368224214a6370ea2d450ae667bfb Issue-ID: SO-2092 Signed-off-by: Benjamin, Max (mb388a) --- .../so/bpmn/common/scripts/ExceptionUtil.groovy | 11 ++ .../so/bpmn/common/scripts/VnfAdapterRestV1.groovy | 43 ++++--- .../tasks/ExecuteBuildingBlockRainyDay.java | 42 +++++++ .../onap/so/client/exception/ExceptionBuilder.java | 91 +++++++++++++- .../ExecuteBuildingBlockRainyDayUnitTest.java | 129 ++++++++++++++++++++ .../so/client/exception/ExceptionBuilderTest.java | 1 + .../client/exception/ExceptionBuilderUnitTest.java | 98 +++++++++++++++ .../org/onap/so/bpmn/core/WorkflowException.java | 27 ++++- .../BuildingBlock/ExecuteBuildingBlock.bpmn | 134 ++++++++++++--------- .../subprocess/BuildingBlock/HomingBB.bpmn | 1 + .../subprocess/BuildingBlock/WorkflowActionBB.bpmn | 1 + .../onap/so/bpmn/buildingblock/SniroHomingV2.java | 16 ++- .../network/tasks/NetworkAdapterRestV1.java | 9 +- .../infrastructure/sdnc/tasks/SDNCQueryTasks.java | 29 ++++- .../sdnc/tasks/SDNCRequestTasks.java | 21 ++-- .../workflow/tasks/WorkflowActionBBTasks.java | 1 - .../network/tasks/NetworkAdapterRestV1Test.java | 9 +- .../sdnc/tasks/SDNCQueryTasksTest.java | 73 ++++++++++- .../sdnc/tasks/SDNCRequestTasksTest.java | 3 +- 19 files changed, 626 insertions(+), 113 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayUnitTest.java create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy index d95dbe2184..c23150384e 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy @@ -34,6 +34,7 @@ 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.logger.MessageEnum +import org.onap.so.utils.TargetEntities import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -283,6 +284,16 @@ class ExceptionUtil extends AbstractServiceTaskProcessor { execution.setVariable("WorkflowException", exception); logger.debug("Outgoing WorkflowException is " + exception) } + + public void buildWorkflowException(DelegateExecution execution, int errorCode, String errorMessage, TargetEntities extSystemErrorSource) { + MsoUtils utils = new MsoUtils() + String processKey = getProcessKey(execution); + logger.debug("Building a WorkflowException for " + processKey) + + WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage, extSystemErrorSource); + execution.setVariable("WorkflowException", exception); + logger.debug("Outgoing WorkflowException is " + exception) + } /** * This error handling method builds a WorkflowException Object and throws a diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy index a769eca3a1..866229f6b8 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy @@ -40,7 +40,6 @@ import java.util.UUID - class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { private static final Logger logger = LoggerFactory.getLogger( VnfAdapterRestV1.class); @@ -81,7 +80,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no messageId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } execution.setVariable('VNFAResponse_CORRELATOR', messageId) @@ -95,7 +94,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no notificationUrl in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } execution.setVariable(prefix + 'notificationUrl', notificationUrl) @@ -109,7 +108,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': mso:adapters:vnf:rest:endpoint URN mapping is not defined' logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } while (vnfAdapterEndpoint.endsWith('/')) { @@ -127,7 +126,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vnfId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'POST' @@ -140,7 +139,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vnfId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } String vfModuleId = getChildText(root, 'vfModuleId') @@ -149,7 +148,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'PUT' @@ -163,7 +162,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vnfId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } String vfModuleId = getChildText(root, 'vfModuleId') @@ -172,7 +171,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'DELETE' @@ -186,7 +185,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vfModuleRollback in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } String vnfId = getChildText(vfModuleRollbackNode, 'vnfId') @@ -195,7 +194,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vnfId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } String vfModuleId = getChildText(vfModuleRollbackNode, 'vfModuleId') @@ -204,7 +203,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'DELETE' @@ -225,7 +224,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'PUT' @@ -241,7 +240,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'DELETE' @@ -257,7 +256,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } vnfAdapterMethod = 'DELETE' @@ -270,7 +269,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = getProcessKey(execution) + ': Unsupported request type: ' + requestType logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } execution.setVariable(prefix + 'vnfAdapterMethod', vnfAdapterMethod) @@ -307,7 +306,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } } @@ -358,7 +357,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = 'Unsupported HTTP method "' + vnfAdapterMethod + '" in ' + method + ": " + e logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } execution.setVariable(prefix + "vnfAdapterStatusCode", response.getStatus()) @@ -371,7 +370,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String msg = 'Caught exception in ' + method + ": " + e logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue()); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO) } } @@ -400,7 +399,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { } } catch (Exception e) { logger.debug("Error encountered within VnfAdapterRest ProcessCallback method: {}", e.getMessage(), e) - exceptionUtil.buildAndThrowWorkflowException(execution, 7020, "Error encountered within VnfAdapterRest ProcessCallback method") + exceptionUtil.buildAndThrowWorkflowException(execution, 7020, "Error encountered within VnfAdapterRest ProcessCallback method", TargetEntity.SO) } } @@ -419,10 +418,10 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor { String rolledBack = getChildText(root, "rolledBack") rolledBack = rolledBack == null || rolledBack.isEmpty() ? "" : " rolledBack='" + rolledBack + "'" exceptionUtil.buildWorkflowException(execution, 7020, "Received " + root.name() + - " from VnfAdapter:" + category + message + rolledBack); + " from VnfAdapter:" + category + message + rolledBack, TargetEntity.OPENSTACK); } catch (Exception e) { response = response == null || String.valueOf(response).isEmpty() ? "NONE" : response - exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response) + exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response, TargetEntity.OPENSTACK) } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java index 122e71851f..ed31e1d079 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java @@ -34,6 +34,8 @@ import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.utils.TargetEntities; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -185,4 +187,44 @@ public class ExecuteBuildingBlockRainyDay { public void setHandlingStatusSuccess(DelegateExecution execution) { execution.setVariable(HANDLING_CODE, "Success"); } + + public void updateExtSystemErrorSource(DelegateExecution execution) { + try { + String requestId = (String) execution.getVariable("mso-request-id"); + WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); + TargetEntities extSystemErrorSource = exception.getExtSystemErrorSource(); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback"); + if (isRollbackFailure == null) { + isRollbackFailure = false; + } + + if (extSystemErrorSource != null) { + String extSystemErrorSourceString = extSystemErrorSource.toString(); + if (isRollbackFailure) { + logger.debug("Updating extSystemErrorSource for isRollbackFailure to {} for request: {}", + extSystemErrorSourceString, requestId); + request.setRollbackExtSystemErrorSource(extSystemErrorSourceString); + } else { + logger.debug("Updating extSystemErrorSource to {} for request: {}", extSystemErrorSourceString, + requestId); + request.setExtSystemErrorSource(extSystemErrorSourceString); + } + } else if (isRollbackFailure) { + logger.debug( + "rollbackExtSystemErrorSource is null for isRollbackFailure. Setting rollbackExtSystemErrorSource to UNKNOWN"); + request.setRollbackExtSystemErrorSource(TargetEntity.UNKNOWN.toString()); + } else { + logger.debug("extSystemErrorSource is null. Setting extSystemErrorSource to UNKNOWN"); + request.setExtSystemErrorSource(TargetEntity.UNKNOWN.toString()); + } + + request.setLastModifiedBy("CamundaBPMN"); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + logger.error("Failed to update Request db with extSystemErrorSource or rollbackExtSystemErrorSource: " + + e.getMessage()); + } + } + } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java index d656314fd1..100887dbbc 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java @@ -43,6 +43,8 @@ import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvide import org.onap.so.logger.MessageEnum; import org.onap.so.objects.audit.AAIObjectAudit; import org.onap.so.objects.audit.AAIObjectAuditList; +import org.onap.so.utils.TargetEntities; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -89,6 +91,39 @@ public class ExceptionBuilder { buildAndThrowWorkflowException(execution, errorCode, msg); } + public void buildAndThrowWorkflowException(BuildingBlockExecution execution, int errorCode, Exception exception, + TargetEntities extSystemErrorSource) { + String msg = "Exception in %s.%s "; + try { + logger.error("Exception occurred", exception); + + String errorVariable = "Error%s%s"; + + StackTraceElement[] trace = Thread.currentThread().getStackTrace(); + for (StackTraceElement traceElement : trace) { + if (!traceElement.getClassName().equals(this.getClass().getName()) + && !traceElement.getClassName().equals(Thread.class.getName())) { + msg = String.format(msg, traceElement.getClassName(), traceElement.getMethodName()); + String shortClassName = + traceElement.getClassName().substring(traceElement.getClassName().lastIndexOf(".") + 1); + errorVariable = String.format(errorVariable, shortClassName, traceElement.getMethodName()); + break; + } + } + + logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", + ErrorCode.UnknownError.getValue(), msg.toString()); + execution.setVariable(errorVariable, exception.getMessage()); + } catch (Exception ex) { + // log trace, allow process to complete gracefully + logger.error("Exception occurred", ex); + } + + if (exception.getMessage() != null) + msg = msg.concat(exception.getMessage()); + buildAndThrowWorkflowException(execution, errorCode, msg, extSystemErrorSource); + } + public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, Exception exception) { String msg = "Exception in %s.%s "; try { @@ -120,6 +155,38 @@ public class ExceptionBuilder { buildAndThrowWorkflowException(execution, errorCode, msg); } + public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, Exception exception, + TargetEntities extSystemErrorSource) { + String msg = "Exception in %s.%s "; + try { + logger.error("Exception occurred", exception); + + String errorVariable = "Error%s%s"; + + StackTraceElement[] trace = Thread.currentThread().getStackTrace(); + for (StackTraceElement traceElement : trace) { + if (!traceElement.getClassName().equals(this.getClass().getName()) + && !traceElement.getClassName().equals(Thread.class.getName())) { + msg = String.format(msg, traceElement.getClassName(), traceElement.getMethodName()); + String shortClassName = + traceElement.getClassName().substring(traceElement.getClassName().lastIndexOf(".") + 1); + errorVariable = String.format(errorVariable, shortClassName, traceElement.getMethodName()); + break; + } + } + logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", + ErrorCode.UnknownError.getValue(), msg.toString()); + execution.setVariable(errorVariable, exception.getMessage()); + } catch (Exception ex) { + // log trace, allow process to complete gracefully + logger.error("Exception occurred", ex); + } + + if (exception.getMessage() != null) + msg = msg.concat(exception.getMessage()); + buildAndThrowWorkflowException(execution, errorCode, msg, extSystemErrorSource); + } + public void buildAndThrowWorkflowException(BuildingBlockExecution execution, int errorCode, String errorMessage) { if (execution instanceof DelegateExecutionImpl) { buildAndThrowWorkflowException(((DelegateExecutionImpl) execution).getDelegateExecution(), errorCode, @@ -127,6 +194,14 @@ public class ExceptionBuilder { } } + public void buildAndThrowWorkflowException(BuildingBlockExecution execution, int errorCode, String errorMessage, + TargetEntities extSystemErrorSource) { + if (execution instanceof DelegateExecutionImpl) { + buildAndThrowWorkflowException(((DelegateExecutionImpl) execution).getDelegateExecution(), errorCode, + errorMessage, extSystemErrorSource); + } + } + public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, String errorMessage) { String processKey = getProcessKey(execution); logger.info("Building a WorkflowException for Subflow"); @@ -139,6 +214,19 @@ public class ExceptionBuilder { throw new BpmnError("MSOWorkflowException"); } + public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, String errorMessage, + TargetEntities extSystemErrorSource) { + String processKey = getProcessKey(execution); + logger.info("Building a WorkflowException for Subflow"); + + WorkflowException exception = new WorkflowException(processKey, errorCode, errorMessage, extSystemErrorSource); + execution.setVariable("WorkflowException", exception); + execution.setVariable("WorkflowExceptionErrorMessage", errorMessage); + logger.info("Outgoing WorkflowException is {}", exception); + logger.info("Throwing MSOWorkflowException"); + throw new BpmnError("MSOWorkflowException"); + } + public void buildAndThrowWorkflowException(DelegateExecution execution, String errorCode, String errorMessage) { execution.setVariable("WorkflowExceptionErrorMessage", errorMessage); throw new BpmnError(errorCode, errorMessage); @@ -204,7 +292,8 @@ public class ExceptionBuilder { if (flowShouldContinue) { execution.setVariable("StatusMessage", errorMessage.toString()); } else { - WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString()); + WorkflowException exception = + new WorkflowException(processKey, 400, errorMessage.toString(), TargetEntity.SO); execution.setVariable("WorkflowException", exception); execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString()); logger.info("Outgoing WorkflowException is {}", exception); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayUnitTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayUnitTest.java new file mode 100644 index 0000000000..6a48558d11 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayUnitTest.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.servicedecomposition.tasks; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +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.onap.so.utils.TargetEntity; + +@RunWith(MockitoJUnitRunner.class) +public class ExecuteBuildingBlockRainyDayUnitTest { + + @Mock + private RequestsDbClient requestsDbClient; + + @InjectMocks + @Spy + private ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay; + + private DelegateExecution execution; + private DelegateExecution executionNullisRollback; + private String msoRequestId = "ef7c004b-829f-4773-a7d8-4de29feef5b1"; + private InfraActiveRequests request = new InfraActiveRequests(); + private WorkflowException exception; + private WorkflowException noExtSystemErrorSourceException; + + @Before + public void setup() { + exception = new WorkflowException("Test exception", 7000, "", "", TargetEntity.SDNC); + noExtSystemErrorSourceException = + new WorkflowException("Test exception without extsystemErrorSource", 7000, "", ""); + + execution = new DelegateExecutionFake(); + execution.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1"); + + executionNullisRollback = new DelegateExecutionFake(); + executionNullisRollback.setVariable("mso-request-id", "ef7c004b-829f-4773-a7d8-4de29feef5b1"); + } + + @Test + public void updateExtSystemErrorSourceTest() { + doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId); + doNothing().when(requestsDbClient).updateInfraActiveRequests(request); + execution.setVariable("isRollback", false); + execution.setVariable("WorkflowException", exception); + executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution); + request.setExtSystemErrorSource(TargetEntity.SDNC.toString()); + + verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request); + } + + @Test + public void updateExtSystemErrorSourceisRollbackTest() { + doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId); + doNothing().when(requestsDbClient).updateInfraActiveRequests(request); + execution.setVariable("isRollback", true); + execution.setVariable("WorkflowException", exception); + executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution); + request.setExtSystemErrorSource(TargetEntity.SDNC.toString()); + + verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request); + } + + @Test + public void updateExtSystemErrorSourceisRollbackTargetEntityNullTest() { + doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId); + doNothing().when(requestsDbClient).updateInfraActiveRequests(request); + execution.setVariable("isRollback", true); + execution.setVariable("WorkflowException", noExtSystemErrorSourceException); + executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution); + request.setExtSystemErrorSource(TargetEntity.UNKNOWN.toString()); + + verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request); + } + + @Test + public void updateExtSystemErrorSourceTargetEntityNullTest() { + doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId); + doNothing().when(requestsDbClient).updateInfraActiveRequests(request); + execution.setVariable("isRollback", false); + execution.setVariable("WorkflowException", noExtSystemErrorSourceException); + executeBuildingBlockRainyDay.updateExtSystemErrorSource(execution); + request.setExtSystemErrorSource(TargetEntity.UNKNOWN.toString()); + + verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request); + } + + @Test + public void updateExtSystemErrorSourceTargetEntityisRollbackNullTest() { + doReturn(request).when(requestsDbClient).getInfraActiveRequestbyRequestId(msoRequestId); + doNothing().when(requestsDbClient).updateInfraActiveRequests(request); + executionNullisRollback.setVariable("WorkflowException", exception); + executeBuildingBlockRainyDay.updateExtSystemErrorSource(executionNullisRollback); + request.setExtSystemErrorSource(TargetEntity.SDNC.toString()); + + verify(requestsDbClient, Mockito.times(1)).updateInfraActiveRequests(request); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java index 5f9aef67e6..aae62445de 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java @@ -55,6 +55,7 @@ public class ExceptionBuilderTest extends BaseTest { @Mock protected ExtractPojosForBB extractPojosForBB; + @Spy @InjectMocks private ExceptionBuilder exceptionBuilder = new ExceptionBuilder(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java new file mode 100644 index 0000000000..b109ae258d --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.exception; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.utils.TargetEntity; + +@RunWith(MockitoJUnitRunner.class) +public class ExceptionBuilderUnitTest { + @Mock + private BuildingBlockExecution buildingBlockExecution; + + @InjectMocks + @Spy + private ExceptionBuilder exceptionBuilder; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Exception e = new Exception("failure message"); + private DelegateExecution execution; + + @Before + public void setup() { + execution = new DelegateExecutionFake(); + } + + + @Test + public void buildAndThrowWorkflowExceptionTest() { + String expectedErrorMessage = + "Exception in org.onap.so.client.exception.ExceptionBuilder.buildAndThrowWorkflowException failure message"; + doNothing().when(exceptionBuilder).buildAndThrowWorkflowException(execution, 7000, expectedErrorMessage, + TargetEntity.SDNC); + + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e, TargetEntity.SDNC); + + verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(execution, 7000, expectedErrorMessage, + TargetEntity.SDNC); + } + + @Test + public void buildAndThrowWorkflowExceptionBuildingBlockExecutionTest() { + String expectedErrorMessage = + "Exception in org.onap.so.client.exception.ExceptionBuilder.buildAndThrowWorkflowException failure message"; + doNothing().when(exceptionBuilder).buildAndThrowWorkflowException(buildingBlockExecution, 7000, + expectedErrorMessage, TargetEntity.SDNC); + + exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, e, TargetEntity.SDNC); + + verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(buildingBlockExecution, 7000, + expectedErrorMessage, TargetEntity.SDNC); + } + + @Test + public void buildAndThrowWorkflowExceptionWithErrorMessageTest() { + doReturn("Process key").when(exceptionBuilder).getProcessKey(execution); + + thrown.expect(BpmnError.class); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), TargetEntity.SDNC); + } +} diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java index 1692045d33..7d5bb0dcf1 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.core; import java.io.Serializable; +import org.onap.so.utils.TargetEntities; /** * An object that represents a workflow exception. @@ -32,6 +33,7 @@ public class WorkflowException implements Serializable { private final int errorCode; private final String errorMessage; private final String workStep; + private TargetEntities extSystemErrorSource; /** * Constructor @@ -47,6 +49,15 @@ public class WorkflowException implements Serializable { workStep = "*"; } + public WorkflowException(String processKey, int errorCode, String errorMessage, + TargetEntities extSystemErrorSource) { + this.processKey = processKey; + this.errorCode = errorCode; + this.errorMessage = errorMessage; + workStep = "*"; + this.extSystemErrorSource = extSystemErrorSource; + } + public WorkflowException(String processKey, int errorCode, String errorMessage, String workStep) { this.processKey = processKey; this.errorCode = errorCode; @@ -54,6 +65,15 @@ public class WorkflowException implements Serializable { this.workStep = workStep; } + public WorkflowException(String processKey, int errorCode, String errorMessage, String workStep, + TargetEntities extSystemErrorSource) { + this.processKey = processKey; + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.workStep = workStep; + this.extSystemErrorSource = extSystemErrorSource; + } + /** * Returns the process key. */ @@ -82,12 +102,17 @@ public class WorkflowException implements Serializable { return workStep; } + public TargetEntities getExtSystemErrorSource() { + return extSystemErrorSource; + } + /** * Returns a string representation of this object. */ @Override public String toString() { return getClass().getSimpleName() + "[processKey=" + getProcessKey() + ",errorCode=" + getErrorCode() - + ",errorMessage=" + getErrorMessage() + ",workStep=" + getWorkStep() + "]"; + + ",errorMessage=" + getErrorMessage() + ",workStep=" + getWorkStep() + ",extSystemErrorSource=" + + extSystemErrorSource + "]"; } } diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn index 0a6a7731ce..e64c44eb94 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ExecuteBuildingBlock.bpmn @@ -11,6 +11,7 @@ + SequenceFlow_19wuics SequenceFlow_01h9qmz @@ -37,13 +38,8 @@ - - SequenceFlow_09synl9 - - - - SequenceFlow_09synl9 + SequenceFlow_0vdeqxv SequenceFlow_0a62t4c @@ -93,6 +89,16 @@ SequenceFlow_0541bid SequenceFlow_12ps9at + + + + SequenceFlow_09synl9 + + + + SequenceFlow_09synl9 + SequenceFlow_0vdeqxv + @@ -163,63 +169,63 @@ - + - + - + - + - + - + - - + + - + - - + + - + - - + + - + - + - - + + - + - - + + - + - + @@ -245,38 +251,25 @@ - - + + - + - - - - - - - + - - - - - - - - + - + - + - + @@ -319,27 +312,50 @@ - - + + - + - - + + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn index b66ecfa329..11227ede4d 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HomingBB.bpmn @@ -50,6 +50,7 @@ ex.processJavaException(execution)]]> + SequenceFlow_0qrwjzu SequenceFlow_03cy5y5 diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn index 35b77d9189..47b9efeb6d 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn @@ -23,6 +23,7 @@ + SequenceFlow_0mew9im SequenceFlow_1hsqed1 diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index e5df3d3f35..f1fd23fe82 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -65,6 +65,7 @@ import org.onap.so.client.sniro.beans.ServiceInfo; import org.onap.so.client.sniro.beans.SniroManagerRequest; import org.onap.so.client.sniro.beans.SubscriberInfo; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -160,14 +161,15 @@ public class SniroHomingV2 { logger.trace("Completed Sniro Homing Call Sniro"); } catch (BpmnError e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), + TargetEntity.SNIRO); } catch (BadResponseException e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), TargetEntity.SNIRO); } catch (Exception e) { logger.error(EXCEPTION_OCCURRED, e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, - "Internal Error - occurred while preparing sniro request: " + e.getMessage()); + "Internal Error - occurred while preparing sniro request: " + e.getMessage(), TargetEntity.SO); } } @@ -211,14 +213,16 @@ public class SniroHomingV2 { logger.trace("Completed Sniro Homing Process Solution"); } catch (BpmnError e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), + TargetEntity.SNIRO); } catch (BadResponseException e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), TargetEntity.SNIRO); } catch (Exception e) { logger.error(EXCEPTION_OCCURRED, e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, - "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage()); + "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage(), + TargetEntity.SO); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java index 859db11037..e9d33f46ab 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java @@ -38,6 +38,7 @@ import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.NetworkAdapterResources; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -93,7 +94,7 @@ public class NetworkAdapterRestV1 { throw new Exception("No Network Request was created. networkAdapterRequest was null."); } } catch (Exception ex) { - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } @@ -138,7 +139,7 @@ public class NetworkAdapterRestV1 { } } catch (Exception e) { logger.error("Error in Openstack Adapter callback", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), TargetEntity.OPENSTACK); } } @@ -151,7 +152,7 @@ public class NetworkAdapterRestV1 { public void handleTimeOutException(DelegateExecution execution) { exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Error timed out waiting on Openstack Async-Response"); + "Error timed out waiting on Openstack Async-Response", TargetEntity.SO); } public void handleSyncError(DelegateExecution execution) { @@ -159,6 +160,6 @@ public class NetworkAdapterRestV1 { String responseString = (String) execution.getVariable(NETWORK_SYNC_RESPONSE); String errorMessage = "Error with Openstack Adapter Sync Request: StatusCode = " + statusCode + " Response = " + responseString; - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage, TargetEntity.OPENSTACK); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java index fcc67d0ef7..9bbe94a077 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java @@ -29,8 +29,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.SDNCVnfResources; +import org.onap.so.utils.TargetEntity; import org.onap.so.client.orchestration.SDNCVfModuleResources; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +41,8 @@ import org.springframework.stereotype.Component; @Component public class SDNCQueryTasks { - + private static final Logger logger = LoggerFactory.getLogger(SDNCQueryTasks.class); + private static final String NO_RESPONSE_FROM_SDNC = "Error did not receive a response from SDNC."; public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; @Autowired private SDNCVnfResources sdncVnfResources; @@ -63,8 +66,14 @@ public class SDNCQueryTasks { } String response = sdncVnfResources.queryVnf(genericVnf); execution.setVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId(), response); + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); + } } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } @@ -88,6 +97,12 @@ public class SDNCQueryTasks { throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value"); } + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); + } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } @@ -109,10 +124,16 @@ public class SDNCQueryTasks { // If we see a bb object not found exception for something that is not a vf module id, then we should throw // the error as normal if (!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException, TargetEntity.SO); + } + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java index cb761f4110..03714db943 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -37,6 +37,7 @@ import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -79,17 +80,19 @@ public class SDNCRequestTasks { } catch (PathNotFoundException e) { logger.error("Error Parsing SDNC Response. Could not find read final ack indicator from JSON.", e); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Recieved invalid response from SDNC, unable to read message content."); + "Recieved invalid response from SDNC, unable to read message content.", TargetEntity.SO); } catch (MapperException e) { logger.error("Failed to map SDNC object to JSON prior to POST.", e); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Failed to map SDNC object to JSON prior to POST."); + "Failed to map SDNC object to JSON prior to POST.", TargetEntity.SO); } catch (BadResponseException e) { logger.error("Did not receive a successful response from SDNC.", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getLocalizedMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getLocalizedMessage(), + TargetEntity.SDNC); } catch (HttpClientErrorException e) { logger.error("HttpClientErrorException: 404 Not Found, Failed to contact SDNC", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "SDNC cannot be contacted."); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "SDNC cannot be contacted.", + TargetEntity.SO); } } @@ -120,16 +123,17 @@ public class SDNCRequestTasks { } } catch (SDNCErrorResponseException e) { logger.error("SDNC error response - " + e.getMessage()); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), TargetEntity.SDNC); } catch (Exception e) { - logger.error("Error procesing SDNC callback", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error procesing SDNC callback"); + logger.error("Error processing SDNC callback", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error processing SDNC callback", + TargetEntity.SO); } } public void handleTimeOutException(DelegateExecution execution) { exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Error timed out waiting on SDNC Async-Response"); + "Error timed out waiting on SDNC Async-Response", TargetEntity.SO); } protected boolean convertIndicatorToBoolean(String finalMessageIndicator) { @@ -149,5 +153,4 @@ public class SDNCRequestTasks { } return result; } - } 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 44152fcaf4..a17556f091 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 @@ -312,7 +312,6 @@ public class WorkflowActionBBTasks { } workflowActionBBFailure.updateRequestErrorStatusMessage(execution); - if (rollbackFlows.isEmpty()) execution.setVariable("isRollbackNeeded", false); else diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java index d0cee42178..8aea2d2650 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -39,12 +39,14 @@ import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; +import org.onap.so.utils.TargetEntity; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -110,8 +112,9 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); delegateExecution.setVariable("NetworkAResponse_MESSAGE", updateNetworkResponse.toXmlString()); - doThrow(new BpmnError("MSOWorkflowException")).when(exceptionBuilder) - .buildAndThrowWorkflowException(any(DelegateExecution.class), anyInt(), any(String.class)); + doThrow(new BpmnError("MSOWorkflowException")).when(exceptionBuilder).buildAndThrowWorkflowException( + any(DelegateExecution.class), anyInt(), any(String.class), any(TargetEntity.class)); + try { networkAdapterRestV1Tasks.processCallback(delegateExecution); } catch (BpmnError be) { @@ -119,6 +122,6 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { } assertNull(delegateExecution.getVariable("updateNetworkResponse")); verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(any(DelegateExecution.class), eq(7000), - eq("test error message")); + eq("test error message"), eq(TargetEntity.OPENSTACK)); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java index 3ea8474b24..0ba9237aaf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java @@ -43,6 +43,9 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.utils.TargetEntities; +import org.onap.so.utils.TargetEntity; public class SDNCQueryTasksTest extends BaseTaskTest { @InjectMocks @@ -61,8 +64,8 @@ public class SDNCQueryTasksTest extends BaseTaskTest { genericVnf = setGenericVnf(); vfModule = setVfModule(); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) - .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException( + any(BuildingBlockExecution.class), eq(7000), any(Exception.class), any(TargetEntities.class)); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); @@ -87,6 +90,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule); } + @Test + public void queryVfModuleBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModule(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVfModuleResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModule(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + @Test public void queryVnfTest() throws Exception { String sdncQueryResponse = "response"; @@ -100,6 +125,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { verify(sdncVnfResources, times(1)).queryVnf(genericVnf); } + @Test + public void queryVnfBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVnfResources).queryVnf(genericVnf); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVnf(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVnfBadResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVnfResources).queryVnf(genericVnf); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVnf(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + @Test public void queryVfModuleForVolumeGroupTest() throws Exception { String sdncQueryResponse = "response"; @@ -114,6 +161,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule); } + @Test + public void queryVfModuleForVolumeGroupBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVfModuleForVolumeGroupBadResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + @Test public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception { expectedException.expect(BpmnError.class); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java index 6a94b357e0..0fc33fe5ce 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import java.io.IOException; @@ -48,6 +49,7 @@ import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.utils.TargetEntity; import org.w3c.dom.Document; import org.xml.sax.InputSource; import com.fasterxml.jackson.core.JsonParseException; @@ -66,7 +68,6 @@ public class SDNCRequestTasksTest extends SDNCRequestTasks { @Mock SDNCClient sdncClient; - @Spy private ExceptionBuilder exceptionBuilder; -- cgit 1.2.3-korg