summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy
blob: 1eb626101e80c72313c595d626b83dfb83f1b348 (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
/*-
 * ============LICENSE_START=======================================================
 * OPENECOMP - SO
 * ================================================================================
 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.onap.so.bpmn.infrastructure.scripts

import org.json.JSONObject
import org.json.XML

import static org.apache.commons.lang3.StringUtils.*
import groovy.xml.XmlUtil
import groovy.json.*
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
import org.onap.so.bpmn.common.scripts.AaiUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.common.recipe.ResourceInput
import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
import org.onap.so.rest.APIResponse
import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
import java.util.UUID
import org.onap.so.logger.MsoLogger

import org.camunda.bpm.engine.runtime.Execution
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.apache.commons.lang3.*
import org.apache.commons.codec.binary.Base64
import org.springframework.web.util.UriUtils
import org.onap.so.rest.RESTClient
import org.onap.so.rest.RESTConfig

/**
 * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
 * flow for Create E2EServiceInstance in 3rdONAP 
 */
public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {

	String Prefix = "CRE3rdONAPESI_"

	ExceptionUtil exceptionUtil = new ExceptionUtil()

	JsonUtils jsonUtil = new JsonUtils()
	
	private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, Create3rdONAPE2EServiceInstance.class)

	public void checkSPPartnerInfo (DelegateExecution execution) {
		msoLogger.info(" ***** Started checkSPPartnerInfo *****")
		try {
			//get bpmn inputs from resource request.
			String requestId = execution.getVariable("mso-request-id")
			String requestAction = execution.getVariable("requestAction")
			msoLogger.info("The requestAction is: " + requestAction)
			String recipeParamsFromRequest = execution.getVariable("recipeParams")
			msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
			String resourceInput = execution.getVariable("resourceInput")
			msoLogger.info("The resourceInput is: " + resourceInput)
			//Get ResourceInput Object
			ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)			
			String resourceInputPrameters = resourceInputObj.getResourceParameters()
			String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
			JSONObject inputParameters = new JSONObject(customizeResourceParam(inputParametersJson))
			
			// set local resourceInput
			execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
			
			boolean is3rdONAPExist = false

			if(inputParameters.has("id"))
			{
				String sppartnerId = inputParameters.get("id")
			}
			if(inputParameters.has("url"))
			{
				String sppartnerUrl = inputParameters.get("url")
				if(!isBlank(sppartnerUrl)) {
					execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
					is3rdONAPExist = true
				}
				else {
					is3rdONAPExist = false
					String msg = "sppartner Url is blank."
					msoLogger.debug(msg)
				}
			}
			if(inputParameters.has("providingServiceInvarianteUuid"))
			{
				String sppartnerInvarianteUUID = inputParameters.get("providingServiceInvarianteUuid")
				execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
				is3rdONAPExist = true
			}
			else {
				is3rdONAPExist = false
				String msg = "sppartner providingServiceInvarianteUuid is blank."
				msoLogger.debug(msg)
			}
			if(inputParameters.has("providingServiceUuid"))
			{
				String sppartnerUUID = inputParameters.get("providingServiceUuid")
				execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
				is3rdONAPExist = true
			}
			else {
				is3rdONAPExist = false
				String msg = "sppartner providingServiceUuid is blank."
				msoLogger.debug(msg)
			}
			
			if(inputParameters.has("handoverMode"))
			{
				String handoverMode = inputParameters.get("handoverMode")
				execution.setVariable(Prefix + "HandoverMode", handoverMode)
			    is3rdONAPExist = true
			}
			else {
				is3rdONAPExist = false
				String msg = "sppartner handoverMode is blank."
				msoLogger.debug(msg)
			}
			
			execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
			execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
			execution.setVariable("mso-request-id", requestId)
			execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())

		} catch (BpmnError e) {
			throw e
		} catch (Exception ex){
			String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
			msoLogger.debug(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
	}

	public void checkLocallCall (DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started checkLocallCall *****")
		try {
					
			//Get ResourceInput Object
			ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")			

			//uuiRequest
			String incomingRequest = resourceInputObj.getRequestsInputs()
			String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
			String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
			JSONObject inputParameters = new JSONObject(customizeResourceParam(requestInputs))
			execution.setVariable(Prefix + "ServiceParameters", inputParameters)
			
			// CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
			boolean isLocalCall = true
			String callSource = "UUI"
			if(inputParameters.has("CallSource"))
			{
				callSource = inputParameters.get("CallSource")
				if("ExternalAPI".equalsIgnoreCase(callSource)) {
					isLocalCall = false
				}							
			}
			execution.setVariable(Prefix + "CallSource", callSource)
			msoLogger.debug("callSource is: " + callSource )
			
			execution.setVariable("IsLocalCall", isLocalCall)

		} catch (Exception ex){
			String msg = "Exception in checkLocallCall " + ex.getMessage()
			msoLogger.debug(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
	}

	public void preProcessRequest(DelegateExecution execution){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started preProcessRequest *****")
		try {
			ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
			String msg = ""

			String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
			if (isBlank(globalSubscriberId)) {
				msg = "Input globalSubscriberId is null"
				msoLogger.info(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			}
			//set local variable
			execution.setVariable("globalSubscriberId", globalSubscriberId)
			msoLogger.info("globalSubscriberId:" + globalSubscriberId)

			String serviceType = resourceInputObj.getServiceType()
			if (isBlank(serviceType)) {
				msg = "Input serviceType is null"
				msoLogger.info(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			}
			execution.setVariable("serviceType", serviceType)
			msoLogger.info("serviceType:" + serviceType)
			
			String resourceName = resourceInputObj.getResourceInstanceName()
			if (isBlank(resourceName)) {
				msg = "Input resourceName is null"
				msoLogger.info(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			}
			execution.setVariable("resourceName", resourceName)
			msoLogger.info("resourceName:" + resourceName)
			
			int beginIndex = resourceName.indexOf("_") + 1
			String serviceInstanceName = resourceName.substring(beginIndex)
			execution.setVariable("serviceInstanceName", serviceInstanceName)
			
			String serviceInstanceId = resourceInputObj.getServiceInstanceId()
			if (isBlank(serviceInstanceId)) {
				msg = "Input serviceInstanceId is null"
				msoLogger.info(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			}
			execution.setVariable("serviceInstanceId", serviceInstanceId)
			msoLogger.info("serviceInstanceId:" + serviceInstanceId)

		} catch (BpmnError e) {
			throw e
		} catch (Exception ex){
			String msg = "Exception in preProcessRequest " + ex.getMessage()
			msoLogger.debug(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
	}

	public void prepareUpdateProgress(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started prepareUpdateProgress *****")
		ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
		String operType = resourceInputObj.getOperationType()
		String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
		String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
		String modelName = resourceInputObj.getResourceModelInfo().getModelName()
		String operationId = resourceInputObj.getOperationId()
		String progress = execution.getVariable("progress")
		String status = execution.getVariable("status")
		String statusDescription = execution.getVariable("statusDescription")

		String body = """
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:ns="http://org.openecomp.mso/requestsdb">
                        <soapenv:Header/>
                <soapenv:Body>
                    <ns:updateResourceOperationStatus>
                               <operType>${operType}</operType>
                               <operationId>${operationId}</operationId>
                               <progress>${progress}</progress>
                               <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
                               <serviceId>${ServiceInstanceId}</serviceId>
                               <status>${status}</status>
                               <statusDescription>${statusDescription}</statusDescription>
                    </ns:updateResourceOperationStatus>
                </soapenv:Body>
                </soapenv:Envelope>"""

		setProgressUpdateVariables(execution, body)
		msoLogger.info(" ***** Exit prepareUpdateProgress *****")
	}

	public void allocateCrossONAPResource(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started allocateCrossONAPResource *****")
		
		//get TP links from AAI for SOTN handoverMode only
		String handoverMode = execution.getVariable(Prefix + "HandoverMode")
		if("SOTN".equalsIgnoreCase(handoverMode)) {
			//to do get tp link in AAI
			
			
			// Put TP Link info into serviceParameters
			String accessProviderId = ""
			String accessClientId = ""
			String accessTopologyId = ""
			String accessNodeId = ""
			String accessLtpId = ""
			JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")			
			inputParameters.put("access-provider-id", accessProviderId)
			inputParameters.put("access-client-id", accessClientId)
			inputParameters.put("access-topology-id", accessTopologyId)
			inputParameters.put("access-node-id", accessNodeId)
			inputParameters.put("access-ltp-id", accessLtpId)
			execution.setVariable(Prefix + "ServiceParameters", inputParameters)
		}
		
		msoLogger.info("Exit " + allocateCrossONAPResource)
	}

	public void prepare3rdONAPRequest(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started prepare3rdONAPRequest *****")
		
		String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
		String extAPIPath = sppartnerUrl + 'serviceOrder'
		execution.setVariable("ExternalAPIURL", extAPIPath)
		
		// ExternalAPI message format
		String externalId = execution.getVariable("resourceName")
		String category = "E2E Service"
		String description = "Service Order from SPPartner"
		String requestedStartDate = utils.generateCurrentTimeInUtc()
		String requestedCompletionDate = utils.generateCurrentTimeInUtc()
		String priority = "1" // 0-4 0:highest
		String subscriberId = execution.getVariable("globalSubscriberId")
		String customerRole = ""
		String subscriberName = ""
		String referredType = "Consumer"
		String orderItemId = "1"
		String action = "add" //for create
		String serviceState = "active"
		String serviceName = execution.getVariable("serviceInstanceName")
		String serviceType = execution.getVariable("serviceType")
		String serviceId = execution.getVariable("serviceInstanceId")
		
		Map<String, String> valueMap = new HashMap<>()
		valueMap.put("externalId", '"' + externalId + '"')
		valueMap.put("category", '"' + category + '"')
		valueMap.put("description", '"' + description + '"')
		valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
		valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
		valueMap.put("priority", '"'+ priority + '"')
		valueMap.put("subscriberId", '"' + subscriberId + '"')
		valueMap.put("customerRole", '"' + customerRole + '"')
		valueMap.put("subscriberName", '"' + subscriberName + '"')
		valueMap.put("referredType", '"' + referredType + '"')
		valueMap.put("orderItemId", '"' + orderItemId + '"')
		valueMap.put("action", '"' + action + '"')
		valueMap.put("serviceState", '"' + serviceState + '"')
		valueMap.put("serviceName", '"' + serviceName + '"')
		valueMap.put("serviceType", '"' + serviceType + '"')
		valueMap.put("serviceId", '"' + serviceId + '"')
		
		ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
		
		// insert CallSource='ExternalAPI' to uuiRequest		
		Map<String, String> callSourceMap = new HashMap<>()
		callSourceMap.put("inputName", "CallSource")
		callSourceMap.put("inputValue", "ExternalAPI")
		String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, callSourceMap)
		
		// Transfer all uuiRequest incomeParameters to ExternalAPI format
		JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
		for(String key : inputParameters.keySet()) {			
			String inputName = key
			String inputValue = inputParameters.opt(key)
			Map<String, String> requestInputsMap = new HashMap<>()
			requestInputsMap.put("inputName", '"' + inputName+ '"')
			requestInputsMap.put("inputValue", '"' + inputValue + '"')
			_requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
		}		 
		valueMap.put("_requestInputs_",  _requestInputs_)
		
		String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
		execution.setVariable(Prefix + "Payload", payload)
		msoLogger.info("Exit " + prepare3rdONAPRequest)
	}

	public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
		
		String extAPIPath = execution.getVariable("ExternalAPIURL")
		String payload = execution.getVariable(Prefix + "Payload")
		
		ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)

		APIResponse response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)

		int responseCode = response.getStatusCode()
		execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
		msoLogger.debug("Post ServiceOrder response code is: " + responseCode)

		String extApiResponse = response.getResponseBodyAsString()
		JSONObject responseObj = new JSONObject(extApiResponse)
		execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
		//Process Response
		if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
			//200 OK 201 CREATED 202 ACCEPTED
		{
			msoLogger.debug("Post ServiceOrder Received a Good Response")
			String serviceOrderId = responseObj.get("ServiceOrderId")
			execution.setVariable(Prefix + "SuccessIndicator", true)
			execution.setVariable("serviceOrderId", serviceOrderId)
		}
		else{
			msoLogger.debug("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
			exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
		}
		
		msoLogger.info("Exit " + doCreateE2ESIin3rdONAP)
	}
	

	public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
		
		String extAPIPath = execution.getVariable("ExternalAPIURL")
		extAPIPath += "/" + execution.getVariable("ServiceOrderId")
		
		ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)

		APIResponse response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)

		int responseCode = response.getStatusCode()
		execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
		msoLogger.debug("Get ServiceOrder response code is: " + responseCode)

		String extApiResponse = response.getResponseBodyAsString()
		JSONObject responseObj = new JSONObject(extApiResponse)
		execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
		
		//Process Response //200 OK 201 CREATED 202 ACCEPTED
		if(responseCode == 200 || responseCode == 201 || responseCode == 202 )			
		{
			msoLogger.debug("Get ServiceOrder Received a Good Response")
			String serviceOrderState = responseObj.get("State")
			execution.setVariable(Prefix + "SuccessIndicator", true)
			execution.setVariable("serviceOrderState", serviceOrderState)			
			
			// Get serviceOrder State and process progress
			if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
				execution.setVariable("progress", 15)
				execution.setVariable("status", "processing")				
			}
			if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
				execution.setVariable("progress", 40)
				execution.setVariable("status", "processing")
			}
			if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
				execution.setVariable("progress", 100)
				execution.setVariable("status", "finished")
			}
			if("FAILED".equalsIgnoreCase(serviceOrderState)) {
				execution.setVariable("progress", 100)
				execution.setVariable("status", "error")
			}
			else {
				execution.setVariable("progress", 100)
				execution.setVariable("status", "error")
				execution.setVariable("statusDescription", "Create Service Order Status is unknown")
			}
			execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
		}
		else{			
			msoLogger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
			execution.setVariable("progress", 100)
			execution.setVariable("status", "error")
			execution.setVariable("statusDescription", "Get ServiceOrder Received a bad response")
			exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get ServiceOrder Received a bad response from 3rdONAP External API")
		}		
		
		msoLogger.info("Exit " + getE2ESIProgressin3rdONAP)
	}
	
	/**
	 * delay 5 sec
	 */
	public void timeDelay(DelegateExecution execution) {
		def isDebugEnabled= execution.getVariable("isDebugLogEnabled")
		try {
			Thread.sleep(5000)
		} catch(InterruptedException e) {
			utils.log("ERROR", "Time Delay exception" + e )
		}
	}

	public void saveSPPartnerInAAI(DelegateExecution execution) {
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started postCreateE2ESIin3rdONAP *****")	
		
		String sppartnerId = UUID.randomUUID().toString()
		String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
		String callSource = execution.getVariable(Prefix + "CallSource")
		String serviceInstanceId = execution.getVariable("serviceInstanceId")
		String globalSubscriberId = execution.getVariable("globalSubscriberId")
		String serviceType = execution.getVariable("serviceType")
		
		AaiUtil aaiUriUtil = new AaiUtil(this)
		String aai_uri = aaiUriUtil.getBusinessSPPartnerUri(execution)
		String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
		
		String payload =
				"""<sp-partner xmlns=\"${namespace}\">
			        <id>${sppartnerId}</id>
			        <url>${sppartnerUrl}</url>
			        <callsource>${callSource}</callsource>
			        <relationship-list>
			          <relationship>
			            <related-to>service-instance</related-to>
			            <related-link>/aai/v14/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}</related-link>
			            <relationship-data>
			                <relationship-key>service-instance.service-instance-id</relationship-key>
			                <relationship-value>${serviceInstanceId}</relationship-value>
			            </relationship-data> 
			          </relationship>
			        </relationship-list>
				</sp-partner>""".trim()
		utils.logAudit(payload)
		
		String aai_endpoint = execution.getVariable("URN_aai_endpoint")
		String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(sppartnerId,"UTF-8")
		
		APIResponse response = aaiUriUtil.executeAAIPutCall(execution, serviceAaiPath, payload)
		int responseCode = response.getStatusCode()
		execution.setVariable(Prefix + "PutSppartnerResponseCode", responseCode)
		msoLogger.debug("  Put sppartner response code is: " + responseCode)

		String aaiResponse = response.getResponseBodyAsString()
		aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
		execution.setVariable(Prefix + "PutSppartnerResponse", aaiResponse)

		//Process Response
		if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
			//200 OK 201 CREATED 202 ACCEPTED
		{
			msoLogger.debug("PUT sppartner Received a Good Response")
			execution.setVariable(Prefix + "SuccessIndicator", true)
		}
		else
		{
			msoLogger.debug("Put sppartner Received a Bad Response Code. Response Code is: " + responseCode)
			exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
			throw new BpmnError("MSOWorkflowException")
		}
		
		msoLogger.info("Exit " + saveSPPartnerInAAI)
	}

	private void setProgressUpdateVariables(DelegateExecution execution, String body) {
		def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
		execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
		execution.setVariable("CVFMI_updateResOperStatusRequest", body)
	}	

	public void postProcess(DelegateExecution execution){
		def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
		msoLogger.info(" ***** Started postProcess *****")
		String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
		String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")

		msoLogger.info("response from AAI for put sppartner, response code :" + responseCode + "  response object :" + responseObj)
		msoLogger.info(" ***** Exit postProcess *****")
	}

	public void sendSyncResponse (DelegateExecution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		msoLogger.debug(" *** sendSyncResponse *** ")

		try {
			String operationStatus = "finished"
			// RESTResponse for main flow
			String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
			msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
			sendWorkflowResponse(execution, 202, resourceOperationResp)
			execution.setVariable("sentSyncResponse", true)

		} catch (Exception ex) {
			String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
			msoLogger.debug(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
		msoLogger.debug(" ***** Exit sendSyncResopnse *****")
	}
	
	String customizeResourceParam(String inputParametersJson) {
		List<Map<String, Object>> paramList = new ArrayList()
		JSONObject jsonObject = new JSONObject(inputParametersJson)
		Iterator iterator = jsonObject.keys()
		while (iterator.hasNext()) {
			String key = iterator.next()
			HashMap<String, String> hashMap = new HashMap()
			hashMap.put("name", key)
			hashMap.put("value", jsonObject.get(key))
			paramList.add(hashMap)
		}
		Map<String, List<Map<String, Object>>> paramMap = new HashMap()
		paramMap.put("param", paramList)

		return  new JSONObject(paramMap).toString()
	}
}