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.entities.AAIResultWrapper
41 import org.onap.so.client.aai.entities.Relationships
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.json.JSONObject
45 import javax.ws.rs.NotFoundException
47 class DoCreateVfModuleVolumeV2 extends VfModuleBase {
49 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleVolumeV2.class);
50 String prefix='DCVFMODVOLV2_'
51 JsonUtils jsonUtil = new JsonUtils()
55 * Perform initial processing, such as request validation, initialization of variables, etc.
58 public void preProcessRequest(DelegateExecution execution) {
59 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
60 preProcessRequest(execution, isDebugEnabled)
63 public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) {
65 execution.setVariable("prefix",prefix)
66 execution.setVariable(prefix+'SuccessIndicator', false)
67 execution.setVariable(prefix+'isPONR', false)
69 displayInput(execution, isDebugLogEnabled)
70 setRollbackData(execution, isDebugLogEnabled)
71 setRollbackEnabled(execution, isDebugLogEnabled)
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)
81 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
82 if (cloudSiteId == null) {
83 String cloudConfiguration = execution.getVariable("cloudConfiguration")
84 cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
85 execution.setVariable("lcpCloudRegionId", cloudSiteId)
88 // Extract attributes from modelInfo
89 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
91 //modelCustomizationUuid
92 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
93 execution.setVariable("modelCustomizationId", modelCustomizationUuid)
94 msoLogger.debug("modelCustomizationId: " + modelCustomizationUuid)
97 def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
98 execution.setVariable("modelName", modelName)
99 msoLogger.debug("modelName: " + modelName)
101 // The following is used on the get Generic Service Instance call
102 execution.setVariable('GENGS_type', 'service-instance')
107 * Display input variables
109 * @param isDebugLogEnabled
111 public void displayInput(DelegateExecution execution, isDebugLogEnabled) {
112 def input = ['mso-request-id', 'msoRequestId', 'isDebugLogEnabled', 'disableRollback', 'failIfExists', 'serviceInstanceId',
113 'vnfId', 'vnfName', 'tenantId', 'volumeGroupId', 'volumeGroupName', 'lcpCloudRegionId', 'vnfType', 'vfModuleModelInfo', 'asdcServiceModelVersion',
114 'test-volume-group-name', 'test-volume-group-id', 'vfModuleInputParams']
116 msoLogger.debug('Begin input: ')
118 msoLogger.debug(it + ': ' + execution.getVariable(it))
120 msoLogger.debug('End input.')
125 * Define and set rollbackdata object
127 * @param isDebugEnabled
129 public void setRollbackData(DelegateExecution execution, isDebugEnabled) {
130 def rollbackData = execution.getVariable("rollbackData")
131 if (rollbackData == null) {
132 rollbackData = new RollbackData()
134 def volumeGroupName = execution.getVariable('volumeGroupName')
135 rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
136 execution.setVariable("rollbackData", rollbackData)
141 * Gets the service instance uri from aai
143 public void getServiceInstance(DelegateExecution execution) {
145 String serviceInstanceId = execution.getVariable('serviceInstanceId')
147 AAIResourcesClient resourceClient = new AAIResourcesClient()
148 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
150 if(!resourceClient.exists(uri)){
151 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
154 }catch(BpmnError e) {
156 }catch (Exception ex){
157 String msg = "Exception in getServiceInstance. " + ex.getMessage()
159 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, msg)
166 * @param isDebugEnabled
168 public void callRESTQueryAAICloudRegion (DelegateExecution execution, isDebugEnabled) {
170 def cloudRegion = execution.getVariable("lcpCloudRegionId")
171 msoLogger.debug('Request cloud region is: ' + cloudRegion)
173 AaiUtil aaiUtil = new AaiUtil(this)
174 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
175 String queryCloudRegionRequest = aaiEndpoint + '/' + cloudRegion
177 msoLogger.debug(queryCloudRegionRequest)
179 cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
181 def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "AAI", cloudRegion)
182 if ((aaiCloudRegion != "ERROR")) {
183 execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
184 msoLogger.debug("AIC Cloud Region for AAI: " + aaiCloudRegion)
186 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
187 msoLogger.debug(errorMessage)
188 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
191 def poCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
192 if ((poCloudRegion != "ERROR")) {
193 execution.setVariable("poLcpCloudRegionId", poCloudRegion)
194 msoLogger.debug("AIC Cloud Region for PO: " + poCloudRegion)
196 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
197 msoLogger.debug(errorMessage)
198 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
201 def rollbackData = execution.getVariable("rollbackData")
202 rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
207 * Query AAI volume group by name
209 * @param isDebugEnabled
211 public void callRESTQueryAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
213 def volumeGroupName = execution.getVariable('volumeGroupName')
214 def cloudRegion = execution.getVariable('lcpCloudRegionId')
216 // This is for stub testing
217 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
218 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
219 volumeGroupName = testVolumeGroupName
222 AaiUtil aaiUtil = new AaiUtil(this)
223 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
224 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
226 msoLogger.debug('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
228 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
230 String returnCode = response.getStatusCode()
231 String aaiResponseAsString = response.getResponseBodyAsString()
233 msoLogger.debug("AAI query volume group by name return code: " + returnCode)
234 msoLogger.debug("AAI query volume group by name response: " + aaiResponseAsString)
236 ExceptionUtil exceptionUtil = new ExceptionUtil()
238 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
239 execution.setVariable(prefix+'AaiReturnCode', returnCode)
241 if (returnCode=='200') {
242 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
243 msoLogger.debug("Volume Group Name $volumeGroupName exists in AAI.")
245 if (returnCode=='404') {
246 msoLogger.debug("Volume Group Name $volumeGroupName does not exist in AAI.")
247 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
249 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
250 throw new BpmnError("MSOWorkflowException")
257 * Create a WorkflowException
259 * @param isDebugEnabled
261 public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage, isDebugEnabled) {
262 msoLogger.debug(errorMessage)
263 (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
268 * Create a WorkflowException
270 * @param isDebugEnabled
272 public void handleError(DelegateExecution execution, isDebugEnabled) {
273 WorkflowException we = execution.getVariable('WorkflowException')
275 (new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
277 throw new BpmnError("MSOWorkflowException")
282 * Create volume group in AAI
284 * @param isDebugEnabled
286 public void callRESTCreateAAIVolGrpName(DelegateExecution execution, isDebugEnabled) {
288 def vnfId = execution.getVariable('vnfId')
289 def volumeGroupId = execution.getVariable('volumeGroupId')
290 def volumeName = execution.getVariable("volumeGroupName")
291 def modelCustomizationId = execution.getVariable("modelCustomizationId")
292 def vnfType = execution.getVariable("vnfType")
293 def tenantId = execution.getVariable("tenantId")
294 def cloudRegion = execution.getVariable('lcpCloudRegionId')
296 msoLogger.debug("volumeGroupId: " + volumeGroupId)
298 def testGroupId = execution.getVariable('test-volume-group-id')
299 if (testGroupId != null && testGroupId.trim() != '') {
300 msoLogger.debug("test volumeGroupId is present: " + testGroupId)
301 volumeGroupId = testGroupId
302 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
305 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
307 AaiUtil aaiUtil = new AaiUtil(this)
308 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
309 String createAAIVolumeGrpNameUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")
311 String namespace = aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
312 msoLogger.debug("AAI namespace is: " + namespace)
314 msoLogger.debug("Request URL for PUT: " + createAAIVolumeGrpNameUrlRequest)
316 NetworkUtils networkUtils = new NetworkUtils()
317 String payload = networkUtils.createCloudRegionVolumeRequest(volumeGroupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId)
318 String payloadXml = utils.formatXml(payload)
319 msoLogger.debug("Request payload for PUT: " + payloadXml)
321 APIResponse response = aaiUtil.executeAAIPutCall(execution, createAAIVolumeGrpNameUrlRequest, payloadXml)
323 String returnCode = response.getStatusCode()
324 String aaiResponseAsString = response.getResponseBodyAsString()
326 msoLogger.debug("AAI create volume group return code: " + returnCode)
327 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
329 execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode)
330 execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString)
332 ExceptionUtil exceptionUtil = new ExceptionUtil()
334 if (returnCode =='201') {
335 RollbackData rollbackData = execution.getVariable("rollbackData")
336 rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
338 execution.setVariable(prefix+"isErrorMessageException", true)
339 if (returnCode=='404') {
340 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
342 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
343 msoLogger.debug(" AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException)
344 throw new BpmnError("MSOWorkflowException")
351 * Prepare VNF adapter create request XML
354 public void prepareVnfAdapterCreateRequest(DelegateExecution execution, isDebugEnabled) {
356 def aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
357 def vnfId = utils.getNodeText(aaiGenericVnfResponse, 'vnf-id')
358 def vnfName = utils.getNodeText(aaiGenericVnfResponse, 'vnf-name')
359 def vnfType = utils.getNodeText(aaiGenericVnfResponse, "vnf-type")
361 def requestId = execution.getVariable('msoRequestId')
362 def serviceId = execution.getVariable('serviceInstanceId')
363 def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
364 def tenantId = execution.getVariable('tenantId')
365 def volumeGroupId = execution.getVariable('volumeGroupId')
366 def volumeGroupnName = execution.getVariable('volumeGroupName')
368 def vnfVersion = execution.getVariable("asdcServiceModelVersion")
369 def vnfModuleType = execution.getVariable("modelName")
371 def modelCustomizationId = execution.getVariable("modelCustomizationId")
374 msoLogger.debug("volumeGroupId: " + volumeGroupId)
375 def testGroupId = execution.getVariable('test-volume-group-id')
376 if (testGroupId != null && testGroupId.trim() != '') {
377 msoLogger.debug("test volumeGroupId is present: " + testGroupId)
378 volumeGroupId = testGroupId
379 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
381 msoLogger.debug("volumeGroupId to be used: " + volumeGroupId)
383 // volume group parameters
385 String volumeGroupParams = ''
386 StringBuilder sbParams = new StringBuilder()
387 Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
388 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
390 String paramName = entry.getKey();
391 String paramValue = entry.getValue()
394 <key>${MsoUtils.xmlEscape(paramName)}</key>
395 <value>${MsoUtils.xmlEscape(paramValue)}</value>
398 sbParams.append(paramsXml)
401 volumeGroupParams = sbParams.toString()
402 msoLogger.debug("volumeGroupParams: "+ volumeGroupParams)
404 def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
405 msoLogger.debug("backoutOnFailure: "+ backoutOnFailure)
407 def failIfExists = execution.getVariable("failIfExists")
408 if(failIfExists == null) {
409 failIfExists = 'true'
412 String messageId = UUID.randomUUID()
413 msoLogger.debug("messageId to be used is generated: " + messageId)
415 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
416 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
417 if ('true'.equals(useQualifiedHostName)) {
418 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
420 msoLogger.debug("CreateVfModuleVolume - notificationUrl: "+ notificationUrl)
423 String vnfSubCreateWorkflowRequest =
425 <createVolumeGroupRequest>
426 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
427 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
428 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
429 <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
430 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
431 <volumeGroupName>${MsoUtils.xmlEscape(volumeGroupnName)}</volumeGroupName>
432 <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
433 <vnfVersion>${MsoUtils.xmlEscape(vnfVersion)}</vnfVersion>
434 <vfModuleType>${MsoUtils.xmlEscape(vnfModuleType)}</vfModuleType>
435 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationId)}</modelCustomizationUuid>
439 <value>${MsoUtils.xmlEscape(vnfId)}</value>
443 <value>${MsoUtils.xmlEscape(vnfName)}</value>
446 <key>vf_module_id</key>
447 <value>${MsoUtils.xmlEscape(volumeGroupId)}</value>
450 <key>vf_module_name</key>
451 <value>${MsoUtils.xmlEscape(volumeGroupnName)}</value>
455 <skipAAI>true</skipAAI>
456 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
457 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
459 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
460 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
462 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
463 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
464 </createVolumeGroupRequest>
467 String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
468 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
469 msoLogger.debug(vnfSubCreateWorkflowRequestAsString)
470 execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)
472 // build rollback request for use later if needed
473 String vnfSubRollbackWorkflowRequest = buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl)
475 msoLogger.debug("Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest)
477 String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
478 execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
481 public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) {
484 <rollbackVolumeGroupRequest>
485 <volumeGroupRollback>
486 <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
487 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
488 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
489 <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
490 <volumeGroupCreated>true</volumeGroupCreated>
492 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
493 <serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
495 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
496 </volumeGroupRollback>
497 <skipAAI>true</skipAAI>
498 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
499 </rollbackVolumeGroupRequest>
505 public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) {
506 String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId)
511 * Validate VNF adapter response
514 public void validateVnfResponse(DelegateExecution execution, isDebugEnabled) {
515 def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
516 msoLogger.debug("vnfAdapterSuccessIndicator: "+ vnfSuccess)
517 if(vnfSuccess==true) {
518 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
519 String heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
520 String vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
521 String updatedVnfRollbackRequest = updateRollbackVolumeGroupRequestXml(vnfRollbackRequest, heatStackID)
522 msoLogger.debug("vnfAdapter rollback request: "+ updatedVnfRollbackRequest)
523 RollbackData rollbackData = execution.getVariable("rollbackData")
524 rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", updatedVnfRollbackRequest)
525 rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
531 * Update voulume group in AAI
532 * @TODO: Can we re-use the create method??
534 * @param isDebugEnabled
536 public void callRESTUpdateCreatedVolGrpName(DelegateExecution execution, isDebugEnabled) {
538 String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse")
539 String volumeGroupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
540 String modelCustomizationId = execution.getVariable("modelCustomizationId")
541 String cloudRegion = execution.getVariable("lcpCloudRegionId")
543 AaiUtil aaiUtil = new AaiUtil(this)
544 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
545 String updateAAIVolumeGroupUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, 'UTF-8')
547 String namespace = aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
549 msoLogger.debug("updateAAIVolumeGroupUrlRequest - " + updateAAIVolumeGroupUrlRequest)
551 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
552 def heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId")
554 execution.setVariable(prefix+"heatStackId", heatStackID)
556 NetworkUtils networkUtils = new NetworkUtils()
557 String payload = networkUtils.updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackID, namespace, modelCustomizationId)
558 String payloadXml = utils.formatXml(payload)
560 msoLogger.debug("Payload to Update Created VolumeGroupName - " + "\n" + payloadXml)
562 APIResponse response = aaiUtil.executeAAIPutCall(execution, updateAAIVolumeGroupUrlRequest, payloadXml)
564 String returnCode = response.getStatusCode()
565 String aaiResponseAsString = response.getResponseBodyAsString()
567 msoLogger.debug("AAI create volume group return code: " + returnCode)
568 msoLogger.debug("AAI create volume group response: " + aaiResponseAsString)
570 ExceptionUtil exceptionUtil = new ExceptionUtil()
572 if (returnCode =='200') {
573 execution.setVariable(prefix+"updateCreatedAAIVolumeGrpNameResponse", aaiResponseAsString)
574 execution.setVariable(prefix+"isPONR", true)
576 execution.setVariable(prefix+"isErrorMessageException", true)
577 if (returnCode=='404') {
578 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
580 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
581 msoLogger.debug(" AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException)
582 throw new BpmnError("MSOWorkflowException")
589 * Query AAI Generic VNF
591 * @param isDebugEnabled
593 public void callRESTQueryAAIGenericVnf(DelegateExecution execution, isDebugEnabled) {
595 def vnfId = execution.getVariable('vnfId')
597 AaiUtil aaiUtil = new AaiUtil(this)
598 String aaiEndpoint = aaiUtil.getNetworkGenericVnfEndpoint(execution)
599 def String queryAAIRequest = aaiEndpoint + "/" + UriUtils.encode(vnfId, "UTF-8")
601 msoLogger.debug("AAI query generic vnf request: " + queryAAIRequest)
603 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
605 String returnCode = response.getStatusCode()
606 String aaiResponseAsString = response.getResponseBodyAsString()
608 msoLogger.debug("AAI query generic vnf return code: " + returnCode)
609 msoLogger.debug("AAI query generic vnf response: " + aaiResponseAsString)
611 ExceptionUtil exceptionUtil = new ExceptionUtil()
613 if (returnCode=='200') {
614 msoLogger.debug('Generic vnf ' + vnfId + ' found in AAI.')
615 execution.setVariable(prefix+'AAIQueryGenericVfnResponse', aaiResponseAsString)
617 if (returnCode=='404') {
618 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
619 msoLogger.debug(message)
620 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
622 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
623 throw new BpmnError("MSOWorkflowException")