aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/workflow/service/WorkflowResource.java
blob: 8d049634c792ae302276d3eeddfa9ab770776233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*-
 * ============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.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.ProcessEngineServices;
import org.camunda.bpm.engine.ProcessEngines;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.history.HistoricVariableInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.Variables.SerializationDataFormats;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.openecomp.mso.bpmn.core.WorkflowException;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
import org.slf4j.MDC;

@Path("/workflow")
public class WorkflowResource {
	
	private ProcessEngineServices pes4junit = null;

	private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
	private static final String LOGMARKER = "[WRKFLOW-RESOURCE]";

	private static final int DEFAULT_WAIT_TIME = 30000;

	@Context
	private UriInfo uriInfo = null;

	/**
	 * Starts the process instance and responds to client synchronously
	 * If the request does not contain mso-service-request-timeout then it waits for the value specified in DEFAULT_WAIT_TIME
	 * Note: value specified in mso-service-request-timeout is in seconds
	 * During polling time, if there is an exception encountered in the process execution then polling is stopped and the error response is 
	 * returned to the client
	 * @param processKey
	 * @param variableMap
	 * @return
	 */
	@POST
	@Path("/services/{processKey}")
	@Produces("application/json")
	@Consumes("application/json")
	public Response startProcessInstanceByKey(@PathParam("processKey") String processKey,
			VariableMapImpl variableMap) {

		Map<String, Object> inputVariables = getInputVariables(variableMap);	
		setLogContext(processKey, inputVariables);

		WorkflowResponse workflowResponse = new WorkflowResponse();
		long startTime = System.currentTimeMillis();
		ProcessInstance processInstance = null;

		try {
			//Kickoff the process
			ProcessThread thread = new ProcessThread(inputVariables,processKey,msoLogger);
			thread.start();

			Map<String, Object> responseMap = null;

			//wait for process to be completed
			long waitTime = getWaitTime(inputVariables);
			long now = System.currentTimeMillis();
			long start = now;
			long endTime = start + waitTime;
			long pollingInterval = 500;

			// TEMPORARY LOGIC FOR UNIT TEST REFACTORING
			// If this is a unit test (method is invoked directly), wait a max
			// of 5 seconds after process ended for a result.  In production,
			// wait up to 60 seconds.
			long timeToWaitAfterProcessEnded = uriInfo == null ? 5000 : 60000;
			AtomicLong timeProcessEnded = new AtomicLong(0);
			boolean endedWithNoResponse = false;

			while (now <= endTime) {
				Thread.sleep(pollingInterval);

				now = System.currentTimeMillis();

				// Increase the polling interval over time

				long elapsed = now - start;

				if (elapsed > 60000) {
					pollingInterval = 5000;
				} else if (elapsed > 10000) {
					pollingInterval = 1000;
				}
				Exception exception = thread.getException();
				if (exception != null) {
					throw new Exception(exception);
				}

				processInstance = thread.getProcessInstance();

				if (processInstance == null) {
					msoLogger.debug(LOGMARKER + processKey + " process has not been created yet");
					continue;
				}

				String processInstanceId = processInstance.getId();
				workflowResponse.setProcessInstanceID(processInstanceId);				

				responseMap = getResponseMap(processInstance, processKey, timeProcessEnded);

				if (responseMap == null) {
					msoLogger.debug(LOGMARKER + processKey + " has not produced a response yet");

					if (timeProcessEnded.longValue() != 0) {
						long elapsedSinceEnded = System.currentTimeMillis() - timeProcessEnded.longValue();

						if (elapsedSinceEnded > timeToWaitAfterProcessEnded) {
							endedWithNoResponse = true;
							break;
						}
					}
				} else {
					processResponseMap(workflowResponse, responseMap);
					recordEvents(processKey, workflowResponse, startTime);
					return Response.status(workflowResponse.getMessageCode()).entity(workflowResponse).build();
				}
			}

			//if we dont get response after waiting then send timeout response

			String state;
			String processInstanceId;

			if (processInstance == null) {
				processInstanceId = "N/A";
				state = "NOT STARTED";
			} else {
				processInstanceId = processInstance.getProcessInstanceId();
				state = isProcessEnded(processInstanceId) ? "ENDED" : "NOT ENDED";
			}

			workflowResponse.setMessage("Fail");
			if (endedWithNoResponse) {
				workflowResponse.setResponse("Process ended without producing a response");
			} else {
				workflowResponse.setResponse("Request timed out, process state: " + state);
			}
			workflowResponse.setProcessInstanceID(processInstanceId);
			recordEvents(processKey, workflowResponse, startTime);
			workflowResponse.setMessageCode(500);
			return Response.status(500).entity(workflowResponse).build();
		} catch (Exception ex) {
			msoLogger.debug(LOGMARKER + "Exception in startProcessInstance by key");
			ex.printStackTrace();
			workflowResponse.setMessage("Fail" );
			workflowResponse.setResponse("Error occurred while executing the process: " + ex.getMessage());
			if (processInstance != null) workflowResponse.setProcessInstanceID(processInstance.getId());
			
			msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG,  "BPMN", MDC.get(processKey), 
					MsoLogger.ErrorCode.UnknownError, LOGMARKER + workflowResponse.getMessage()
					+ " for processKey: " + processKey + " with response: " + workflowResponse.getResponse());
			
			workflowResponse.setMessageCode(500);
			recordEvents(processKey, workflowResponse, startTime);
			return Response.status(500).entity(workflowResponse).build();
		}
	}

	/**
	 * Returns the wait time, this is used by the resource on how long it should wait to send a response
	 * If none specified DEFAULT_WAIT_TIME is used
	 * @param inputVariables
	 * @return
	 */
	private int getWaitTime(Map<String, Object> inputVariables)
	{
		String timeout = inputVariables.get("mso-service-request-timeout") == null
			? null : inputVariables.get("mso-service-request-timeout").toString();		

		if (timeout != null) {
			try {
				return Integer.parseInt(timeout)*1000;
			} catch (NumberFormatException nex) {
				msoLogger.debug("Invalid input for mso-service-request-timeout");
			}
		}
		return DEFAULT_WAIT_TIME;
	}
	
	private void recordEvents(String processKey, WorkflowResponse response, long startTime) {
		
		msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
				LOGMARKER + response.getMessage() + " for processKey: "
				+ processKey + " with response: " + response.getResponse(), "BPMN", MDC.get(processKey), null);
		
		msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
				LOGMARKER + response.getMessage() + " for processKey: "
				+ processKey + " with response: " + response.getResponse());
	}

	private void setLogContext(String processKey, Map<String, Object> inputVariables) {
		MsoLogger.setServiceName("MSO." + processKey);
		if (inputVariables != null) {
			MsoLogger.setLogContext(getValueFromInputVariables(inputVariables, "mso-request-id"),
				getValueFromInputVariables(inputVariables, "mso-service-instance-id"));
		}
	}

	private String getValueFromInputVariables(Map<String,Object> inputVariables, String key) {
		Object value = inputVariables.get(key);
		if (value == null) {
			return "N/A";
		} else {
			return value.toString();
		}
	}
	
	/**
	 * Checks to see if the specified process is ended.
	 * @param processInstanceId the process instance ID
	 * @return true if the process is ended
	 */
	private boolean isProcessEnded(String processInstanceId) {
		ProcessEngineServices pes = getProcessEngineServices();
		try {
			return pes.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null ? true : false ;
		} catch (Exception e) {
			return true;
		}        
	}

	private void processResponseMap(WorkflowResponse workflowResponse, Map<String, Object> responseMap) {
		Object object = responseMap.get("Response");
		String response = object == null ? null : String.valueOf(object);
		if(response == null){
			object = responseMap.get("WorkflowResponse");
			response = object == null ? null : String.valueOf(object);
		}

		workflowResponse.setResponse(response); 

		object = responseMap.get("ResponseCode");
		String responseCode = object == null ? null : String.valueOf(object);

		try {
			workflowResponse.setMessageCode(Integer.parseInt(responseCode));
		} catch(NumberFormatException nex) {
			msoLogger.debug(LOGMARKER + "Failed to parse ResponseCode: " + responseCode);
			workflowResponse.setMessageCode(-1);
		}

		Object status = responseMap.get("Status");

		if ("Success".equalsIgnoreCase(String.valueOf(status))) {
			workflowResponse.setMessage("Success");
		} else if ("Fail".equalsIgnoreCase(String.valueOf(status))) {
			workflowResponse.setMessage("Fail");
		} else {
			msoLogger.debug(LOGMARKER + "Unrecognized Status: " + responseCode);
			workflowResponse.setMessage("Fail");
		}
	}

	/**
	 * @version 1.0
	 * Triggers the workflow in a separate thread
	 */
	private class ProcessThread extends Thread {
		private final Map<String,Object> inputVariables;
		private final String processKey;
		private final MsoLogger msoLogger;
		private final String businessKey;
		private ProcessInstance processInstance = null;
		private Exception exception = null;

		public ProcessThread(Map<String, Object> inputVariables, String processKey, MsoLogger msoLogger) {
			this.inputVariables = inputVariables;
			this.processKey = processKey;
			this.msoLogger = msoLogger;
			this.businessKey = UUID.randomUUID().toString();
		}

		/**
		 * If an exception occurs when starting the process instance, it may
		 * be obtained by calling this method.  Note that exceptions are only
		 * recorded while the process is executing in its original thread.
		 * Once a process is suspended, exception recording stops.
		 * @return the exception, or null if none has occurred
		 */
		public Exception getException() {
			return exception;
		}

		
		public ProcessInstance getProcessInstance() {
			return this.processInstance;
		}
		
		/**
		 * Sets the process instance exception.
		 * @param exception the exception
		 */
		private void setException(Exception exception) {
			this.exception = exception;
		}

		public void run() {
			setLogContext(processKey, inputVariables);

			long startTime = System.currentTimeMillis();
			
			try {
				msoLogger.debug(LOGMARKER + "***Received MSO startProcessInstanceByKey with processKey:"
					+ processKey + " and variables: " + inputVariables);
				
				msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, LOGMARKER
						+ "Call to MSO workflow/services in Camunda. Received MSO startProcessInstanceByKey with"
						+ " processKey:" + processKey
						+ " businessKey:" + businessKey
						+ " variables: " + inputVariables);
						
				RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();

				// Note that this method doesn't return until the process suspends
				// itself or finishes.  We provide a business key so we can identify
				// the process instance immediately.
				processInstance = runtimeService.startProcessInstanceByKey(
					processKey, inputVariables);

			} catch (Exception e) {
				msoLogger.debug(LOGMARKER + "ProcessThread caught an exception executing "
					+ processKey + ": " + e);
				setException(e);
			}
		}

	}

	private Map<String, Object> getInputVariables(VariableMapImpl variableMap) {
		VariableMap inputVariables = Variables.createVariables();
		@SuppressWarnings("unchecked")
		Map<String, Object> vMap = (Map<String, Object>) variableMap.get("variables");
		for (String key : vMap.keySet()) { //variabe name vn
			@SuppressWarnings("unchecked")
			Map<String, Object> valueMap = (Map<String,Object>)vMap.get(key); //value, type
			inputVariables.putValueTyped(key, Variables
			.objectValue(valueMap.get("value"))
			.serializationDataFormat(SerializationDataFormats.JAVA) // tells the engine to use java serialization for persisting the value
			.create());
		}
		return inputVariables;
	}

	/**
	 * Attempts to get a response map from the specified process instance.
	 * @return the response map, or null if it is unavailable
	 */
	private Map<String, Object> getResponseMap(ProcessInstance processInstance,
			String processKey, AtomicLong timeProcessEnded) {

		String responseMapVariable = processKey + "ResponseMap";
		String processInstanceId = processInstance.getId();

		// Query the runtime service to see if a response map is ready.

/*		RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();
		List<Execution> executions = runtimeService.createExecutionQuery()
			.processInstanceId(processInstanceId).list();

		for (Execution execution : executions) {
			@SuppressWarnings("unchecked")
			Map<String, Object> responseMap = (Map<String, Object>)
				getVariableFromExecution(runtimeService, execution.getId(),
					responseMapVariable);

			if (responseMap != null) {
				msoLogger.debug(LOGMARKER + "Obtained " + responseMapVariable
					+ " from process " + processInstanceId + " execution "
					+ execution.getId());
				return responseMap;
			}
		}
*/
		//Querying history seem to return consistent results compared to querying the runtime service

		boolean alreadyEnded = timeProcessEnded.longValue() != 0;

		if (alreadyEnded || isProcessEnded(processInstance.getId())) {
			if (!alreadyEnded) {
				timeProcessEnded.set(System.currentTimeMillis());
			}

			// Query the history service to see if a response map exists.

			HistoryService historyService = getProcessEngineServices().getHistoryService();
			@SuppressWarnings("unchecked")
			Map<String, Object> responseMap = (Map<String, Object>)
				getVariableFromHistory(historyService, processInstance.getId(),
					responseMapVariable);

			if (responseMap != null) {
				msoLogger.debug(LOGMARKER + "Obtained " + responseMapVariable
					+ " from process " + processInstanceId + " history");
				return responseMap;
			}

			// Query the history service for old-style response variables.

			String prefix = (String) getVariableFromHistory(historyService, processInstanceId, "prefix");

			if (prefix != null) {
				
				// Check for 'WorkflowResponse' variable
				Object workflowResponseObject = getVariableFromHistory(historyService, processInstanceId, "WorkflowResponse");
				String workflowResponse = workflowResponseObject == null ? null : String.valueOf(workflowResponseObject);
				msoLogger.debug(LOGMARKER + "WorkflowResponse: " + workflowResponse);
				
				if (workflowResponse != null) {
					Object responseCodeObject = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
					String responseCode = responseCodeObject == null ? null : String.valueOf(responseCodeObject);
					msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
					responseMap = new HashMap<String, Object>();
					responseMap.put("WorkflowResponse", workflowResponse);
					responseMap.put("ResponseCode", responseCode);
					responseMap.put("Status", "Success");
					return responseMap;
				}
				
				
				// Check for 'WorkflowException' variable
				WorkflowException workflowException = null;
				String workflowExceptionText = null;

				Object workflowExceptionObject = getVariableFromHistory(historyService, processInstanceId, "WorkflowException");
				if(workflowExceptionObject != null) {
					if(workflowExceptionObject instanceof WorkflowException) {
						workflowException = (WorkflowException) workflowExceptionObject;
						workflowExceptionText = workflowException.toString();
						responseMap = new HashMap<String, Object>();
						responseMap.put("WorkflowException", workflowExceptionText);
						responseMap.put("ResponseCode", workflowException.getErrorCode());
						responseMap.put("Status", "Fail");
						return responseMap;
					}
					else if (workflowExceptionObject instanceof String) {
						Object object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
						String responseCode = object == null ? null : String.valueOf(object);
						workflowExceptionText = (String) workflowExceptionObject;
						responseMap = new HashMap<String, Object>();
						responseMap.put("WorkflowException", workflowExceptionText);
						responseMap.put("ResponseCode", responseCode);
						responseMap.put("Status", "Fail");
						return responseMap;
					}
					
				}
				msoLogger.debug(LOGMARKER + "WorkflowException: " + workflowExceptionText);
				
				// BEGIN LEGACY SUPPORT.  TODO: REMOVE THIS CODE
				Object object = getVariableFromHistory(historyService, processInstanceId, processKey + "Response");
				String response = object == null ? null : String.valueOf(object);
				msoLogger.debug(LOGMARKER + processKey + "Response: " + response);

				if (response != null) {
					object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
					String responseCode = object == null ? null : String.valueOf(object);
					msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
					responseMap = new HashMap<String, Object>();
					responseMap.put("Response", response);
					responseMap.put("ResponseCode", responseCode);
					responseMap.put("Status", "Success");
					return responseMap;
				}
	
				object = getVariableFromHistory(historyService, processInstanceId, prefix + "ErrorResponse");
				String errorResponse = object == null ? null : String.valueOf(object);
				msoLogger.debug(LOGMARKER + prefix + "ErrorResponse: " + errorResponse);

				if (errorResponse != null) {
					object = getVariableFromHistory(historyService, processInstanceId, prefix + "ResponseCode");
					String responseCode = object == null ? null : String.valueOf(object);
					msoLogger.debug(LOGMARKER + prefix + "ResponseCode: " + responseCode);
					responseMap = new HashMap<String, Object>();
					responseMap.put("Response", errorResponse);
					responseMap.put("ResponseCode", responseCode);
					responseMap.put("Status", "Fail");
					return responseMap;
				}
				// END LEGACY SUPPORT.  TODO: REMOVE THIS CODE
			}
		}
		return null;
	}
	
	/**
	 * Gets a variable value from the specified execution.
	 * @return the variable value, or null if the variable could not be
	 * obtained
	 */
	private Object getVariableFromExecution(RuntimeService runtimeService,
			String executionId, String variableName) {
		try {
			return runtimeService.getVariable(executionId, variableName);
		} catch (ProcessEngineException e) {
			// Most likely cause is that the execution no longer exists.
			msoLogger.debug("Error retrieving execution " + executionId
				+ " variable " + variableName + ": " + e);
			return null;
		}
	}
	/**
	 * Gets a variable value from specified historical process instance.
	 * @return the variable value, or null if the variable could not be
	 * obtained
	 */
	private Object getVariableFromHistory(HistoryService historyService,
			String processInstanceId, String variableName) {
		try {
			HistoricVariableInstance v = historyService.createHistoricVariableInstanceQuery()
				.processInstanceId(processInstanceId).variableName(variableName).singleResult();
			return v == null ? null : v.getValue();
		} catch (Exception e) {
			msoLogger.debug("Error retrieving process " + processInstanceId
				+ " variable " + variableName + " from history: " + e);
			return null;
		}
	}
	
	@POST
	@Path("/services/{processKey}/{processInstanceId}")
	@Produces("application/json")
	@Consumes("application/json")
	public WorkflowResponse getProcessVariables(@PathParam("processKey") String processKey, @PathParam("processInstanceId") String processInstanceId) {
		//TODO filter only set of variables
		WorkflowResponse response = new WorkflowResponse();

		long startTime = System.currentTimeMillis();
		try {
			ProcessEngineServices engine = getProcessEngineServices();
			List<HistoricVariableInstance> variables = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
			Map<String,String> variablesMap = new HashMap<String,String>();
			for (HistoricVariableInstance variableInstance: variables) {
				variablesMap.put(variableInstance.getName(), variableInstance.getValue().toString());
			}

			msoLogger.debug(LOGMARKER + "***Received MSO getProcessVariables with processKey:" + processKey + " and variables: " + variablesMap.toString());
			
			msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, LOGMARKER 
					+ "Call to MSO workflow/services in Camunda. Received MSO getProcessVariables with processKey:" 
					+ processKey + " and variables: " 
					+ variablesMap.toString());
			
			
			response.setVariables(variablesMap);
			response.setMessage("Success");
			response.setResponse("Successfully retrieved the variables"); 
			response.setProcessInstanceID(processInstanceId);

			msoLogger.debug(LOGMARKER + response.getMessage() + " for processKey: " + processKey + " with response: " + response.getResponse());
		} catch (Exception ex) {
			response.setMessage("Fail");
			response.setResponse("Failed to retrieve the variables," + ex.getMessage()); 
			response.setProcessInstanceID(processInstanceId);
			
			msoLogger.error (MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "BPMN", MDC.get(processKey), MsoLogger.ErrorCode.UnknownError, LOGMARKER 
					+ response.getMessage() 
					+ " for processKey: " 
					+ processKey 
					+ " with response: " 
					+ response.getResponse());
			
		}
		
		msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
				LOGMARKER + response.getMessage() + " for processKey: "
				+ processKey + " with response: " + response.getResponse(), "BPMN", MDC.get(processKey), null);
		
		msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, 
				LOGMARKER + response.getMessage() + " for processKey: "
				+ processKey + " with response: " + response.getResponse());
		
		return response;
	}

	private ProcessEngineServices getProcessEngineServices() {
		if (pes4junit == null) {
			return ProcessEngines.getDefaultProcessEngine();
		} else {
			return pes4junit;
		}
	}

	public void setProcessEngineServices4junit(ProcessEngineServices pes) {
		pes4junit = pes;
	}
}