aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java
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/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java
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/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowMessageResource.java103
1 files changed, 25 insertions, 78 deletions
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 5afbded..698ec13 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