Initial OpenECOMP MSO commit
[so.git] / bpmn / MSOGammaBPMN / src / main / java / org / openecomp / mso / bpmn / gamma / workflow / service / WorkflowResource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.gamma.workflow.service;
22
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.UUID;
27 import java.util.concurrent.atomic.AtomicLong;
28
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.core.Context;
35 import javax.ws.rs.core.Response;
36 import javax.ws.rs.core.UriInfo;
37
38 import org.camunda.bpm.engine.HistoryService;
39 import org.camunda.bpm.engine.ProcessEngineException;
40 import org.camunda.bpm.engine.ProcessEngineServices;
41 import org.camunda.bpm.engine.ProcessEngines;
42 import org.camunda.bpm.engine.RuntimeService;
43 import org.camunda.bpm.engine.history.HistoricVariableInstance;
44 import org.camunda.bpm.engine.impl.core.variable.VariableMapImpl;
45 import org.camunda.bpm.engine.runtime.ProcessInstance;
46 import org.camunda.bpm.engine.variable.VariableMap;
47 import org.camunda.bpm.engine.variable.Variables;
48 import org.camunda.bpm.engine.variable.Variables.SerializationDataFormats;
49
50 import org.openecomp.mso.bpmn.core.WorkflowException;
51 import org.openecomp.mso.logger.MessageEnum;
52 import org.openecomp.mso.logger.MsoLogger;
53 import org.slf4j.MDC;
54
55 @Path("/workflow")
56 public class WorkflowResource {
57         
58         private ProcessEngineServices pes4junit = null;
59
60         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
61         private static final String LOGMARKER = "[WRKFLOW-RESOURCE]";
62
63         private static final int DEFAULT_WAIT_TIME = 30000;
64
65         @Context
66         private UriInfo uriInfo = null;
67
68         /**
69          * Starts the process instance and responds to client synchronously
70          * If the request does not contain att-mso-service-request-timeout then it waits for the value specified in DEFAULT_WAIT_TIME
71          * Note: value specified in att-mso-service-request-timeout is in seconds
72          * During polling time, if there is an exception encountered in the process execution then polling is stopped and the error response is 
73          * returned to the client
74          * @param processKey
75          * @param variableMap
76          * @return
77          */
78         @POST
79         @Path("/services/{processKey}")
80         @Produces("application/json")
81         @Consumes("application/json")
82         public Response startProcessInstanceByKey(@PathParam("processKey") String processKey,
83                         VariableMapImpl variableMap) {
84
85                 Map<String, Object> inputVariables = getInputVariables(variableMap);    
86                 setLogContext(processKey, inputVariables);
87
88                 WorkflowResponse workflowResponse = new WorkflowResponse();
89                 long startTime = System.currentTimeMillis();
90                 ProcessInstance processInstance = null;
91
92                 try {
93                         //Kickoff the process
94                         ProcessThread thread = new ProcessThread(inputVariables,processKey,msoLogger);
95                         thread.start();
96
97                         Map<String, Object> responseMap = null;
98
99                         //wait for process to be completed
100                         long waitTime = getWaitTime(inputVariables);
101                         long now = System.currentTimeMillis();
102                         long start = now;
103                         long endTime = start + waitTime;
104                         long pollingInterval = 500;
105
106                         // TEMPORARY LOGIC FOR UNIT TEST REFACTORING
107                         // If this is a unit test (method is invoked directly), wait a max
108                         // of 5 seconds after process ended for a result.  In production,
109                         // wait up to 60 seconds.
110                         long timeToWaitAfterProcessEnded = uriInfo == null ? 5000 : 60000;
111                         AtomicLong timeProcessEnded = new AtomicLong(0);
112                         boolean endedWithNoResponse = false;
113
114                         while (now <= endTime) {
115                                 Thread.sleep(pollingInterval);
116
117                                 now = System.currentTimeMillis();
118
119                                 // Increase the polling interval over time
120
121                                 long elapsed = now - start;
122
123                                 if (elapsed > 60000) {
124                                         pollingInterval = 5000;
125                                 } else if (elapsed > 10000) {
126                                         pollingInterval = 1000;
127                                 }
128                                 Exception exception = thread.getException();
129                                 if (exception != null) {
130                                         throw new Exception(exception);
131                                 }
132
133                                 processInstance = thread.getProcessInstance();
134
135                                 if (processInstance == null) {
136                                         msoLogger.debug(LOGMARKER + processKey + " process has not been created yet");
137                                         continue;
138                                 }
139
140                                 String processInstanceId = processInstance.getId();
141                                 workflowResponse.setProcessInstanceID(processInstanceId);                               
142
143                                 responseMap = getResponseMap(processInstance, processKey, timeProcessEnded);
144
145                                 if (responseMap == null) {
146                                         msoLogger.debug(LOGMARKER + processKey + " has not produced a response yet");
147
148                                         if (timeProcessEnded.longValue() != 0) {
149                                                 long elapsedSinceEnded = System.currentTimeMillis() - timeProcessEnded.longValue();
150
151                                                 if (elapsedSinceEnded > timeToWaitAfterProcessEnded) {
152                                                         endedWithNoResponse = true;
153                                                         break;
154                                                 }
155                                         }
156                                 } else {
157                                         processResponseMap(workflowResponse, responseMap);
158                                         recordEvents(processKey, workflowResponse, startTime);
159                                         return Response.status(workflowResponse.getMessageCode()).entity(workflowResponse).build();
160                                 }
161                         }
162
163                         //if we dont get response after waiting then send timeout response
164
165                         String state;
166                         String processInstanceId;
167
168                         if (processInstance == null) {
169                                 processInstanceId = "N/A";
170                                 state = "NOT STARTED";
171                         } else {
172                                 processInstanceId = processInstance.getProcessInstanceId();
173                                 state = isProcessEnded(processInstanceId) ? "ENDED" : "NOT ENDED";
174                         }
175
176                         workflowResponse.setMessage("Fail");
177                         if (endedWithNoResponse) {
178                                 workflowResponse.setResponse("Process ended without producing a response");
179                         } else {
180                                 workflowResponse.setResponse("Request timed out, process state: " + state);
181                         }
182                         workflowResponse.setProcessInstanceID(processInstanceId);
183                         recordEvents(processKey, workflowResponse, startTime);
184                         workflowResponse.setMessageCode(500);
185                         return Response.status(500).entity(workflowResponse).build();
186                 } catch (Exception ex) {
187                         msoLogger.debug(LOGMARKER + "Exception in startProcessInstance by key");
188                         ex.printStackTrace();
189                         workflowResponse.setMessage("Fail" );
190                         workflowResponse.setResponse("Error occurred while executing the process: " + ex.getMessage());
191                         if (processInstance != null) workflowResponse.setProcessInstanceID(processInstance.getId());
192                         
193                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG,  "BPMN", MDC.get(processKey), 
194                                         MsoLogger.ErrorCode.UnknownError, LOGMARKER + workflowResponse.getMessage()
195                                         + " for processKey: " + processKey + " with response: " + workflowResponse.getResponse());
196                         
197                         workflowResponse.setMessageCode(500);
198                         recordEvents(processKey, workflowResponse, startTime);
199                         return Response.status(500).entity(workflowResponse).build();
200                 }
201         }
202
203         /**
204          * Returns the wait time, this is used by the resource on how long it should wait to send a response
205          * If none specified DEFAULT_WAIT_TIME is used
206          * @param inputVariables
207          * @return
208          */
209         private int getWaitTime(Map<String, Object> inputVariables)
210         {
211                 String timeout = inputVariables.get("att-mso-service-request-timeout") == null
212                         ? null : inputVariables.get("att-mso-service-request-timeout").toString();              
213
214                 if (timeout != null) {
215                         try {
216                                 return Integer.parseInt(timeout)*1000;
217                         } catch (NumberFormatException nex) {
218                                 msoLogger.debug("Invalid input for att-mso-service-request-timeout");
219                         }
220                 }
221                 return DEFAULT_WAIT_TIME;
222         }
223         
224         private void recordEvents(String processKey, WorkflowResponse response, long startTime) {
225                 
226                 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
227                                 LOGMARKER + response.getMessage() + " for processKey: "
228                                 + processKey + " with response: " + response.getResponse(), "BPMN", MDC.get(processKey), null);
229                 
230                 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
231                                 LOGMARKER + response.getMessage() + " for processKey: "
232                                 + processKey + " with response: " + response.getResponse());
233         }
234
235         private void setLogContext(String processKey, Map<String, Object> inputVariables) {
236                 MsoLogger.setServiceName("MSO." + processKey);
237                 if (inputVariables != null) {
238                         MsoLogger.setLogContext(getValueFromInputVariables(inputVariables, "att-mso-request-id"),
239                                 getValueFromInputVariables(inputVariables, "att-mso-service-instance-id"));
240                 }
241         }
242
243         private String getValueFromInputVariables(Map<String,Object> inputVariables, String key) {
244                 Object value = inputVariables.get(key);
245                 if (value == null) {
246                         return "N/A";
247                 } else {
248                         return value.toString();
249                 }
250         }
251         
252         /**
253          * Checks to see if the specified process is ended.
254          * @param processInstanceId the process instance ID
255          * @return true if the process is ended
256          */
257         private boolean isProcessEnded(String processInstanceId) {
258                 ProcessEngineServices pes = getProcessEngineServices();
259                 return pes.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null ? true : false ;        
260         }
261
262         private void processResponseMap(WorkflowResponse workflowResponse, Map<String, Object> responseMap) {
263                 Object object = responseMap.get("Response");
264                 String response = object == null ? null : String.valueOf(object);
265                 if(response == null){
266                         object = responseMap.get("WorkflowResponse");
267                         response = object == null ? null : String.valueOf(object);
268                 }
269
270                 workflowResponse.setResponse(response); 
271
272                 object = responseMap.get("ResponseCode");
273                 String responseCode = object == null ? null : String.valueOf(object);
274
275                 try {
276                         workflowResponse.setMessageCode(Integer.parseInt(responseCode));
277                 } catch(NumberFormatException nex) {
278                         msoLogger.debug(LOGMARKER + "Failed to parse ResponseCode: " + responseCode);
279                         workflowResponse.setMessageCode(-1);
280                 }
281
282                 Object status = responseMap.get("Status");
283
284                 if ("Success".equalsIgnoreCase(String.valueOf(status))) {
285                         workflowResponse.setMessage("Success");
286                 } else if ("Fail".equalsIgnoreCase(String.valueOf(status))) {
287                         workflowResponse.setMessage("Fail");
288                 } else {
289                         msoLogger.debug(LOGMARKER + "Unrecognized Status: " + responseCode);
290                         workflowResponse.setMessage("Fail");
291                 }
292         }
293
294         /**
295          * @version 1.0
296          * Triggers the workflow in a separate thread
297          */
298         private class ProcessThread extends Thread {
299                 private final Map<String,Object> inputVariables;
300                 private final String processKey;
301                 private final MsoLogger msoLogger;
302                 private final String businessKey;
303                 private ProcessInstance processInstance = null;
304                 private Exception exception = null;
305
306                 public ProcessThread(Map<String, Object> inputVariables, String processKey, MsoLogger msoLogger) {
307                         this.inputVariables = inputVariables;
308                         this.processKey = processKey;
309                         this.msoLogger = msoLogger;
310                         this.businessKey = UUID.randomUUID().toString();
311                 }
312
313                 /**
314                  * If an exception occurs when starting the process instance, it may
315                  * be obtained by calling this method.  Note that exceptions are only
316                  * recorded while the process is executing in its original thread.
317                  * Once a process is suspended, exception recording stops.
318                  * @return the exception, or null if none has occurred
319                  */
320                 public Exception getException() {
321                         return exception;
322                 }
323
324                 
325                 public ProcessInstance getProcessInstance() {
326                         return this.processInstance;
327                 }
328                 
329                 /**
330                  * Sets the process instance exception.
331                  * @param exception the exception
332                  */
333                 private void setException(Exception exception) {
334                         this.exception = exception;
335                 }
336
337                 public void run() {
338                         setLogContext(processKey, inputVariables);
339
340                         long startTime = System.currentTimeMillis();
341                         
342                         try {
343                                 msoLogger.debug(LOGMARKER + "***Received MSO startProcessInstanceByKey with processKey:"
344                                         + processKey + " and variables: " + inputVariables);
345                                 
346                                 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, LOGMARKER
347                                                 + "Call to MSO workflow/services in Camunda. Received MSO startProcessInstanceByKey with"
348                                                 + " processKey:" + processKey
349                                                 + " businessKey:" + businessKey
350                                                 + " variables: " + inputVariables);
351                                                 
352                                 RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();
353
354                                 // Note that this method doesn't return until the process suspends
355                                 // itself or finishes.  We provide a business key so we can identify
356                                 // the process instance immediately.
357                                 processInstance = runtimeService.startProcessInstanceByKey(
358                                         processKey, inputVariables);
359
360                         } catch (Exception e) {
361                                 msoLogger.debug(LOGMARKER + "ProcessThread caught an exception executing "
362                                         + processKey + ": " + e);
363                                 setException(e);
364                         }
365                 }
366
367         }
368
369         private Map<String, Object> getInputVariables(VariableMapImpl variableMap) {
370                 VariableMap inputVariables = Variables.createVariables();
371                 @SuppressWarnings("unchecked")
372                 Map<String, Object> vMap = (Map<String, Object>) variableMap.get("variables");
373                 for (String key : vMap.keySet()) { //variabe name vn
374                         @SuppressWarnings("unchecked")
375                         Map<String, Object> valueMap = (Map<String,Object>)vMap.get(key); //value, type
376                         inputVariables.putValueTyped(key, Variables
377                         .objectValue(valueMap.get("value"))
378                         .serializationDataFormat(SerializationDataFormats.JAVA) // tells the engine to use java serialization for persisting the value
379                         .create());
380                 }
381                 return inputVariables;
382         }
383
384         /**
385          * Attempts to get a response map from the specified process instance.
386          * @return the response map, or null if it is unavailable
387          */
388         private Map<String, Object> getResponseMap(ProcessInstance processInstance,
389                         String processKey, AtomicLong timeProcessEnded) {
390
391                 String responseMapVariable = processKey + "ResponseMap";
392                 String processInstanceId = processInstance.getId();
393
394                 // Query the runtime service to see if a response map is ready.
395
396 /*              RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();
397                 List<Execution> executions = runtimeService.createExecutionQuery()
398                         .processInstanceId(processInstanceId).list();
399
400                 for (Execution execution : executions) {
401                         @SuppressWarnings("unchecked")
402                         Map<String, Object> responseMap = (Map<String, Object>)
403                                 getVariableFromExecution(runtimeService, execution.getId(),
404                                         responseMapVariable);
405
406                         if (responseMap != null) {
407                                 msoLogger.debug(LOGMARKER + "Obtained " + responseMapVariable
408                                         + " from process " + processInstanceId + " execution "
409                                         + execution.getId());
410                                 return responseMap;
411                         }
412                 }
413 */
414                 //Querying history seem to return consistent results compared to querying the runtime service
415
416                 boolean alreadyEnded = timeProcessEnded.longValue() != 0;
417
418                 if (alreadyEnded || isProcessEnded(processInstance.getId())) {
419                         if (!alreadyEnded) {
420                                 timeProcessEnded.set(System.currentTimeMillis());
421                         }
422
423                         // Query the history service to see if a response map exists.
424
425                         HistoryService historyService = getProcessEngineServices().getHistoryService();
426                         @SuppressWarnings("unchecked")
427                         Map<String, Object> responseMap = (Map<String, Object>)
428                                 getVariableFromHistory(historyService, processInstance.getId(),
429                                         responseMapVariable);
430
431                         if (responseMap != null) {
432                                 msoLogger.debug(LOGMARKER + "Obtained " + responseMapVariable
433                                         + " from process " + processInstanceId + " history");
434                                 return responseMap;
435                         }
436
437                         // Query the history service for old-style response variables.
438
439                         String prefix = (String) getVariableFromHistory(historyService, processInstanceId, "prefix");
440
441                         if (prefix != null) {
442                                 
443                                 // Check for 'WorkflowResponse' variable
444                                 Object workflowResponseObject = getVariableFromHistory(historyService, processInstanceId, "WorkflowResponse");
445                                 String workflowResponse = workflowResponseObject == null ? null : String.valueOf(workflowResponseObject);
446                                 msoLogger.debug(LOGMARKER + "WorkflowResponse: " + workflowResponse);
447                                 
448                                 if (workflowResponse != null) {
449                                         Object responseCodeObject = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
450                                         String responseCode = responseCodeObject == null ? null : String.valueOf(responseCodeObject);
451                                         msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
452                                         responseMap = new HashMap<String, Object>();
453                                         responseMap.put("WorkflowResponse", workflowResponse);
454                                         responseMap.put("ResponseCode", responseCode);
455                                         responseMap.put("Status", "Success");
456                                         return responseMap;
457                                 }
458                                 
459                                 
460                                 // Check for 'WorkflowException' variable
461                                 WorkflowException workflowException = null;
462                                 String workflowExceptionText = null;
463
464                                 Object workflowExceptionObject = getVariableFromHistory(historyService, processInstanceId, "WorkflowException");
465                                 if(workflowExceptionObject != null) {
466                                         if(workflowExceptionObject instanceof WorkflowException) {
467                                                 workflowException = (WorkflowException) workflowExceptionObject;
468                                                 workflowExceptionText = workflowException.toString();
469                                                 responseMap = new HashMap<String, Object>();
470                                                 responseMap.put("WorkflowException", workflowExceptionText);
471                                                 responseMap.put("ResponseCode", workflowException.getErrorCode());
472                                                 responseMap.put("Status", "Fail");
473                                                 return responseMap;
474                                         }
475                                         else if (workflowExceptionObject instanceof String) {
476                                                 Object object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
477                                                 String responseCode = object == null ? null : String.valueOf(object);
478                                                 workflowExceptionText = (String) workflowExceptionObject;
479                                                 responseMap = new HashMap<String, Object>();
480                                                 responseMap.put("WorkflowException", workflowExceptionText);
481                                                 responseMap.put("ResponseCode", responseCode);
482                                                 responseMap.put("Status", "Fail");
483                                                 return responseMap;
484                                         }
485                                         
486                                 }
487                                 msoLogger.debug(LOGMARKER + "WorkflowException: " + workflowExceptionText);
488                                 
489                                 // BEGIN LEGACY SUPPORT.  TODO: REMOVE THIS CODE
490                                 Object object = getVariableFromHistory(historyService, processInstanceId, processKey + "Response");
491                                 String response = object == null ? null : String.valueOf(object);
492                                 msoLogger.debug(LOGMARKER + processKey + "Response: " + response);
493
494                                 if (response != null) {
495                                         object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
496                                         String responseCode = object == null ? null : String.valueOf(object);
497                                         msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
498                                         responseMap = new HashMap<String, Object>();
499                                         responseMap.put("Response", response);
500                                         responseMap.put("ResponseCode", responseCode);
501                                         responseMap.put("Status", "Success");
502                                         return responseMap;
503                                 }
504         
505                                 object = getVariableFromHistory(historyService, processInstanceId, prefix + "ErrorResponse");
506                                 String errorResponse = object == null ? null : String.valueOf(object);
507                                 msoLogger.debug(LOGMARKER + prefix + "ErrorResponse: " + errorResponse);
508
509                                 if (errorResponse != null) {
510                                         object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
511                                         String responseCode = object == null ? null : String.valueOf(object);
512                                         msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
513                                         responseMap = new HashMap<String, Object>();
514                                         responseMap.put("Response", errorResponse);
515                                         responseMap.put("ResponseCode", responseCode);
516                                         responseMap.put("Status", "Fail");
517                                         return responseMap;
518                                 }
519                                 // END LEGACY SUPPORT.  TODO: REMOVE THIS CODE
520                         }
521                 }
522                 return null;
523         }
524         
525         /**
526          * Gets a variable value from the specified execution.
527          * @return the variable value, or null if the variable could not be
528          * obtained
529          */
530         private Object getVariableFromExecution(RuntimeService runtimeService,
531                         String executionId, String variableName) {
532                 try {
533                         return runtimeService.getVariable(executionId, variableName);
534                 } catch (ProcessEngineException e) {
535                         // Most likely cause is that the execution no longer exists.
536                         msoLogger.debug("Error retrieving execution " + executionId
537                                 + " variable " + variableName + ": " + e);
538                         return null;
539                 }
540         }
541         
542         /**
543          * Gets a variable value from specified historical process instance.
544          * @return the variable value, or null if the variable could not be
545          * obtained
546          */
547         private Object getVariableFromHistory(HistoryService historyService,
548                         String processInstanceId, String variableName) {
549                 try {
550                         HistoricVariableInstance v = historyService.createHistoricVariableInstanceQuery()
551                                 .processInstanceId(processInstanceId).variableName(variableName).singleResult();
552                         return v == null ? null : v.getValue();
553                 } catch (Exception e) {
554                         msoLogger.debug("Error retrieving process " + processInstanceId
555                                 + " variable " + variableName + " from history: " + e);
556                         return null;
557                 }
558         }
559         
560         @POST
561         @Path("/services/{processKey}/{processInstanceId}")
562         @Produces("application/json")
563         @Consumes("application/json")
564         public WorkflowResponse getProcessVariables(@PathParam("processKey") String processKey, @PathParam("processInstanceId") String processInstanceId) {
565                 //TODO filter only set of variables
566                 WorkflowResponse response = new WorkflowResponse();
567
568                 long startTime = System.currentTimeMillis();
569                 try {
570                         ProcessEngineServices engine = getProcessEngineServices();
571                         List<HistoricVariableInstance> variables = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
572                         Map<String,String> variablesMap = new HashMap<String,String>();
573                         for (HistoricVariableInstance variableInstance: variables) {
574                                 variablesMap.put(variableInstance.getName(), variableInstance.getValue().toString());
575                         }
576
577                         msoLogger.debug(LOGMARKER + "***Received MSO getProcessVariables with processKey:" + processKey + " and variables: " + variablesMap.toString());
578                         
579                         msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, LOGMARKER 
580                                         + "Call to MSO workflow/services in Camunda. Received MSO getProcessVariables with processKey:" 
581                                         + processKey + " and variables: " 
582                                         + variablesMap.toString());
583                         
584                         
585                         response.setVariables(variablesMap);
586                         response.setMessage("Success");
587                         response.setResponse("Successfully retrieved the variables"); 
588                         response.setProcessInstanceID(processInstanceId);
589
590                         msoLogger.debug(LOGMARKER + response.getMessage() + " for processKey: " + processKey + " with response: " + response.getResponse());
591                 } catch (Exception ex) {
592                         response.setMessage("Fail");
593                         response.setResponse("Failed to retrieve the variables," + ex.getMessage()); 
594                         response.setProcessInstanceID(processInstanceId);
595                         
596                         msoLogger.error (MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "BPMN", MDC.get(processKey), MsoLogger.ErrorCode.UnknownError, LOGMARKER 
597                                         + response.getMessage() 
598                                         + " for processKey: " 
599                                         + processKey 
600                                         + " with response: " 
601                                         + response.getResponse());
602                         
603                 }
604                 
605                 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
606                                 LOGMARKER + response.getMessage() + " for processKey: "
607                                 + processKey + " with response: " + response.getResponse(), "BPMN", MDC.get(processKey), null);
608                 
609                 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
610                                 LOGMARKER + response.getMessage() + " for processKey: "
611                                 + processKey + " with response: " + response.getResponse());
612                 
613                 return response;
614         }
615
616         private ProcessEngineServices getProcessEngineServices() {
617                 if (pes4junit == null) {
618                         return ProcessEngines.getDefaultProcessEngine();
619                 } else {
620                         return pes4junit;
621                 }
622         }
623
624         public void setProcessEngineServices4junit(ProcessEngineServices pes) {
625                 pes4junit = pes;
626         }
627 }