summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN
diff options
context:
space:
mode:
authorPlummer, Brittany <brittany.plummer@att.com>2019-07-05 10:23:16 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-07-05 10:23:22 -0400
commit0e2cda138f35ee6a7a8a54c29a6c4edf07d51745 (patch)
treebed0d4cdf6ad783a5a58a3f00f594d43e41902f7 /bpmn/MSOCommonBPMN
parent294a68f814de3820ae3d5fdcf976615ad233c11a (diff)
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) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy11
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy43
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java42
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java91
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDayUnitTest.java129
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java1
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderUnitTest.java98
7 files changed, 392 insertions, 23 deletions
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);
+ }
+}