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.aaiclient.client.graphinventory.entities.uri.Depth
44 import org.onap.aaiclient.client.aai.AAIObjectPlurals
45 import org.onap.aaiclient.client.aai.AAIObjectType
46 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
47 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
48 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
49 import org.onap.so.logger.MessageEnum
50 import org.slf4j.Logger
51 import org.slf4j.LoggerFactory
53 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
54 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModuleFromVnf.class);
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
60 public void initProcessVariables(DelegateExecution execution) {
61 execution.setVariable("prefix",Prefix)
62 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
65 // parse the incoming request
66 public void preProcessRequest(DelegateExecution execution) {
68 initProcessVariables(execution)
72 // Building Block-type request
74 // Set mso-request-id to request-id for VNF Adapter interface
75 String requestId = execution.getVariable("msoRequestId")
76 execution.setVariable("mso-request-id", requestId)
77 execution.setVariable("requestId", requestId)
78 logger.debug("msoRequestId: " + requestId)
79 String tenantId = execution.getVariable("tenantId")
80 logger.debug("tenantId: " + tenantId)
81 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
82 execution.setVariable("cloudSiteId", cloudSiteId)
83 logger.debug("cloudSiteId: " + cloudSiteId)
84 String cloudOwner = execution.getVariable("cloudOwner")
85 execution.setVariable("cloudOwner", cloudOwner)
86 logger.debug("cloudOwner: " + cloudOwner)
87 // Source is HARDCODED
89 execution.setVariable("source", source)
90 // isVidRequest is hardcoded to "true"
91 execution.setVariable("isVidRequest", "true")
92 // SrvInstId is hardcoded to empty
93 execution.setVariable("srvInstId", "")
94 // ServiceId is hardcoded to empty
95 execution.setVariable("serviceId", "")
96 String serviceInstanceId = execution.getVariable("serviceInstanceId")
97 logger.debug("serviceInstanceId: " + serviceInstanceId)
98 String vnfId = execution.getVariable("vnfId")
99 logger.debug("vnfId: " + vnfId)
100 String vfModuleId = execution.getVariable("vfModuleId")
101 logger.debug("vfModuleId: " + vfModuleId)
102 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
103 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
106 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
109 String sdncVersion = execution.getVariable("sdncVersion")
110 if (sdncVersion == null) {
113 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
114 logger.debug("Incoming Sdnc Version is: " + sdncVersion)
116 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
117 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
118 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
119 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
120 ErrorCode.UnknownError.getValue(), "Exception");
121 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
123 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
124 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
125 logger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
130 logger.debug("Exception is: " + e.getMessage())
131 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
135 public void queryAAIForVfModule(DelegateExecution execution) {
136 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
137 'execution=' + execution.getId() +
140 logger.trace('Entered ' + method)
143 def vnfId = execution.getVariable('vnfId')
145 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
147 Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class,uri)
149 if(genericVnf.isPresent()){
150 execution.setVariable('DDVMFV_getVnfResponseCode', 200)
151 execution.setVariable('DDVMFV_getVnfResponse', genericVnf.get())
153 execution.setVariable('DDVMFV_getVnfResponseCode', 404)
154 execution.setVariable('DDVMFV_getVnfResponse', "Generic Vnf not found!")
156 } catch (Exception ex) {
157 logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
158 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
159 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
161 logger.trace('Exited ' + method)
162 } catch (BpmnError e) {
164 } catch (Exception e) {
165 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
166 'Caught exception in ' + method, "BPMN",
167 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
168 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
173 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
174 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
175 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
176 * attempting to delete it.
178 * @param execution The flow's execution instance.
180 public void validateVfModule(DelegateExecution execution) {
181 def method = getClass().getSimpleName() + '.validateVfModule(' +
182 'execution=' + execution.getId() +
184 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
185 logger.trace('Entered ' + method)
188 GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
189 def vnfId = execution.getVariable('_vnfId')
190 def vfModuleId = execution.getVariable('vfModuleId')
191 Optional<VfModule> vfModule = Optional.empty()
192 if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
193 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
195 if (!vfModule.isPresent()) {
196 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
198 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
200 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
201 if (isDebugLogEnabled) {
202 logger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
204 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
205 String msg = 'Cannot delete VF Module \'' + vfModuleId +
206 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
208 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
210 def heatStackId = vfModule.get().getHeatStackId()
211 execution.setVariable('DDVMFV_heatStackId', heatStackId)
212 logger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
214 logger.trace('Exited ' + method)
215 } catch (BpmnError e) {
217 } catch (Exception e) {
218 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
219 'Caught exception in ' + method, "BPMN",
220 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
221 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
226 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
228 execution.setVariable("prefix", Prefix)
229 logger.trace("STARTED preProcessSDNCDeactivateRequest ")
231 def serviceInstanceId = execution.getVariable("serviceInstanceId")
236 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
238 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
239 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
240 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
244 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
245 "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN",
246 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
247 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
249 logger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
252 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
253 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
254 'execution=' + execution.getId() +
257 logger.trace('Entered ' + method)
258 execution.setVariable("prefix", Prefix)
259 logger.trace("STARTED preProcessSDNCUnassignRequest Process ")
261 String serviceInstanceId = execution.getVariable("serviceInstanceId")
263 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
265 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
266 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
270 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
271 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
273 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
276 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
278 String uuid = execution.getVariable('testReqId') // for junits
280 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
282 def callbackURL = execution.getVariable("sdncCallbackUrl")
283 def requestId = execution.getVariable("msoRequestId")
284 def serviceId = execution.getVariable("serviceId")
285 def serviceInstanceId = execution.getVariable("serviceInstanceId")
286 def vfModuleId = execution.getVariable("vfModuleId")
287 def source = execution.getVariable("source")
288 def vnfId = execution.getVariable("vnfId")
290 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
293 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
294 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
295 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
296 <sdncadapter:RequestHeader>
297 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
298 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
299 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
300 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
301 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
302 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
303 </sdncadapter:RequestHeader>
304 <sdncadapterworkflow:SDNCRequestData>
305 <request-information>
306 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
307 <request-action>DeleteVfModuleInstance</request-action>
308 <source>${MsoUtils.xmlEscape(source)}</source>
312 </request-information>
313 <service-information>
315 <subscription-service-type/>
316 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
317 <global-customer-id/>
318 </service-information>
320 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
323 <vf-module-information>
324 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
325 </vf-module-information>
326 <vf-module-request-input/>
327 </sdncadapterworkflow:SDNCRequestData>
328 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
330 logger.debug("sdncRequest: " + sdncRequest)
334 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
336 execution.setVariable("prefix",Prefix)
337 logger.trace("STARTED ValidateSDNCResponse Process")
339 WorkflowException workflowException = execution.getVariable("WorkflowException")
340 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
342 logger.debug("workflowException: " + workflowException)
344 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
345 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
347 logger.debug("SDNCResponse: " + response)
349 String sdncResponse = response
350 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
351 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
353 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
354 throw new BpmnError("MSOWorkflowException")
356 logger.trace("COMPLETED ValidateSDNCResponse Process")
360 // parse the incoming DELETE_VF_MODULE request
361 // and formulate the outgoing VnfAdapterDeleteV1 request
362 public void prepVNFAdapterRequest(DelegateExecution execution) {
364 def requestId = UUID.randomUUID().toString()
365 def origRequestId = execution.getVariable('requestId')
366 def srvInstId = execution.getVariable("serviceInstanceId")
367 def aicCloudRegion = execution.getVariable("cloudSiteId")
368 def cloudOwner = execution.getVariable("cloudOwner")
369 def vnfId = execution.getVariable("vnfId")
370 def vfModuleId = execution.getVariable("vfModuleId")
371 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
372 def tenantId = execution.getVariable("tenantId")
373 def messageId = execution.getVariable('requestId') + '-' +
374 System.currentTimeMillis()
375 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
376 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
377 if ('true'.equals(useQualifiedHostName)) {
378 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
382 <deleteVfModuleRequest>
383 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
384 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
385 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
386 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
387 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
388 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
389 <skipAAI>true</skipAAI>
391 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
392 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
394 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
395 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
396 </deleteVfModuleRequest>
400 logger.debug("deleteVfModuleRequest: " + request)
401 execution.setVariable("vnfAdapterTaskRequest", request)
405 // generates a WorkflowException if
407 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
408 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
409 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"),
410 "BPMN", ErrorCode.UnknownError.getValue(), "Exception");
411 String processKey = getProcessKey(execution);
412 WorkflowException exception = new WorkflowException(processKey, 5000,
413 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
414 execution.setVariable("WorkflowException", exception)
417 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
418 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
419 'execution=' + execution.getId() +
422 logger.trace('Entered ' + method)
423 execution.setVariable("prefix",Prefix)
425 logger.trace("STARTED postProcessVNFAdapterRequest Process")
427 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
428 logger.debug("VNF Adapter Response is: " + vnfResponse)
429 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
431 if(vnfResponse != null){
433 if(vnfResponse.contains("deleteVfModuleResponse")){
434 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
435 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
437 // Parse vnfOutputs for contrail network polcy FQDNs
438 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
439 if(!isBlank(vfModuleOutputsXml)) {
440 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
441 List contrailNetworkPolicyFqdnList = []
442 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
443 String key = utils.getChildNodeText(node, "key")
446 } else if (key.endsWith("contrail_network_policy_fqdn")) {
447 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
448 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
449 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
451 else if (key.equals("oam_management_v4_address")) {
452 String oamManagementV4Address = utils.getChildNodeText(node, "value")
453 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
454 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
456 else if (key.equals("oam_management_v6_address")) {
457 String oamManagementV6Address = utils.getChildNodeText(node, "value")
458 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
459 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
462 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
463 logger.debug("Setting the fqdn list")
464 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
468 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
469 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
472 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
473 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
479 logger.debug("Internal Error Occured in PostProcess Method")
480 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
482 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
485 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
486 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
487 'execution=' + execution.getId() +
490 logger.trace('Entered ' + method)
491 execution.setVariable("prefix", Prefix)
492 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
496 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
497 if (fqdnList == null) {
498 logger.debug("No network policies to delete")
501 int fqdnCount = fqdnList.size()
503 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
504 logger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
506 AaiUtil aaiUriUtil = new AaiUtil(this)
509 // AII loop call over contrail network policy fqdn list
510 for (i in 0..fqdnCount-1) {
513 String fqdn = fqdnList[i]
515 // Query AAI for this network policy FQDN
517 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
518 uri.queryParam("network-policy-fqdn", fqdn)
521 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
523 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
524 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
525 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
526 // This network policy FQDN exists in AAI - need to delete it now
527 // Retrieve the network policy id for this FQDN
528 def networkPolicyId = networkPolicy.getNetworkPolicyId()
529 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
531 // Retrieve the resource version for this network policy
533 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
534 getAAIClient().delete(delUri)
535 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
536 logger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
537 // This network policy was deleted from AAI successfully
538 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
539 } catch (Exception e) {
541 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
542 logger.debug(delErrorMessage)
543 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
546 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
547 // This network policy FQDN is not in AAI. No need to delete.
548 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
549 logger.debug("Network policy FQDN is not in AAI")
551 } catch (Exception e) {
553 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
554 logger.debug(dataErrorMessage)
555 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
559 logger.debug("No contrail network policies to query/create")
563 } catch (BpmnError e) {
566 } catch (Exception ex) {
567 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
568 logger.debug(exceptionMessage)
569 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
574 // and formulate the outgoing DeleteAAIVfModuleRequest request
575 public void prepDeleteAAIVfModule(DelegateExecution execution) {
578 def vnfId = execution.getVariable("vnfId")
579 def vfModuleId = execution.getVariable("vfModuleId")
580 // formulate the request for UpdateAAIVfModule
581 String request = """<DeleteAAIVfModuleRequest>
582 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
583 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
584 </DeleteAAIVfModuleRequest>""" as String
585 logger.debug("DeleteAAIVfModuleRequest :" + request)
587 execution.setVariable("DeleteAAIVfModuleRequest", request)