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