--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.common.workflow.service;\r
+\r
+import org.camunda.bpm.engine.ProcessEngineServices;\r
+import org.camunda.bpm.engine.ProcessEngines;\r
+\r
+\r
+public class WorkflowAsyncCommonResource extends WorkflowAsyncResource {\r
+\r
+ protected ProcessEngineServices getProcessEngineServices() {\r
+ return pes4junit.orElse(ProcessEngines.getProcessEngine("common"));\r
+ }\r
+}\r
\r
import java.util.HashMap;\r
import java.util.Map;\r
+import java.util.Objects;\r
+import java.util.Optional;\r
import java.util.UUID;\r
\r
import javax.ws.rs.Consumes;\r
import javax.ws.rs.core.Response;\r
\r
import org.camunda.bpm.engine.ProcessEngineServices;\r
-import org.camunda.bpm.engine.ProcessEngines;\r
import org.camunda.bpm.engine.RuntimeService;\r
import org.camunda.bpm.engine.runtime.ProcessInstance;\r
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;\r
* For asynchronous process - the activity may send a acknowledgement response and then proceed further on executing the process\r
*/\r
@Path("/async")\r
-public class WorkflowAsyncResource {\r
+public abstract class WorkflowAsyncResource {
\r
- private WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();\r
- protected ProcessEngineServices pes4junit = null;\r
+ private static final WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();\r
+ protected Optional<ProcessEngineServices> pes4junit = Optional.empty();\r
\r
- private MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
+ private final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
\r
private static final String logMarker = "[WRKFLOW-RESOURCE]";\r
- private static final int DEFAULT_WAIT_TIME = 30000; //default wait time\r
+ private static final long DEFAULT_WAIT_TIME = 30000; //default wait time\r
\r
/**\r
* Asynchronous JAX-RS method that starts a process instance.\r
public void startProcessInstanceByKey(final @Suspend(180000) AsynchronousResponse asyncResponse,\r
@PathParam("processKey") String processKey, VariableMapImpl variableMap) {\r
\r
- WorkflowResponse response = new WorkflowResponse();\r
long startTime = System.currentTimeMillis();\r
Map<String, Object> inputVariables = null;\r
WorkflowContext workflowContext = null;\r
}\r
\r
msoLogger.debug(logMarker + "Exception in startProcessInstance by key");\r
+ WorkflowResponse response = new WorkflowResponse();\r
response.setMessage("Fail" );\r
response.setResponse("Error occurred while executing the process: " + e);\r
response.setMessageCode(500);\r
return contextHolder.processCallback(processKey, processInstanceId, requestId, callbackResponse);\r
}\r
\r
+ private static String getOrCreate(Map<String, Object> inputVariables, String key) {\r
+ String value = Objects.toString(inputVariables.get(key), null);\r
+ if (value == null) {\r
+ value = UUID.randomUUID().toString();\r
+ inputVariables.put(key, value);\r
+ }\r
+ return value;\r
+ }\r
+ \r
// Note: the business key is used to identify the process in unit tests\r
- private String getBusinessKey(Map<String, Object> inputVariables) {\r
- Object businessKey = inputVariables.get("mso-business-key");\r
- if (businessKey == null ) {\r
- businessKey = UUID.randomUUID().toString();\r
- inputVariables.put("mso-business-key", businessKey);\r
- }\r
- return businessKey.toString();\r
+ private static String getBusinessKey(Map<String, Object> inputVariables) {\r
+ return getOrCreate(inputVariables, "mso-business-key");\r
}\r
\r
- private String getRequestId(Map<String, Object> inputVariables) {\r
- Object requestId = inputVariables.get("mso-request-id");\r
- if (requestId == null ) {\r
- requestId = UUID.randomUUID().toString();\r
- inputVariables.put("mso-request-id", requestId);\r
- } \r
- return requestId.toString();\r
+ private static String getRequestId(Map<String, Object> inputVariables) {\r
+ return getOrCreate(inputVariables, "mso-request-id");\r
}\r
\r
private long getWaitTime(Map<String, Object> inputVariables)\r
{\r
- String timeout = inputVariables.get("mso-service-request-timeout") == null\r
- ? null : inputVariables.get("mso-service-request-timeout").toString(); \r
+ \r
+ String timeout = Objects.toString(inputVariables.get("mso-service-request-timeout"), null);\r
\r
if (timeout != null) {\r
try {\r
\r
}\r
\r
- private void setLogContext(String processKey,\r
+ private static void setLogContext(String processKey,\r
Map<String, Object> inputVariables) {\r
MsoLogger.setServiceName("MSO." + processKey);\r
if (inputVariables != null) {\r
}\r
}\r
\r
- private String getKeyValueFromInputVariables(Map<String,Object> inputVariables, String key) {\r
+ private static String getKeyValueFromInputVariables(Map<String,Object> inputVariables, String key) {\r
if (inputVariables == null) return "";\r
- Object requestId = inputVariables.get(key);\r
- if (requestId != null) return requestId.toString();\r
- return "N/A";\r
+ return Objects.toString(inputVariables.get(key), "N/A");\r
}\r
\r
private boolean isProcessEnded(String processInstanceId) {\r
ProcessEngineServices pes = getProcessEngineServices();\r
- return pes.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null ? true : false ; \r
+ return pes.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null;\r
}\r
\r
\r
- protected ProcessEngineServices getProcessEngineServices() {\r
- if (pes4junit == null) {\r
- return ProcessEngines.getDefaultProcessEngine();\r
- } else {\r
- return pes4junit;\r
- }\r
- }\r
+ protected abstract ProcessEngineServices getProcessEngineServices();
\r
public void setProcessEngineServices4junit(ProcessEngineServices pes) {\r
- pes4junit = pes;\r
+ pes4junit = Optional.ofNullable(pes);\r
}\r
\r
- private Map<String, Object> getInputVariables(VariableMapImpl variableMap) {\r
+ private static Map<String, Object> getInputVariables(VariableMapImpl variableMap) {\r
Map<String, Object> inputVariables = new HashMap<String,Object>();\r
@SuppressWarnings("unchecked")\r
Map<String, Object> vMap = (Map<String, Object>) variableMap.get("variables");\r
\r
public WorkflowResourceApplication() {\r
singletons.add(new WorkflowResource());\r
- singletons.add(new WorkflowAsyncResource());\r
+ singletons.add(new WorkflowAsyncCommonResource());\r
singletons.add(new WorkflowMessageResource());\r
}\r
\r
import org.jboss.resteasy.spi.AsynchronousResponse;\r
import org.mockito.invocation.InvocationOnMock;\r
import org.mockito.stubbing.Answer;\r
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;\r
* @param variables\r
*/\r
private static void executeAsyncFlow(ProcessEngineServices processEngineServices, String processKey, AsynchronousResponse asyncResponse, Map<String,String> variables) {\r
- WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();\r
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncCommonResource();\r
VariableMapImpl variableMap = new VariableMapImpl();\r
\r
Map<String, Object> variableValueType = new HashMap<String, Object>();\r
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.jboss.resteasy.spi.AsynchronousResponse;
import org.junit.Test;
-import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
public class WorkflowAsyncResourceTest extends WorkflowTest {
}
private void executeWorkflow(String request, String requestId, AsynchronousResponse asyncResponse, String processKey) {
- WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
+ WorkflowAsyncCommonResource workflowResource = new WorkflowAsyncCommonResource();
VariableMapImpl variableMap = new VariableMapImpl();
Map<String, Object> variableValueType = new HashMap<String, Object>();
import org.openecomp.mso.bpmn.common.adapter.vnf.VnfRollback;\r
import org.openecomp.mso.bpmn.common.workflow.service.SDNCAdapterCallbackServiceImpl;\r
import org.openecomp.mso.bpmn.common.workflow.service.VnfAdapterNotifyServiceImpl;\r
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;\r
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;\r
VariableMapImpl variableMapImpl = createVariableMapImpl(variables);\r
\r
System.out.println("Sending " + request + " to " + processKey + " process");\r
- WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();\r
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncCommonResource();\r
workflowResource.setProcessEngineServices4junit(processEngineRule);\r
\r
TestAsyncResponse asyncResponse = new TestAsyncResponse();\r
VariableMapImpl variableMapImpl = createVariableMapImpl(variables);\r
\r
System.out.println("Sending " + request + " to " + processKey + " process");\r
- WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();\r
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncCommonResource();\r
workflowResource.setProcessEngineServices4junit(processEngineRule);\r
\r
TestAsyncResponse asyncResponse = new TestAsyncResponse();\r
* @since Version 1.0\r
*\r
*/\r
-@ProcessApplication(name="MSO Infrastructure Application", deploymentDescriptors={"../processes.xml"})\r
+@ProcessApplication("MSO Infrastructure Application")\r
public class MSOInfrastructureApplication extends ServletProcessApplication {\r
\r
private MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.infrastructure.workflow.service;\r
+\r
+import javax.ws.rs.Path;\r
+\r
+import org.camunda.bpm.engine.ProcessEngineServices;\r
+import org.camunda.bpm.engine.ProcessEngines;\r
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;\r
+\r
+\r
+/**\r
+ * \r
+ * @version 1.0\r
+ * Asynchronous Workflow processing using JAX RS RESTeasy implementation\r
+ * Both Synchronous and Asynchronous BPMN process can benefit from this implementation since the workflow gets executed in the background\r
+ * and the server thread is freed up, server scales better to process more incoming requests\r
+ * \r
+ * Usage: For synchronous process, when you are ready to send the response invoke the callback to write the response\r
+ * For asynchronous process - the activity may send a acknowledgement response and then proceed further on executing the process\r
+ */\r
+@Path("/async")\r
+public class WorkflowAsyncInfrastructureResource extends WorkflowAsyncResource {\r
+ \r
+ protected ProcessEngineServices getProcessEngineServices() {\r
+ return pes4junit.orElse(ProcessEngines.getProcessEngine("infrastructure"));\r
+ }\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.infrastructure.workflow.service;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import javax.ws.rs.ApplicationPath;\r
+import javax.ws.rs.core.Application;\r
+\r
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;\r
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResource;\r
+\r
+/**\r
+ * @version 1.0\r
+ * RESTeasy workflow application which wires synchronous and asynchronous response\r
+ *\r
+ */\r
+@ApplicationPath("/")\r
+public class WorkflowResourceApplication extends Application {\r
+ private Set<Object> singletons = new HashSet<Object>();\r
+ private Set<Class<?>> classes = new HashSet<Class<?>>();\r
+\r
+ public WorkflowResourceApplication() {\r
+ singletons.add(new WorkflowResource());\r
+ singletons.add(new WorkflowAsyncInfrastructureResource());\r
+ singletons.add(new WorkflowMessageResource());\r
+ }\r
+\r
+ @Override\r
+ public Set<Class<?>> getClasses() {\r
+ return classes;\r
+ }\r
+\r
+ @Override\r
+ public Set<Object> getSingletons() {\r
+ return singletons;\r
+ }\r
+}\r
<?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.10.0">
- <bpmn:process id="Process_1" isExecutable="true">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.6.0">
+ <bpmn:process id="Process_1" name="CreateCustomE2EServiceInstance" isExecutable="true">
<bpmn:startEvent id="StartEvent_00qj6ro" name="Create SI Start Flow">
<bpmn:outgoing>SequenceFlow_0s2spoq</bpmn:outgoing>
</bpmn:startEvent>
</bpmn:exclusiveGateway>
<bpmn:endEvent id="EndEvent_07uk5iy">
<bpmn:incoming>SequenceFlow_1fueo69</bpmn:incoming>
- <bpmn:errorEventDefinition />
+ <bpmn:errorEventDefinition errorRef="Error_0nbdy47" />
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_0s2spoq" sourceRef="StartEvent_00qj6ro" targetRef="ScriptTask_1s09c7d" />
<bpmn:sequenceFlow id="SequenceFlow_19eilro" sourceRef="ScriptTask_0xupxj9" targetRef="CallActivity_0rhljy8" />
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[#{execution.getVariable("WorkflowException") != null}]]></bpmn:conditionExpression>
</bpmn:sequenceFlow>
</bpmn:process>
+ <bpmn:error id="Error_0nbdy47" name="MSOWorkflowException" errorCode="MSOWorkflowException" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="StartEvent_00qj6ro_di" bpmnElement="StartEvent_00qj6ro">
--- /dev/null
+###
+# ============LICENSE_START=======================================================
+# ECOMP 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=========================================================
+###
+processEngineName=infrastructure
<?xml version="1.0" encoding="UTF-8"?>
-<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_MagIIMOUEeW8asg-vCEgWQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.10.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
- <bpmn2:process id="DoCreateServiceInstance" name="DoCreateServiceInstance" isExecutable="true">
+<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_MagIIMOUEeW8asg-vCEgWQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.6.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
+ <bpmn2:process id="DoCreateE2EServiceInstance" name="DoCreateE2EServiceInstance" isExecutable="true">
<bpmn2:startEvent id="createSI_startEvent" name="Start Flow">
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:error id="Error_2" name="MSOWorkflowException" errorCode="MSOWorkflowException" />
<bpmn2:error id="Error_1" name="java.lang.Exception" errorCode="java.lang.Exception" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
- <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoCreateServiceInstance">
+ <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoCreateE2EServiceInstance">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_47" bpmnElement="createSI_startEvent">
<dc:Bounds x="152" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>\r
<init-param>\r
<param-name>javax.ws.rs.Application</param-name>\r
- <param-value>org.openecomp.mso.bpmn.common.workflow.service.WorkflowResourceApplication</param-value>\r
+ <param-value>org.openecomp.mso.bpmn.infrastructure.workflow.service.WorkflowResourceApplication</param-value>\r
</init-param>\r
</servlet>\r
<servlet-mapping>\r
<servlet-name>resteasy-servlet</servlet-name>\r
<url-pattern>/*</url-pattern>\r
</servlet-mapping>\r
- <context-param>\r
- <param-name>contextConfigLocation</param-name>\r
- <param-value>/WEB-INF/applicationContext.xml</param-value>\r
- </context-param>\r
<context-param>\r
<param-name>mso.configuration</param-name>\r
<param-value>MSO_PROP_TOPOLOGY=topology.properties</param-value>\r
<param-name>resteasy.resources</param-name>\r
<param-value>org.openecomp.mso.logger.MsoLoggingServlet,org.openecomp.mso.bpmn.core.HealthCheckHandler</param-value>\r
</context-param>\r
- <listener>\r
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>\r
- </listener>\r
<filter>\r
<filter-name>LogFilter</filter-name>\r
<filter-class>org.openecomp.mso.logger.LogFilter</filter-class>\r
<security-role>\r
<role-name>BPMN-Client</role-name>\r
</security-role>\r
-</web-app>
\ No newline at end of file
+</web-app>\r