Merge "Fix Critical & Major issues in adapters"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVfModuleVolumeV2.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import javax.ws.rs.NotFoundException
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.GenericVnf
29 import org.onap.aai.domain.yang.VolumeGroup
30 import org.onap.aai.domain.yang.VolumeGroups
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.common.scripts.VfModuleBase
35 import org.onap.so.bpmn.core.RollbackData
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.client.aai.AAIObjectPlurals
40 import org.onap.so.client.aai.AAIObjectType
41 import org.onap.so.client.aai.AAIResourcesClient
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.constants.Defaults
45 import org.onap.so.db.catalog.beans.OrchestrationStatus
46 import org.slf4j.Logger
47 import org.slf4j.LoggerFactory
48
49 class DoCreateVfModuleVolumeV2 extends VfModuleBase {
50
51     private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleVolumeV2.class);
52     String prefix='DCVFMODVOLV2_'
53     JsonUtils jsonUtil = new JsonUtils()
54     private ExceptionUtil exceptionUtil = new ExceptionUtil()
55
56
57     /**
58      * Perform initial processing, such as request validation, initialization of variables, etc.
59      * * @param execution
60      */
61     public void preProcessRequest(DelegateExecution execution) {
62         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
63         preProcessRequest(execution, isDebugEnabled)
64     }
65
66     public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
67
68         execution.setVariable("prefix",prefix)
69         execution.setVariable(prefix+'SuccessIndicator', false)
70         execution.setVariable(prefix+'isPONR', false)
71
72         displayInput(execution, isDebugLogEnabled)
73         setRollbackData(execution, isDebugLogEnabled)
74         setRollbackEnabled(execution, isDebugLogEnabled)
75
76
77         def tenantId = execution.getVariable("tenantId")
78         if (tenantId == null) {
79             String cloudConfiguration = execution.getVariable("cloudConfiguration")
80             tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
81             execution.setVariable("tenantId", tenantId)
82         }
83
84         def cloudSiteId = execution.getVariable("lcpCloudRegionId")
85         if (cloudSiteId == null) {
86             String cloudConfiguration = execution.getVariable("cloudConfiguration")
87             cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
88             def cloudOwner = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.cloudOwner")
89             execution.setVariable("lcpCloudRegionId", cloudSiteId)
90             execution.setVariable("cloudOwner", cloudOwner)
91         }
92
93         // Extract attributes from modelInfo
94         String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
95
96         //modelCustomizationUuid
97         def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
98         execution.setVariable("modelCustomizationId", modelCustomizationUuid)
99         logger.debug("modelCustomizationId: " + modelCustomizationUuid)
100
101         //modelName
102         def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
103         execution.setVariable("modelName", modelName)
104         logger.debug("modelName: " + modelName)
105
106         // The following is used on the get Generic Service Instance call
107         execution.setVariable('GENGS_type', 'service-instance')
108     }
109
110
111     /**
112      * Display input variables
113      * @param execution
114      * @param isDebugLogEnabled
115      */
116     public void displayInput(DelegateExecution execution, isDebugLogEnabled) {
117         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']
118
119         logger.debug('Begin input: ')
120         input.each {
121             logger.debug(it + ': ' + execution.getVariable(it))
122         }
123         logger.debug('End input.')
124     }
125
126
127     /**
128      * Define and set rollbackdata object
129      * @param execution
130      * @param isDebugEnabled
131      */
132     public void setRollbackData(DelegateExecution execution, isDebugEnabled) {
133         def rollbackData = execution.getVariable("rollbackData")
134         if (rollbackData == null) {
135             rollbackData = new RollbackData()
136         }
137         def volumeGroupName = execution.getVariable('volumeGroupName')
138         rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
139         execution.setVariable("rollbackData", rollbackData)
140     }
141
142
143     /**
144      * Gets the service instance uri from aai
145      */
146     public void getServiceInstance(DelegateExecution execution) {
147         try {
148             String serviceInstanceId = execution.getVariable('serviceInstanceId')
149
150             AAIResourcesClient resourceClient = new AAIResourcesClient()
151             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
152
153             if(!resourceClient.exists(uri)){
154                 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
155             }
156         }catch(BpmnError e) {
157             throw e
158         }catch (Exception ex){
159             String msg = "Exception in getServiceInstance. " + ex.getMessage()
160             logger.debug(msg)
161             (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, msg)
162         }
163     }
164
165     /**
166      * Get cloud region
167      * @param execution
168      * @param isDebugEnabled
169      */
170     public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
171
172         def cloudRegion = execution.getVariable("lcpCloudRegionId")
173         logger.debug('Request cloud region is: ' + cloudRegion)
174
175         AaiUtil aaiUtil = new AaiUtil(this)
176
177         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, Defaults.CLOUD_OWNER.toString(), cloudRegion)
178         def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
179
180         cloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
181
182         def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "AAI", cloudRegion)
183         if ((aaiCloudRegion != "ERROR")) {
184             execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
185             logger.debug("AIC Cloud Region for AAI: " + aaiCloudRegion)
186         } else {
187             String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
188             logger.debug(errorMessage)
189             (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
190         }
191
192         def poCloudRegion = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
193         if ((poCloudRegion != "ERROR")) {
194             execution.setVariable("poLcpCloudRegionId", poCloudRegion)
195             logger.debug("AIC Cloud Region for PO: " + poCloudRegion)
196         } else {
197             String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
198             logger.debug(errorMessage)
199             (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
200         }
201
202         def rollbackData = execution.getVariable("rollbackData")
203         rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
204     }
205
206
207     /**
208      * Query AAI volume group by name
209      * @param execution
210      * @param isDebugEnabled
211      */
212     public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
213
214         def volumeGroupName = execution.getVariable('volumeGroupName')
215         def cloudRegion = execution.getVariable('lcpCloudRegionId')
216
217         try {
218             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion).queryParam("volume-group-name", volumeGroupName)
219             Optional<VolumeGroups> volumeGroups = getAAIClient().get(VolumeGroups.class,uri)
220             if(volumeGroups.isPresent()){
221                 VolumeGroup volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
222                 execution.setVariable(prefix+'AaiReturnCode', 200)
223                 execution.setVariable("queriedVolumeGroupId",volumeGroup.getVolumeGroupId())
224                 logger.debug("Volume Group Name $volumeGroupName exists in AAI.")
225             }else{
226                 execution.setVariable(prefix+'AaiReturnCode', 404)
227                 exceptionUtil.buildAndThrowWorkflowException(execution,25000, "Volume Group Name $volumeGroupName does not exist in AAI.")
228             }
229         }catch(BpmnError error){
230             throw error
231         }catch(Exception e){
232             execution.setVariable(prefix+'AaiReturnCode', 500)
233             exceptionUtil.buildAndThrowWorkflowException(execution,25000, "Exception in get volume group by name: " + e.getMessage())
234         }
235     }
236
237
238     /**
239      * Create a WorkflowException
240      * @param execution
241      * @param isDebugEnabled
242      */
243     public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage) {
244         logger.debug(errorMessage)
245         (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
246     }
247
248
249     /**
250      * Create a WorkflowException
251      * @param execution
252      * @param isDebugEnabled
253      */
254     public void handleError(DelegateExecution execution, isDebugEnabled) {
255         WorkflowException we = execution.getVariable('WorkflowException')
256         if (we == null) {
257             (new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
258         }
259         throw new BpmnError("MSOWorkflowException")
260     }
261
262
263     /**
264      * Create volume group in AAI
265      * @param execution
266      * @param isDebugEnabled
267      */
268     public void callRESTCreateAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
269
270         def vnfId = execution.getVariable('vnfId')
271         def volumeGroupId = execution.getVariable('volumeGroupId')
272         def volumeName = execution.getVariable("volumeGroupName")
273         def modelCustomizationId = execution.getVariable("modelCustomizationId")
274         def vnfType = execution.getVariable("vnfType")
275         def tenantId = execution.getVariable("tenantId")
276         def cloudRegion = execution.getVariable('lcpCloudRegionId')
277         def cloudOwner = execution.getVariable('cloudOwner')
278
279         def testGroupId = execution.getVariable('test-volume-group-id')
280         if (testGroupId != null && testGroupId.trim() != '') {
281             logger.debug("test volumeGroupId is present: " + testGroupId)
282             volumeGroupId = testGroupId
283             execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
284         }
285
286         VolumeGroup volumeGroup = new VolumeGroup()
287         volumeGroup.setVolumeGroupId(volumeGroupId)
288         volumeGroup.setVolumeGroupName(volumeName)
289         volumeGroup.setVnfType(vnfType)
290         volumeGroup.setOrchestrationStatus(OrchestrationStatus.PENDING.toString())
291         volumeGroup.setModelCustomizationId(modelCustomizationId)
292
293         logger.debug("volumeGroupId to be used: " + volumeGroupId)
294
295         AAIResourceUri volumeGroupUri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwner, cloudRegion, volumeGroupId)
296         AAIResourceUri tenantUri = AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId)
297         AAIResourceUri vnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
298         try {
299             getAAIClient().create(volumeGroupUri, volumeGroup)
300             getAAIClient().connect(volumeGroupUri, vnfUri)
301             getAAIClient().connect(volumeGroupUri, tenantUri)
302             execution.setVariable("queriedVolumeGroupId", volumeGroupId)
303             RollbackData rollbackData = execution.getVariable("rollbackData")
304             rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
305         } catch (NotFoundException ignored) {
306             execution.setVariable(prefix + "isErrorMessageException", true)
307             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
308         } catch (Exception ex) {
309             execution.setVariable(prefix + "isErrorMessageException", true)
310             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, ex.getMessage())
311         }
312     }
313
314     /**
315      * Prepare VNF adapter create request XML
316      * @param execution
317      */
318     public void prepareVnfAdapterCreateRequest(DelegateExecution execution, isDebugEnabled) {
319
320         GenericVnf aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
321         def vnfId = aaiGenericVnfResponse.getVnfId()
322         def vnfName = aaiGenericVnfResponse.getVnfName()
323         def vnfType = aaiGenericVnfResponse.getVnfType()
324
325         def requestId = execution.getVariable('msoRequestId')
326         def serviceId = execution.getVariable('serviceInstanceId')
327         def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
328         def tenantId = execution.getVariable('tenantId')
329         def volumeGroupId = execution.getVariable('volumeGroupId')
330         def volumeGroupnName = execution.getVariable('volumeGroupName')
331
332         def vnfVersion = execution.getVariable("asdcServiceModelVersion")
333         def vnfModuleType = execution.getVariable("modelName")
334
335         def modelCustomizationId = execution.getVariable("modelCustomizationId")
336
337         // for testing
338         logger.debug("volumeGroupId: " + volumeGroupId)
339         def testGroupId = execution.getVariable('test-volume-group-id')
340         if (testGroupId != null && testGroupId.trim() != '') {
341             logger.debug("test volumeGroupId is present: " + testGroupId)
342             volumeGroupId = testGroupId
343             execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
344         }
345         logger.debug("volumeGroupId to be used: " + volumeGroupId)
346
347         // volume group parameters
348
349         String volumeGroupParams = ''
350         StringBuilder sbParams = new StringBuilder()
351         Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
352         for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
353             String paramsXml
354             String paramName = entry.getKey()
355             String paramValue = entry.getValue()
356             paramsXml =
357                     """ <entry>
358                            <key>${MsoUtils.xmlEscape(paramName)}</key>
359                            <value>${MsoUtils.xmlEscape(paramValue)}</value>
360                         </entry>
361                         """
362             sbParams.append(paramsXml)
363         }
364
365         volumeGroupParams = sbParams.toString()
366         logger.debug("volumeGroupParams: "+ volumeGroupParams)
367
368         def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
369         logger.debug("backoutOnFailure: "+ backoutOnFailure)
370
371         def failIfExists = execution.getVariable("failIfExists")
372         if(failIfExists == null) {
373             failIfExists = 'true'
374         }
375
376         String messageId = UUID.randomUUID()
377         logger.debug("messageId to be used is generated: " + messageId)
378
379         def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
380         def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
381         if ('true'.equals(useQualifiedHostName)) {
382             notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
383         }
384         logger.debug("CreateVfModuleVolume - notificationUrl: "+ notificationUrl)
385
386         // build request
387         String vnfSubCreateWorkflowRequest =
388                 """
389                         <createVolumeGroupRequest>
390                                 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
391                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
392                                 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
393                                 <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
394                                 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
395                                 <volumeGroupName>${MsoUtils.xmlEscape(volumeGroupnName)}</volumeGroupName>
396                                 <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
397                                 <vnfVersion>${MsoUtils.xmlEscape(vnfVersion)}</vnfVersion>
398                                 <vfModuleType>${MsoUtils.xmlEscape(vnfModuleType)}</vfModuleType>
399                                 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationId)}</modelCustomizationUuid>
400                                 <volumeGroupParams>
401                                         <entry>
402                                                 <key>vnf_id</key>
403                                                 <value>${MsoUtils.xmlEscape(vnfId)}</value>
404                                         </entry>
405                                         <entry>
406                                                 <key>vnf_name</key>
407                                                 <value>${MsoUtils.xmlEscape(vnfName)}</value>
408                                         </entry>
409                                         <entry>
410                                                 <key>vf_module_id</key>
411                                                 <value>${MsoUtils.xmlEscape(volumeGroupId)}</value>
412                                         </entry>
413                                         <entry>
414                                                 <key>vf_module_name</key>
415                                                 <value>${MsoUtils.xmlEscape(volumeGroupnName)}</value>
416                                         </entry>
417                                         ${volumeGroupParams}
418                             </volumeGroupParams>
419                                 <skipAAI>true</skipAAI>
420                                 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
421                                 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
422                             <msoRequest>
423                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
424                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
425                             </msoRequest>
426                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
427                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
428                         </createVolumeGroupRequest>
429                 """
430
431         String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
432         logger.debug(vnfSubCreateWorkflowRequestAsString)
433         logger.debug(vnfSubCreateWorkflowRequestAsString)
434         execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)
435
436         // build rollback request for use later if needed
437         String vnfSubRollbackWorkflowRequest = buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl)
438
439         logger.debug("Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest)
440
441         String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
442         execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
443     }
444
445     public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) {
446
447         String request = """
448                 <rollbackVolumeGroupRequest>
449                         <volumeGroupRollback>
450                            <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
451                            <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
452                            <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
453                            <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
454                            <volumeGroupCreated>true</volumeGroupCreated>
455                            <msoRequest>
456                               <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
457                               <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
458                            </msoRequest>
459                            <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
460                         </volumeGroupRollback>
461                         <skipAAI>true</skipAAI>
462                         <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
463                 </rollbackVolumeGroupRequest>
464                 """
465
466         return request
467     }
468
469     public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) {
470         String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId)
471         return newRequest
472     }
473
474     /**
475      * Validate VNF adapter response
476      * @param execution
477      */
478     public void validateVnfResponse(DelegateExecution execution, isDebugEnabled) {
479         def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
480         logger.debug("vnfAdapterSuccessIndicator: "+ vnfSuccess)
481         if(vnfSuccess==true) {
482             String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
483             String heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
484             String vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
485             String updatedVnfRollbackRequest = updateRollbackVolumeGroupRequestXml(vnfRollbackRequest, heatStackID)
486             logger.debug("vnfAdapter rollback request: "+ updatedVnfRollbackRequest)
487             RollbackData rollbackData = execution.getVariable("rollbackData")
488             rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", updatedVnfRollbackRequest)
489             rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
490         }
491     }
492
493
494     /**
495      * Update voulume group in AAI
496      * @TODO: Can we re-use the create method??
497      * @param execution
498      * @param isDebugEnabled
499      */
500     public void callRESTUpdateCreatedVolGrpName(DelegateExecution execution, isDebugEnabled) {
501         String volumeGroupId = execution.getVariable("queriedVolumeGroupId")
502         String modelCustomizationId = execution.getVariable("modelCustomizationId")
503         String cloudRegion = execution.getVariable("lcpCloudRegionId")
504         String cloudOwner = execution.getVariable('cloudOwner')
505         String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
506         def heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
507         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudOwner, cloudRegion, volumeGroupId)
508
509         execution.setVariable(prefix+"heatStackId", heatStackID)
510
511         VolumeGroup volumeGroup = new VolumeGroup()
512         volumeGroup.setHeatStackId(heatStackID)
513         volumeGroup.setModelCustomizationId(modelCustomizationId)
514         try {
515             getAAIClient().update(uri, volumeGroup)
516             execution.setVariable(prefix+"isPONR", true)
517         }catch(NotFoundException ignored){
518             execution.setVariable(prefix+"isErrorMessageException", true)
519             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
520         }catch(BpmnError error){
521             throw error
522         }catch(Exception e){
523             execution.setVariable(prefix+"isErrorMessageException", true)
524             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "AAI Adapter Query Failed. "+ e.getMessage())
525         }
526     }
527
528
529     /**
530      * Query AAI Generic VNF
531      * @param execution
532      * @param isDebugEnabled
533      */
534     public void callRESTQueryAAIGenericVnf(DelegateExecution execution, isDebugEnabled) {
535
536         def vnfId = execution.getVariable('vnfId')
537         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
538         try {
539             Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class, uri)
540             if (genericVnf.isPresent()) {
541                 execution.setVariable(prefix + 'AAIQueryGenericVfnResponse', genericVnf.get())
542             } else {
543                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.')
544             }
545         }catch(Exception e){
546             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Exception in get generic VNF: " + e.getMessage())
547         }
548     }
549
550 }