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.onap.aai.domain.yang.GenericVnf
24 import org.onap.aai.domain.yang.NetworkPolicies
25 import org.onap.aai.domain.yang.NetworkPolicy
26 import org.onap.aai.domain.yang.VfModule
28 import static org.apache.commons.lang3.StringUtils.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import org.onap.so.bpmn.common.scripts.VfModuleBase
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.client.graphinventory.entities.uri.Depth
40 import org.onap.so.client.aai.AAIObjectPlurals
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.logger.MessageEnum
45 import org.onap.so.logger.MsoLogger
47 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
48 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVfModuleFromVnf.class);
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
54 public void initProcessVariables(DelegateExecution execution) {
55 execution.setVariable("prefix",Prefix)
56 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
59 // parse the incoming request
60 public void preProcessRequest(DelegateExecution execution) {
62 initProcessVariables(execution)
66 // Building Block-type request
68 // Set mso-request-id to request-id for VNF Adapter interface
69 String requestId = execution.getVariable("msoRequestId")
70 execution.setVariable("mso-request-id", requestId)
71 execution.setVariable("requestId", requestId)
72 msoLogger.debug("msoRequestId: " + requestId)
73 String tenantId = execution.getVariable("tenantId")
74 msoLogger.debug("tenantId: " + tenantId)
75 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
76 execution.setVariable("cloudSiteId", cloudSiteId)
77 msoLogger.debug("cloudSiteId: " + cloudSiteId)
78 // Source is HARDCODED
80 execution.setVariable("source", source)
81 // isVidRequest is hardcoded to "true"
82 execution.setVariable("isVidRequest", "true")
83 // SrvInstId is hardcoded to empty
84 execution.setVariable("srvInstId", "")
85 // ServiceId is hardcoded to empty
86 execution.setVariable("serviceId", "")
87 String serviceInstanceId = execution.getVariable("serviceInstanceId")
88 msoLogger.debug("serviceInstanceId: " + serviceInstanceId)
89 String vnfId = execution.getVariable("vnfId")
90 msoLogger.debug("vnfId: " + vnfId)
91 String vfModuleId = execution.getVariable("vfModuleId")
92 msoLogger.debug("vfModuleId: " + vfModuleId)
93 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
94 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
97 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
100 String sdncVersion = execution.getVariable("sdncVersion")
101 if (sdncVersion == null) {
104 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
105 msoLogger.debug("Incoming Sdnc Version is: " + sdncVersion)
107 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
108 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
109 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
110 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
111 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
113 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
114 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
115 msoLogger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
122 msoLogger.debug("Exception is: " + e.getMessage())
123 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
127 public void queryAAIForVfModule(DelegateExecution execution) {
128 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
129 'execution=' + execution.getId() +
132 msoLogger.trace('Entered ' + method)
135 def vnfId = execution.getVariable('vnfId')
137 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
139 Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class,uri)
141 if(genericVnf.isPresent()){
142 execution.setVariable('DDVMFV_getVnfResponseCode', 200)
143 execution.setVariable('DDVMFV_getVnfResponse', genericVnf.get())
145 execution.setVariable('DDVMFV_getVnfResponseCode', 404)
146 execution.setVariable('DDVMFV_getVnfResponse', "Generic Vnf not found!")
148 } catch (Exception ex) {
150 msoLogger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
151 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
152 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
154 msoLogger.trace('Exited ' + method)
155 } catch (BpmnError e) {
157 } catch (Exception e) {
158 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
159 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
164 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
165 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
166 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
167 * attempting to delete it.
169 * @param execution The flow's execution instance.
171 public void validateVfModule(DelegateExecution execution) {
172 def method = getClass().getSimpleName() + '.validateVfModule(' +
173 'execution=' + execution.getId() +
175 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
176 msoLogger.trace('Entered ' + method)
179 GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
180 def vnfId = execution.getVariable('_vnfId')
181 def vfModuleId = execution.getVariable('vfModuleId')
182 Optional<VfModule> vfModule = Optional.empty()
183 if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
184 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
186 if (!vfModule.isPresent()) {
187 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
189 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
191 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
192 if (isDebugLogEnabled) {
193 msoLogger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
195 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
196 String msg = 'Cannot delete VF Module \'' + vfModuleId +
197 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
199 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
201 def heatStackId = vfModule.get().getHeatStackId()
202 execution.setVariable('DDVMFV_heatStackId', heatStackId)
203 msoLogger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
205 msoLogger.trace('Exited ' + method)
206 } catch (BpmnError e) {
208 } catch (Exception e) {
209 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
210 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
215 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
217 execution.setVariable("prefix", Prefix)
218 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest ")
220 def serviceInstanceId = execution.getVariable("serviceInstanceId")
225 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
227 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
228 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
229 msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
233 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);
234 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
236 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
239 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
240 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
241 'execution=' + execution.getId() +
244 msoLogger.trace('Entered ' + method)
245 execution.setVariable("prefix", Prefix)
246 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process ")
248 String serviceInstanceId = execution.getVariable("serviceInstanceId")
250 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
252 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
253 msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
257 msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
258 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
260 msoLogger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
263 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
265 String uuid = execution.getVariable('testReqId') // for junits
267 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
269 def callbackURL = execution.getVariable("sdncCallbackUrl")
270 def requestId = execution.getVariable("msoRequestId")
271 def serviceId = execution.getVariable("serviceId")
272 def serviceInstanceId = execution.getVariable("serviceInstanceId")
273 def vfModuleId = execution.getVariable("vfModuleId")
274 def source = execution.getVariable("source")
275 def vnfId = execution.getVariable("vnfId")
277 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
280 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
281 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
282 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
283 <sdncadapter:RequestHeader>
284 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
285 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
286 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
287 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
288 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
289 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
290 </sdncadapter:RequestHeader>
291 <sdncadapterworkflow:SDNCRequestData>
292 <request-information>
293 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
294 <request-action>DeleteVfModuleInstance</request-action>
295 <source>${MsoUtils.xmlEscape(source)}</source>
299 </request-information>
300 <service-information>
302 <subscription-service-type/>
303 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
304 <global-customer-id/>
305 </service-information>
307 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
310 <vf-module-information>
311 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
312 </vf-module-information>
313 <vf-module-request-input/>
314 </sdncadapterworkflow:SDNCRequestData>
315 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
317 msoLogger.debug("sdncRequest: " + sdncRequest)
321 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
323 execution.setVariable("prefix",Prefix)
324 msoLogger.trace("STARTED ValidateSDNCResponse Process")
326 WorkflowException workflowException = execution.getVariable("WorkflowException")
327 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
329 msoLogger.debug("workflowException: " + workflowException)
331 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
332 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
334 msoLogger.debug("SDNCResponse: " + response)
336 String sdncResponse = response
337 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
338 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
340 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
341 throw new BpmnError("MSOWorkflowException")
343 msoLogger.trace("COMPLETED ValidateSDNCResponse Process")
347 // parse the incoming DELETE_VF_MODULE request
348 // and formulate the outgoing VnfAdapterDeleteV1 request
349 public void prepVNFAdapterRequest(DelegateExecution execution) {
351 def requestId = UUID.randomUUID().toString()
352 def origRequestId = execution.getVariable('requestId')
353 def srvInstId = execution.getVariable("serviceInstanceId")
354 def aicCloudRegion = execution.getVariable("cloudSiteId")
355 def vnfId = execution.getVariable("vnfId")
356 def vfModuleId = execution.getVariable("vfModuleId")
357 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
358 def tenantId = execution.getVariable("tenantId")
359 def messageId = execution.getVariable('requestId') + '-' +
360 System.currentTimeMillis()
361 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
362 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
363 if ('true'.equals(useQualifiedHostName)) {
364 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
368 <deleteVfModuleRequest>
369 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
370 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
371 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
372 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
373 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
374 <skipAAI>true</skipAAI>
376 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
377 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
379 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
380 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
381 </deleteVfModuleRequest>
384 msoLogger.debug("vnfAdapterRestV1Request: " + request)
385 msoLogger.debug("deleteVfModuleRequest: " + request)
386 execution.setVariable("vnfAdapterRestV1Request", request)
390 // generates a WorkflowException if
392 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
393 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");
394 String processKey = getProcessKey(execution);
395 WorkflowException exception = new WorkflowException(processKey, 5000,
396 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
397 execution.setVariable("WorkflowException", exception)
400 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
401 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
402 'execution=' + execution.getId() +
405 msoLogger.trace('Entered ' + method)
406 execution.setVariable("prefix",Prefix)
408 msoLogger.trace("STARTED postProcessVNFAdapterRequest Process")
410 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
411 msoLogger.debug("VNF Adapter Response is: " + vnfResponse)
412 msoLogger.debug("deleteVnfAResponse is: \n" + vnfResponse)
414 if(vnfResponse != null){
416 if(vnfResponse.contains("deleteVfModuleResponse")){
417 msoLogger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
418 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
420 // Parse vnfOutputs for contrail network polcy FQDNs
421 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
422 if(!isBlank(vfModuleOutputsXml)) {
423 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
424 List contrailNetworkPolicyFqdnList = []
425 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
426 String key = utils.getChildNodeText(node, "key")
429 } else if (key.endsWith("contrail_network_policy_fqdn")) {
430 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
431 msoLogger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
432 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
434 else if (key.equals("oam_management_v4_address")) {
435 String oamManagementV4Address = utils.getChildNodeText(node, "value")
436 msoLogger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
437 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
439 else if (key.equals("oam_management_v6_address")) {
440 String oamManagementV6Address = utils.getChildNodeText(node, "value")
441 msoLogger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
442 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
445 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
446 msoLogger.debug("Setting the fqdn list")
447 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
451 msoLogger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
452 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
455 msoLogger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
456 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
462 msoLogger.debug("Internal Error Occured in PostProcess Method")
463 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
465 msoLogger.trace("COMPLETED postProcessVnfAdapterResponse Process")
468 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
469 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
470 'execution=' + execution.getId() +
473 msoLogger.trace('Entered ' + method)
474 execution.setVariable("prefix", Prefix)
475 msoLogger.trace("STARTED deleteNetworkPoliciesFromAAI ")
479 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
480 if (fqdnList == null) {
481 msoLogger.debug("No network policies to delete")
484 int fqdnCount = fqdnList.size()
486 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
487 msoLogger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
489 AaiUtil aaiUriUtil = new AaiUtil(this)
492 // AII loop call over contrail network policy fqdn list
493 for (i in 0..fqdnCount-1) {
496 String fqdn = fqdnList[i]
498 // Query AAI for this network policy FQDN
500 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
501 uri.queryParam("network-policy-fqdn", fqdn)
504 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
506 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
507 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
508 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
509 // This network policy FQDN exists in AAI - need to delete it now
510 // Retrieve the network policy id for this FQDN
511 def networkPolicyId = networkPolicy.getNetworkPolicyId()
512 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
514 // Retrieve the resource version for this network policy
516 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
517 getAAIClient().delete(delUri)
518 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
519 msoLogger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
520 // This network policy was deleted from AAI successfully
521 msoLogger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
522 } catch (Exception e) {
524 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
525 msoLogger.debug(delErrorMessage)
526 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
529 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
530 // This network policy FQDN is not in AAI. No need to delete.
531 msoLogger.debug("This network policy FQDN is not in AAI: " + fqdn)
532 msoLogger.debug("Network policy FQDN is not in AAI")
534 } catch (Exception e) {
536 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
537 msoLogger.debug(dataErrorMessage)
538 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
542 msoLogger.debug("No contrail network policies to query/create")
546 } catch (BpmnError e) {
549 } catch (Exception ex) {
550 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
551 msoLogger.debug(exceptionMessage)
552 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
557 // and formulate the outgoing DeleteAAIVfModuleRequest request
558 public void prepDeleteAAIVfModule(DelegateExecution execution) {
561 def vnfId = execution.getVariable("vnfId")
562 def vfModuleId = execution.getVariable("vfModuleId")
563 // formulate the request for UpdateAAIVfModule
564 String request = """<DeleteAAIVfModuleRequest>
565 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
566 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
567 </DeleteAAIVfModuleRequest>""" as String
568 msoLogger.debug("DeleteAAIVfModuleRequest :" + request)
570 execution.setVariable("DeleteAAIVfModuleRequest", request)