aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy
blob: 13a7ffa49825bb9e9474170820b73da306cd328f (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
package org.openecomp.mso.bpmn.infrastructure.scripts

import static org.camunda.spin.Spin.XML;
import groovy.json.JsonSlurper
import groovy.lang.GroovyInterceptable;
import groovy.xml.XmlUtil

import org.openecomp.mso.bpmn.common.scripts.AaiUtil
import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
import org.openecomp.mso.bpmn.common.scripts.VfModuleBase;
import org.openecomp.mso.bpmn.core.RollbackData
import org.openecomp.mso.bpmn.core.WorkflowException
import org.openecomp.mso.bpmn.core.json.JsonUtils;
import org.openecomp.mso.rest.APIResponse
import org.springframework.web.util.UriUtils




import java.util.UUID;

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;

class DoCreateVfModuleVolumeV2 extends VfModuleBase {

	String prefix='DCVFMODVOLV2_'
	JsonUtils jsonUtil = new JsonUtils()


    /**
     * Perform initial processing, such as request validation, initialization of variables, etc.
     * * @param execution
     */
    public void preProcessRequest(DelegateExecution execution) {
        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
        preProcessRequest(execution, isDebugEnabled)
    }

    public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
		
		execution.setVariable("prefix",prefix)
		execution.setVariable(prefix+'SuccessIndicator', false)
		execution.setVariable(prefix+'isPONR', false)

		displayInput(execution, isDebugLogEnabled)
		setRollbackData(execution, isDebugLogEnabled)
		setRollbackEnabled(execution, isDebugLogEnabled) 
		
		
		def tenantId = execution.getVariable("tenantId")
		if (tenantId == null) {
			String cloudConfiguration = execution.getVariable("cloudConfiguration")
			tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
			execution.setVariable("tenantId", tenantId)
		}

		def cloudSiteId = execution.getVariable("lcpCloudRegionId")
		if (cloudSiteId == null) {
			String cloudConfiguration = execution.getVariable("cloudConfiguration")
			cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
			execution.setVariable("lcpCloudRegionId", cloudSiteId)
		}

		// Extract attributes from modelInfo
		String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")

		//modelCustomizationUuid
		def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
		execution.setVariable("modelCustomizationId", modelCustomizationUuid)
		logDebug("modelCustomizationId: " + modelCustomizationUuid, isDebugLogEnabled)
		
		//modelName
		def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
		execution.setVariable("modelName", modelName)
		logDebug("modelName: " + modelName, isDebugLogEnabled)
		
		// The following is used on the get Generic Service Instance call
		execution.setVariable('GENGS_type', 'service-instance')
	}

	
	/**
	 * Display input variables
	 * @param execution
	 * @param isDebugLogEnabled
	 */
	public void displayInput(DelegateExecution execution, isDebugLogEnabled) {
		def input = ['mso-request-id', 'msoRequestId', 'isDebugLogEnabled', 'disableRollback', 'failIfExists', 'serviceInstanceId',
			'vnfId', 'vnfName', 'tenantId', 'volumeGroupId', 'volumeGroupName', 'lcpCloudRegionId', 'vnfType', 'vfModuleModelInfo',  'asdcServiceModelVersion',
			'test-volume-group-name', 'test-volume-group-id', 'vfModuleInputParams']

		logDebug('Begin input: ', isDebugLogEnabled)
		input.each {
			logDebug(it + ': ' + execution.getVariable(it), isDebugLogEnabled)
		}
		logDebug('End input.', isDebugLogEnabled)
	}
	
	
	/**
	 * Define and set rollbackdata object 
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void setRollbackData(DelegateExecution execution, isDebugEnabled) {
		def rollbackData = execution.getVariable("rollbackData")
		if (rollbackData == null) {
			rollbackData = new RollbackData()
		}
		def volumeGroupName = execution.getVariable('volumeGroupName')
		rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
		execution.setVariable("rollbackData", rollbackData)
	}
	
		
	/**
	 * validate getServiceInstance response
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void validateGetServiceInstanceCall(DelegateExecution execution, isDebugEnabled) {
		def found = execution.getVariable('GENGS_FoundIndicator')
		def success = execution.getVariable('GENGS_SuccessIndicator')
		def serviceInstanceId = execution.getVariable('serviceInstanceId')
		utils.log("DEBUG", "getServiceInstance success: " + success, isDebugEnabled)
		utils.log("DEBUG", "getServiceInstance found: " + found, isDebugEnabled)
		if(!found || !success) {
			String errorMessage = "Service instance id not found in AAI: ${serviceInstanceId}."
			utils.log("DEBUG", errorMessage, isDebugEnabled)
			(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
		}
		
	}

	/**
	 * Get cloud region
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {

		def cloudRegion = execution.getVariable("lcpCloudRegionId")
		utils.log("DEBUG", 'Request cloud region is: ' + cloudRegion, isDebugEnabled)

		AaiUtil aaiUtil = new AaiUtil(this)
		String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
		String queryCloudRegionRequest = aaiEndpoint + '/' + cloudRegion

		utils.logAudit(queryCloudRegionRequest)

		cloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)

		def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "AAI", cloudRegion)
		if ((aaiCloudRegion != "ERROR")) {
			execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
			utils.log("DEBUG", "AIC Cloud Region for AAI: " + aaiCloudRegion, isDebugEnabled)
		} else {
			String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
			utils.log("DEBUG", errorMessage, isDebugEnabled)
			(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
		}
		
		def poCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
		if ((poCloudRegion != "ERROR")) {
			execution.setVariable("poLcpCloudRegionId", poCloudRegion)
			utils.log("DEBUG", "AIC Cloud Region for PO: " + poCloudRegion, isDebugEnabled)
		} else {
			String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
			utils.log("DEBUG", errorMessage, isDebugEnabled)
			(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
		}
		
		def rollbackData = execution.getVariable("rollbackData")
		rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
	}


	/**
	 * Query AAI volume group by name
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {

		def volumeGroupName = execution.getVariable('volumeGroupName')
		def cloudRegion = execution.getVariable('lcpCloudRegionId')

		// This is for stub testing
		def testVolumeGroupName = execution.getVariable('test-volume-group-name')
		if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
			volumeGroupName = testVolumeGroupName
		}

		AaiUtil aaiUtil = new AaiUtil(this)
		String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
		String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')

		utils.logAudit('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)

		APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)

		String returnCode = response.getStatusCode()
		String aaiResponseAsString = response.getResponseBodyAsString()
		aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)

		utils.logAudit("AAI query volume group by name return code: " + returnCode)
		utils.logAudit("AAI query volume group by name response: " + aaiResponseAsString)

		ExceptionUtil exceptionUtil = new ExceptionUtil()

		execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
		execution.setVariable(prefix+'AaiReturnCode', returnCode)

		if (returnCode=='200') {
			execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
			utils.log("DEBUG", "Volume Group Name $volumeGroupName exists in AAI.", isDebugEnabled)
		} else {
			if (returnCode=='404') {
				utils.log("DEBUG", "Volume Group Name $volumeGroupName does not exist in AAI.", isDebugEnabled)
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
			} else {
				WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
				throw new BpmnError("MSOWorkflowException")
			}
		}
	}


	/**
	 * Create a WorkflowException 
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage, isDebugEnabled) {
		utils.log("DEBUG", errorMessage, isDebugEnabled)
		(new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
	}


	/**
	 * Create a WorkflowException
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void handleError(DelegateExecution execution, isDebugEnabled) {
		WorkflowException we = execution.getVariable('WorkflowException')
		if (we == null) {
			(new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
		}
		throw new BpmnError("MSOWorkflowException")
	}

	
	/**
	 * Create volume group in AAI
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void callRESTCreateAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {

		def vnfId = execution.getVariable('vnfId')
		def volumeGroupId = execution.getVariable('volumeGroupId')
		def volumeName = execution.getVariable("volumeGroupName")
		def modelCustomizationId = execution.getVariable("modelCustomizationId")
		def vnfType = execution.getVariable("vnfType")
		def tenantId = execution.getVariable("tenantId")
		def cloudRegion = execution.getVariable('lcpCloudRegionId')
		
		utils.log("DEBUG", "volumeGroupId: " + volumeGroupId, isDebugEnabled)

		def testGroupId = execution.getVariable('test-volume-group-id')
		if (testGroupId != null && testGroupId.trim() != '') {
			utils.log("DEBUG", "test volumeGroupId is present: " + testGroupId, isDebugEnabled)
			volumeGroupId = testGroupId
			execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
		}

		utils.log("DEBUG", "volumeGroupId to be used: " + volumeGroupId, isDebugEnabled)

		AaiUtil aaiUtil = new AaiUtil(this)
		String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
		String createAAIVolumeGrpNameUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")

		String namespace =  aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
		utils.log("DEBUG", "AAI namespace is: " + namespace, isDebugEnabled)

		utils.logAudit("Request URL for PUT: " + createAAIVolumeGrpNameUrlRequest)

		NetworkUtils networkUtils = new NetworkUtils()
		String payload = networkUtils.createCloudRegionVolumeRequest(volumeGroupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId)
		String payloadXml = utils.formatXml(payload)
		utils.logAudit("Request payload for PUT: " + payloadXml)

		APIResponse response = aaiUtil.executeAAIPutCall(execution, createAAIVolumeGrpNameUrlRequest, payloadXml)

		String returnCode = response.getStatusCode()
		String aaiResponseAsString = response.getResponseBodyAsString()
		aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)

		utils.logAudit("AAI create volume group return code: " + returnCode)
		utils.logAudit("AAI create volume group response: " + aaiResponseAsString)

		execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode)
		execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString)
		
		ExceptionUtil exceptionUtil = new ExceptionUtil()

		if (returnCode =='201') {
			RollbackData rollbackData = execution.getVariable("rollbackData")
			rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
		} else {
			execution.setVariable(prefix+"isErrorMessageException", true)
			if (returnCode=='404') {
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
			} else {
				WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
				utils.log("DEBUG", " AAI Adapter Query Failed.  WorkflowException - " + "\n" + aWorkflowException, isDebugEnabled)
				throw new BpmnError("MSOWorkflowException")
			}
		}
	}
	

	/**
	 * Prepare VNF adapter create request XML
	 * @param execution
	 */
	public void prepareVnfAdapterCreateRequest(DelegateExecution execution, isDebugEnabled) {

		def aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
		def vnfId = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-id')
		def vnfName = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-name')
		def vnfType = utils.getNodeText1(aaiGenericVnfResponse, "vnf-type")
		
		def requestId = execution.getVariable('msoRequestId')
		def serviceId = execution.getVariable('serviceInstanceId')
		def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
		def tenantId = execution.getVariable('tenantId')
		def volumeGroupId = execution.getVariable('volumeGroupId')
		def volumeGroupnName = execution.getVariable('volumeGroupName')

		def vnfVersion = execution.getVariable("asdcServiceModelVersion") 
		def vnfModuleType = execution.getVariable("modelName")

		def modelCustomizationId = execution.getVariable("modelCustomizationId")
		
		// for testing
		utils.log("DEBUG", "volumeGroupId: " + volumeGroupId, isDebugEnabled)
		def testGroupId = execution.getVariable('test-volume-group-id')
		if (testGroupId != null && testGroupId.trim() != '') {
			utils.log("DEBUG", "test volumeGroupId is present: " + testGroupId, isDebugEnabled)
			volumeGroupId = testGroupId
			execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
		}
		utils.log("DEBUG", "volumeGroupId to be used: " + volumeGroupId, isDebugEnabled)
				
		// volume group parameters
		
		String volumeGroupParams = ''
		StringBuilder sbParams = new StringBuilder()
		Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
		for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
			String paramsXml
			String paramName = entry.getKey();
			String paramValue = entry.getValue()
			paramsXml =
				"""	<entry>
			   <key>${paramName}</key>
			   <value>${paramValue}</value>
			</entry>
			"""
			sbParams.append(paramsXml)
		}

		volumeGroupParams = sbParams.toString()
		utils.log("DEBUG", "volumeGroupParams: "+ volumeGroupParams, isDebugEnabled)

		def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
		utils.log("DEBUG", "backoutOnFailure: "+ backoutOnFailure, isDebugEnabled)

		def failIfExists = execution.getVariable("failIfExists")
		if(failIfExists == null) {
			failIfExists = 'true'
		}
		
		String messageId = UUID.randomUUID()
		utils.log("DEBUG", "messageId to be used is generated: " + messageId, isDebugEnabled)
		
		def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
		def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
		if ('true'.equals(useQualifiedHostName)) {
			notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
		}
		utils.log("DEBUG", "CreateVfModuleVolume - notificationUrl: "+ notificationUrl, isDebugEnabled)
		
		// build request
		String vnfSubCreateWorkflowRequest =
				"""
			<createVolumeGroupRequest>
				<cloudSiteId>${cloudSiteId}</cloudSiteId>
				<tenantId>${tenantId}</tenantId>
				<vnfId>${vnfId}</vnfId>
				<vnfName>${vnfName}</vnfName>
				<volumeGroupId>${volumeGroupId}</volumeGroupId>
				<volumeGroupName>${volumeGroupnName}</volumeGroupName>
				<vnfType>${vnfType}</vnfType>
				<vnfVersion>${vnfVersion}</vnfVersion>
				<vfModuleType>${vnfModuleType}</vfModuleType>
				<modelCustomizationUuid>${modelCustomizationId}</modelCustomizationUuid>
				<volumeGroupParams>
					<entry>
						<key>vnf_id</key>
						<value>${vnfId}</value>
					</entry>
					<entry>
						<key>vnf_name</key>
						<value>${vnfName}</value>
					</entry>
					<entry>
						<key>vf_module_id</key>
						<value>${volumeGroupId}</value>
					</entry>
					<entry>
						<key>vf_module_name</key>
						<value>${volumeGroupnName}</value>
					</entry>
					${volumeGroupParams}
			    </volumeGroupParams>
				<skipAAI>true</skipAAI>
				<backout>${backoutOnFailure}</backout>
				<failIfExists>${failIfExists}</failIfExists>
			    <msoRequest>
			        <requestId>${requestId}</requestId>
			        <serviceInstanceId>${serviceId}</serviceInstanceId>
			    </msoRequest>
			    <messageId>${messageId}</messageId>
			    <notificationUrl>${notificationUrl}</notificationUrl>
			</createVolumeGroupRequest>
		"""

		String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
		utils.logAudit(vnfSubCreateWorkflowRequestAsString)
		utils.log('DEBUG', vnfSubCreateWorkflowRequestAsString, isDebugEnabled)
		execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)

		// build rollback request for use later if needed
		String vnfSubRollbackWorkflowRequest = buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl)

		utils.log("DEBUG", "Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest, isDebugEnabled)

		String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
		execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
	}
	
	public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) {
		
		def request = """
		<rollbackVolumeGroupRequest>
			<volumeGroupRollback>
			   <volumeGroupId>${volumeGroupId}</volumeGroupId>
			   <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
			   <tenantId>${tenantId}</tenantId>
			   <cloudSiteId>${cloudSiteId}</cloudSiteId>
			   <volumeGroupCreated>true</volumeGroupCreated>
			   <msoRequest>
			      <requestId>${requestId}</requestId>
			      <serviceInstanceId>${serviceId}</serviceInstanceId>
			   </msoRequest>
			   <messageId>${messageId}</messageId>
			</volumeGroupRollback>
			<skipAAI>true</skipAAI>
			<notificationUrl>${notificationUrl}</notificationUrl>
		</rollbackVolumeGroupRequest>
		""" 
		
		return request	
	}

	public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) {
		String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId)
		return newRequest
	}
	
	/**
	 * Validate VNF adapter response
	 * @param execution
	 */
	public void validateVnfResponse(DelegateExecution execution, isDebugEnabled) {
		def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
		utils.log("DEBUG", "vnfAdapterSuccessIndicator: "+ vnfSuccess, isDebugEnabled)
		if(vnfSuccess==true) {
			String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
			String heatStackID = utils.getNodeText1(createVnfAResponse, "volumeGroupStackId")
			String vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
			String updatedVnfRollbackRequest = updateRollbackVolumeGroupRequestXml(vnfRollbackRequest, heatStackID)
			utils.log("DEBUG", "vnfAdapter rollback request: "+ updatedVnfRollbackRequest, isDebugEnabled)
			RollbackData rollbackData = execution.getVariable("rollbackData")
			rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", updatedVnfRollbackRequest)
			rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
		}
	}
	

	/**
	 * Update voulume group in AAI 
	 * @TODO: Can we re-use the create method??
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void callRESTUpdateCreatedVolGrpName(DelegateExecution execution, isDebugEnabled) {

		String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse")
		String volumeGroupId = utils.getNodeText1(requeryAAIVolGrpNameResponse, "volume-group-id")
		String modelCustomizationId = execution.getVariable("modelCustomizationId")  
		String cloudRegion = execution.getVariable("lcpCloudRegionId")

		AaiUtil aaiUtil = new AaiUtil(this)
		String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
		String updateAAIVolumeGroupUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, 'UTF-8')

		String namespace =  aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))

		utils.logAudit(updateAAIVolumeGroupUrlRequest)
		utils.log("DEBUG", "updateAAIVolumeGroupUrlRequest - " +  updateAAIVolumeGroupUrlRequest, isDebugEnabled)

		String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
		def heatStackID = utils.getNodeText1(createVnfAResponse, "volumeGroupStackId")
		
		execution.setVariable(prefix+"heatStackId", heatStackID)

		NetworkUtils networkUtils = new NetworkUtils()
		String payload = networkUtils.updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackID, namespace, modelCustomizationId)
		String payloadXml = utils.formatXml(payload)

		utils.logAudit("Payload to Update Created VolumeGroupName - " + "\n" + payloadXml)

		APIResponse response = aaiUtil.executeAAIPutCall(execution, updateAAIVolumeGroupUrlRequest, payloadXml)

		String returnCode = response.getStatusCode()
		String aaiResponseAsString = response.getResponseBodyAsString()
		aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)

		utils.logAudit("AAI create volume group return code: " + returnCode)
		utils.logAudit("AAI create volume group response: " + aaiResponseAsString)

		ExceptionUtil exceptionUtil = new ExceptionUtil()

		if (returnCode =='200') {
			execution.setVariable(prefix+"updateCreatedAAIVolumeGrpNameResponse", aaiResponseAsString)
			execution.setVariable(prefix+"isPONR", true)
		} else {
			execution.setVariable(prefix+"isErrorMessageException", true)
			if (returnCode=='404') {
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
			} else {
				WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
				utils.log("DEBUG", " AAI Adapter Query Failed.  WorkflowException - " + "\n" + aWorkflowException, isDebugEnabled)
				throw new BpmnError("MSOWorkflowException")
			}
		}
	}


	/**
	 * Query AAI Generic VNF
	 * @param execution
	 * @param isDebugEnabled
	 */
	public void callRESTQueryAAIGenericVnf(DelegateExecution execution, isDebugEnabled) {

		def vnfId = execution.getVariable('vnfId')

		AaiUtil aaiUtil = new AaiUtil(this)
		String aaiEndpoint = aaiUtil.getNetworkGenericVnfEndpoint(execution)
		def String queryAAIRequest = aaiEndpoint + "/" + UriUtils.encode(vnfId, "UTF-8")

		utils.logAudit("AAI query generic vnf request: " + queryAAIRequest)

		APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)

		String returnCode = response.getStatusCode()
		String aaiResponseAsString = response.getResponseBodyAsString()
		aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)

		utils.logAudit("AAI query generic vnf return code: " + returnCode)
		utils.logAudit("AAI query generic vnf response: " + aaiResponseAsString)

		ExceptionUtil exceptionUtil = new ExceptionUtil()

		if (returnCode=='200') {
			utils.log("DEBUG", 'Generic vnf ' + vnfId + ' found in AAI.', isDebugEnabled)
			execution.setVariable(prefix+'AAIQueryGenericVfnResponse', aaiResponseAsString)
		} else {
			if (returnCode=='404') {
				def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
				utils.log("DEBUG", message, isDebugEnabled)
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
			} else {
				WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
				throw new BpmnError("MSOWorkflowException")
			}
		}
	}

}