1 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
3 import static org.camunda.spin.Spin.XML;
\r
4 import groovy.json.JsonSlurper
\r
5 import groovy.lang.GroovyInterceptable;
\r
6 import groovy.xml.XmlUtil
\r
8 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
10 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
\r
11 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase;
\r
12 import org.openecomp.mso.bpmn.core.RollbackData
\r
13 import org.openecomp.mso.bpmn.core.WorkflowException
\r
14 import org.openecomp.mso.bpmn.core.json.JsonUtils;
\r
15 import org.openecomp.mso.rest.APIResponse
\r
16 import org.springframework.web.util.UriUtils
\r
21 import java.util.UUID;
\r
23 import org.camunda.bpm.engine.delegate.BpmnError
\r
24 import org.camunda.bpm.engine.runtime.Execution
\r
25 import org.apache.commons.lang3.*
\r
26 import org.apache.commons.codec.binary.Base64;
\r
28 class DoCreateVfModuleVolumeV2 extends VfModuleBase {
\r
30 String prefix='DCVFMODVOLV2_'
\r
31 JsonUtils jsonUtil = new JsonUtils()
\r
35 * Perform initial processing, such as request validation, initialization of variables, etc.
\r
36 * * @param execution
\r
38 public void preProcessRequest(Execution execution) {
\r
39 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
40 preProcessRequest(execution, isDebugEnabled)
\r
43 public void preProcessRequest(Execution execution, isDebugLogEnabled) {
\r
45 execution.setVariable("prefix",prefix)
\r
46 execution.setVariable(prefix+'SuccessIndicator', false)
\r
47 execution.setVariable(prefix+'isPONR', false)
\r
49 displayInput(execution, isDebugLogEnabled)
\r
50 setRollbackData(execution, isDebugLogEnabled)
\r
51 setRollbackEnabled(execution, isDebugLogEnabled)
\r
54 def tenantId = execution.getVariable("tenantId")
\r
55 if (tenantId == null) {
\r
56 String cloudConfiguration = execution.getVariable("cloudConfiguration")
\r
57 tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
\r
58 execution.setVariable("tenantId", tenantId)
\r
61 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
\r
62 if (cloudSiteId == null) {
\r
63 String cloudConfiguration = execution.getVariable("cloudConfiguration")
\r
64 cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
\r
65 execution.setVariable("lcpCloudRegionId", cloudSiteId)
\r
68 // Extract attributes from modelInfo
\r
69 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
\r
71 //modelCustomizationUuid
\r
72 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
\r
73 execution.setVariable("modelCustomizationId", modelCustomizationUuid)
\r
74 logDebug("modelCustomizationId: " + modelCustomizationUuid, isDebugLogEnabled)
\r
77 def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
\r
78 execution.setVariable("modelName", modelName)
\r
79 logDebug("modelName: " + modelName, isDebugLogEnabled)
\r
81 // The following is used on the get Generic Service Instance call
\r
82 execution.setVariable('GENGS_type', 'service-instance')
\r
87 * Display input variables
\r
89 * @param isDebugLogEnabled
\r
91 public void displayInput(Execution execution, isDebugLogEnabled) {
\r
92 def input = ['mso-request-id', 'msoRequestId', 'isDebugLogEnabled', 'disableRollback', 'failIfExists', 'serviceInstanceId',
\r
93 'vnfId', 'vnfName', 'tenantId', 'volumeGroupId', 'volumeGroupName', 'lcpCloudRegionId', 'vnfType', 'vfModuleModelInfo', 'asdcServiceModelVersion',
\r
94 'test-volume-group-name', 'test-volume-group-id', 'vfModuleInputParams']
\r
96 logDebug('Begin input: ', isDebugLogEnabled)
\r
98 logDebug(it + ': ' + execution.getVariable(it), isDebugLogEnabled)
\r
100 logDebug('End input.', isDebugLogEnabled)
\r
105 * Define and set rollbackdata object
\r
107 * @param isDebugEnabled
\r
109 public void setRollbackData(Execution execution, isDebugEnabled) {
\r
110 def rollbackData = execution.getVariable("rollbackData")
\r
111 if (rollbackData == null) {
\r
112 rollbackData = new RollbackData()
\r
114 def volumeGroupName = execution.getVariable('volumeGroupName')
\r
115 rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName)
\r
116 execution.setVariable("rollbackData", rollbackData)
\r
121 * validate getServiceInstance response
\r
123 * @param isDebugEnabled
\r
125 public void validateGetServiceInstanceCall(Execution execution, isDebugEnabled) {
\r
126 def found = execution.getVariable('GENGS_FoundIndicator')
\r
127 def success = execution.getVariable('GENGS_SuccessIndicator')
\r
128 def serviceInstanceId = execution.getVariable('serviceInstanceId')
\r
129 utils.log("DEBUG", "getServiceInstance success: " + success, isDebugEnabled)
\r
130 utils.log("DEBUG", "getServiceInstance found: " + found, isDebugEnabled)
\r
131 if(!found || !success) {
\r
132 String errorMessage = "Service instance id not found in AAI: ${serviceInstanceId}."
\r
133 utils.log("DEBUG", errorMessage, isDebugEnabled)
\r
134 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
\r
142 * @param isDebugEnabled
\r
144 public void callRESTQueryAAICloudRegion (Execution execution, isDebugEnabled) {
\r
146 def cloudRegion = execution.getVariable("lcpCloudRegionId")
\r
147 utils.log("DEBUG", 'Request cloud region is: ' + cloudRegion, isDebugEnabled)
\r
149 AaiUtil aaiUtil = new AaiUtil(this)
\r
150 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
151 String queryCloudRegionRequest = aaiEndpoint + '/' + cloudRegion
\r
153 utils.logAudit(queryCloudRegionRequest)
\r
155 cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
\r
157 def aaiCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "AAI", cloudRegion)
\r
158 if ((aaiCloudRegion != "ERROR")) {
\r
159 execution.setVariable("lcpCloudRegionId", aaiCloudRegion)
\r
160 utils.log("DEBUG", "AIC Cloud Region for AAI: " + aaiCloudRegion, isDebugEnabled)
\r
162 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
\r
163 utils.log("DEBUG", errorMessage, isDebugEnabled)
\r
164 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
\r
167 def poCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
\r
168 if ((poCloudRegion != "ERROR")) {
\r
169 execution.setVariable("poLcpCloudRegionId", poCloudRegion)
\r
170 utils.log("DEBUG", "AIC Cloud Region for PO: " + poCloudRegion, isDebugEnabled)
\r
172 String errorMessage = "AAI Query Cloud Region Unsuccessful. Return Code: " + execution.getVariable(prefix+"queryCloudRegionReturnCode")
\r
173 utils.log("DEBUG", errorMessage, isDebugEnabled)
\r
174 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage)
\r
177 def rollbackData = execution.getVariable("rollbackData")
\r
178 rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion)
\r
183 * Query AAI volume group by name
\r
185 * @param isDebugEnabled
\r
187 public void callRESTQueryAAIVolGrpName(Execution execution, isDebugEnabled) {
\r
189 def volumeGroupName = execution.getVariable('volumeGroupName')
\r
190 def cloudRegion = execution.getVariable('lcpCloudRegionId')
\r
192 // This is for stub testing
\r
193 def testVolumeGroupName = execution.getVariable('test-volume-group-name')
\r
194 if (testVolumeGroupName != null && testVolumeGroupName.length() > 0) {
\r
195 volumeGroupName = testVolumeGroupName
\r
198 AaiUtil aaiUtil = new AaiUtil(this)
\r
199 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
200 String queryAAIVolumeNameRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups" + "?volume-group-name=" + UriUtils.encode(volumeGroupName, 'UTF-8')
\r
202 utils.logAudit('Query AAI volume group by name: ' + queryAAIVolumeNameRequest)
\r
204 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeNameRequest)
\r
206 String returnCode = response.getStatusCode()
\r
207 String aaiResponseAsString = response.getResponseBodyAsString()
\r
208 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
210 utils.logAudit("AAI query volume group by name return code: " + returnCode)
\r
211 utils.logAudit("AAI query volume group by name response: " + aaiResponseAsString)
\r
213 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
215 execution.setVariable(prefix+"queryAAIVolGrpNameResponse", aaiResponseAsString)
\r
216 execution.setVariable(prefix+'AaiReturnCode', returnCode)
\r
218 if (returnCode=='200') {
\r
219 execution.setVariable(prefix+'queryAAIVolGrpNameResponse', aaiResponseAsString)
\r
220 utils.log("DEBUG", "Volume Group Name $volumeGroupName exists in AAI.", isDebugEnabled)
\r
222 if (returnCode=='404') {
\r
223 utils.log("DEBUG", "Volume Group Name $volumeGroupName does not exist in AAI.", isDebugEnabled)
\r
224 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume group $volumeGroupName not found in AAI. Response code: 404")
\r
226 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
227 throw new BpmnError("MSOWorkflowException")
\r
234 * Create a WorkflowException
\r
236 * @param isDebugEnabled
\r
238 public void buildWorkflowException(Execution execution, int errorCode, errorMessage, isDebugEnabled) {
\r
239 utils.log("DEBUG", errorMessage, isDebugEnabled)
\r
240 (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
\r
245 * Create a WorkflowException
\r
247 * @param isDebugEnabled
\r
249 public void handleError(Execution execution, isDebugEnabled) {
\r
250 WorkflowException we = execution.getVariable('WorkflowException')
\r
252 (new ExceptionUtil()).buildWorkflowException(execution, 2500, "Enexpected error encountered!")
\r
254 throw new BpmnError("MSOWorkflowException")
\r
259 * Create volume group in AAI
\r
261 * @param isDebugEnabled
\r
263 public void callRESTCreateAAIVolGrpName(Execution execution, isDebugEnabled) {
\r
265 def vnfId = execution.getVariable('vnfId')
\r
266 def volumeGroupId = execution.getVariable('volumeGroupId')
\r
267 def volumeName = execution.getVariable("volumeGroupName")
\r
268 def modelCustomizationId = execution.getVariable("modelCustomizationId")
\r
269 def vnfType = execution.getVariable("vnfType")
\r
270 def tenantId = execution.getVariable("tenantId")
\r
271 def cloudRegion = execution.getVariable('lcpCloudRegionId')
\r
273 utils.log("DEBUG", "volumeGroupId: " + volumeGroupId, isDebugEnabled)
\r
275 def testGroupId = execution.getVariable('test-volume-group-id')
\r
276 if (testGroupId != null && testGroupId.trim() != '') {
\r
277 utils.log("DEBUG", "test volumeGroupId is present: " + testGroupId, isDebugEnabled)
\r
278 volumeGroupId = testGroupId
\r
279 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
\r
282 utils.log("DEBUG", "volumeGroupId to be used: " + volumeGroupId, isDebugEnabled)
\r
284 AaiUtil aaiUtil = new AaiUtil(this)
\r
285 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
286 String createAAIVolumeGrpNameUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")
\r
288 String namespace = aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
\r
289 utils.log("DEBUG", "AAI namespace is: " + namespace, isDebugEnabled)
\r
291 utils.logAudit("Request URL for PUT: " + createAAIVolumeGrpNameUrlRequest)
\r
293 NetworkUtils networkUtils = new NetworkUtils()
\r
294 String payload = networkUtils.createCloudRegionVolumeRequest(volumeGroupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId)
\r
295 String payloadXml = utils.formatXml(payload)
\r
296 utils.logAudit("Request payload for PUT: " + payloadXml)
\r
298 APIResponse response = aaiUtil.executeAAIPutCall(execution, createAAIVolumeGrpNameUrlRequest, payloadXml)
\r
300 String returnCode = response.getStatusCode()
\r
301 String aaiResponseAsString = response.getResponseBodyAsString()
\r
302 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
304 utils.logAudit("AAI create volume group return code: " + returnCode)
\r
305 utils.logAudit("AAI create volume group response: " + aaiResponseAsString)
\r
307 execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode)
\r
308 execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString)
\r
310 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
312 if (returnCode =='201') {
\r
313 RollbackData rollbackData = execution.getVariable("rollbackData")
\r
314 rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true")
\r
316 execution.setVariable(prefix+"isErrorMessageException", true)
\r
317 if (returnCode=='404') {
\r
318 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to create volume group in AAI. Response code: 404")
\r
320 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
321 utils.log("DEBUG", " AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException, isDebugEnabled)
\r
322 throw new BpmnError("MSOWorkflowException")
\r
329 * Prepare VNF adapter create request XML
\r
332 public void prepareVnfAdapterCreateRequest(Execution execution, isDebugEnabled) {
\r
334 def aaiGenericVnfResponse = execution.getVariable(prefix+'AAIQueryGenericVfnResponse')
\r
335 def vnfId = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-id')
\r
336 def vnfName = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-name')
\r
337 def vnfType = utils.getNodeText1(aaiGenericVnfResponse, "vnf-type")
\r
339 def requestId = execution.getVariable('msoRequestId')
\r
340 def serviceId = execution.getVariable('serviceInstanceId')
\r
341 def cloudSiteId = execution.getVariable('poLcpCloudRegionId')
\r
342 def tenantId = execution.getVariable('tenantId')
\r
343 def volumeGroupId = execution.getVariable('volumeGroupId')
\r
344 def volumeGroupnName = execution.getVariable('volumeGroupName')
\r
346 def vnfVersion = execution.getVariable("asdcServiceModelVersion")
\r
347 def vnfModuleType = execution.getVariable("modelName")
\r
349 def modelCustomizationId = execution.getVariable("modelCustomizationId")
\r
352 utils.log("DEBUG", "volumeGroupId: " + volumeGroupId, isDebugEnabled)
\r
353 def testGroupId = execution.getVariable('test-volume-group-id')
\r
354 if (testGroupId != null && testGroupId.trim() != '') {
\r
355 utils.log("DEBUG", "test volumeGroupId is present: " + testGroupId, isDebugEnabled)
\r
356 volumeGroupId = testGroupId
\r
357 execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0")
\r
359 utils.log("DEBUG", "volumeGroupId to be used: " + volumeGroupId, isDebugEnabled)
\r
361 // volume group parameters
\r
363 String volumeGroupParams = ''
\r
364 StringBuilder sbParams = new StringBuilder()
\r
365 Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams")
\r
366 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
\r
368 String paramName = entry.getKey();
\r
369 String paramValue = entry.getValue()
\r
372 <key>${paramName}</key>
\r
373 <value>${paramValue}</value>
\r
376 sbParams.append(paramsXml)
\r
379 volumeGroupParams = sbParams.toString()
\r
380 utils.log("DEBUG", "volumeGroupParams: "+ volumeGroupParams, isDebugEnabled)
\r
382 def backoutOnFailure = execution.getVariable(prefix+"backoutOnFailure")
\r
383 utils.log("DEBUG", "backoutOnFailure: "+ backoutOnFailure, isDebugEnabled)
\r
385 def failIfExists = execution.getVariable("failIfExists")
\r
386 if(failIfExists == null) {
\r
387 failIfExists = 'true'
\r
390 String messageId = UUID.randomUUID()
\r
391 utils.log("DEBUG", "messageId to be used is generated: " + messageId, isDebugEnabled)
\r
393 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
\r
394 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
\r
395 if ('true'.equals(useQualifiedHostName)) {
\r
396 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
\r
398 utils.log("DEBUG", "CreateVfModuleVolume - notificationUrl: "+ notificationUrl, isDebugEnabled)
\r
401 String vnfSubCreateWorkflowRequest =
\r
403 <createVolumeGroupRequest>
\r
404 <cloudSiteId>${cloudSiteId}</cloudSiteId>
\r
405 <tenantId>${tenantId}</tenantId>
\r
406 <vnfId>${vnfId}</vnfId>
\r
407 <vnfName>${vnfName}</vnfName>
\r
408 <volumeGroupId>${volumeGroupId}</volumeGroupId>
\r
409 <volumeGroupName>${volumeGroupnName}</volumeGroupName>
\r
410 <vnfType>${vnfType}</vnfType>
\r
411 <vnfVersion>${vnfVersion}</vnfVersion>
\r
412 <vfModuleType>${vnfModuleType}</vfModuleType>
\r
413 <modelCustomizationUuid>${modelCustomizationId}</modelCustomizationUuid>
\r
414 <volumeGroupParams>
\r
417 <value>${vnfId}</value>
\r
420 <key>vnf_name</key>
\r
421 <value>${vnfName}</value>
\r
424 <key>vf_module_id</key>
\r
425 <value>${volumeGroupId}</value>
\r
428 <key>vf_module_name</key>
\r
429 <value>${volumeGroupnName}</value>
\r
431 ${volumeGroupParams}
\r
432 </volumeGroupParams>
\r
433 <skipAAI>true</skipAAI>
\r
434 <backout>${backoutOnFailure}</backout>
\r
435 <failIfExists>${failIfExists}</failIfExists>
\r
437 <requestId>${requestId}</requestId>
\r
438 <serviceInstanceId>${serviceId}</serviceInstanceId>
\r
440 <messageId>${messageId}</messageId>
\r
441 <notificationUrl>${notificationUrl}</notificationUrl>
\r
442 </createVolumeGroupRequest>
\r
445 String vnfSubCreateWorkflowRequestAsString = utils.formatXml(vnfSubCreateWorkflowRequest)
\r
446 utils.logAudit(vnfSubCreateWorkflowRequestAsString)
\r
447 utils.log('DEBUG', vnfSubCreateWorkflowRequestAsString, isDebugEnabled)
\r
448 execution.setVariable(prefix+"createVnfARequest", vnfSubCreateWorkflowRequestAsString)
\r
450 // build rollback request for use later if needed
\r
452 String vnfSubRollbackWorkflowRequest =
\r
453 """<rollbackVolumeGroupRequest>
\r
454 <cloudSiteId>${cloudSiteId}</cloudSiteId>
\r
455 <tenantId>${tenantId}</tenantId>
\r
456 <volumeGroupId>${volumeGroupId}</volumeGroupId>
\r
457 <skipAAI>true</skipAAI>
\r
458 <volumeGroupCreated>true</volumeGroupCreated>
\r
460 <requestId>${requestId}</requestId>
\r
461 <serviceInstanceId>${serviceId}</serviceInstanceId>
\r
463 <messageId>${messageId}</messageId>
\r
464 <notificationUrl>${notificationUrl}</notificationUrl>
\r
465 </rollbackVolumeGroupRequest>"""
\r
467 utils.log("DEBUG", "Sub Vnf flow rollback request: vnfSubRollbackWorkflowRequest " + "\n" + vnfSubRollbackWorkflowRequest, isDebugEnabled)
\r
469 String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest)
\r
470 execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString)
\r
475 * Validate VNF adapter response
\r
478 public void validateVnfResponse(Execution execution, isDebugEnabled) {
\r
479 def vnfSuccess = execution.getVariable('VNFREST_SuccessIndicator')
\r
480 utils.log("DEBUG", "vnfAdapterSuccessIndicator: "+ vnfSuccess, isDebugEnabled)
\r
481 if(vnfSuccess==true) {
\r
482 def vnfRollbackRequest = execution.getVariable(prefix+"rollbackVnfARequest")
\r
483 utils.log("DEBUG", "vnfAdapter rollback request: "+ vnfRollbackRequest, isDebugEnabled)
\r
484 RollbackData rollbackData = execution.getVariable("rollbackData")
\r
485 rollbackData.put("DCVFMODULEVOL", "rollbackVnfARequest", vnfRollbackRequest)
\r
486 rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true")
\r
493 * Update voulume group in AAI
\r
494 * @TODO: Can we re-use the create method??
\r
496 * @param isDebugEnabled
\r
498 public void callRESTUpdateCreatedVolGrpName(Execution execution, isDebugEnabled) {
\r
500 String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse")
\r
501 String volumeGroupId = utils.getNodeText1(requeryAAIVolGrpNameResponse, "volume-group-id")
\r
502 String modelCustomizationId = execution.getVariable("modelCustomizationId")
\r
503 String cloudRegion = execution.getVariable("lcpCloudRegionId")
\r
505 AaiUtil aaiUtil = new AaiUtil(this)
\r
506 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)
\r
507 String updateAAIVolumeGroupUrlRequest = aaiEndpoint + '/' + cloudRegion + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, 'UTF-8')
\r
509 String namespace = aaiUtil.getNamespaceFromUri(aaiUtil.getCloudInfrastructureCloudRegionUri(execution))
\r
511 utils.logAudit(updateAAIVolumeGroupUrlRequest)
\r
512 utils.log("DEBUG", "updateAAIVolumeGroupUrlRequest - " + updateAAIVolumeGroupUrlRequest, isDebugEnabled)
\r
514 String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse")
\r
515 def heatStackID = utils.getNodeText1(createVnfAResponse, "volumeGroupStackId")
\r
517 execution.setVariable(prefix+"heatStackId", heatStackID)
\r
519 NetworkUtils networkUtils = new NetworkUtils()
\r
520 String payload = networkUtils.updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackID, namespace, modelCustomizationId)
\r
521 String payloadXml = utils.formatXml(payload)
\r
523 utils.logAudit("Payload to Update Created VolumeGroupName - " + "\n" + payloadXml)
\r
525 APIResponse response = aaiUtil.executeAAIPutCall(execution, updateAAIVolumeGroupUrlRequest, payloadXml)
\r
527 String returnCode = response.getStatusCode()
\r
528 String aaiResponseAsString = response.getResponseBodyAsString()
\r
529 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
531 utils.logAudit("AAI create volume group return code: " + returnCode)
\r
532 utils.logAudit("AAI create volume group response: " + aaiResponseAsString)
\r
534 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
536 if (returnCode =='200') {
\r
537 execution.setVariable(prefix+"updateCreatedAAIVolumeGrpNameResponse", aaiResponseAsString)
\r
538 execution.setVariable(prefix+"isPONR", true)
\r
540 execution.setVariable(prefix+"isErrorMessageException", true)
\r
541 if (returnCode=='404') {
\r
542 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Unable to update volume group in AAI. Response code: 404")
\r
544 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
545 utils.log("DEBUG", " AAI Adapter Query Failed. WorkflowException - " + "\n" + aWorkflowException, isDebugEnabled)
\r
546 throw new BpmnError("MSOWorkflowException")
\r
553 * Query AAI Generic VNF
\r
555 * @param isDebugEnabled
\r
557 public void callRESTQueryAAIGenericVnf(Execution execution, isDebugEnabled) {
\r
559 def vnfId = execution.getVariable('vnfId')
\r
561 AaiUtil aaiUtil = new AaiUtil(this)
\r
562 String aaiEndpoint = aaiUtil.getNetworkGenericVnfEndpoint(execution)
\r
563 def String queryAAIRequest = aaiEndpoint + "/" + UriUtils.encode(vnfId, "UTF-8")
\r
565 utils.logAudit("AAI query generic vnf request: " + queryAAIRequest)
\r
567 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
\r
569 String returnCode = response.getStatusCode()
\r
570 String aaiResponseAsString = response.getResponseBodyAsString()
\r
571 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
573 utils.logAudit("AAI query generic vnf return code: " + returnCode)
\r
574 utils.logAudit("AAI query generic vnf response: " + aaiResponseAsString)
\r
576 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
578 if (returnCode=='200') {
\r
579 utils.log("DEBUG", 'Generic vnf ' + vnfId + ' found in AAI.', isDebugEnabled)
\r
580 execution.setVariable(prefix+'AAIQueryGenericVfnResponse', aaiResponseAsString)
\r
582 if (returnCode=='404') {
\r
583 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'
\r
584 utils.log("DEBUG", message, isDebugEnabled)
\r
585 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
\r
587 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
588 throw new BpmnError("MSOWorkflowException")
\r