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
29 import org.onap.so.logger.ErrorCode
31 import static org.apache.commons.lang3.StringUtils.*
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.delegate.DelegateExecution
34 import org.onap.so.bpmn.common.scripts.AaiUtil
35 import org.onap.so.bpmn.common.scripts.ExceptionUtil
36 import org.onap.so.bpmn.common.scripts.MsoUtils
37 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
38 import org.onap.so.bpmn.common.scripts.VfModuleBase
39 import org.onap.so.bpmn.core.UrnPropertiesReader
40 import org.onap.so.bpmn.core.WorkflowException
41 import org.onap.so.bpmn.core.json.JsonUtils
42 import org.onap.so.client.graphinventory.entities.uri.Depth
43 import org.onap.so.client.aai.AAIObjectPlurals
44 import org.onap.so.client.aai.AAIObjectType
45 import org.onap.so.client.aai.entities.uri.AAIResourceUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.onap.so.logger.MessageEnum
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 String cloudOwner = execution.getVariable("cloudOwner")
83 execution.setVariable("cloudOwner", cloudOwner)
84 logger.debug("cloudOwner: " + cloudOwner)
85 // Source is HARDCODED
87 execution.setVariable("source", source)
88 // isVidRequest is hardcoded to "true"
89 execution.setVariable("isVidRequest", "true")
90 // SrvInstId is hardcoded to empty
91 execution.setVariable("srvInstId", "")
92 // ServiceId is hardcoded to empty
93 execution.setVariable("serviceId", "")
94 String serviceInstanceId = execution.getVariable("serviceInstanceId")
95 logger.debug("serviceInstanceId: " + serviceInstanceId)
96 String vnfId = execution.getVariable("vnfId")
97 logger.debug("vnfId: " + vnfId)
98 String vfModuleId = execution.getVariable("vfModuleId")
99 logger.debug("vfModuleId: " + vfModuleId)
100 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
101 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
104 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
107 String sdncVersion = execution.getVariable("sdncVersion")
108 if (sdncVersion == null) {
111 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
112 logger.debug("Incoming Sdnc Version is: " + sdncVersion)
114 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
115 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
116 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
117 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
118 ErrorCode.UnknownError.getValue(), "Exception");
119 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
121 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
122 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
123 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) {
158 logger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
159 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
160 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
162 logger.trace('Exited ' + method)
163 } catch (BpmnError e) {
165 } catch (Exception e) {
166 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
167 'Caught exception in ' + method, "BPMN",
168 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
169 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
174 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
175 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
176 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
177 * attempting to delete it.
179 * @param execution The flow's execution instance.
181 public void validateVfModule(DelegateExecution execution) {
182 def method = getClass().getSimpleName() + '.validateVfModule(' +
183 'execution=' + execution.getId() +
185 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
186 logger.trace('Entered ' + method)
189 GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
190 def vnfId = execution.getVariable('_vnfId')
191 def vfModuleId = execution.getVariable('vfModuleId')
192 Optional<VfModule> vfModule = Optional.empty()
193 if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
194 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
196 if (!vfModule.isPresent()) {
197 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
199 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
201 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
202 if (isDebugLogEnabled) {
203 logger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
205 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
206 String msg = 'Cannot delete VF Module \'' + vfModuleId +
207 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
209 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
211 def heatStackId = vfModule.get().getHeatStackId()
212 execution.setVariable('DDVMFV_heatStackId', heatStackId)
213 logger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
215 logger.trace('Exited ' + method)
216 } catch (BpmnError e) {
218 } catch (Exception e) {
219 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
220 'Caught exception in ' + method, "BPMN",
221 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
222 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
227 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
229 execution.setVariable("prefix", Prefix)
230 logger.trace("STARTED preProcessSDNCDeactivateRequest ")
232 def serviceInstanceId = execution.getVariable("serviceInstanceId")
237 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
239 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
240 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
241 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
245 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
246 "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN",
247 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
248 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
250 logger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
253 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
254 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
255 'execution=' + execution.getId() +
258 logger.trace('Entered ' + method)
259 execution.setVariable("prefix", Prefix)
260 logger.trace("STARTED preProcessSDNCUnassignRequest Process ")
262 String serviceInstanceId = execution.getVariable("serviceInstanceId")
264 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
266 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
267 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
271 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
272 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
274 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process ")
277 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
279 String uuid = execution.getVariable('testReqId') // for junits
281 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
283 def callbackURL = execution.getVariable("sdncCallbackUrl")
284 def requestId = execution.getVariable("msoRequestId")
285 def serviceId = execution.getVariable("serviceId")
286 def serviceInstanceId = execution.getVariable("serviceInstanceId")
287 def vfModuleId = execution.getVariable("vfModuleId")
288 def source = execution.getVariable("source")
289 def vnfId = execution.getVariable("vnfId")
291 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
294 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
295 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
296 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
297 <sdncadapter:RequestHeader>
298 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
299 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
300 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
301 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
302 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
303 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
304 </sdncadapter:RequestHeader>
305 <sdncadapterworkflow:SDNCRequestData>
306 <request-information>
307 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
308 <request-action>DeleteVfModuleInstance</request-action>
309 <source>${MsoUtils.xmlEscape(source)}</source>
313 </request-information>
314 <service-information>
316 <subscription-service-type/>
317 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
318 <global-customer-id/>
319 </service-information>
321 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
324 <vf-module-information>
325 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
326 </vf-module-information>
327 <vf-module-request-input/>
328 </sdncadapterworkflow:SDNCRequestData>
329 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
331 logger.debug("sdncRequest: " + sdncRequest)
335 public void validateSDNCResponse(DelegateExecution execution, String response, String method){
337 execution.setVariable("prefix",Prefix)
338 logger.trace("STARTED ValidateSDNCResponse Process")
340 WorkflowException workflowException = execution.getVariable("WorkflowException")
341 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
343 logger.debug("workflowException: " + workflowException)
345 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
346 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
348 logger.debug("SDNCResponse: " + response)
350 String sdncResponse = response
351 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
352 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
354 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
355 throw new BpmnError("MSOWorkflowException")
357 logger.trace("COMPLETED ValidateSDNCResponse Process")
361 // parse the incoming DELETE_VF_MODULE request
362 // and formulate the outgoing VnfAdapterDeleteV1 request
363 public void prepVNFAdapterRequest(DelegateExecution execution) {
365 def requestId = UUID.randomUUID().toString()
366 def origRequestId = execution.getVariable('requestId')
367 def srvInstId = execution.getVariable("serviceInstanceId")
368 def aicCloudRegion = execution.getVariable("cloudSiteId")
369 def cloudOwner = execution.getVariable("cloudOwner")
370 def vnfId = execution.getVariable("vnfId")
371 def vfModuleId = execution.getVariable("vfModuleId")
372 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
373 def tenantId = execution.getVariable("tenantId")
374 def messageId = execution.getVariable('requestId') + '-' +
375 System.currentTimeMillis()
376 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
377 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
378 if ('true'.equals(useQualifiedHostName)) {
379 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
383 <deleteVfModuleRequest>
384 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
385 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
386 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
387 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
388 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
389 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
390 <skipAAI>true</skipAAI>
392 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
393 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
395 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
396 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
397 </deleteVfModuleRequest>
400 logger.debug("vnfAdapterRestV1Request: " + request)
401 logger.debug("deleteVfModuleRequest: " + request)
402 execution.setVariable("vnfAdapterRestV1Request", request)
406 // generates a WorkflowException if
408 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
409 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
410 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"),
411 "BPMN", ErrorCode.UnknownError.getValue(), "Exception");
412 String processKey = getProcessKey(execution);
413 WorkflowException exception = new WorkflowException(processKey, 5000,
414 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
415 execution.setVariable("WorkflowException", exception)
418 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
419 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
420 'execution=' + execution.getId() +
423 logger.trace('Entered ' + method)
424 execution.setVariable("prefix",Prefix)
426 logger.trace("STARTED postProcessVNFAdapterRequest Process")
428 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
429 logger.debug("VNF Adapter Response is: " + vnfResponse)
430 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
432 if(vnfResponse != null){
434 if(vnfResponse.contains("deleteVfModuleResponse")){
435 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
436 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
438 // Parse vnfOutputs for contrail network polcy FQDNs
439 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
440 if(!isBlank(vfModuleOutputsXml)) {
441 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
442 List contrailNetworkPolicyFqdnList = []
443 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
444 String key = utils.getChildNodeText(node, "key")
447 } else if (key.endsWith("contrail_network_policy_fqdn")) {
448 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
449 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
450 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
452 else if (key.equals("oam_management_v4_address")) {
453 String oamManagementV4Address = utils.getChildNodeText(node, "value")
454 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
455 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
457 else if (key.equals("oam_management_v6_address")) {
458 String oamManagementV6Address = utils.getChildNodeText(node, "value")
459 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
460 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
463 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
464 logger.debug("Setting the fqdn list")
465 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
469 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
470 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
473 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
474 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
480 logger.debug("Internal Error Occured in PostProcess Method")
481 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
483 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
486 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
487 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
488 'execution=' + execution.getId() +
491 logger.trace('Entered ' + method)
492 execution.setVariable("prefix", Prefix)
493 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
497 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
498 if (fqdnList == null) {
499 logger.debug("No network policies to delete")
502 int fqdnCount = fqdnList.size()
504 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
505 logger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
507 AaiUtil aaiUriUtil = new AaiUtil(this)
510 // AII loop call over contrail network policy fqdn list
511 for (i in 0..fqdnCount-1) {
514 String fqdn = fqdnList[i]
516 // Query AAI for this network policy FQDN
518 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
519 uri.queryParam("network-policy-fqdn", fqdn)
522 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
524 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
525 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
526 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
527 // This network policy FQDN exists in AAI - need to delete it now
528 // Retrieve the network policy id for this FQDN
529 def networkPolicyId = networkPolicy.getNetworkPolicyId()
530 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
532 // Retrieve the resource version for this network policy
534 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
535 getAAIClient().delete(delUri)
536 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
537 logger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
538 // This network policy was deleted from AAI successfully
539 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
540 } catch (Exception e) {
542 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
543 logger.debug(delErrorMessage)
544 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
547 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
548 // This network policy FQDN is not in AAI. No need to delete.
549 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
550 logger.debug("Network policy FQDN is not in AAI")
552 } catch (Exception e) {
554 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
555 logger.debug(dataErrorMessage)
556 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
560 logger.debug("No contrail network policies to query/create")
564 } catch (BpmnError e) {
567 } catch (Exception ex) {
568 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
569 logger.debug(exceptionMessage)
570 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
575 // and formulate the outgoing DeleteAAIVfModuleRequest request
576 public void prepDeleteAAIVfModule(DelegateExecution execution) {
579 def vnfId = execution.getVariable("vnfId")
580 def vfModuleId = execution.getVariable("vfModuleId")
581 // formulate the request for UpdateAAIVfModule
582 String request = """<DeleteAAIVfModuleRequest>
583 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
584 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
585 </DeleteAAIVfModuleRequest>""" as String
586 logger.debug("DeleteAAIVfModuleRequest :" + request)
588 execution.setVariable("DeleteAAIVfModuleRequest", request)