f87f32c610c0b96696578a5f799629c55da80d86
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.bpmn.infrastructure.scripts
22
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.common.scripts.MsoUtils
29 import org.onap.so.bpmn.common.scripts.NetworkUtils
30 import org.onap.so.bpmn.common.scripts.VfModuleBase;
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.UrnPropertiesReader
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils;
35 import org.onap.so.logger.MsoLogger
36 import org.onap.so.rest.APIResponse
37 import org.springframework.web.util.UriUtils
38 import org.onap.so.client.aai.AAIResourcesClient
39 import org.onap.so.client.aai.AAIObjectType
40 import org.onap.so.client.aai.entities.AAIResultWrapper
41 import org.onap.so.client.aai.entities.Relationships
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.json.JSONObject
45 import javax.ws.rs.NotFoundException
46
47 class DoCreateVfModuleVolumeV2 extends VfModuleBase {
48
49         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleVolumeV2.class);
50         String prefix='DCVFMODVOLV2_'
51         JsonUtils jsonUtil = new JsonUtils()
52
53
54     /**
55      * Perform initial processing, such as request validation, initialization of variables, etc.
56      * * @param execution
57      */
58     public void preProcessRequest(DelegateExecution execution) {
59         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
60         preProcessRequest(execution, isDebugEnabled)
61     }
62
63     public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
64
65                 execution.setVariable("prefix",prefix)
66                 execution.setVariable(prefix+'SuccessIndicator', false)
67                 execution.setVariable(prefix+'isPONR', false)
68
69                 displayInput(execution, isDebugLogEnabled)
70                 setRollbackData(execution, isDebugLogEnabled)
71                 setRollbackEnabled(execution, isDebugLogEnabled)
72
73
74                 def tenantId = execution.getVariable("tenantId")
75                 if (tenantId == null) {
76                         String cloudConfiguration = execution.getVariable("cloudConfiguration")
77                         tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
78                         execution.setVariable("tenantId", tenantId)
79                 }
80
81                 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
82                 if (cloudSiteId == null) {
83                         String cloudConfiguration = execution.getVariable("cloudConfiguration")
84                         cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
85                         execution.setVariable("lcpCloudRegionId", cloudSiteId)
86                 }
87
88                 // Extract attributes from modelInfo
89                 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
90
91                 //modelCustomizationUuid
92                 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
93                 execution.setVariable("modelCustomizationId", modelCustomizationUuid)
94                 msoLogger.debug("modelCustomizationId: " + modelCustomizationUuid)
95
96                 //modelName
97                 def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
98                 execution.setVariable("modelName", modelName)
99                 msoLogger.debug("modelName: " + modelName)
100
101                 // The following is used on the get Generic Service Instance call
102                 execution.setVariable('GENGS_type', 'service-instance')
103         }
104
105
106         /**
107          * Display input variables
108          * @param execution
109          * @param isDebugLogEnabled
110          */
111         public void displayInput(DelegateExecution execution, isDebugLogEnabled) {
112                 def input = ['mso-request-id', 'msoRequestId', 'isDebugLogEnabled', 'disableRollback', 'failIfExists', 'serviceInstanceId',
113                         'vnfId', 'vnfName', 'tenantId', 'volumeGroupId', 'volumeGroupName', 'lcpCloudRegionId', 'vnfType', 'vfModuleModelInfo',  'asdcServiceModelVersion',
114                         'test-volume-group-name', 'test-volume-group-id', 'vfModuleInputParams']
115
116                 msoLogger.debug('Begin input: ')
117                 input.each {
118                         msoLogger.debug(it + ': ' + execution.getVariable(it))
119                 }
120                 msoLogger.debug('End input.')
121         }
122
123
124         /**
125          * Define and set rollbackdata object
126          * @param execution
127          * @param isDebugEnabled
128          */
129         public void setRollbackData(DelegateExecution execution, isDebugEnabled) {
130                 def rollbackData = execution.getVariable("rollbackData")
131                 if (rollbackData == null) {
132                         rollbackData = new RollbackData()
133                 }
134                 def volumeGroupName = execution.getVariable('volumeGroupName')
135                 rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
136                 execution.setVariable("rollbackData", rollbackData)
137         }
138
139
140         /**
141          * Gets the service instance uri from aai
142          */
143         public void getServiceInstance(DelegateExecution execution) {
144                 try {
145                         String serviceInstanceId = execution.getVariable('serviceInstanceId')
146
147                         AAIResourcesClient resourceClient = new AAIResourcesClient()
148                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
149
150                         if(!resourceClient.exists(uri)){
151                                 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
152                         }
153
154                 }catch(BpmnError e) {
155                         throw e;
156                 }catch (Exception ex){
157                         String msg = "Exception in getServiceInstance. " + ex.getMessage()
158                         msoLogger.debug(msg)
159                         (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, msg)
160                 }
161         }
162
163         /**
164          * Get cloud region
165          * @param execution
166          * @param isDebugEnabled
167          */
168         public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
169
170                 def cloudRegion = execution.getVariable("lcpCloudRegionId")
171                 msoLogger.debug('Request cloud region is: ' + cloudRegion)
172
173                 AaiUtil aaiUtil = new AaiUtil(this)
174                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
175                 String queryCloudRegionRequest = aaiEndpoint + '/' + cloudRegion
176
177                 msoLogger.debug(queryCloudRegionRequest)
178
179                 cloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
180
181                 def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "AAI", cloudRegion)
182                 if ((aaiCloudRegion != "ERROR")) {
183                         execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
184                         msoLogger.debug("AIC Cloud Region for AAI: " + aaiCloudRegion)
185                 } else {
186                         String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
187                         msoLogger.debug(errorMessage)
188                         (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
189                 }
190
191                 def poCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
192                 if ((poCloudRegion != "ERROR")) {
193                         execution.setVariable("poLcpCloudRegionId", poCloudRegion)
194                         msoLogger.debug("AIC Cloud Region for PO: " + poCloudRegion)
195                 } else {
196                         String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
197                         msoLogger.debug(errorMessage)
198                         (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
199                 }
200
201                 def rollbackData = execution.getVariable("rollbackData")
202                 rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
203         }
204
205
206         /**
207          * Query AAI volume group by name
208          * @param execution
209          * @param isDebugEnabled
210          */
211         public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
212
213                 def volumeGroupName = execution.getVariable('volumeGroupName')
214                 def cloudRegion = execution.getVariable('lcpCloudRegionId')
215
216                 // This is for stub testing
217                 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
218                 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
219                         volumeGroupName = testVolumeGroupName
220                 }
221
222                 AaiUtil aaiUtil = new AaiUtil(this)
223                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
224                 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
225
226                 msoLogger.debug('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
227
228                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
229
230                 String returnCode = response.getStatusCode()
231                 String aaiResponseAsString = response.getResponseBodyAsString()
232
233                 msoLogger.debug("AAI query volume group by name return code: " + returnCode)
234                 msoLogger.debug("AAI query volume group by name response: " + aaiResponseAsString)
235
236                 ExceptionUtil exceptionUtil = new ExceptionUtil()
237
238                 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
239                 execution.setVariable(prefix+'AaiReturnCode', returnCode)
240
241                 if (returnCode=='200') {
242                         execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
243                         msoLogger.debug("Volume Group Name $volumeGroupName exists in AAI.")
244                 } else {
245                         if (returnCode=='404') {
246                                 msoLogger.debug("Volume Group Name $volumeGroupName does not exist in AAI.")
247                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
248                         } else {
249                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
250                                 throw new BpmnError("MSOWorkflowException")
251                         }
252                 }
253         }
254
255
256         /**
257          * Create a WorkflowException
258          * @param execution
259          * @param isDebugEnabled
260          */
261         public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage, isDebugEnabled) {
262                 msoLogger.debug(errorMessage)
263                 (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
264         }
265
266
267         /**
268          * Create a WorkflowException
269          * @param execution
270          * @param isDebugEnabled
271          */
272         public void handleError(DelegateExecution execution, isDebugEnabled) {
273                 WorkflowException we = execution.getVariable('WorkflowException')
274                 if (we == null) {
275                         (new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
276                 }
277                 throw new BpmnError("MSOWorkflowException")
278         }
279
280
281         /**
282          * Create volume group in AAI
283          * @param execution
284          * @param isDebugEnabled
285          */
286         public void callRESTCreateAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
287
288                 def vnfId = execution.getVariable('vnfId')
289                 def volumeGroupId = execution.getVariable('volumeGroupId')
290                 def volumeName = execution.getVariable("volumeGroupName")
291                 def modelCustomizationId = execution.getVariable("modelCustomizationId")
292                 def vnfType = execution.getVariable("vnfType")
293                 def tenantId = execution.getVariable("tenantId")
294                 def cloudRegion = execution.getVariable('lcpCloudRegionId')
295
296                 msoLogger.debug("volumeGroupId: " + volumeGroupId)
297
298                 def testGroupId = execution.getVariable('test-volume-group-id')
299                 if (testGroupId != null && testGroupId.trim() != '') {
300                         msoLogger.debug("test volumeGroupId is present: " + testGroupId)
301                         volumeGroupId = testGroupId
302                         execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
303                 }
304
305                 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
306
307                 AaiUtil aaiUtil = new AaiUtil(this)
308                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
309                 String createAAIVolumeGrpNameUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")
310
311                 String namespace =  aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
312                 msoLogger.debug("AAI namespace is: " + namespace)
313
314                 msoLogger.debug("Request URL for PUT: " + createAAIVolumeGrpNameUrlRequest)
315
316                 NetworkUtils networkUtils = new NetworkUtils()
317                 String payload = networkUtils.createCloudRegionVolumeRequest(volumeGroupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId)
318                 String payloadXml = utils.formatXml(payload)
319                 msoLogger.debug("Request payload for PUT: " + payloadXml)
320
321                 APIResponse response = aaiUtil.executeAAIPutCall(execution, createAAIVolumeGrpNameUrlRequest, payloadXml)
322
323                 String returnCode = response.getStatusCode()
324                 String aaiResponseAsString = response.getResponseBodyAsString()
325
326                 msoLogger.debug("AAI create volume group return code: " + returnCode)
327                 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
328
329                 execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode)
330                 execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString)
331
332                 ExceptionUtil exceptionUtil = new ExceptionUtil()
333
334                 if (returnCode =='201') {
335                         RollbackData rollbackData = execution.getVariable("rollbackData")
336                         rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
337                 } else {
338                         execution.setVariable(prefix+"isErrorMessageException", true)
339                         if (returnCode=='404') {
340                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
341                         } else {
342                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
343                                 msoLogger.debug(" AAI Adapter Query Failed.  WorkflowException - " + "\n" + aWorkflowException)
344                                 throw new BpmnError("MSOWorkflowException")
345                         }
346                 }
347         }
348
349
350         /**
351          * Prepare VNF adapter create request XML
352          * @param execution
353          */
354         public void prepareVnfAdapterCreateRequest(DelegateExecution execution, isDebugEnabled) {
355
356                 def aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
357                 def vnfId = utils.getNodeText(aaiGenericVnfResponse, 'vnf-id')
358                 def vnfName = utils.getNodeText(aaiGenericVnfResponse, 'vnf-name')
359                 def vnfType = utils.getNodeText(aaiGenericVnfResponse, "vnf-type")
360
361                 def requestId = execution.getVariable('msoRequestId')
362                 def serviceId = execution.getVariable('serviceInstanceId')
363                 def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
364                 def tenantId = execution.getVariable('tenantId')
365                 def volumeGroupId = execution.getVariable('volumeGroupId')
366                 def volumeGroupnName = execution.getVariable('volumeGroupName')
367
368                 def vnfVersion = execution.getVariable("asdcServiceModelVersion")
369                 def vnfModuleType = execution.getVariable("modelName")
370
371                 def modelCustomizationId = execution.getVariable("modelCustomizationId")
372
373                 // for testing
374                 msoLogger.debug("volumeGroupId: " + volumeGroupId)
375                 def testGroupId = execution.getVariable('test-volume-group-id')
376                 if (testGroupId != null && testGroupId.trim() != '') {
377                         msoLogger.debug("test volumeGroupId is present: " + testGroupId)
378                         volumeGroupId = testGroupId
379                         execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
380                 }
381                 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
382
383                 // volume group parameters
384
385                 String volumeGroupParams = ''
386                 StringBuilder sbParams = new StringBuilder()
387                 Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
388                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
389                         String paramsXml
390                         String paramName = entry.getKey();
391                         String paramValue = entry.getValue()
392                         paramsXml =
393                                 """     <entry>
394                            <key>${MsoUtils.xmlEscape(paramName)}</key>
395                            <value>${MsoUtils.xmlEscape(paramValue)}</value>
396                         </entry>
397                         """
398                         sbParams.append(paramsXml)
399                 }
400
401                 volumeGroupParams = sbParams.toString()
402                 msoLogger.debug("volumeGroupParams: "+ volumeGroupParams)
403
404                 def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
405                 msoLogger.debug("backoutOnFailure: "+ backoutOnFailure)
406
407                 def failIfExists = execution.getVariable("failIfExists")
408                 if(failIfExists == null) {
409                         failIfExists = 'true'
410                 }
411
412                 String messageId = UUID.randomUUID()
413                 msoLogger.debug("messageId to be used is generated: " + messageId)
414
415                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
416                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
417                 if ('true'.equals(useQualifiedHostName)) {
418                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
419                 }
420                 msoLogger.debug("CreateVfModuleVolume - notificationUrl: "+ notificationUrl)
421
422                 // build request
423                 String vnfSubCreateWorkflowRequest =
424                                 """
425                         <createVolumeGroupRequest>
426                                 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
427                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
428                                 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
429                                 <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
430                                 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
431                                 <volumeGroupName>${MsoUtils.xmlEscape(volumeGroupnName)}</volumeGroupName>
432                                 <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
433                                 <vnfVersion>${MsoUtils.xmlEscape(vnfVersion)}</vnfVersion>
434                                 <vfModuleType>${MsoUtils.xmlEscape(vnfModuleType)}</vfModuleType>
435                                 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationId)}</modelCustomizationUuid>
436                                 <volumeGroupParams>
437                                         <entry>
438                                                 <key>vnf_id</key>
439                                                 <value>${MsoUtils.xmlEscape(vnfId)}</value>
440                                         </entry>
441                                         <entry>
442                                                 <key>vnf_name</key>
443                                                 <value>${MsoUtils.xmlEscape(vnfName)}</value>
444                                         </entry>
445                                         <entry>
446                                                 <key>vf_module_id</key>
447                                                 <value>${MsoUtils.xmlEscape(volumeGroupId)}</value>
448                                         </entry>
449                                         <entry>
450                                                 <key>vf_module_name</key>
451                                                 <value>${MsoUtils.xmlEscape(volumeGroupnName)}</value>
452                                         </entry>
453                                         ${volumeGroupParams}
454                             </volumeGroupParams>
455                                 <skipAAI>true</skipAAI>
456                                 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
457                                 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
458                             <msoRequest>
459                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
460                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
461                             </msoRequest>
462                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
463                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
464                         </createVolumeGroupRequest>
465                 """
466
467                 String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
468                 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
469                 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
470                 execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)
471
472                 // build rollback request for use later if needed
473                 String vnfSubRollbackWorkflowRequest = buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl)
474
475                 msoLogger.debug("Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest)
476
477                 String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
478                 execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
479         }
480
481         public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) {
482
483                 def request = """
484                 <rollbackVolumeGroupRequest>
485                         <volumeGroupRollback>
486                            <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
487                            <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
488                            <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
489                            <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
490                            <volumeGroupCreated>true</volumeGroupCreated>
491                            <msoRequest>
492                               <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
493                               <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
494                            </msoRequest>
495                            <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
496                         </volumeGroupRollback>
497                         <skipAAI>true</skipAAI>
498                         <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
499                 </rollbackVolumeGroupRequest>
500                 """
501
502                 return request
503         }
504
505         public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) {
506                 String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId)
507                 return newRequest
508         }
509
510         /**
511          * Validate VNF adapter response
512          * @param execution
513          */
514         public void validateVnfResponse(DelegateExecution execution, isDebugEnabled) {
515                 def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
516                 msoLogger.debug("vnfAdapterSuccessIndicator: "+ vnfSuccess)
517                 if(vnfSuccess==true) {
518                         String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
519                         String heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
520                         String vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
521                         String updatedVnfRollbackRequest = updateRollbackVolumeGroupRequestXml(vnfRollbackRequest, heatStackID)
522                         msoLogger.debug("vnfAdapter rollback request: "+ updatedVnfRollbackRequest)
523                         RollbackData rollbackData = execution.getVariable("rollbackData")
524                         rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", updatedVnfRollbackRequest)
525                         rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
526                 }
527         }
528
529
530         /**
531          * Update voulume group in AAI
532          * @TODO: Can we re-use the create method??
533          * @param execution
534          * @param isDebugEnabled
535          */
536         public void callRESTUpdateCreatedVolGrpName(DelegateExecution execution, isDebugEnabled) {
537
538                 String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse")
539                 String volumeGroupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
540                 String modelCustomizationId = execution.getVariable("modelCustomizationId")
541                 String cloudRegion = execution.getVariable("lcpCloudRegionId")
542
543                 AaiUtil aaiUtil = new AaiUtil(this)
544                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
545                 String updateAAIVolumeGroupUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, 'UTF-8')
546
547                 String namespace =  aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
548
549                 msoLogger.debug("updateAAIVolumeGroupUrlRequest - " +  updateAAIVolumeGroupUrlRequest)
550
551                 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
552                 def heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
553
554                 execution.setVariable(prefix+"heatStackId", heatStackID)
555
556                 NetworkUtils networkUtils = new NetworkUtils()
557                 String payload = networkUtils.updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackID, namespace, modelCustomizationId)
558                 String payloadXml = utils.formatXml(payload)
559
560                 msoLogger.debug("Payload to Update Created VolumeGroupName - " + "\n" + payloadXml)
561
562                 APIResponse response = aaiUtil.executeAAIPutCall(execution, updateAAIVolumeGroupUrlRequest, payloadXml)
563
564                 String returnCode = response.getStatusCode()
565                 String aaiResponseAsString = response.getResponseBodyAsString()
566
567                 msoLogger.debug("AAI create volume group return code: " + returnCode)
568                 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
569
570                 ExceptionUtil exceptionUtil = new ExceptionUtil()
571
572                 if (returnCode =='200') {
573                         execution.setVariable(prefix+"updateCreatedAAIVolumeGrpNameResponse", aaiResponseAsString)
574                         execution.setVariable(prefix+"isPONR", true)
575                 } else {
576                         execution.setVariable(prefix+"isErrorMessageException", true)
577                         if (returnCode=='404') {
578                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
579                         } else {
580                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
581                                 msoLogger.debug(" AAI Adapter Query Failed.  WorkflowException - " + "\n" + aWorkflowException)
582                                 throw new BpmnError("MSOWorkflowException")
583                         }
584                 }
585         }
586
587
588         /**
589          * Query AAI Generic VNF
590          * @param execution
591          * @param isDebugEnabled
592          */
593         public void callRESTQueryAAIGenericVnf(DelegateExecution execution, isDebugEnabled) {
594
595                 def vnfId = execution.getVariable('vnfId')
596
597                 AaiUtil aaiUtil = new AaiUtil(this)
598                 String aaiEndpoint = aaiUtil.getNetworkGenericVnfEndpoint(execution)
599                 def String queryAAIRequest = aaiEndpoint + "/" + UriUtils.encode(vnfId, "UTF-8")
600
601                 msoLogger.debug("AAI query generic vnf request: " + queryAAIRequest)
602
603                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
604
605                 String returnCode = response.getStatusCode()
606                 String aaiResponseAsString = response.getResponseBodyAsString()
607
608                 msoLogger.debug("AAI query generic vnf return code: " + returnCode)
609                 msoLogger.debug("AAI query generic vnf response: " + aaiResponseAsString)
610
611                 ExceptionUtil exceptionUtil = new ExceptionUtil()
612
613                 if (returnCode=='200') {
614                         msoLogger.debug('Generic vnf ' + vnfId + ' found in AAI.')
615                         execution.setVariable(prefix+'AAIQueryGenericVfnResponse', aaiResponseAsString)
616                 } else {
617                         if (returnCode=='404') {
618                                 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
619                                 msoLogger.debug(message)
620                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
621                         } else {
622                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
623                                 throw new BpmnError("MSOWorkflowException")
624                         }
625                 }
626         }
627
628 }