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 static org.apache.commons.lang3.StringUtils.*
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AaiUtil
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.bpmn.common.scripts.VfModule
32 import org.onap.so.bpmn.common.scripts.VfModuleBase
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.logger.MessageEnum
37 import org.onap.so.logger.MsoLogger
38 import org.onap.so.rest.APIResponse
39 import org.springframework.web.util.UriUtils
41 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
42 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVfModuleFromVnf.class);
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
48 public void initProcessVariables(DelegateExecution execution) {
49 execution.setVariable("prefix",Prefix)
50 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
53 // parse the incoming request
54 public void preProcessRequest(DelegateExecution execution) {
56 initProcessVariables(execution)
60 // Building Block-type request
62 // Set mso-request-id to request-id for VNF Adapter interface
63 String requestId = execution.getVariable("msoRequestId")
64 execution.setVariable("mso-request-id", requestId)
65 execution.setVariable("requestId", requestId)
66 msoLogger.debug("msoRequestId: " + requestId)
67 String tenantId = execution.getVariable("tenantId")
68 msoLogger.debug("tenantId: " + tenantId)
69 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
70 execution.setVariable("cloudSiteId", cloudSiteId)
71 msoLogger.debug("cloudSiteId: " + cloudSiteId)
72 // Source is HARDCODED
74 execution.setVariable("source", source)
75 // isVidRequest is hardcoded to "true"
76 execution.setVariable("isVidRequest", "true")
77 // SrvInstId is hardcoded to empty
78 execution.setVariable("srvInstId", "")
79 // ServiceId is hardcoded to empty
80 execution.setVariable("serviceId", "")
81 String serviceInstanceId = execution.getVariable("serviceInstanceId")
82 msoLogger.debug("serviceInstanceId: " + serviceInstanceId)
83 String vnfId = execution.getVariable("vnfId")
84 msoLogger.debug("vnfId: " + vnfId)
85 String vfModuleId = execution.getVariable("vfModuleId")
86 msoLogger.debug("vfModuleId: " + vfModuleId)
87 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
88 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
91 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
94 String sdncVersion = execution.getVariable("sdncVersion")
95 if (sdncVersion == null) {
98 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
99 msoLogger.debug("Incoming Sdnc Version is: " + sdncVersion)
101 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
102 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
103 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
104 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
105 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
107 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
108 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
109 msoLogger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
116 msoLogger.debug("Exception is: " + e.getMessage())
117 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
121 public void queryAAIForVfModule(DelegateExecution execution) {
122 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
123 'execution=' + execution.getId() +
126 msoLogger.trace('Entered ' + method)
129 def vnfId = execution.getVariable('vnfId')
131 AaiUtil aaiUriUtil = new AaiUtil(this)
132 def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
133 msoLogger.debug('AAI URI is: ' + aai_uri)
135 String endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
137 msoLogger.debug("DoDeleteVfModuleFromVnf: AAI endPoint : " + endPoint)
140 msoLogger.debug("DoDeleteVfModuleFromVnf: - invoking httpGet to AAI")
141 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
143 def responseData = response.getResponseBodyAsString()
144 execution.setVariable('DDVMFV_getVnfResponseCode', response.getStatusCode())
145 execution.setVariable('DDVMFV_getVnfResponse', responseData)
147 msoLogger.debug("DoDeleteVfModuleFromVnf: AAI Response : " + responseData)
148 msoLogger.debug("DoDeleteVfModuleFromVnf: AAI ResponseCode : " + response.getStatusCode())
150 msoLogger.debug('Response code:' + response.getStatusCode())
151 msoLogger.debug('Response:' + System.lineSeparator() + responseData)
153 } catch (Exception ex) {
155 msoLogger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
156 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
157 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
159 msoLogger.trace('Exited ' + method)
160 } catch (BpmnError e) {
162 } catch (Exception e) {
163 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
164 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
169 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
170 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
171 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
172 * attempting to delete it.
174 * @param execution The flow's execution instance.
176 public void validateVfModule(DelegateExecution execution) {
177 def method = getClass().getSimpleName() + '.validateVfModule(' +
178 'execution=' + execution.getId() +
180 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
181 msoLogger.trace('Entered ' + method)
184 def genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
185 def vnfId = execution.getVariable('_vnfId')
186 def vfModuleId = execution.getVariable('vfModuleId')
187 def VfModule vfModule = findVfModule(genericVnf, vfModuleId)
188 if (vfModule == null) {
189 def String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
191 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
194 if (isDebugLogEnabled) {
195 msoLogger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.isBaseVfModule() + ', isOnlyVfModule=' + vfModule.isOnlyVfModule())
197 if (vfModule.isBaseVfModule() && !vfModule.isOnlyVfModule()) {
198 def String msg = 'Cannot delete VF Module \'' + vfModuleId +
199 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
200 msoLogger.debug("Received a BAD Response from VNF Adapter for CREATE_VF_MODULE Call.")
201 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
204 def heatStackId = vfModule.getElementText('heat-stack-id')
205 execution.setVariable('DDVMFV_heatStackId', heatStackId)
206 msoLogger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
209 msoLogger.trace('Exited ' + method)
210 } catch (BpmnError e) {
212 } catch (Exception e) {
213 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
214 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
219 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
221 execution.setVariable("prefix", Prefix)
222 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest ")
224 def serviceInstanceId = execution.getVariable("serviceInstanceId")
229 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
231 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
232 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
233 msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
237 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
238 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
240 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
243 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
244 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
245 'execution=' + execution.getId() +
248 msoLogger.trace('Entered ' + method)
249 execution.setVariable("prefix", Prefix)
250 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process ")
252 String serviceInstanceId = execution.getVariable("serviceInstanceId")
254 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
256 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
257 msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
261 msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
262 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
264 msoLogger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
267 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
269 String uuid = execution.getVariable('testReqId') // for junits
271 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
273 def callbackURL = execution.getVariable("sdncCallbackUrl")
274 def requestId = execution.getVariable("msoRequestId")
275 def serviceId = execution.getVariable("serviceId")
276 def serviceInstanceId = execution.getVariable("serviceInstanceId")
277 def vfModuleId = execution.getVariable("vfModuleId")
278 def source = execution.getVariable("source")
279 def vnfId = execution.getVariable("vnfId")
281 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
284 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
285 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
286 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
287 <sdncadapter:RequestHeader>
288 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
289 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
290 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
291 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
292 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
293 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
294 </sdncadapter:RequestHeader>
295 <sdncadapterworkflow:SDNCRequestData>
296 <request-information>
297 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
298 <request-action>DeleteVfModuleInstance</request-action>
299 <source>${MsoUtils.xmlEscape(source)}</source>
303 </request-information>
304 <service-information>
306 <subscription-service-type/>
307 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
308 <global-customer-id/>
309 </service-information>
311 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
314 <vf-module-information>
315 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
316 </vf-module-information>
317 <vf-module-request-input/>
318 </sdncadapterworkflow:SDNCRequestData>
319 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
321 msoLogger.debug("sdncRequest: " + sdncRequest)
325 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
327 execution.setVariable("prefix",Prefix)
328 msoLogger.trace("STARTED ValidateSDNCResponse Process")
330 WorkflowException workflowException = execution.getVariable("WorkflowException")
331 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
333 msoLogger.debug("workflowException: " + workflowException)
335 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
336 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
338 msoLogger.debug("SDNCResponse: " + response)
340 String sdncResponse = response
341 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
342 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
344 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
345 throw new BpmnError("MSOWorkflowException")
347 msoLogger.trace("COMPLETED ValidateSDNCResponse Process")
351 // parse the incoming DELETE_VF_MODULE request
352 // and formulate the outgoing VnfAdapterDeleteV1 request
353 public void prepVNFAdapterRequest(DelegateExecution execution) {
355 def requestId = UUID.randomUUID().toString()
356 def origRequestId = execution.getVariable('requestId')
357 def srvInstId = execution.getVariable("serviceInstanceId")
358 def aicCloudRegion = execution.getVariable("cloudSiteId")
359 def vnfId = execution.getVariable("vnfId")
360 def vfModuleId = execution.getVariable("vfModuleId")
361 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
362 def tenantId = execution.getVariable("tenantId")
363 def messageId = execution.getVariable('requestId') + '-' +
364 System.currentTimeMillis()
365 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
366 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
367 if ('true'.equals(useQualifiedHostName)) {
368 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
372 <deleteVfModuleRequest>
373 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
374 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
375 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
376 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
377 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
378 <skipAAI>true</skipAAI>
380 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
381 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
383 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
384 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
385 </deleteVfModuleRequest>
388 msoLogger.debug("vnfAdapterRestV1Request: " + request)
389 msoLogger.debug("deleteVfModuleRequest: " + request)
390 execution.setVariable("vnfAdapterRestV1Request", request)
394 // generates a WorkflowException if
396 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
397 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
398 String processKey = getProcessKey(execution);
399 WorkflowException exception = new WorkflowException(processKey, 5000,
400 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
401 execution.setVariable("WorkflowException", exception)
404 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
405 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
406 'execution=' + execution.getId() +
409 msoLogger.trace('Entered ' + method)
410 execution.setVariable("prefix",Prefix)
412 msoLogger.trace("STARTED postProcessVNFAdapterRequest Process")
414 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
415 msoLogger.debug("VNF Adapter Response is: " + vnfResponse)
416 msoLogger.debug("deleteVnfAResponse is: \n" + vnfResponse)
418 if(vnfResponse != null){
420 if(vnfResponse.contains("deleteVfModuleResponse")){
421 msoLogger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
422 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
424 // Parse vnfOutputs for contrail network polcy FQDNs
425 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
426 if(!isBlank(vfModuleOutputsXml)) {
427 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
428 List contrailNetworkPolicyFqdnList = []
429 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
430 String key = utils.getChildNodeText(node, "key")
433 } else if (key.endsWith("contrail_network_policy_fqdn")) {
434 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
435 msoLogger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
436 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
438 else if (key.equals("oam_management_v4_address")) {
439 String oamManagementV4Address = utils.getChildNodeText(node, "value")
440 msoLogger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
441 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
443 else if (key.equals("oam_management_v6_address")) {
444 String oamManagementV6Address = utils.getChildNodeText(node, "value")
445 msoLogger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
446 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
449 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
450 msoLogger.debug("Setting the fqdn list")
451 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
455 msoLogger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
456 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
459 msoLogger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
460 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
466 msoLogger.debug("Internal Error Occured in PostProcess Method")
467 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
469 msoLogger.trace("COMPLETED postProcessVnfAdapterResponse Process")
472 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
473 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
474 'execution=' + execution.getId() +
477 msoLogger.trace('Entered ' + method)
478 execution.setVariable("prefix", Prefix)
479 msoLogger.trace("STARTED deleteNetworkPoliciesFromAAI ")
483 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
484 if (fqdnList == null) {
485 msoLogger.debug("No network policies to delete")
488 int fqdnCount = fqdnList.size()
490 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
491 msoLogger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
493 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
494 AaiUtil aaiUriUtil = new AaiUtil(this)
495 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
498 // AII loop call over contrail network policy fqdn list
499 for (i in 0..fqdnCount-1) {
502 String fqdn = fqdnList[i]
504 // Query AAI for this network policy FQDN
506 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
507 msoLogger.debug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
510 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
511 int returnCode = response.getStatusCode()
512 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
513 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
515 String aaiResponseAsString = response.getResponseBodyAsString()
517 if (isOneOf(returnCode, 200, 201)) {
518 msoLogger.debug("The return code is: " + returnCode)
519 // This network policy FQDN exists in AAI - need to delete it now
520 msoLogger.debug(aaiResponseAsString)
521 execution.setVariable("DDVFMV_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
522 msoLogger.debug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
523 // Retrieve the network policy id for this FQDN
524 def networkPolicyId = utils.getNodeText(aaiResponseAsString, "network-policy-id")
525 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
527 // Retrieve the resource version for this network policy
528 def resourceVersion = utils.getNodeText(aaiResponseAsString, "resource-version")
529 msoLogger.debug("Deleting network-policy with resource-version " + resourceVersion)
531 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
532 "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
533 msoLogger.debug("AAI request endpoint: " + delNetworkPolicyAAIRequest)
535 msoLogger.debug("invoking DELETE call to AAI")
536 msoLogger.debug("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
537 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
538 int returnCodeDel = responseDel.getStatusCode()
539 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
540 msoLogger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel)
542 if (isOneOf(returnCodeDel, 200, 201, 204)) {
543 msoLogger.debug("The return code from deleting network policy is: " + returnCodeDel)
544 // This network policy was deleted from AAI successfully
545 msoLogger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
549 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
550 msoLogger.debug(delErrorMessage)
551 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
553 } else if (returnCode == 404) {
554 // This network policy FQDN is not in AAI. No need to delete.
555 msoLogger.debug("The return code is: " + returnCode)
556 msoLogger.debug("This network policy FQDN is not in AAI: " + fqdn)
557 msoLogger.debug("Network policy FQDN is not in AAI")
559 if (aaiResponseAsString.contains("RESTFault")) {
560 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
561 execution.setVariable("WorkflowException", exceptionObject)
562 throw new BpmnError("MSOWorkflowException")
566 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
567 msoLogger.debug(dataErrorMessage)
568 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
579 msoLogger.debug("No contrail network policies to query/create")
583 } catch (BpmnError e) {
586 } catch (Exception ex) {
587 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
588 msoLogger.debug(exceptionMessage)
589 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
594 // and formulate the outgoing DeleteAAIVfModuleRequest request
595 public void prepDeleteAAIVfModule(DelegateExecution execution) {
598 def vnfId = execution.getVariable("vnfId")
599 def vfModuleId = execution.getVariable("vfModuleId")
600 // formulate the request for UpdateAAIVfModule
601 String request = """<DeleteAAIVfModuleRequest>
602 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
603 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
604 </DeleteAAIVfModuleRequest>""" as String
605 msoLogger.debug("DeleteAAIVfModuleRequest :" + request)
607 execution.setVariable("DeleteAAIVfModuleRequest", request)