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