2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.onap.so.logger.LoggingAnchor
26 import org.onap.aai.domain.yang.GenericVnf
27 import org.onap.aai.domain.yang.NetworkPolicies
28 import org.onap.aai.domain.yang.NetworkPolicy
29 import org.onap.aai.domain.yang.VfModule
30 import org.onap.logging.filter.base.ErrorCode
32 import static org.apache.commons.lang3.StringUtils.*
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.onap.so.bpmn.common.scripts.AaiUtil
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
39 import org.onap.so.bpmn.common.scripts.VfModuleBase
40 import org.onap.so.bpmn.core.UrnPropertiesReader
41 import org.onap.so.bpmn.core.WorkflowException
42 import org.onap.so.bpmn.core.json.JsonUtils
43 import org.onap.so.client.graphinventory.entities.uri.Depth
44 import org.onap.so.client.aai.AAIObjectPlurals
45 import org.onap.so.client.aai.AAIObjectType
46 import org.onap.so.client.aai.entities.uri.AAIResourceUri
47 import org.onap.so.client.aai.entities.uri.AAIUriFactory
48 import org.onap.so.logger.MessageEnum
49 import org.slf4j.Logger
50 import org.slf4j.LoggerFactory
52 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
53 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModuleFromVnf.class);
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
57 JsonUtils jsonUtil = new JsonUtils()
59 public void initProcessVariables(DelegateExecution execution) {
60 execution.setVariable("prefix",Prefix)
61 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
64 // parse the incoming request
65 public void preProcessRequest(DelegateExecution execution) {
67 initProcessVariables(execution)
71 // Building Block-type request
73 // Set mso-request-id to request-id for VNF Adapter interface
74 String requestId = execution.getVariable("msoRequestId")
75 execution.setVariable("mso-request-id", requestId)
76 execution.setVariable("requestId", requestId)
77 logger.debug("msoRequestId: " + requestId)
78 String tenantId = execution.getVariable("tenantId")
79 logger.debug("tenantId: " + tenantId)
80 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
81 execution.setVariable("cloudSiteId", cloudSiteId)
82 logger.debug("cloudSiteId: " + cloudSiteId)
83 String cloudOwner = execution.getVariable("cloudOwner")
84 execution.setVariable("cloudOwner", cloudOwner)
85 logger.debug("cloudOwner: " + cloudOwner)
86 // Source is HARDCODED
88 execution.setVariable("source", source)
89 // isVidRequest is hardcoded to "true"
90 execution.setVariable("isVidRequest", "true")
91 // SrvInstId is hardcoded to empty
92 execution.setVariable("srvInstId", "")
93 // ServiceId is hardcoded to empty
94 execution.setVariable("serviceId", "")
95 String serviceInstanceId = execution.getVariable("serviceInstanceId")
96 logger.debug("serviceInstanceId: " + serviceInstanceId)
97 String vnfId = execution.getVariable("vnfId")
98 logger.debug("vnfId: " + vnfId)
99 String vfModuleId = execution.getVariable("vfModuleId")
100 logger.debug("vfModuleId: " + vfModuleId)
101 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
102 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
105 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
108 String sdncVersion = execution.getVariable("sdncVersion")
109 if (sdncVersion == null) {
112 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
113 logger.debug("Incoming Sdnc Version is: " + sdncVersion)
115 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
116 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
117 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
118 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
119 ErrorCode.UnknownError.getValue(), "Exception");
120 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
122 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
123 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
124 logger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
129 logger.debug("Exception is: " + e.getMessage())
130 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
134 public void queryAAIForVfModule(DelegateExecution execution) {
135 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
136 'execution=' + execution.getId() +
139 logger.trace('Entered ' + method)
142 def vnfId = execution.getVariable('vnfId')
144 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
146 Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class,uri)
148 if(genericVnf.isPresent()){
149 execution.setVariable('DDVMFV_getVnfResponseCode', 200)
150 execution.setVariable('DDVMFV_getVnfResponse', genericVnf.get())
152 execution.setVariable('DDVMFV_getVnfResponseCode', 404)
153 execution.setVariable('DDVMFV_getVnfResponse', "Generic Vnf not found!")
155 } catch (Exception ex) {
156 logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
157 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
158 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
160 logger.trace('Exited ' + method)
161 } catch (BpmnError e) {
163 } catch (Exception e) {
164 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
165 'Caught exception in ' + method, "BPMN",
166 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
167 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
172 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
173 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
174 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
175 * attempting to delete it.
177 * @param execution The flow's execution instance.
179 public void validateVfModule(DelegateExecution execution) {
180 def method = getClass().getSimpleName() + '.validateVfModule(' +
181 'execution=' + execution.getId() +
183 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
184 logger.trace('Entered ' + method)
187 GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
188 def vnfId = execution.getVariable('_vnfId')
189 def vfModuleId = execution.getVariable('vfModuleId')
190 Optional<VfModule> vfModule = Optional.empty()
191 if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
192 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
194 if (!vfModule.isPresent()) {
195 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
197 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
199 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
200 if (isDebugLogEnabled) {
201 logger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
203 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
204 String msg = 'Cannot delete VF Module \'' + vfModuleId +
205 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
207 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
209 def heatStackId = vfModule.get().getHeatStackId()
210 execution.setVariable('DDVMFV_heatStackId', heatStackId)
211 logger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
213 logger.trace('Exited ' + method)
214 } catch (BpmnError e) {
216 } catch (Exception e) {
217 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
218 'Caught exception in ' + method, "BPMN",
219 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
220 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
225 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
227 execution.setVariable("prefix", Prefix)
228 logger.trace("STARTED preProcessSDNCDeactivateRequest ")
230 def serviceInstanceId = execution.getVariable("serviceInstanceId")
235 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
237 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
238 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
239 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
243 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
244 "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN",
245 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
246 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
248 logger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
251 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
252 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
253 'execution=' + execution.getId() +
256 logger.trace('Entered ' + method)
257 execution.setVariable("prefix", Prefix)
258 logger.trace("STARTED preProcessSDNCUnassignRequest Process ")
260 String serviceInstanceId = execution.getVariable("serviceInstanceId")
262 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
264 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
265 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
269 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
270 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
272 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
275 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
277 String uuid = execution.getVariable('testReqId') // for junits
279 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
281 def callbackURL = execution.getVariable("sdncCallbackUrl")
282 def requestId = execution.getVariable("msoRequestId")
283 def serviceId = execution.getVariable("serviceId")
284 def serviceInstanceId = execution.getVariable("serviceInstanceId")
285 def vfModuleId = execution.getVariable("vfModuleId")
286 def source = execution.getVariable("source")
287 def vnfId = execution.getVariable("vnfId")
289 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
292 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
293 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
294 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
295 <sdncadapter:RequestHeader>
296 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
297 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
298 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
299 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
300 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
301 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
302 </sdncadapter:RequestHeader>
303 <sdncadapterworkflow:SDNCRequestData>
304 <request-information>
305 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
306 <request-action>DeleteVfModuleInstance</request-action>
307 <source>${MsoUtils.xmlEscape(source)}</source>
311 </request-information>
312 <service-information>
314 <subscription-service-type/>
315 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
316 <global-customer-id/>
317 </service-information>
319 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
322 <vf-module-information>
323 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
324 </vf-module-information>
325 <vf-module-request-input/>
326 </sdncadapterworkflow:SDNCRequestData>
327 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
329 logger.debug("sdncRequest: " + sdncRequest)
333 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
335 execution.setVariable("prefix",Prefix)
336 logger.trace("STARTED ValidateSDNCResponse Process")
338 WorkflowException workflowException = execution.getVariable("WorkflowException")
339 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
341 logger.debug("workflowException: " + workflowException)
343 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
344 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
346 logger.debug("SDNCResponse: " + response)
348 String sdncResponse = response
349 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
350 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
352 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
353 throw new BpmnError("MSOWorkflowException")
355 logger.trace("COMPLETED ValidateSDNCResponse Process")
359 // parse the incoming DELETE_VF_MODULE request
360 // and formulate the outgoing VnfAdapterDeleteV1 request
361 public void prepVNFAdapterRequest(DelegateExecution execution) {
363 def requestId = UUID.randomUUID().toString()
364 def origRequestId = execution.getVariable('requestId')
365 def srvInstId = execution.getVariable("serviceInstanceId")
366 def aicCloudRegion = execution.getVariable("cloudSiteId")
367 def cloudOwner = execution.getVariable("cloudOwner")
368 def vnfId = execution.getVariable("vnfId")
369 def vfModuleId = execution.getVariable("vfModuleId")
370 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
371 def tenantId = execution.getVariable("tenantId")
372 def messageId = execution.getVariable('requestId') + '-' +
373 System.currentTimeMillis()
374 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
375 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
376 if ('true'.equals(useQualifiedHostName)) {
377 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
381 <deleteVfModuleRequest>
382 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
383 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
384 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
385 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
386 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
387 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
388 <skipAAI>true</skipAAI>
390 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
391 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
393 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
394 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
395 </deleteVfModuleRequest>
398 logger.debug("vnfAdapterRestV1Request: " + request)
399 logger.debug("deleteVfModuleRequest: " + request)
400 execution.setVariable("vnfAdapterRestV1Request", request)
404 // generates a WorkflowException if
406 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
407 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
408 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"),
409 "BPMN", ErrorCode.UnknownError.getValue(), "Exception");
410 String processKey = getProcessKey(execution);
411 WorkflowException exception = new WorkflowException(processKey, 5000,
412 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
413 execution.setVariable("WorkflowException", exception)
416 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
417 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
418 'execution=' + execution.getId() +
421 logger.trace('Entered ' + method)
422 execution.setVariable("prefix",Prefix)
424 logger.trace("STARTED postProcessVNFAdapterRequest Process")
426 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
427 logger.debug("VNF Adapter Response is: " + vnfResponse)
428 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
430 if(vnfResponse != null){
432 if(vnfResponse.contains("deleteVfModuleResponse")){
433 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
434 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
436 // Parse vnfOutputs for contrail network polcy FQDNs
437 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
438 if(!isBlank(vfModuleOutputsXml)) {
439 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
440 List contrailNetworkPolicyFqdnList = []
441 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
442 String key = utils.getChildNodeText(node, "key")
445 } else if (key.endsWith("contrail_network_policy_fqdn")) {
446 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
447 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
448 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
450 else if (key.equals("oam_management_v4_address")) {
451 String oamManagementV4Address = utils.getChildNodeText(node, "value")
452 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
453 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
455 else if (key.equals("oam_management_v6_address")) {
456 String oamManagementV6Address = utils.getChildNodeText(node, "value")
457 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
458 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
461 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
462 logger.debug("Setting the fqdn list")
463 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
467 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
468 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
471 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
472 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
478 logger.debug("Internal Error Occured in PostProcess Method")
479 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
481 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
484 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
485 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
486 'execution=' + execution.getId() +
489 logger.trace('Entered ' + method)
490 execution.setVariable("prefix", Prefix)
491 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
495 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
496 if (fqdnList == null) {
497 logger.debug("No network policies to delete")
500 int fqdnCount = fqdnList.size()
502 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
503 logger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
505 AaiUtil aaiUriUtil = new AaiUtil(this)
508 // AII loop call over contrail network policy fqdn list
509 for (i in 0..fqdnCount-1) {
512 String fqdn = fqdnList[i]
514 // Query AAI for this network policy FQDN
516 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
517 uri.queryParam("network-policy-fqdn", fqdn)
520 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
522 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
523 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
524 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
525 // This network policy FQDN exists in AAI - need to delete it now
526 // Retrieve the network policy id for this FQDN
527 def networkPolicyId = networkPolicy.getNetworkPolicyId()
528 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
530 // Retrieve the resource version for this network policy
532 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
533 getAAIClient().delete(delUri)
534 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
535 logger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
536 // This network policy was deleted from AAI successfully
537 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
538 } catch (Exception e) {
540 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
541 logger.debug(delErrorMessage)
542 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
545 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
546 // This network policy FQDN is not in AAI. No need to delete.
547 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
548 logger.debug("Network policy FQDN is not in AAI")
550 } catch (Exception e) {
552 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
553 logger.debug(dataErrorMessage)
554 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
558 logger.debug("No contrail network policies to query/create")
562 } catch (BpmnError e) {
565 } catch (Exception ex) {
566 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
567 logger.debug(exceptionMessage)
568 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
573 // and formulate the outgoing DeleteAAIVfModuleRequest request
574 public void prepDeleteAAIVfModule(DelegateExecution execution) {
577 def vnfId = execution.getVariable("vnfId")
578 def vfModuleId = execution.getVariable("vfModuleId")
579 // formulate the request for UpdateAAIVfModule
580 String request = """<DeleteAAIVfModuleRequest>
581 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
582 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
583 </DeleteAAIVfModuleRequest>""" as String
584 logger.debug("DeleteAAIVfModuleRequest :" + request)
586 execution.setVariable("DeleteAAIVfModuleRequest", request)