aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/java/org
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-05-09 03:55:30 -0700
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-05-09 05:18:51 -0700
commitb1e5734ef566af5d49ba17d05ca0ab7b56d6666d (patch)
tree92a232e908ae587cb244fd102e9c2c5648c66a9f /bpmn/MSOCommonBPMN/src/main/java/org
parentd4f2190943216278826f39e7010d57f872bda90d (diff)
[MSO-8] Additional fixes for the second rebase
DB fixes + BPMN flows and groovy fixes + Fix issue with CloudConfig file not reloaded properly when it's wrong (JSON error or model hierarchy mistake) at MSO startup Change-Id: I2853030b78499e2a761706b643ea210955e72de3 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com> [MSO-8] Restore files removed in patch set 2 Those groovy files must be there Change-Id: I9a47ac3d9c8fc06774a1b8f518491b1b0b00af04 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/AbstractCallbackService.java352
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/SDNCAdapterCallbackServiceImpl.java235
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java763
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java103
4 files changed, 639 insertions, 814 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/AbstractCallbackService.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/AbstractCallbackService.java
new file mode 100644
index 0000000000..214ae28b70
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/AbstractCallbackService.java
@@ -0,0 +1,352 @@
+package org.openecomp.mso.bpmn.common.workflow.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.camunda.bpm.BpmPlatform;
+import org.camunda.bpm.engine.MismatchingMessageCorrelationException;
+import org.camunda.bpm.engine.ProcessEngineServices;
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.runtime.Execution;
+import org.camunda.bpm.engine.runtime.MessageCorrelationResult;
+import org.openecomp.mso.bpmn.core.PropertyConfiguration;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+/**
+ * Abstract base class for callback services.
+ */
+public abstract class AbstractCallbackService {
+ public static final long DEFAULT_TIMEOUT_SECONDS = 60;
+ public static final long FAST_POLL_DUR_SECONDS = 5;
+ public static final long FAST_POLL_INT_MS = 100;
+ public static final long SLOW_POLL_INT_MS = 1000;
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
+
+ protected volatile ProcessEngineServices pes4junit = null;
+
+ /**
+ * Parameterized callback handler.
+ */
+ protected CallbackResult handleCallback(String method, Object message,
+ String messageEventName, String messageVariable,
+ String correlationVariable, String correlationValue,
+ String logMarker) {
+
+ return handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker, null);
+ }
+
+ /**
+ * Parameterized callback handler.
+ */
+ protected CallbackResult handleCallback(String method, Object message,
+ String messageEventName, String messageVariable,
+ String correlationVariable, String correlationValue,
+ String logMarker, Map<String, Object> injectedVariables) {
+
+ long startTime = System.currentTimeMillis();
+
+ LOGGER.debug(logMarker + " " + method + " received message: "
+ + (message == null ? "" : System.lineSeparator()) + message);
+
+ try {
+ Map<String, Object> variables = new HashMap<String, Object>();
+
+ if (injectedVariables != null) {
+ variables.putAll(injectedVariables);
+ }
+
+ variables.put(correlationVariable, correlationValue);
+ variables.put(messageVariable, message == null ? null : message.toString());
+
+ boolean ok = correlate(messageEventName, correlationVariable,
+ correlationValue, variables, logMarker);
+
+ if (!ok) {
+ String msg = "No process is waiting for " + messageEventName
+ + " with " + correlationVariable + " = '" + correlationValue + "'";
+ logCallbackError(method, startTime, msg);
+ return new CallbackError(msg);
+ }
+
+ logCallbackSuccess(method, startTime);
+ return new CallbackSuccess();
+ } catch (Exception e) {
+ String msg = "Caught " + e.getClass().getSimpleName()
+ + " processing " + messageEventName + " with " + correlationVariable
+ + " = '" + correlationValue + "'";
+ logCallbackError(method, startTime, msg);
+ return new CallbackError(msg);
+ }
+ }
+
+ /**
+ * Performs message correlation. Waits a limited amount of time for
+ * a process to become ready for correlation. The return value indicates
+ * whether or not a process was found to receive the message. Due to the
+ * synchronous nature of message injection in Camunda, by the time this
+ * method returns, one of 3 things will have happened: (1) the process
+ * received the message and ended, (2) the process received the message
+ * and reached an activity that suspended, or (3) an exception occurred
+ * during correlation or while the process was executing. Correlation
+ * exceptions are handled differently from process execution exceptions.
+ * Correlation exceptions are thrown so the client knows something went
+ * wrong with the delivery of the message. Process execution exceptions
+ * are logged but not thrown.
+ * @param messageEventName the message event name
+ * @param correlationVariable the process variable used as the correlator
+ * @param correlationValue the correlation value
+ * @param variables variables to inject into the process
+ * @param logMarker a marker for debug logging
+ * @return true if a process could be found, false if not
+ * @throws Exception for correlation errors
+ */
+ protected boolean correlate(String messageEventName, String correlationVariable,
+ String correlationValue, Map<String, Object> variables, String logMarker)
+ throws Exception {
+
+ LOGGER.debug(logMarker + " Attempting to find process waiting"
+ + " for " + messageEventName + " with " + correlationVariable
+ + " = '" + correlationValue + "'");
+
+ RuntimeService runtimeService =
+ getProcessEngineServices().getRuntimeService();
+
+ Map<String, String> properties =
+ PropertyConfiguration.getInstance().getProperties("mso.bpmn.urn.properties");
+
+ long timeout = DEFAULT_TIMEOUT_SECONDS;
+
+ // The code is here in case we ever need to change the default.
+ String s = properties.get("mso.correlation.timeout");
+ if (s != null) {
+ try {
+ timeout = Long.parseLong(s);
+ } catch (NumberFormatException e) {
+ // Ignore
+ }
+ }
+
+ long now = System.currentTimeMillis();
+ long fastPollEndTime = now + (FAST_POLL_DUR_SECONDS * 1000);
+ long endTime = now + (timeout * 1000);
+ long sleep = FAST_POLL_INT_MS;
+
+ List<Execution> waitingProcesses = null;
+ Exception queryException = null;
+ int queryCount = 0;
+ int queryFailCount = 0;
+
+ while (true) {
+ try {
+ ++queryCount;
+ waitingProcesses = runtimeService.createExecutionQuery()
+ .messageEventSubscriptionName(messageEventName)
+ .processVariableValueEquals(correlationVariable, correlationValue)
+ .list();
+ } catch (Exception e) {
+ ++queryFailCount;
+ queryException = e;
+ }
+
+ if (waitingProcesses != null && waitingProcesses.size() > 0) {
+ break;
+ }
+
+ if (now > endTime - sleep) {
+ break;
+ }
+
+ Thread.sleep(sleep);
+ now = System.currentTimeMillis();
+
+ if (now > fastPollEndTime) {
+ sleep = SLOW_POLL_INT_MS;
+ }
+ }
+
+ if (waitingProcesses == null) {
+ waitingProcesses = new ArrayList<Execution>(0);
+ }
+
+ int count = waitingProcesses.size();
+
+ List<ExecInfo> execInfoList = new ArrayList<ExecInfo>(count);
+ for (Execution execution : waitingProcesses) {
+ execInfoList.add(new ExecInfo(execution));
+ }
+
+ LOGGER.debug(logMarker + " Found " + count + " process(es) waiting"
+ + " for " + messageEventName + " with " + correlationVariable
+ + " = '" + correlationValue + "': " + execInfoList);
+
+ if (count == 0) {
+ if (queryFailCount > 0) {
+ String msg = queryFailCount + "/" + queryCount
+ + " execution queries failed attempting to correlate "
+ + messageEventName + " with " + correlationVariable
+ + " = '" + correlationValue + "'; last exception was:"
+ + queryException;
+ LOGGER.debug(msg);
+ LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.UnknownError, msg, queryException);
+ }
+
+ return false;
+ }
+
+ if (count > 1) {
+ // Only one process should be waiting. Throw an exception back to the client.
+ throw new MismatchingMessageCorrelationException(messageEventName,
+ "more than 1 process is waiting with " + correlationVariable
+ + " = '" + correlationValue + "'");
+ }
+
+ // We prototyped an asynchronous solution, i.e. resuming the process
+ // flow in a separate thread, but this affected too many existing tests,
+ // and we went back to the synchronous solution. The synchronous solution
+ // has some troublesome characteristics though. For example, the
+ // resumed flow may send request #2 to a remote system before MSO has
+ // acknowledged the notification associated with request #1.
+
+ try {
+ LOGGER.debug(logMarker + " Running " + execInfoList.get(0) + " to receive "
+ + messageEventName + " with " + correlationVariable + " = '"
+ + correlationValue + "'");
+
+ @SuppressWarnings("unused")
+ MessageCorrelationResult result = runtimeService
+ .createMessageCorrelation(messageEventName)
+ .setVariables(variables)
+ .processInstanceVariableEquals(correlationVariable, correlationValue)
+ .correlateWithResult();
+
+ } catch (MismatchingMessageCorrelationException e) {
+ // A correlation exception occurred even after we identified
+ // one waiting process. Throw it back to the client.
+ throw e;
+ } catch (Exception e) {
+ // This must be an exception from the flow itself. Log it, but don't
+ // report it back to the client.
+ String msg = "Caught " + e.getClass().getSimpleName() + " running "
+ + execInfoList.get(0) + " after receiving " + messageEventName
+ + " with " + correlationVariable + " = '" + correlationValue
+ + "': " + e;
+ LOGGER.debug(msg);
+ LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.UnknownError, msg, e);
+ }
+
+ return true;
+ }
+
+ /**
+ * Records audit and metric events in the log for a callback success.
+ * @param method the method name
+ * @param startTime the request start time
+ */
+ protected void logCallbackSuccess(String method, long startTime) {
+ LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE,
+ MsoLogger.ResponseCode.Suc, "Completed " + method);
+
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE,
+ MsoLogger.ResponseCode.Suc, "Completed " + method,
+ "BPMN", MsoLogger.getServiceName(), null);
+ }
+
+ /**
+ * Records error, audit and metric events in the log for a callback
+ * internal error.
+ * @param method the method name
+ * @param startTime the request start time
+ * @param msg the error message
+ */
+ protected void logCallbackError(String method, long startTime, String msg) {
+ logCallbackError(method, startTime, msg, null);
+ }
+
+ /**
+ * Records error, audit and metric events in the log for a callback
+ * internal error.
+ * @param method the method name
+ * @param startTime the request start time
+ * @param msg the error message
+ * @param e the exception
+ */
+ protected void logCallbackError(String method, long startTime, String msg, Exception e) {
+ if (e == null) {
+ LOGGER.error(MessageEnum.BPMN_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.UnknownError, msg);
+ } else {
+ LOGGER.error(MessageEnum.BPMN_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.UnknownError, msg, e);
+ }
+
+ LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE,
+ MsoLogger.ResponseCode.InternalError, "Completed " + method);
+
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE,
+ MsoLogger.ResponseCode.InternalError, "Completed " + method,
+ "BPMN", MsoLogger.getServiceName(), null);
+ }
+
+ /**
+ * Abstract callback result object.
+ */
+ protected abstract class CallbackResult {
+ }
+
+ /**
+ * Indicates that callback handling was successful.
+ */
+ protected class CallbackSuccess extends CallbackResult {
+ }
+
+ /**
+ * Indicates that callback handling failed.
+ */
+ protected class CallbackError extends CallbackResult {
+ private final String errorMessage;
+
+ public CallbackError(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ /**
+ * Gets the error message.
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+ }
+
+ private static class ExecInfo {
+ private final Execution execution;
+
+ public ExecInfo(Execution execution) {
+ this.execution = execution;
+ }
+
+ @Override
+ public String toString() {
+ return "Process[" + execution.getProcessInstanceId()
+ + ":" + execution.getId() + "]";
+ }
+ }
+
+ protected ProcessEngineServices getProcessEngineServices() {
+ if (pes4junit == null) {
+ return BpmPlatform.getDefaultProcessEngine();
+ } else {
+ return pes4junit;
+ }
+ }
+
+ public void setProcessEngineServices4junit(ProcessEngineServices pes) {
+ pes4junit = pes;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/SDNCAdapterCallbackServiceImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/SDNCAdapterCallbackServiceImpl.java
index 4585d620ac..16fa51515e 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/SDNCAdapterCallbackServiceImpl.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/SDNCAdapterCallbackServiceImpl.java
@@ -41,240 +41,53 @@ import org.openecomp.mso.bpmn.common.adapter.sdnc.SDNCCallbackAdapterPortType;
import org.openecomp.mso.bpmn.core.PropertyConfiguration;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
+
/**
- * @version 1.0
- *
+ * Implementation of SDNCAdapterCallbackService.
*/
@WebService(serviceName="SDNCAdapterCallbackService", targetNamespace="http://org.openecomp/workflow/sdnc/adapter/schema/v1")
-public class SDNCAdapterCallbackServiceImpl implements SDNCCallbackAdapterPortType {
-
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
- private final int DEFAULT_RETRY_ATTEMPTS = 60;
- private final int DEFAULT_SLEEP_TIME = 500;
+public class SDNCAdapterCallbackServiceImpl extends AbstractCallbackService implements SDNCCallbackAdapterPortType {
private final String logMarker = "[SDNC-CALLBACK]";
@Context WebServiceContext wsContext;
- private volatile ProcessEngineServices pes4junit = null;
-
@WebMethod(operationName = "SDNCAdapterCallback")
@WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.openecomp/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackResponse")
public SDNCAdapterResponse sdncAdapterCallback(
@WebParam(name = "SDNCAdapterCallbackRequest", targetNamespace = "http://org.openecomp/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackRequest")
SDNCAdapterCallbackRequest sdncAdapterCallbackRequest) {
- //Callback URL to use http://localhost:28080/mso/SDNCAdapterCallbackService
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
- String receivedRequestId = sdncAdapterCallbackRequest.getCallbackHeader().getRequestId();
- MsoLogger.setServiceName("MSO." + "sdncAdapter");
- MsoLogger.setLogContext(receivedRequestId, "N/A");
- msoLogger.debug(logMarker + "Received callback response:" + sdncAdapterCallbackRequest.toString());
- SDNCAdapterResponse sdncAdapterResponse;
- long startTime = System.currentTimeMillis();
-
- /*Correlating the response with the running instance*/
-
- // NOTE: the following loop is a workaround for problems we've had
- // with reliability of the runtime service. It seems that queries
- // sometimes return results, and sometimes they don't. This might
- // be a problem in mysql only. We aren't sure if it affects camunda
- // on oracle or mariadb. The workaround is to repeat the request
- // a number of times until it succeeds. If it doesn't succeed after
- // 60 tries, then we give up.
-
- int maxAttempts = DEFAULT_RETRY_ATTEMPTS;
- int attempt = 1;
- int sleepTime = DEFAULT_SLEEP_TIME;
+ String method = "sdncAdapterCallback";
+ Object message = sdncAdapterCallbackRequest;
+ String messageEventName = "sdncAdapterCallbackRequest";
+ String messageVariable = "sdncAdapterCallbackRequest";
+ String correlationVariable = "SDNCA_requestId";
+ String correlationValue = sdncAdapterCallbackRequest.getCallbackHeader().getRequestId();
- Map<String,String> bpmnProperties = getMSOBPMNURNProperties();
- if (bpmnProperties != null) {
- try {
- maxAttempts = Integer.parseInt(bpmnProperties.get("mso.callbackRetryAttempts"));
- msoLogger.debug(logMarker + "mso.callbackRetryAttempts=" + maxAttempts);
- sleepTime = Integer.parseInt(bpmnProperties.get("mso.callbackRetrySleepTime"));
- msoLogger.debug(logMarker + "mso.callbackRetrySleepTime:" + sleepTime);
- } catch (Exception ex) {
-
- msoLogger.debug (logMarker
- + "Error parsing mso.callbackRetrySleepTime/mso.callbackRetryAttempts:"
- + sleepTime + ":"
- + maxAttempts);
-
- }
- }
-
- /* Check to make sure the process instance is reay for correlation*/
- try{
- isReadyforCorrelation(runtimeService, receivedRequestId, maxAttempts, sleepTime );
- }catch(Exception e){
- String msg =
- "SDNC Adapter Callback Service received a SDNC Adapter Callback Request with RequestId '"
- + receivedRequestId
- + "' but that RequestId doesn't exist or has timed out waiting for the callback";
- sdncAdapterResponse = new SDNCAdapterExceptionResponse(e);
-
- msoLogger.error (MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, logMarker
- + "Completed the execution of MSO SDNCAdapterCallbackService." );
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO SDNCAdapterCallbackService.", "BPMN",
- MsoLogger.getServiceName(), "sdncAdapterCallback");
-
- return sdncAdapterResponse;
- }
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlationValue, "N/A");
- msoLogger.debug(logMarker + "*** Received MSO sdncAdapterCallbackService ******");
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO sdncAdapterCallbackService");
-
- msoLogger.debug(logMarker + "Callback response string:\n" + sdncAdapterCallbackRequest.toString());
+ CallbackResult result = handleCallback(method, message, messageEventName,
+ messageVariable, correlationVariable, correlationValue, logMarker);
- String reqId = receivedRequestId;
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("SDNCA_requestId", reqId );
- variables.put("sdncAdapterCallbackRequest", sdncAdapterCallbackRequest.toString());
- while (true) {
- try {
- // sdncAdapterCallbackRequest is the message event name (defined in the bpmn process)
- runtimeService.createMessageCorrelation("sdncAdapterCallbackRequest")
- .setVariables(variables)
- .processInstanceVariableEquals("SDNCA_requestId", reqId).correlate();
- sdncAdapterResponse = new SDNCAdapterResponse();
- msoLogger.debug(logMarker + "***** Completed processing of MSO sdncAdapterCallbackService ******");
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, logMarker
- + "Completed the execution of MSO SDNCAdapterCallbackService.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO SDNCAdapterCallbackService.", "BPMN",
- MsoLogger.getServiceName(), "sdncAdapterCallback");
-
- return sdncAdapterResponse;
- } catch(MismatchingMessageCorrelationException e) {
- msoLogger.debug(logMarker + "[CORM]correlation id mismatch (attempt " + attempt + "/" + maxAttempts + ")");
- if (attempt == maxAttempts) {
- // Couldn't correlate requestId to any active flow
- //MsoLogger logger = MsoLogger.getMsoLogger("SDNCAdapterCallbackService");
- String msg =
- "SDNC Adapter Callback Service received a SDNC Adapter Callback Request with RequestId '"
- + receivedRequestId
- + "' but that RequestId could not be correlated to any active process - ignoring the Request";
- sdncAdapterResponse = new SDNCAdapterExceptionResponse(e);
-
- msoLogger.error (MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, logMarker
- + "Completed the execution of MSO SDNCAdapterCallbackService." );
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO SDNCAdapterCallbackService.", "BPMN",
- MsoLogger.getServiceName(), "sdncAdapterCallback");
-
- return sdncAdapterResponse;
- }
-
- try {
- Thread.sleep(sleepTime);
- } catch (InterruptedException e2) {
- String msg =
- "SDNC Adapter Callback Service received a SDNC Adapter Callback Request with RequestId '"
- + receivedRequestId
- + "' but correlation was interrupted";
- sdncAdapterResponse = new SDNCAdapterExceptionResponse(e);
-
- msoLogger.error (MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, logMarker
- + "Completed the execution of MSO SDNCAdapterCallbackService.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO SDNCAdapterCallbackService.", "BPMN",
- MsoLogger.getServiceName(), "sdncAdapterCallback");
-
- return sdncAdapterResponse;
- }
- }
-
- attempt++;
- }
- }
-
-
- private Map<String,String> getMSOBPMNURNProperties() {
- PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
- Map<String,String> props = propertyConfiguration.getProperties("mso.bpmn.urn.properties");
- return props;
- }
-
- private void isReadyforCorrelation(RuntimeService runtimeService,
- String receivedRequestId, int retries, int sleepTime){
- ExecutionQuery waitingInstances = null;
- long waitingInstancesCount = 0;
-
- //Workaround for performance testing, explicit wait for a second for the transactions to be committed
- //Also check to make sure the process didn't timeout before trying to correlate
-
- do{
- waitingInstances = runtimeService.createExecutionQuery() //
- .messageEventSubscriptionName("sdncAdapterCallbackRequest")
- .processVariableValueEquals("SDNCA_requestId", receivedRequestId);
- waitingInstancesCount = waitingInstances.count();
- retries--;
- msoLogger.debug(logMarker + "waitingInstancesCount: " + waitingInstancesCount);
- try {
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
-
- msoLogger.error (MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker, e);
-
- }
- }while (waitingInstancesCount==0 && retries > 0);
- if(waitingInstancesCount > 0){
- msoLogger.debug(logMarker + "waitingInstancesCount before timeout check: " + waitingInstancesCount);
- waitingInstancesCount = waitingInstances.processVariableValueEquals("asynchronousResponseTimeout", false).count();
- msoLogger.debug(logMarker + "waitingInstancesCount after timeout check: " + waitingInstancesCount);
- if(waitingInstancesCount<=0){
- msoLogger.debug(logMarker + "detected timeout on flow to correlate");
- throw new IllegalStateException("process timed out");
- }
- }else{
- //flow may have already ended, so can't check timeout variable. Throw exception?
- msoLogger.debug(logMarker + "no flow to correlate to");
- throw new IllegalStateException("no flow to correlate to");
- }
- }
-
- private ProcessEngineServices getProcessEngineServices() {
- if (pes4junit == null) {
- return BpmPlatform.getDefaultProcessEngine();
+ if (result instanceof CallbackError) {
+ return new SDNCAdapterErrorResponse(((CallbackError)result).getErrorMessage());
} else {
- return pes4junit;
+ return new SDNCAdapterResponse();
}
}
- @WebMethod(exclude=true)
- public void setProcessEngineServices4junit(ProcessEngineServices pes) {
- pes4junit = pes;
- }
-
- public class SDNCAdapterExceptionResponse extends SDNCAdapterResponse {
- private Exception ex;
+ // This subclass allows unit tests to extract the error
+ public class SDNCAdapterErrorResponse extends SDNCAdapterResponse {
+ private String error;
- public SDNCAdapterExceptionResponse(Exception ex) {
- super();
- this.ex = ex;
+ public SDNCAdapterErrorResponse(String error) {
+ this.error = error;
}
- public Exception getException() {
- return ex;
+ public String getError() {
+ return error;
}
}
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java
index 457717243a..0faf5feafc 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java
@@ -1,536 +1,249 @@
-/*-
- * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
- * ================================================================================
- * Copyright (C) 2017 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.openecomp.mso.bpmn.common.workflow.service;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jws.Oneway;
-import javax.jws.WebMethod;
-import javax.jws.WebParam;
-import javax.jws.WebService;
-import javax.ws.rs.core.Context;
-import javax.xml.ws.Action;
-import javax.xml.ws.RequestWrapper;
-import javax.xml.ws.WebServiceContext;
-
-import org.camunda.bpm.BpmPlatform;
-import org.camunda.bpm.engine.MismatchingMessageCorrelationException;
-import org.camunda.bpm.engine.ProcessEngineServices;
-import org.camunda.bpm.engine.RuntimeService;
-import org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification;
-import org.openecomp.mso.bpmn.common.adapter.vnf.DeleteVnfNotification;
-import org.openecomp.mso.bpmn.common.adapter.vnf.MsoExceptionCategory;
-import org.openecomp.mso.bpmn.common.adapter.vnf.QueryVnfNotification;
-import org.openecomp.mso.bpmn.common.adapter.vnf.RollbackVnfNotification;
-import org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification;
-import org.openecomp.mso.bpmn.common.adapter.vnf.VnfAdapterNotify;
-import org.openecomp.mso.bpmn.common.adapter.vnf.VnfRollback;
-import org.openecomp.mso.bpmn.common.adapter.vnf.VnfStatus;
-import org.openecomp.mso.logger.MessageEnum;
-import org.openecomp.mso.logger.MsoLogger;
-
-/**
- * This is the service class for VnfAdapterNotify
- * TODO: Add addition VnfAdapterNotify Methods for remaining VnfAdapterNotify operations.
- */
-
-@WebService(serviceName = "vnfAdapterNotify", targetNamespace = "http://org.openecomp.mso/vnfNotify")
-public class VnfAdapterNotifyServiceImpl implements VnfAdapterNotify{
-
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.bpmn.common.workflow.service;
+
+import javax.jws.Oneway;
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.ws.rs.core.Context;
+import javax.xml.ws.Action;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.WebServiceContext;
+
+import org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification;
+import org.openecomp.mso.bpmn.common.adapter.vnf.DeleteVnfNotification;
+import org.openecomp.mso.bpmn.common.adapter.vnf.MsoExceptionCategory;
+import org.openecomp.mso.bpmn.common.adapter.vnf.QueryVnfNotification;
+import org.openecomp.mso.bpmn.common.adapter.vnf.RollbackVnfNotification;
+import org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification;
+import org.openecomp.mso.bpmn.common.adapter.vnf.VnfAdapterNotify;
+import org.openecomp.mso.bpmn.common.adapter.vnf.VnfRollback;
+import org.openecomp.mso.bpmn.common.adapter.vnf.VnfStatus;
+import org.openecomp.mso.logger.MsoLogger;
+
+/**
+ * Implementation of the VnfAdapterNotify service.
+ */
+@WebService(serviceName = "vnfAdapterNotify", targetNamespace = "http://org.openecomp.mso/vnfNotify")
+public class VnfAdapterNotifyServiceImpl extends AbstractCallbackService implements VnfAdapterNotify{
+
private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
- private final String logMarker = "[VNF-NOTIFY]";
-
- @Context WebServiceContext wsContext;
-
- private volatile ProcessEngineServices pes4junit = null;
-
- /**
- *
- * @param errorMessage
- * @param exception
- * @param messageId
- * @param completed
- */
- @WebMethod(operationName = "rollbackVnfNotification")
- @Oneway
- @RequestWrapper(localName = "rollbackVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.RollbackVnfNotification")
+ private final String logMarker = "[VNF-NOTIFY]";
+
+ @Context WebServiceContext wsContext;
+
+ @WebMethod(operationName = "rollbackVnfNotification")
+ @Oneway
+ @RequestWrapper(localName = "rollbackVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.RollbackVnfNotification")
@Action(input = "http://org.openecomp.mso/notify/adapterNotify/rollbackVnfNotificationRequest")
- public void rollbackVnfNotification(
- @WebParam(name = "messageId", targetNamespace = "")
- String messageId,
- @WebParam(name = "completed", targetNamespace = "")
- boolean completed,
- @WebParam(name = "exception", targetNamespace = "")
- MsoExceptionCategory exception,
- @WebParam(name = "errorMessage", targetNamespace = "")
- String errorMessage) {
-
-
-
- RollbackVnfNotification rollbackVnfNotification = new RollbackVnfNotification();
-
- rollbackVnfNotification.setMessageId(messageId);
- rollbackVnfNotification.setCompleted(completed);
- rollbackVnfNotification.setException(exception);
- rollbackVnfNotification.setErrorMessage(errorMessage);
-
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
-
- MsoLogger.setServiceName("MSO." + "vnfAdapterRollback");
- MsoLogger.setLogContext(messageId, "N/A");
- msoLogger.debug(logMarker + "Received RollbackVnfNotification" + rollbackVnfNotification.toString());
-
- long startTime = System.currentTimeMillis();
- try {
-
- /* Check to make sure the process instance is ready for correlation*/
- isReadyforCorrelation(runtimeService, messageId, "rollbackVnfNotificationCallback", "VNFRB_messageId");
-
- msoLogger.debug(logMarker + "*** Received MSO rollbackVnfNotification Callback ******");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
- msoLogger.debug(logMarker + "Rollback VNF Notification string:\n" + rollbackVnfNotification.toString());
-
- System.out.println("testing ROllbackVnfNotification : " + rollbackVnfNotification.toString());
-
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("VNFRB_messageId", messageId );
- variables.put("rollbackVnfNotificationCallback", rollbackVnfNotification.toString());
-
- /*Correlating the response with the running instance*/
-
- runtimeService.createMessageCorrelation("rollbackVnfNotificationCallback").setVariables(variables)
- .processInstanceVariableEquals("VNFRB_messageId", messageId).correlate();
-
- msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
- } catch(MismatchingMessageCorrelationException e) {
- msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
- String msg =
- "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
- + messageId
- + "' but that RequestId could not be correlated to any active process - ignoring the request";
-
- msoLogger.error (MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg);
-
- }
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.", "BPMN",
- MsoLogger.getServiceName(), "rollbackVnfNotification");
-
- return;
- }
-
-
-
- /**
- *
- * @param errorMessage
- * @param vnfExists
- * @param status
- * @param exception
- * @param outputs
- * @param messageId
- * @param vnfId
- * @param completed
- */
- @WebMethod(operationName = "queryVnfNotification")
- @Oneway
+ public void rollbackVnfNotification(
+ @WebParam(name = "messageId", targetNamespace = "")
+ String messageId,
+ @WebParam(name = "completed", targetNamespace = "")
+ boolean completed,
+ @WebParam(name = "exception", targetNamespace = "")
+ MsoExceptionCategory exception,
+ @WebParam(name = "errorMessage", targetNamespace = "")
+ String errorMessage) {
+
+ RollbackVnfNotification rollbackVnfNotification = new RollbackVnfNotification();
+
+ rollbackVnfNotification.setMessageId(messageId);
+ rollbackVnfNotification.setCompleted(completed);
+ rollbackVnfNotification.setException(exception);
+ rollbackVnfNotification.setErrorMessage(errorMessage);
+
+ String method = "rollbackVnfNotification";
+ Object message = rollbackVnfNotification;
+ String messageEventName = "rollbackVnfNotificationCallback";
+ String messageVariable = "rollbackVnfNotificationCallback";
+ String correlationVariable = "VNFRB_messageId";
+ String correlationValue = messageId;
+
+ handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker);
+ }
+
+ @WebMethod(operationName = "queryVnfNotification")
+ @Oneway
@RequestWrapper(localName = "queryVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification")
@Action(input = "http://org.openecomp.mso/notify/adapterNotify/queryVnfNotificationRequest")
- public void queryVnfNotification(
- @WebParam(name = "messageId", targetNamespace = "")
- String messageId,
- @WebParam(name = "completed", targetNamespace = "")
- boolean completed,
- @WebParam(name = "exception", targetNamespace = "")
- MsoExceptionCategory exception,
- @WebParam(name = "errorMessage", targetNamespace = "")
- String errorMessage,
- @WebParam(name = "vnfExists", targetNamespace = "")
- Boolean vnfExists,
- @WebParam(name = "vnfId", targetNamespace = "")
- String vnfId,
- @WebParam(name = "status", targetNamespace = "")
- VnfStatus status,
- @WebParam(name = "outputs", targetNamespace = "")
- org.openecomp.mso.bpmn.common.adapter.vnf.QueryVnfNotification.Outputs outputs){
-
- QueryVnfNotification queryVnfNotification = new QueryVnfNotification();
-
- queryVnfNotification.setMessageId(messageId);
- queryVnfNotification.setCompleted(completed);
- queryVnfNotification.setException(exception);
- queryVnfNotification.setErrorMessage(errorMessage);
- queryVnfNotification.setVnfExists(vnfExists);
- queryVnfNotification.setVnfId(vnfId);
- queryVnfNotification.setStatus(status);
- queryVnfNotification.setOutputs(outputs);
-
-
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
-
- MsoLogger.setServiceName("MSO." + "vnf Adapter Query");
- MsoLogger.setLogContext(messageId, "N/A");
- msoLogger.debug(logMarker + "Received QueryVnfNotification" + queryVnfNotification.toString());
-
- System.out.println("Received QueryVnfNotification : " + queryVnfNotification.toString());
-
- long startTime = System.currentTimeMillis();
- try {
-
- /* Check to make sure the process instance is ready for correlation*/
- isReadyforCorrelation(runtimeService, messageId, "queryVnfNotificationCallback", "VNFQ_messageId");
-
- msoLogger.debug(logMarker + "*** Received MSO queryVnfNotification Callback ******");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
- msoLogger.debug(logMarker + "Query VNF Notification string:\n" + queryVnfNotification.toString());
-
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("VNFQ_messageId", messageId );
- variables.put("queryVnfNotificationCallback", queryVnfNotification.toString());
-
- /*Correlating the response with the running instance*/
-
- runtimeService.createMessageCorrelation("queryVnfNotificationCallback").setVariables(variables)
- .processInstanceVariableEquals("VNFQ_messageId", messageId).correlate();
-
- msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
- } catch(MismatchingMessageCorrelationException e) {
- msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
- String msg =
- "VNF Adapter Notify Service received a Query VNF Notification request with RequestId '"
- + messageId
- + "' but that RequestId could not be correlated to any active process - ignoring the request";
-
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
- }
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
-
- return;
- }
-
-
-
-
- /**
- *
- * @param errorMessage
- * @param exception
- * @param rollback
- * @param outputs
- * @param messageId
- * @param vnfId
- * @param completed
- */
- @WebMethod(operationName = "createVnfNotification")
- @Oneway
+ public void queryVnfNotification(
+ @WebParam(name = "messageId", targetNamespace = "")
+ String messageId,
+ @WebParam(name = "completed", targetNamespace = "")
+ boolean completed,
+ @WebParam(name = "exception", targetNamespace = "")
+ MsoExceptionCategory exception,
+ @WebParam(name = "errorMessage", targetNamespace = "")
+ String errorMessage,
+ @WebParam(name = "vnfExists", targetNamespace = "")
+ Boolean vnfExists,
+ @WebParam(name = "vnfId", targetNamespace = "")
+ String vnfId,
+ @WebParam(name = "status", targetNamespace = "")
+ VnfStatus status,
+ @WebParam(name = "outputs", targetNamespace = "")
+ QueryVnfNotification.Outputs outputs){
+
+ String method = "queryVnfNotification";
+ String messageEventName = "queryVnfNotificationCallback";
+ String messageVariable = "queryVnfNotificationCallback";
+ String correlationVariable = "VNFQ_messageId";
+ String correlationValue = messageId;
+
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlationValue, "N/A");
+
+ QueryVnfNotification message = new QueryVnfNotification();
+
+ message.setMessageId(messageId);
+ message.setCompleted(completed);
+ message.setException(exception);
+ message.setErrorMessage(errorMessage);
+ message.setVnfExists(vnfExists);
+ message.setVnfId(vnfId);
+ message.setStatus(status);
+ message.setOutputs(outputs);
+
+ handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker);
+ }
+
+ @WebMethod(operationName = "createVnfNotification")
+ @Oneway
@RequestWrapper(localName = "createVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.CreateVnfNotification")
@Action(input = "http://org.openecomp.mso/notify/adapterNotify/createVnfNotificationRequest")
- public void createVnfNotification(
- @WebParam(name = "messageId", targetNamespace = "")
- String messageId,
- @WebParam(name = "completed", targetNamespace = "")
- boolean completed,
- @WebParam(name = "exception", targetNamespace = "")
- MsoExceptionCategory exception,
- @WebParam(name = "errorMessage", targetNamespace = "")
- String errorMessage,
- @WebParam(name = "vnfId", targetNamespace = "")
- String vnfId,
- @WebParam(name = "outputs", targetNamespace = "")
- org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification.Outputs outputs,
- @WebParam(name = "rollback", targetNamespace = "")
- VnfRollback rollback){
-
- CreateVnfNotification createVnfNotification = new CreateVnfNotification();
-
- createVnfNotification.setMessageId(messageId);
- createVnfNotification.setCompleted(completed);
- createVnfNotification.setException(exception);
- createVnfNotification.setErrorMessage(errorMessage);
- createVnfNotification.setVnfId(vnfId);
- createVnfNotification.setOutputs(outputs);
- createVnfNotification.setRollback(rollback);
-
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
-
- MsoLogger.setServiceName("MSO." + "vnf Adapter Create");
- MsoLogger.setLogContext(messageId, "N/A");
- msoLogger.debug(logMarker + "Received CreateVnfNotification - " + createVnfNotification.toString());
-
- long startTime = System.currentTimeMillis();
- try {
-
- /* Check to make sure the process instance is ready for correlation*/
- isReadyforCorrelation(runtimeService, messageId, "createVnfNotificationCallback", "VNFC_messageId");
-
- msoLogger.debug(logMarker + "*** Received MSO createVnfNotification Callback ******");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
-
- msoLogger.debug(logMarker + "Create VNF Notification string:\n" + createVnfNotification.toString());
-
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("VNFC_messageId", messageId );
- variables.put("createVnfNotificationCallback", createVnfNotification.toString());
-
- /*Correlating the response with the running instance*/
-
- runtimeService.createMessageCorrelation("createVnfNotificationCallback").setVariables(variables)
- .processInstanceVariableEquals("VNFC_messageId", messageId).correlate();
-
- msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
- } catch(MismatchingMessageCorrelationException e) {
- msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
- String msg =
- "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
- + messageId
- + "' but that RequestId could not be correlated to any active process - ignoring the request";
-
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- }
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.", "BPMN",
- MsoLogger.getServiceName(), "createVnfNotification");
-
- return;
- }
-
- /**
- *
- * @param errorMessage
- * @param exception
- * @param rollback
- * @param outputs
- * @param messageId
- * @param completed
- */
- @WebMethod(operationName = "updateVnfNotification")
- @Oneway
+ public void createVnfNotification(
+ @WebParam(name = "messageId", targetNamespace = "")
+ String messageId,
+ @WebParam(name = "completed", targetNamespace = "")
+ boolean completed,
+ @WebParam(name = "exception", targetNamespace = "")
+ MsoExceptionCategory exception,
+ @WebParam(name = "errorMessage", targetNamespace = "")
+ String errorMessage,
+ @WebParam(name = "vnfId", targetNamespace = "")
+ String vnfId,
+ @WebParam(name = "outputs", targetNamespace = "")
+ CreateVnfNotification.Outputs outputs,
+ @WebParam(name = "rollback", targetNamespace = "")
+ VnfRollback rollback){
+
+ String method = "createVnfNotification";
+ String messageEventName = "createVnfNotificationCallback";
+ String messageVariable = "createVnfNotificationCallback";
+ String correlationVariable = "VNFC_messageId";
+ String correlationValue = messageId;
+
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlationValue, "N/A");
+
+ CreateVnfNotification message = new CreateVnfNotification();
+
+ message.setMessageId(messageId);
+ message.setCompleted(completed);
+ message.setException(exception);
+ message.setErrorMessage(errorMessage);
+ message.setVnfId(vnfId);
+ message.setOutputs(outputs);
+ message.setRollback(rollback);
+
+ handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker);
+ }
+
+ @WebMethod(operationName = "updateVnfNotification")
+ @Oneway
@RequestWrapper(localName = "updateVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification")
@Action(input = "http://org.openecomp.mso/notify/adapterNotify/updateVnfNotificationRequest")
- public void updateVnfNotification(
- @WebParam(name = "messageId", targetNamespace = "")
- String messageId,
- @WebParam(name = "completed", targetNamespace = "")
- boolean completed,
- @WebParam(name = "exception", targetNamespace = "")
- MsoExceptionCategory exception,
- @WebParam(name = "errorMessage", targetNamespace = "")
- String errorMessage,
- @WebParam(name = "outputs", targetNamespace = "")
- org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification.Outputs outputs,
- @WebParam(name = "rollback", targetNamespace = "")
- VnfRollback rollback){
-
- UpdateVnfNotification updateVnfNotification = new UpdateVnfNotification();
-
- updateVnfNotification.setMessageId(messageId);
- updateVnfNotification.setCompleted(completed);
- updateVnfNotification.setException(exception);
- updateVnfNotification.setErrorMessage(errorMessage);
- updateVnfNotification.setOutputs(outputs);
- updateVnfNotification.setRollback(rollback);
-
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
-
- MsoLogger.setServiceName("MSO." + "vnf Adapter Update");
- MsoLogger.setLogContext(messageId, "N/A");
- msoLogger.debug(logMarker + "Received UpdateVnfNotification - " + updateVnfNotification.toString());
-
- long startTime = System.currentTimeMillis();
- try {
-
- // Check to make sure the process instance is ready for correlation
- isReadyforCorrelation(runtimeService, messageId, "updateVnfNotificationCallback", "VNFU_messageId");
-
- msoLogger.debug(logMarker + "*** Received MSO updateVnfNotification Callback ******");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
-
- msoLogger.debug(logMarker + "Update VNF Notification string:\n" + updateVnfNotification.toString());
-
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("VNFU_messageId", messageId );
- variables.put("updateVnfNotificationCallback", updateVnfNotification.toString());
-
- //Correlating the response with the running instance
- runtimeService.createMessageCorrelation("updateVnfNotificationCallback").setVariables(variables)
- .processInstanceVariableEquals("VNFU_messageId", messageId).correlate();
-
- msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
-
- } catch(MismatchingMessageCorrelationException e) {
- msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
- String msg =
- "VNF Adapter Notify Service received a Update VNF Notification request with RequestId '"
- + messageId
- + "' but that RequestId could not be correlated to any active process - ignoring the request";
-
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- }
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.", "BPMN",
- MsoLogger.getServiceName(), "updateVnfNotification");
-
- return;
- }
-
- /**
- *
- * @param errorMessage
- * @param exception
- * @param messageId
- * @param completed
- */
-
- //@WebService(serviceName="VNFAdapterDeleteCallbackV1", targetNamespace="http://org.openecomp.mso/vnfNotify")
- @WebMethod(operationName = "deleteVnfNotification")
- @Oneway
+ public void updateVnfNotification(
+ @WebParam(name = "messageId", targetNamespace = "")
+ String messageId,
+ @WebParam(name = "completed", targetNamespace = "")
+ boolean completed,
+ @WebParam(name = "exception", targetNamespace = "")
+ MsoExceptionCategory exception,
+ @WebParam(name = "errorMessage", targetNamespace = "")
+ String errorMessage,
+ @WebParam(name = "outputs", targetNamespace = "")
+ UpdateVnfNotification.Outputs outputs,
+ @WebParam(name = "rollback", targetNamespace = "")
+ VnfRollback rollback){
+
+ String method = "updateVnfNotification";
+ String messageEventName = "updateVnfNotificationCallback";
+ String messageVariable = "updateVnfNotificationCallback";
+ String correlationVariable = "VNFU_messageId";
+ String correlationValue = messageId;
+
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlationValue, "N/A");
+
+ UpdateVnfNotification message = new UpdateVnfNotification();
+
+ message.setMessageId(messageId);
+ message.setCompleted(completed);
+ message.setException(exception);
+ message.setErrorMessage(errorMessage);
+ message.setOutputs(outputs);
+ message.setRollback(rollback);
+
+ handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker);
+ }
+
+ @WebMethod(operationName = "deleteVnfNotification")
+ @Oneway
@RequestWrapper(localName = "deleteVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.DeleteVnfNotification")
@Action(input = "http://org.openecomp.mso/notify/adapterNotify/deleteVnfNotificationRequest")
- public void deleteVnfNotification(
- @WebParam(name = "messageId", targetNamespace = "")
- String messageId,
- @WebParam(name = "completed", targetNamespace = "")
- boolean completed,
- @WebParam(name = "exception", targetNamespace = "")
- MsoExceptionCategory exception,
- @WebParam(name = "errorMessage", targetNamespace = "")
- String errorMessage) {
-
- //Callback URL to use http://localhost:28080/mso/services/VNFAdapterDeleteCallbackV1
-
- //DeleteVnfNotification Class
- DeleteVnfNotification deleteVnfNotification = new DeleteVnfNotification();
- deleteVnfNotification.setMessageId(messageId);
- deleteVnfNotification.setCompleted(completed);
- deleteVnfNotification.setException(exception);
- deleteVnfNotification.setErrorMessage(errorMessage);
-
- ProcessEngineServices pes = getProcessEngineServices();
- RuntimeService runtimeService = pes.getRuntimeService();
-
- MsoLogger.setServiceName("MSO." + "vnfAdapterDelete");
- MsoLogger.setLogContext(messageId, "N/A");
- msoLogger.debug(logMarker + "Received DeleteVnfNotification callback: " + deleteVnfNotification.toString());
-
- long startTime = System.currentTimeMillis();
- try {
-
- /* Check to make sure the process instance is ready for correlation*/
- //isReadyforCorrelation(runtimeService, messageId, "deleteVnfACallback", "VNFDEL_uuid");
-
- msoLogger.debug(logMarker + " *** Received MSO deleteVnfACallback ******");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO deleteVnfACallback ");
- msoLogger.debug(logMarker + " Callback response string:\n" + deleteVnfNotification.toString());
-
- Map<String,Object> variables = new HashMap<String,Object>();
- variables.put("VNFDEL_uuid", messageId);
- variables.put("deleteVnfACallback", deleteVnfNotification.toString());
-
- /*Correlating the response with the running instance*/
-
- runtimeService.createMessageCorrelation("deleteVnfACallback")
- .setVariables(variables)
- .processInstanceVariableEquals("VNFDEL_uuid", messageId).correlate();
-
- msoLogger.debug(logMarker + "***** Completed processing of MSO deleteVnfACallback ******");
-
- } catch(MismatchingMessageCorrelationException e) {
-
- msoLogger.debug(logMarker + " [CORM]correlation id mismatch");
- // Couldn't correlate requestId to any active flow
- //MsoLogger logger = MsoLogger.getMsoLogger("SDNCAdapterCallbackService");
-
- String msg =
- "Vnf Adapter Callback Service received a Vnf Adapter Callback with messageId '"
- + messageId
- + "' but that messageId could not be correlated to any active process - ignoring the Request";
-
- msoLogger.error(MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
- MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
-
- }
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.");
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.", "BPMN",
- MsoLogger.getServiceName(), "deleteVnfNotification");
-
- return;
- }
-
- private void isReadyforCorrelation(RuntimeService runtimeService, String requestId, String responseName, String correlationValue) {
-
- long waitingInstances = runtimeService.createExecutionQuery().messageEventSubscriptionName(responseName).processVariableValueEquals(correlationValue, requestId).count();
- int retries = 50;
- while (waitingInstances==0 && retries > 0) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- // should I add new exception Message to MessageEnum???
- msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, logMarker, e);
-
- } // you can still play with the numbers
- waitingInstances = runtimeService.createExecutionQuery() //
- .messageEventSubscriptionName(responseName)
- .processVariableValueEquals(correlationValue, requestId).count();
- retries--;
- }
- }
-
-
- private ProcessEngineServices getProcessEngineServices() {
- if (pes4junit == null) {
- return BpmPlatform.getDefaultProcessEngine();
- } else {
- return pes4junit;
- }
- }
-
- @WebMethod(exclude=true)
- public void setProcessEngineServices4junit(ProcessEngineServices pes) {
- pes4junit = pes;
- }
-}
+ public void deleteVnfNotification(
+ @WebParam(name = "messageId", targetNamespace = "")
+ String messageId,
+ @WebParam(name = "completed", targetNamespace = "")
+ boolean completed,
+ @WebParam(name = "exception", targetNamespace = "")
+ MsoExceptionCategory exception,
+ @WebParam(name = "errorMessage", targetNamespace = "")
+ String errorMessage) {
+
+ String method = "deleteVnfNotification";
+ String messageEventName = "deleteVnfACallback";
+ String messageVariable = "deleteVnfACallback";
+ String correlationVariable = "VNFDEL_uuid";
+ String correlationValue = messageId;
+
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlationValue, "N/A");
+
+ DeleteVnfNotification message = new DeleteVnfNotification();
+
+ message.setMessageId(messageId);
+ message.setCompleted(completed);
+ message.setException(exception);
+ message.setErrorMessage(errorMessage);
+
+ handleCallback(method, message, messageEventName, messageVariable,
+ correlationVariable, correlationValue, logMarker);
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java
index 5afbded982..698ec13c00 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java
@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -11,10 +12,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.camunda.bpm.BpmPlatform;
-import org.camunda.bpm.engine.ProcessEngineServices;
-import org.camunda.bpm.engine.RuntimeService;
-
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
@@ -27,25 +24,29 @@ import org.openecomp.mso.logger.MsoLogger;
* </pre>
*/
@Path("/")
-public class WorkflowMessageResource {
+public class WorkflowMessageResource extends AbstractCallbackService {
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
private static final String LOGMARKER = "[WORKFLOW-MESSAGE]";
-
- private ProcessEngineServices pes4junit = null;
@POST
@Path("/WorkflowMessage/{messageType}/{correlator}")
@Consumes("*/*")
@Produces(MediaType.TEXT_PLAIN)
- public Response deliver(@PathParam("messageType") String messageType,
- @PathParam("correlator") String correlator, String message) {
+ public Response deliver(
+ @HeaderParam("Content-Type") String contentType,
+ @PathParam("messageType") String messageType,
+ @PathParam("correlator") String correlator,
+ String message) {
+
+ String method = "receiveWorkflowMessage";
+ MsoLogger.setServiceName("MSO." + method);
+ MsoLogger.setLogContext(correlator, "N/A");
LOGGER.debug(LOGMARKER + " Received workflow message"
+ " type='" + messageType + "'"
+ " correlator='" + correlator + "'"
- + System.lineSeparator() + message);
-
- MsoLogger.setServiceName("MSO." + "WorkflowMessage");
+ + (contentType == null ? "" : " contentType='" + contentType + "'")
+ + " message=" + System.lineSeparator() + message);
if (messageType == null || messageType.isEmpty()) {
String msg = "Missing message type";
@@ -63,79 +64,25 @@ public class WorkflowMessageResource {
return Response.status(400).entity(msg).build();
}
- String correlatorVariable = messageType + "_CORRELATOR";
+ String messageEventName = "WorkflowMessage";
String messageVariable = messageType + "_MESSAGE";
+ String correlationVariable = messageType + "_CORRELATOR";
+ String correlationValue = correlator;
+ String contentTypeVariable = messageType + "_CONTENT_TYPE";
- long startTime = System.currentTimeMillis();
-
- try {
- RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();
-
- if (!isReadyforCorrelation(runtimeService, correlatorVariable, correlator)) {
- String msg = "No process is waiting to receive '" + messageType + "' WorkflowMessage with correlator '" + correlator + "'";
- LOGGER.debug(LOGMARKER + " " + msg);
- LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, LOGMARKER + ":" + msg);
- LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BusinessProcesssError, msg, "BPMN", MsoLogger.getServiceName(), messageType);
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BusinessProcesssError, msg);
- return Response.status(500).entity(msg).build();
- }
+ Map<String, Object> variables = new HashMap<String, Object>();
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put(correlatorVariable, correlator);
- variables.put(messageVariable, message);
-
- runtimeService.createMessageCorrelation("WorkflowMessage").setVariables(variables)
- .processInstanceVariableEquals(correlatorVariable, correlator).correlate();
-
- String msg = "Completed delivery of '" + messageType + "' WorkflowMessage with correlator '" + correlator + "'";
- LOGGER.debug(LOGMARKER + msg);
- LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, msg, "BPMN", MsoLogger.getServiceName(), messageType);
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, msg);
- return Response.status(204).build();
- } catch (Exception e) {
- // For example: MismatchingMessageCorrelationException
- String msg = "Caught " + e.getClass().getSimpleName() + " processing '" + messageType + "' WorkflowMessage with " + correlatorVariable + "='" + correlator + "'";
- LOGGER.debug(LOGMARKER + " " + msg);
- LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, LOGMARKER + ":" + msg, e);
- LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, msg, "BPMN", MsoLogger.getServiceName(), messageType);
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, msg);
- return Response.status(500).entity(msg).build();
+ if (contentType != null) {
+ variables.put(contentTypeVariable, contentType);
}
- }
-
- private boolean isReadyforCorrelation(RuntimeService runtimeService,
- String correlationVariable, String correlationValue)
- throws InterruptedException {
-
- long waitingInstances = runtimeService.createExecutionQuery()
- .messageEventSubscriptionName("WorkflowMessage")
- .processVariableValueEquals(correlationVariable, correlationValue)
- .count();
-
- int retries = 50;
- while (waitingInstances == 0 && retries > 0) {
- Thread.sleep(100);
- waitingInstances = runtimeService.createExecutionQuery()
- .messageEventSubscriptionName("WorkflowMessage")
- .processVariableValueEquals(correlationVariable, correlationValue)
- .count();
-
- retries--;
- }
+ CallbackResult result = handleCallback(method, message, messageEventName,
+ messageVariable, correlationVariable, correlationValue, LOGMARKER, variables);
- return waitingInstances != 0;
- }
-
- private ProcessEngineServices getProcessEngineServices() {
- if (pes4junit == null) {
- return BpmPlatform.getDefaultProcessEngine();
+ if (result instanceof CallbackError) {
+ return Response.status(500).entity(((CallbackError)result).getErrorMessage()).build();
} else {
- return pes4junit;
+ return Response.status(204).build();
}
}
-
- public void setProcessEngineServices4junit(ProcessEngineServices pes) {
- pes4junit = pes;
- }
} \ No newline at end of file