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