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.aai.domain.yang.GenericVnf
26 import org.onap.aai.domain.yang.NetworkPolicies
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.aai.domain.yang.VfModule
30 import static org.apache.commons.lang3.StringUtils.*
31 import org.camunda.bpm.engine.delegate.BpmnError
32 import org.camunda.bpm.engine.delegate.DelegateExecution
33 import org.onap.so.bpmn.common.scripts.AaiUtil
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.common.scripts.MsoUtils
36 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
37 import org.onap.so.bpmn.common.scripts.VfModuleBase
38 import org.onap.so.bpmn.core.UrnPropertiesReader
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.core.json.JsonUtils
41 import org.onap.so.client.graphinventory.entities.uri.Depth
42 import org.onap.so.client.aai.AAIObjectPlurals
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
45 import org.onap.so.client.aai.entities.uri.AAIUriFactory
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
48 import org.slf4j.Logger
49 import org.slf4j.LoggerFactory
51 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
52 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModuleFromVnf.class);
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
56 JsonUtils jsonUtil = new JsonUtils()
58 public void initProcessVariables(DelegateExecution execution) {
59 execution.setVariable("prefix",Prefix)
60 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
63 // parse the incoming request
64 public void preProcessRequest(DelegateExecution execution) {
66 initProcessVariables(execution)
70 // Building Block-type request
72 // Set mso-request-id to request-id for VNF Adapter interface
73 String requestId = execution.getVariable("msoRequestId")
74 execution.setVariable("mso-request-id", requestId)
75 execution.setVariable("requestId", requestId)
76 logger.debug("msoRequestId: " + requestId)
77 String tenantId = execution.getVariable("tenantId")
78 logger.debug("tenantId: " + tenantId)
79 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
80 execution.setVariable("cloudSiteId", cloudSiteId)
81 logger.debug("cloudSiteId: " + cloudSiteId)
82 // Source is HARDCODED
84 execution.setVariable("source", source)
85 // isVidRequest is hardcoded to "true"
86 execution.setVariable("isVidRequest", "true")
87 // SrvInstId is hardcoded to empty
88 execution.setVariable("srvInstId", "")
89 // ServiceId is hardcoded to empty
90 execution.setVariable("serviceId", "")
91 String serviceInstanceId = execution.getVariable("serviceInstanceId")
92 logger.debug("serviceInstanceId: " + serviceInstanceId)
93 String vnfId = execution.getVariable("vnfId")
94 logger.debug("vnfId: " + vnfId)
95 String vfModuleId = execution.getVariable("vfModuleId")
96 logger.debug("vfModuleId: " + vfModuleId)
97 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
98 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
101 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
104 String sdncVersion = execution.getVariable("sdncVersion")
105 if (sdncVersion == null) {
108 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
109 logger.debug("Incoming Sdnc Version is: " + sdncVersion)
111 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
112 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
113 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
114 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
115 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception");
116 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
118 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
119 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
120 logger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
127 logger.debug("Exception is: " + e.getMessage())
128 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
132 public void queryAAIForVfModule(DelegateExecution execution) {
133 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
134 'execution=' + execution.getId() +
137 logger.trace('Entered ' + method)
140 def vnfId = execution.getVariable('vnfId')
142 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
144 Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class,uri)
146 if(genericVnf.isPresent()){
147 execution.setVariable('DDVMFV_getVnfResponseCode', 200)
148 execution.setVariable('DDVMFV_getVnfResponse', genericVnf.get())
150 execution.setVariable('DDVMFV_getVnfResponseCode', 404)
151 execution.setVariable('DDVMFV_getVnfResponse', "Generic Vnf not found!")
153 } catch (Exception ex) {
155 logger.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 logger.trace('Exited ' + method)
160 } catch (BpmnError e) {
162 } catch (Exception e) {
163 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
164 'Caught exception in ' + method, "BPMN",
165 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
166 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
171 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
172 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
173 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
174 * attempting to delete it.
176 * @param execution The flow's execution instance.
178 public void validateVfModule(DelegateExecution execution) {
179 def method = getClass().getSimpleName() + '.validateVfModule(' +
180 'execution=' + execution.getId() +
182 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
183 logger.trace('Entered ' + method)
186 GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
187 def vnfId = execution.getVariable('_vnfId')
188 def vfModuleId = execution.getVariable('vfModuleId')
189 Optional<VfModule> vfModule = Optional.empty()
190 if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
191 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
193 if (!vfModule.isPresent()) {
194 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
196 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
198 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
199 if (isDebugLogEnabled) {
200 logger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
202 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
203 String msg = 'Cannot delete VF Module \'' + vfModuleId +
204 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
206 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
208 def heatStackId = vfModule.get().getHeatStackId()
209 execution.setVariable('DDVMFV_heatStackId', heatStackId)
210 logger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
212 logger.trace('Exited ' + method)
213 } catch (BpmnError e) {
215 } catch (Exception e) {
216 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
217 'Caught exception in ' + method, "BPMN",
218 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
219 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
224 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
226 execution.setVariable("prefix", Prefix)
227 logger.trace("STARTED preProcessSDNCDeactivateRequest ")
229 def serviceInstanceId = execution.getVariable("serviceInstanceId")
234 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
236 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
237 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
238 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
242 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
243 "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN",
244 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
245 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
247 logger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
250 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
251 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
252 'execution=' + execution.getId() +
255 logger.trace('Entered ' + method)
256 execution.setVariable("prefix", Prefix)
257 logger.trace("STARTED preProcessSDNCUnassignRequest Process ")
259 String serviceInstanceId = execution.getVariable("serviceInstanceId")
261 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
263 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
264 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
268 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
269 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
271 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
274 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
276 String uuid = execution.getVariable('testReqId') // for junits
278 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
280 def callbackURL = execution.getVariable("sdncCallbackUrl")
281 def requestId = execution.getVariable("msoRequestId")
282 def serviceId = execution.getVariable("serviceId")
283 def serviceInstanceId = execution.getVariable("serviceInstanceId")
284 def vfModuleId = execution.getVariable("vfModuleId")
285 def source = execution.getVariable("source")
286 def vnfId = execution.getVariable("vnfId")
288 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
291 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
292 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
293 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
294 <sdncadapter:RequestHeader>
295 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
296 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
297 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
298 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
299 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
300 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
301 </sdncadapter:RequestHeader>
302 <sdncadapterworkflow:SDNCRequestData>
303 <request-information>
304 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
305 <request-action>DeleteVfModuleInstance</request-action>
306 <source>${MsoUtils.xmlEscape(source)}</source>
310 </request-information>
311 <service-information>
313 <subscription-service-type/>
314 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
315 <global-customer-id/>
316 </service-information>
318 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
321 <vf-module-information>
322 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
323 </vf-module-information>
324 <vf-module-request-input/>
325 </sdncadapterworkflow:SDNCRequestData>
326 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
328 logger.debug("sdncRequest: " + sdncRequest)
332 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
334 execution.setVariable("prefix",Prefix)
335 logger.trace("STARTED ValidateSDNCResponse Process")
337 WorkflowException workflowException = execution.getVariable("WorkflowException")
338 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
340 logger.debug("workflowException: " + workflowException)
342 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
343 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
345 logger.debug("SDNCResponse: " + response)
347 String sdncResponse = response
348 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
349 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
351 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
352 throw new BpmnError("MSOWorkflowException")
354 logger.trace("COMPLETED ValidateSDNCResponse Process")
358 // parse the incoming DELETE_VF_MODULE request
359 // and formulate the outgoing VnfAdapterDeleteV1 request
360 public void prepVNFAdapterRequest(DelegateExecution execution) {
362 def requestId = UUID.randomUUID().toString()
363 def origRequestId = execution.getVariable('requestId')
364 def srvInstId = execution.getVariable("serviceInstanceId")
365 def aicCloudRegion = execution.getVariable("cloudSiteId")
366 def vnfId = execution.getVariable("vnfId")
367 def vfModuleId = execution.getVariable("vfModuleId")
368 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
369 def tenantId = execution.getVariable("tenantId")
370 def messageId = execution.getVariable('requestId') + '-' +
371 System.currentTimeMillis()
372 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
373 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
374 if ('true'.equals(useQualifiedHostName)) {
375 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
379 <deleteVfModuleRequest>
380 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
381 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
382 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
383 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
384 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
385 <skipAAI>true</skipAAI>
387 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
388 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
390 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
391 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
392 </deleteVfModuleRequest>
395 logger.debug("vnfAdapterRestV1Request: " + request)
396 logger.debug("deleteVfModuleRequest: " + request)
397 execution.setVariable("vnfAdapterRestV1Request", request)
401 // generates a WorkflowException if
403 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
404 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
405 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"),
406 "BPMN", MsoLogger.ErrorCode.UnknownError.getValue(), "Exception");
407 String processKey = getProcessKey(execution);
408 WorkflowException exception = new WorkflowException(processKey, 5000,
409 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
410 execution.setVariable("WorkflowException", exception)
413 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
414 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
415 'execution=' + execution.getId() +
418 logger.trace('Entered ' + method)
419 execution.setVariable("prefix",Prefix)
421 logger.trace("STARTED postProcessVNFAdapterRequest Process")
423 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
424 logger.debug("VNF Adapter Response is: " + vnfResponse)
425 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
427 if(vnfResponse != null){
429 if(vnfResponse.contains("deleteVfModuleResponse")){
430 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
431 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
433 // Parse vnfOutputs for contrail network polcy FQDNs
434 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
435 if(!isBlank(vfModuleOutputsXml)) {
436 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
437 List contrailNetworkPolicyFqdnList = []
438 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
439 String key = utils.getChildNodeText(node, "key")
442 } else if (key.endsWith("contrail_network_policy_fqdn")) {
443 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
444 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
445 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
447 else if (key.equals("oam_management_v4_address")) {
448 String oamManagementV4Address = utils.getChildNodeText(node, "value")
449 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
450 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
452 else if (key.equals("oam_management_v6_address")) {
453 String oamManagementV6Address = utils.getChildNodeText(node, "value")
454 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
455 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
458 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
459 logger.debug("Setting the fqdn list")
460 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
464 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
465 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
468 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
469 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
475 logger.debug("Internal Error Occured in PostProcess Method")
476 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
478 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
481 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
482 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
483 'execution=' + execution.getId() +
486 logger.trace('Entered ' + method)
487 execution.setVariable("prefix", Prefix)
488 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
492 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
493 if (fqdnList == null) {
494 logger.debug("No network policies to delete")
497 int fqdnCount = fqdnList.size()
499 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
500 logger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
502 AaiUtil aaiUriUtil = new AaiUtil(this)
505 // AII loop call over contrail network policy fqdn list
506 for (i in 0..fqdnCount-1) {
509 String fqdn = fqdnList[i]
511 // Query AAI for this network policy FQDN
513 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
514 uri.queryParam("network-policy-fqdn", fqdn)
517 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
519 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
520 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
521 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
522 // This network policy FQDN exists in AAI - need to delete it now
523 // Retrieve the network policy id for this FQDN
524 def networkPolicyId = networkPolicy.getNetworkPolicyId()
525 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
527 // Retrieve the resource version for this network policy
529 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
530 getAAIClient().delete(delUri)
531 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
532 logger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
533 // This network policy was deleted from AAI successfully
534 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
535 } catch (Exception e) {
537 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
538 logger.debug(delErrorMessage)
539 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
542 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
543 // This network policy FQDN is not in AAI. No need to delete.
544 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
545 logger.debug("Network policy FQDN is not in AAI")
547 } catch (Exception e) {
549 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
550 logger.debug(dataErrorMessage)
551 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
555 logger.debug("No contrail network policies to query/create")
559 } catch (BpmnError e) {
562 } catch (Exception ex) {
563 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
564 logger.debug(exceptionMessage)
565 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
570 // and formulate the outgoing DeleteAAIVfModuleRequest request
571 public void prepDeleteAAIVfModule(DelegateExecution execution) {
574 def vnfId = execution.getVariable("vnfId")
575 def vfModuleId = execution.getVariable("vfModuleId")
576 // formulate the request for UpdateAAIVfModule
577 String request = """<DeleteAAIVfModuleRequest>
578 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
579 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
580 </DeleteAAIVfModuleRequest>""" as String
581 logger.debug("DeleteAAIVfModuleRequest :" + request)
583 execution.setVariable("DeleteAAIVfModuleRequest", request)