2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.common.scripts.MsoUtils
29 import org.onap.so.bpmn.common.scripts.NetworkUtils
30 import org.onap.so.bpmn.common.scripts.VfModuleBase;
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.UrnPropertiesReader
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils;
35 import org.onap.so.logger.MsoLogger
36 import org.onap.so.rest.APIResponse
37 import org.springframework.web.util.UriUtils
38 import org.onap.so.client.aai.AAIResourcesClient
39 import org.onap.so.client.aai.AAIObjectType
40 import org.onap.so.client.aai.AAIObjectPlurals
41 import org.onap.so.client.aai.entities.AAIResultWrapper
42 import org.onap.so.client.aai.entities.Relationships
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.constants.Defaults
46 import org.json.JSONObject
47 import javax.ws.rs.NotFoundException
49 class DoCreateVfModuleVolumeV2 extends VfModuleBase {
51 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleVolumeV2.class);
52 String prefix='DCVFMODVOLV2_'
53 JsonUtils jsonUtil = new JsonUtils()
57 * Perform initial processing, such as request validation, initialization of variables, etc.
60 public void preProcessRequest(DelegateExecution execution) {
61 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
62 preProcessRequest(execution, isDebugEnabled)
65 public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
67 execution.setVariable("prefix",prefix)
68 execution.setVariable(prefix+'SuccessIndicator', false)
69 execution.setVariable(prefix+'isPONR', false)
71 displayInput(execution, isDebugLogEnabled)
72 setRollbackData(execution, isDebugLogEnabled)
73 setRollbackEnabled(execution, isDebugLogEnabled)
76 def tenantId = execution.getVariable("tenantId")
77 if (tenantId == null) {
78 String cloudConfiguration = execution.getVariable("cloudConfiguration")
79 tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
80 execution.setVariable("tenantId", tenantId)
83 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
84 if (cloudSiteId == null) {
85 String cloudConfiguration = execution.getVariable("cloudConfiguration")
86 cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
87 def cloudOwner = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.cloudOwner")
88 execution.setVariable("lcpCloudRegionId", cloudSiteId)
89 execution.setVariable("cloudOwner", cloudOwner)
92 // Extract attributes from modelInfo
93 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
95 //modelCustomizationUuid
96 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
97 execution.setVariable("modelCustomizationId", modelCustomizationUuid)
98 msoLogger.debug("modelCustomizationId: " + modelCustomizationUuid)
101 def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
102 execution.setVariable("modelName", modelName)
103 msoLogger.debug("modelName: " + modelName)
105 // The following is used on the get Generic Service Instance call
106 execution.setVariable('GENGS_type', 'service-instance')
111 * Display input variables
113 * @param isDebugLogEnabled
115 public void displayInput(DelegateExecution execution, isDebugLogEnabled) {
116 def input = ['mso-request-id', 'msoRequestId', 'isDebugLogEnabled', 'disableRollback', 'failIfExists', 'serviceInstanceId',
117 'vnfId', 'vnfName', 'tenantId', 'volumeGroupId', 'volumeGroupName', 'lcpCloudRegionId', 'vnfType', 'vfModuleModelInfo', 'asdcServiceModelVersion',
118 'test-volume-group-name', 'test-volume-group-id', 'vfModuleInputParams']
120 msoLogger.debug('Begin input: ')
122 msoLogger.debug(it + ': ' + execution.getVariable(it))
124 msoLogger.debug('End input.')
129 * Define and set rollbackdata object
131 * @param isDebugEnabled
133 public void setRollbackData(DelegateExecution execution, isDebugEnabled) {
134 def rollbackData = execution.getVariable("rollbackData")
135 if (rollbackData == null) {
136 rollbackData = new RollbackData()
138 def volumeGroupName = execution.getVariable('volumeGroupName')
139 rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
140 execution.setVariable("rollbackData", rollbackData)
145 * Gets the service instance uri from aai
147 public void getServiceInstance(DelegateExecution execution) {
149 String serviceInstanceId = execution.getVariable('serviceInstanceId')
151 AAIResourcesClient resourceClient = new AAIResourcesClient()
152 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
154 if(!resourceClient.exists(uri)){
155 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
158 }catch(BpmnError e) {
160 }catch (Exception ex){
161 String msg = "Exception in getServiceInstance. " + ex.getMessage()
163 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, msg)
170 * @param isDebugEnabled
172 public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
174 def cloudRegion = execution.getVariable("lcpCloudRegionId")
175 msoLogger.debug('Request cloud region is: ' + cloudRegion)
177 AaiUtil aaiUtil = new AaiUtil(this)
179 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, Defaults.CLOUD_OWNER.toString(), cloudRegion)
180 def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
182 cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
184 def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "AAI", cloudRegion)
185 if ((aaiCloudRegion != "ERROR")) {
186 execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
187 msoLogger.debug("AIC Cloud Region for AAI: " + aaiCloudRegion)
189 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
190 msoLogger.debug(errorMessage)
191 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
194 def poCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
195 if ((poCloudRegion != "ERROR")) {
196 execution.setVariable("poLcpCloudRegionId", poCloudRegion)
197 msoLogger.debug("AIC Cloud Region for PO: " + poCloudRegion)
199 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
200 msoLogger.debug(errorMessage)
201 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
204 def rollbackData = execution.getVariable("rollbackData")
205 rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
210 * Query AAI volume group by name
212 * @param isDebugEnabled
214 public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
216 def volumeGroupName = execution.getVariable('volumeGroupName')
217 def cloudRegion = execution.getVariable('lcpCloudRegionId')
219 // This is for stub testing
220 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
221 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
222 volumeGroupName = testVolumeGroupName
225 AaiUtil aaiUtil = new AaiUtil(this)
227 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion).queryParam("volume-group-name", volumeGroupName)
228 def queryAAIVolumeNameRequest = aaiUtil.createAaiUri(uri)
230 msoLogger.debug('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
232 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
234 String returnCode = response.getStatusCode()
235 String aaiResponseAsString = response.getResponseBodyAsString()
237 msoLogger.debug("AAI query volume group by name return code: " + returnCode)
238 msoLogger.debug("AAI query volume group by name response: " + aaiResponseAsString)
240 ExceptionUtil exceptionUtil = new ExceptionUtil()
242 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
243 execution.setVariable(prefix+'AaiReturnCode', returnCode)
245 if (returnCode=='200') {
246 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
247 msoLogger.debug("Volume Group Name $volumeGroupName exists in AAI.")
249 if (returnCode=='404') {
250 msoLogger.debug("Volume Group Name $volumeGroupName does not exist in AAI.")
251 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
253 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
254 throw new BpmnError("MSOWorkflowException")
261 * Create a WorkflowException
263 * @param isDebugEnabled
265 public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage, isDebugEnabled) {
266 msoLogger.debug(errorMessage)
267 (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
272 * Create a WorkflowException
274 * @param isDebugEnabled
276 public void handleError(DelegateExecution execution, isDebugEnabled) {
277 WorkflowException we = execution.getVariable('WorkflowException')
279 (new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
281 throw new BpmnError("MSOWorkflowException")
286 * Create volume group in AAI
288 * @param isDebugEnabled
290 public void callRESTCreateAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
292 def vnfId = execution.getVariable('vnfId')
293 def volumeGroupId = execution.getVariable('volumeGroupId')
294 def volumeName = execution.getVariable("volumeGroupName")
295 def modelCustomizationId = execution.getVariable("modelCustomizationId")
296 def vnfType = execution.getVariable("vnfType")
297 def tenantId = execution.getVariable("tenantId")
298 def cloudRegion = execution.getVariable('lcpCloudRegionId')
299 def cloudOwner = execution.getVariable('cloudOwner')
300 msoLogger.debug("volumeGroupId: " + volumeGroupId)
302 def testGroupId = execution.getVariable('test-volume-group-id')
303 if (testGroupId != null && testGroupId.trim() != '') {
304 msoLogger.debug("test volumeGroupId is present: " + testGroupId)
305 volumeGroupId = testGroupId
306 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
309 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
311 AaiUtil aaiUtil = new AaiUtil(this)
313 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion, volumeGroupId)
314 def createAAIVolumeGrpNameUrlRequest = aaiUtil.createAaiUri(uri)
316 String namespace = aaiUtil.getNamespaceFromUri(createAAIVolumeGrpNameUrlRequest)
317 msoLogger.debug("AAI namespace is: " + namespace)
319 msoLogger.debug("Request URL for PUT: " + createAAIVolumeGrpNameUrlRequest)
321 NetworkUtils networkUtils = new NetworkUtils()
322 String payload = networkUtils.createCloudRegionVolumeRequest(volumeGroupId, volumeName, vnfType, vnfId, tenantId, cloudOwner, cloudRegion, namespace, modelCustomizationId)
323 String payloadXml = utils.formatXml(payload)
324 msoLogger.debug("Request payload for PUT: " + payloadXml)
326 APIResponse response = aaiUtil.executeAAIPutCall(execution, createAAIVolumeGrpNameUrlRequest, payloadXml)
328 String returnCode = response.getStatusCode()
329 String aaiResponseAsString = response.getResponseBodyAsString()
331 msoLogger.debug("AAI create volume group return code: " + returnCode)
332 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
334 execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode)
335 execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString)
337 ExceptionUtil exceptionUtil = new ExceptionUtil()
339 if (returnCode =='201') {
340 RollbackData rollbackData = execution.getVariable("rollbackData")
341 rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
343 execution.setVariable(prefix+"isErrorMessageException", true)
344 if (returnCode=='404') {
345 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
347 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
348 msoLogger.debug(" AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException)
349 throw new BpmnError("MSOWorkflowException")
356 * Prepare VNF adapter create request XML
359 public void prepareVnfAdapterCreateRequest(DelegateExecution execution, isDebugEnabled) {
361 def aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
362 def vnfId = utils.getNodeText(aaiGenericVnfResponse, 'vnf-id')
363 def vnfName = utils.getNodeText(aaiGenericVnfResponse, 'vnf-name')
364 def vnfType = utils.getNodeText(aaiGenericVnfResponse, "vnf-type")
366 def requestId = execution.getVariable('msoRequestId')
367 def serviceId = execution.getVariable('serviceInstanceId')
368 def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
369 def tenantId = execution.getVariable('tenantId')
370 def volumeGroupId = execution.getVariable('volumeGroupId')
371 def volumeGroupnName = execution.getVariable('volumeGroupName')
373 def vnfVersion = execution.getVariable("asdcServiceModelVersion")
374 def vnfModuleType = execution.getVariable("modelName")
376 def modelCustomizationId = execution.getVariable("modelCustomizationId")
379 msoLogger.debug("volumeGroupId: " + volumeGroupId)
380 def testGroupId = execution.getVariable('test-volume-group-id')
381 if (testGroupId != null && testGroupId.trim() != '') {
382 msoLogger.debug("test volumeGroupId is present: " + testGroupId)
383 volumeGroupId = testGroupId
384 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
386 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
388 // volume group parameters
390 String volumeGroupParams = ''
391 StringBuilder sbParams = new StringBuilder()
392 Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
393 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
395 String paramName = entry.getKey();
396 String paramValue = entry.getValue()
399 <key>${MsoUtils.xmlEscape(paramName)}</key>
400 <value>${MsoUtils.xmlEscape(paramValue)}</value>
403 sbParams.append(paramsXml)
406 volumeGroupParams = sbParams.toString()
407 msoLogger.debug("volumeGroupParams: "+ volumeGroupParams)
409 def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
410 msoLogger.debug("backoutOnFailure: "+ backoutOnFailure)
412 def failIfExists = execution.getVariable("failIfExists")
413 if(failIfExists == null) {
414 failIfExists = 'true'
417 String messageId = UUID.randomUUID()
418 msoLogger.debug("messageId to be used is generated: " + messageId)
420 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
421 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
422 if ('true'.equals(useQualifiedHostName)) {
423 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
425 msoLogger.debug("CreateVfModuleVolume - notificationUrl: "+ notificationUrl)
428 String vnfSubCreateWorkflowRequest =
430 <createVolumeGroupRequest>
431 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
432 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
433 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
434 <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
435 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
436 <volumeGroupName>${MsoUtils.xmlEscape(volumeGroupnName)}</volumeGroupName>
437 <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
438 <vnfVersion>${MsoUtils.xmlEscape(vnfVersion)}</vnfVersion>
439 <vfModuleType>${MsoUtils.xmlEscape(vnfModuleType)}</vfModuleType>
440 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationId)}</modelCustomizationUuid>
444 <value>${MsoUtils.xmlEscape(vnfId)}</value>
448 <value>${MsoUtils.xmlEscape(vnfName)}</value>
451 <key>vf_module_id</key>
452 <value>${MsoUtils.xmlEscape(volumeGroupId)}</value>
455 <key>vf_module_name</key>
456 <value>${MsoUtils.xmlEscape(volumeGroupnName)}</value>
460 <skipAAI>true</skipAAI>
461 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
462 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
464 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
465 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
467 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
468 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
469 </createVolumeGroupRequest>
472 String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
473 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
474 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
475 execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)
477 // build rollback request for use later if needed
478 String vnfSubRollbackWorkflowRequest = buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl)
480 msoLogger.debug("Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest)
482 String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
483 execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
486 public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) {
489 <rollbackVolumeGroupRequest>
490 <volumeGroupRollback>
491 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
492 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
493 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
494 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
495 <volumeGroupCreated>true</volumeGroupCreated>
497 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
498 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
500 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
501 </volumeGroupRollback>
502 <skipAAI>true</skipAAI>
503 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
504 </rollbackVolumeGroupRequest>
510 public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) {
511 String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId)
516 * Validate VNF adapter response
519 public void validateVnfResponse(DelegateExecution execution, isDebugEnabled) {
520 def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
521 msoLogger.debug("vnfAdapterSuccessIndicator: "+ vnfSuccess)
522 if(vnfSuccess==true) {
523 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
524 String heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
525 String vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
526 String updatedVnfRollbackRequest = updateRollbackVolumeGroupRequestXml(vnfRollbackRequest, heatStackID)
527 msoLogger.debug("vnfAdapter rollback request: "+ updatedVnfRollbackRequest)
528 RollbackData rollbackData = execution.getVariable("rollbackData")
529 rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", updatedVnfRollbackRequest)
530 rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
536 * Update voulume group in AAI
537 * @TODO: Can we re-use the create method??
539 * @param isDebugEnabled
541 public void callRESTUpdateCreatedVolGrpName(DelegateExecution execution, isDebugEnabled) {
543 String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse")
544 String volumeGroupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
545 String modelCustomizationId = execution.getVariable("modelCustomizationId")
546 String cloudRegion = execution.getVariable("lcpCloudRegionId")
548 AaiUtil aaiUtil = new AaiUtil(this)
550 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), cloudRegion, volumeGroupId)
551 def updateAAIVolumeGroupUrlRequest = aaiUtil.createAaiUri(uri)
553 String namespace = aaiUtil.getNamespaceFromUri(updateAAIVolumeGroupUrlRequest)
555 msoLogger.debug("updateAAIVolumeGroupUrlRequest - " + updateAAIVolumeGroupUrlRequest)
557 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
558 def heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
560 execution.setVariable(prefix+"heatStackId", heatStackID)
562 NetworkUtils networkUtils = new NetworkUtils()
563 String payload = networkUtils.updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackID, namespace, modelCustomizationId)
564 String payloadXml = utils.formatXml(payload)
566 msoLogger.debug("Payload to Update Created VolumeGroupName - " + "\n" + payloadXml)
568 APIResponse response = aaiUtil.executeAAIPutCall(execution, updateAAIVolumeGroupUrlRequest, payloadXml)
570 String returnCode = response.getStatusCode()
571 String aaiResponseAsString = response.getResponseBodyAsString()
573 msoLogger.debug("AAI create volume group return code: " + returnCode)
574 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
576 ExceptionUtil exceptionUtil = new ExceptionUtil()
578 if (returnCode =='200') {
579 execution.setVariable(prefix+"updateCreatedAAIVolumeGrpNameResponse", aaiResponseAsString)
580 execution.setVariable(prefix+"isPONR", true)
582 execution.setVariable(prefix+"isErrorMessageException", true)
583 if (returnCode=='404') {
584 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
586 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
587 msoLogger.debug(" AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException)
588 throw new BpmnError("MSOWorkflowException")
595 * Query AAI Generic VNF
597 * @param isDebugEnabled
599 public void callRESTQueryAAIGenericVnf(DelegateExecution execution, isDebugEnabled) {
601 def vnfId = execution.getVariable('vnfId')
603 AaiUtil aaiUtil = new AaiUtil(this)
604 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
605 String queryAAIRequest = aaiUtil.createAaiUri(uri)
607 msoLogger.debug("AAI query generic vnf endpoint: " + queryAAIRequest)
609 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
611 String returnCode = response.getStatusCode()
612 String aaiResponseAsString = response.getResponseBodyAsString()
614 msoLogger.debug("AAI query generic vnf return code: " + returnCode)
615 msoLogger.debug("AAI query generic vnf response: " + aaiResponseAsString)
617 ExceptionUtil exceptionUtil = new ExceptionUtil()
619 if (returnCode=='200') {
620 msoLogger.debug('Generic vnf ' + vnfId + ' found in AAI.')
621 execution.setVariable(prefix+'AAIQueryGenericVfnResponse', aaiResponseAsString)
623 if (returnCode=='404') {
624 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
625 msoLogger.debug(message)
626 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
628 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
629 throw new BpmnError("MSOWorkflowException")