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.NetworkPolicies
26 import org.onap.aai.domain.yang.NetworkPolicy
28 import javax.xml.parsers.DocumentBuilder
29 import javax.xml.parsers.DocumentBuilderFactory
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.AbstractServiceTaskProcessor
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.VfModule
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.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
50 import org.springframework.web.util.UriUtils
51 import org.w3c.dom.Document
52 import org.w3c.dom.Element
53 import org.w3c.dom.Node
54 import org.w3c.dom.NodeList;
55 import org.xml.sax.InputSource
57 /* Subflow for Delete VF Module. When no DoDeleteVfModuleRequest is specified on input,
58 * functions as a building block subflow
60 * Inputs for building block interface:
62 * @param - isDebugLogEnabled
65 * @param - serviceInstanceId
66 * @param - vfModuleName O
67 * @param - vfModuleModelInfo
68 * @param - cloudConfiguration*
69 * @param - sdncVersion ("1610")
70 * @param - retainResources
74 * @param - WorkflowException
77 public class DoDeleteVfModule extends AbstractServiceTaskProcessor{
78 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModule.class);
80 def Prefix="DoDVfMod_"
82 ExceptionUtil exceptionUtil = new ExceptionUtil()
83 JsonUtils jsonUtil = new JsonUtils()
85 public void initProcessVariables(DelegateExecution execution) {
86 execution.setVariable("prefix",Prefix)
87 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", null)
88 execution.setVariable("DoDVfMod_oamManagementV4Address", null)
89 execution.setVariable("DoDVfMod_oamManagementV6Address", null)
93 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
94 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
95 public void preProcessRequest(DelegateExecution execution) {
97 initProcessVariables(execution)
100 def xml = execution.getVariable("DoDeleteVfModuleRequest")
102 String vfModuleId = ""
104 if (xml == null || xml.isEmpty()) {
105 // Building Block-type request
107 // Set mso-request-id to request-id for VNF Adapter interface
108 String requestId = execution.getVariable("requestId")
109 execution.setVariable("mso-request-id", requestId)
111 String cloudConfiguration = execution.getVariable("cloudConfiguration")
112 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
113 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
114 execution.setVariable("tenantId", tenantId)
115 String cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
116 execution.setVariable("cloudSiteId", cloudSiteId)
117 // Source is HARDCODED
118 String source = "VID"
119 execution.setVariable("source", source)
120 // SrvInstId is hardcoded to empty
121 execution.setVariable("srvInstId", "")
122 // ServiceId is hardcoded to empty
123 execution.setVariable("serviceId", "")
124 String serviceInstanceId = execution.getVariable("serviceInstanceId")
125 vnfId = execution.getVariable("vnfId")
126 vfModuleId = execution.getVariable("vfModuleId")
127 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
128 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
131 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
134 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
135 execution.setVariable("vfModuleModelName", vfModuleModelName)
137 def retainResources = execution.getVariable("retainResources")
138 if (retainResources == null) {
139 retainResources = false
141 execution.setVariable("retainResources", retainResources)
145 logger.debug("DoDeleteVfModule Request: " + xml)
147 logger.debug("input request xml: " + xml)
149 vnfId = utils.getNodeText(xml,"vnf-id")
150 execution.setVariable("vnfId", vnfId)
151 vfModuleId = utils.getNodeText(xml,"vf-module-id")
152 execution.setVariable("vfModuleId", vfModuleId)
153 def srvInstId = execution.getVariable("mso-service-instance-id")
154 execution.setVariable("srvInstId", srvInstId)
155 String requestId = ""
157 requestId = execution.getVariable("mso-request-id")
158 } catch (Exception ex) {
159 requestId = utils.getNodeText(xml, "request-id")
161 execution.setVariable("requestId", requestId)
162 String source = utils.getNodeText(xml, "source")
163 execution.setVariable("source", source)
164 String serviceId = utils.getNodeText(xml, "service-id")
165 execution.setVariable("serviceId", serviceId)
166 String tenantId = utils.getNodeText(xml, "tenant-id")
167 execution.setVariable("tenantId", tenantId)
169 String serviceInstanceIdToSdnc = ""
170 if (xml.contains("service-instance-id")) {
171 serviceInstanceIdToSdnc = utils.getNodeText(xml, "service-instance-id")
173 serviceInstanceIdToSdnc = vfModuleId
175 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceIdToSdnc)
176 String vfModuleName = utils.getNodeText(xml, "vf-module-name")
177 execution.setVariable("vfModuleName", vfModuleName)
178 String vfModuleModelName = utils.getNodeText(xml, "vf-module-model-name")
179 execution.setVariable("vfModuleModelName", vfModuleModelName)
180 String cloudSiteId = utils.getNodeText(xml, "aic-cloud-region")
181 execution.setVariable("cloudSiteId", cloudSiteId)
184 // formulate the request for PrepareUpdateAAIVfModule
185 String request = """<PrepareUpdateAAIVfModuleRequest>
186 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
187 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
188 <orchestration-status>pending-delete</orchestration-status>
189 </PrepareUpdateAAIVfModuleRequest>""" as String
190 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
191 logger.debug("UpdateAAIVfModule Request: " + request)
192 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
193 execution.setVariable("vfModuleFromAAI", null)
197 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
201 // build a SDNC vnf-topology-operation request for the specified action
202 // (note: the action passed is expected to be 'changedelete' or 'delete')
203 public void prepSDNCAdapterRequest(DelegateExecution execution, String action) {
206 String uuid = execution.getVariable('testReqId') // for junits
208 uuid = execution.getVariable("requestId") + "-" + System.currentTimeMillis()
211 def srvInstId = execution.getVariable("srvInstId")
212 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
213 String requestId = execution.getVariable("requestId")
214 String source = execution.getVariable("source")
215 String serviceId = execution.getVariable("serviceId")
216 String vnfId = execution.getVariable("vnfId")
217 String tenantId = execution.getVariable("tenantId")
218 String vfModuleId = execution.getVariable("vfModuleId")
219 String serviceInstanceIdToSdnc = execution.getVariable(Prefix + "serviceInstanceIdToSdnc")
220 String vfModuleName = execution.getVariable("vfModuleName")
221 // Get vfModuleName from AAI response if it was not specified on the request
222 if (vfModuleName == null || vfModuleName.isEmpty()) {
223 if (execution.getVariable("vfModuleFromAAI") != null) {
224 org.onap.aai.domain.yang.VfModule vfModuleFromAAI = execution.getVariable("vfModuleFromAAI")
225 vfModuleName = vfModuleFromAAI.getVfModuleName()
228 String vfModuleModelName = execution.getVariable("vfModuleModelName")
229 String cloudSiteId = execution.getVariable("cloudSiteId")
230 boolean retainResources = execution.getVariable("retainResources")
231 String requestSubActionString = ""
232 if (retainResources) {
233 requestSubActionString = "<request-sub-action>RetainResource</request-sub-action>"
235 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
236 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
237 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
238 <sdncadapter:RequestHeader>
239 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
240 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
241 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
242 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
243 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
244 </sdncadapter:RequestHeader>
245 <sdncadapterworkflow:SDNCRequestData>
246 <request-information>
247 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
248 <request-action>DisconnectVNFRequest</request-action>
249 ${requestSubActionString}
250 <source>${MsoUtils.xmlEscape(source)}</source>
254 </request-information>
255 <service-information>
256 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
257 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
258 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
259 <subscriber-name>notsurewecare</subscriber-name>
260 </service-information>
261 <vnf-request-information>
262 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
263 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
264 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
265 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
266 <generic-vnf-name></generic-vnf-name>
267 <generic-vnf-type></generic-vnf-type>
268 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
269 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
270 </vnf-request-information>
271 </sdncadapterworkflow:SDNCRequestData>
272 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
274 logger.debug("sdncAdapterWorkflowRequest: " + request)
275 logger.debug("DoDeleteVfModule - SDNCAdapterWorkflowRequest: " + request)
276 execution.setVariable("sdncAdapterWorkflowRequest", request)
279 // parse the incoming DELETE_VF_MODULE request
280 // and formulate the outgoing VnfAdapterDeleteV1 request
281 public void prepVNFAdapterRequest(DelegateExecution execution) {
283 def requestId = UUID.randomUUID().toString()
284 def origRequestId = execution.getVariable('requestId')
285 def srvInstId = execution.getVariable("serviceInstanceId")
286 def aicCloudRegion = execution.getVariable("cloudSiteId")
287 def vnfId = execution.getVariable("vnfId")
288 def vfModuleId = execution.getVariable("vfModuleId")
289 def vfModuleStackId = execution.getVariable('DoDVfMod_heatStackId')
290 def tenantId = execution.getVariable("tenantId")
291 def messageId = execution.getVariable('requestId') + '-' +
292 System.currentTimeMillis()
293 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
294 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
295 if ('true'.equals(useQualifiedHostName)) {
296 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
300 <deleteVfModuleRequest>
301 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
302 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
303 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
304 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
305 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
306 <skipAAI>true</skipAAI>
308 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
309 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
311 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
312 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
313 </deleteVfModuleRequest>
316 logger.debug("vnfAdapterRestV1Request: " + request)
317 logger.debug("deleteVfModuleRequest: " + request)
318 execution.setVariable("vnfAdapterRestV1Request", request)
321 // parse the incoming DELETE_VF_MODULE request
322 // and formulate the outgoing UpdateAAIVfModuleRequest request
323 public void prepUpdateAAIVfModule(DelegateExecution execution) {
325 def vnfId = execution.getVariable("vnfId")
326 def vfModuleId = execution.getVariable("vfModuleId")
327 // formulate the request for UpdateAAIVfModule
328 String request = """<UpdateAAIVfModuleRequest>
329 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
330 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
331 <heat-stack-id>DELETE</heat-stack-id>
332 <orchestration-status>deleted</orchestration-status>
333 </UpdateAAIVfModuleRequest>""" as String
334 logger.debug("UpdateAAIVfModuleRequest :" + request)
335 logger.debug("UpdateAAIVfModuleRequest: " + request)
336 execution.setVariable("UpdateAAIVfModuleRequest", request)
339 // parse the incoming DELETE_VF_MODULE request
340 // and formulate the outgoing DeleteAAIVfModuleRequest request
341 public void prepDeleteAAIVfModule(DelegateExecution execution) {
344 def vnfId = execution.getVariable("vnfId")
345 def vfModuleId = execution.getVariable("vfModuleId")
346 // formulate the request for UpdateAAIVfModule
347 String request = """<DeleteAAIVfModuleRequest>
348 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
349 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
350 </DeleteAAIVfModuleRequest>""" as String
351 logger.debug("DeleteAAIVfModuleRequest :" + request)
352 logger.debug("DeleteAAIVfModuleRequest: " + request)
353 execution.setVariable("DeleteAAIVfModuleRequest", request)
356 // generates a WorkflowException if
358 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
359 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
360 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
361 "BPMN", MsoLogger.ErrorCode.UnknownError.getValue(), "Exception");
362 String processKey = getProcessKey(execution);
363 WorkflowException exception = new WorkflowException(processKey, 5000,
364 execution.getVariable("DoDVfMod_deleteGenericVnfResponse"))
365 execution.setVariable("WorkflowException", exception)
368 public void sdncValidateResponse(DelegateExecution execution, String response){
370 execution.setVariable("prefix",Prefix)
372 WorkflowException workflowException = execution.getVariable("WorkflowException")
373 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
375 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
376 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
378 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
379 logger.debug("Successfully Validated SDNC Response")
381 throw new BpmnError("MSOWorkflowException")
385 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
386 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
387 'execution=' + execution.getId() +
390 logger.trace('Entered ' + method)
391 execution.setVariable("prefix",Prefix)
393 logger.trace("STARTED postProcessVNFAdapterRequest Process")
395 String vnfResponse = execution.getVariable("DoDVfMod_doDeleteVfModuleResponse")
396 logger.debug("VNF Adapter Response is: " + vnfResponse)
397 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
399 if(vnfResponse != null){
401 if(vnfResponse.contains("deleteVfModuleResponse")){
402 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
403 execution.setVariable("DoDVfMod_vnfVfModuleDeleteCompleted", true)
405 // Parse vnfOutputs for contrail network polcy FQDNs
406 if (vnfResponse.contains("vfModuleOutputs")) {
407 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
408 InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
409 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
410 docFactory.setNamespaceAware(true)
411 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
412 Document outputsXml = docBuilder.parse(source)
414 NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
415 List contrailNetworkPolicyFqdnList = []
416 for (int i = 0; i< entries.getLength(); i++) {
417 Node node = entries.item(i)
418 if (node.getNodeType() == Node.ELEMENT_NODE) {
419 Element element = (Element) node
420 String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
421 if (key.endsWith("contrail_network_policy_fqdn")) {
422 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
423 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
424 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
426 else if (key.equals("oam_management_v4_address")) {
427 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
428 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
429 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
431 else if (key.equals("oam_management_v6_address")) {
432 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
433 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
434 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
439 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
440 logger.debug("Setting the fqdn list")
441 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
445 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
446 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
449 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
450 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
456 logger.debug("Internal Error Occured in PostProcess Method")
457 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
459 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
462 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
463 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
464 'execution=' + execution.getId() +
467 logger.trace('Entered ' + method)
468 execution.setVariable("prefix", Prefix)
469 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
473 List fqdnList = execution.getVariable("DoDVfMod_contrailNetworkPolicyFqdnList")
474 if (fqdnList == null) {
475 logger.debug("No network policies to delete")
478 int fqdnCount = fqdnList.size()
480 execution.setVariable("DoDVfMod_networkPolicyFqdnCount", fqdnCount)
481 logger.debug("DoDVfMod_networkPolicyFqdnCount - " + fqdnCount)
484 // AII loop call over contrail network policy fqdn list
485 for (i in 0..fqdnCount-1) {
486 String fqdn = fqdnList[i]
487 // Query AAI for this network policy FQDN
488 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
489 uri.queryParam("network-policy-fqdn", fqdn)
491 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
492 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
493 // This network policy FQDN exists in AAI - need to delete it now
494 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
495 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
496 // Retrieve the network policy id for this FQDN
497 def networkPolicyId = networkPolicy.getNetworkPolicyId()
498 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
500 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
501 getAAIClient().delete(delUri)
502 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 200)
503 } catch (Exception e) {
504 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 500)
505 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
506 logger.debug(delErrorMessage)
507 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
510 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
511 // This network policy FQDN is not in AAI. No need to delete.
512 logger.debug("The return code is: " + 404)
513 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
514 logger.debug("Network policy FQDN is not in AAI")
516 }catch(Exception e ) {
518 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
519 logger.debug(dataErrorMessage)
523 logger.debug("No contrail network policies to query/create")
525 } catch (BpmnError e) {
527 } catch (Exception ex) {
528 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
529 logger.debug(exceptionMessage)
530 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
536 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
538 * @param execution The flow's execution instance.
540 public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
541 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
542 'execution=' + execution.getId() +
545 logger.trace('Entered ' + method)
548 def vnfId = execution.getVariable('vnfId')
549 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
550 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
551 def ipv4OamAddressElement = ''
552 def managementV6AddressElement = ''
554 if (oamManagementV4Address != null) {
555 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
558 if (oamManagementV6Address != null) {
559 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
563 String updateAAIGenericVnfRequest = """
564 <UpdateAAIGenericVnfRequest>
565 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
566 ${ipv4OamAddressElement}
567 ${managementV6AddressElement}
568 </UpdateAAIGenericVnfRequest>
570 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
571 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
572 logger.debug("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
573 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
576 logger.trace('Exited ' + method)
577 } catch (BpmnError e) {
579 } catch (Exception e) {
580 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
581 'Caught exception in ' + method, "BPMN",
582 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
583 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
588 * Using the vnfId and vfModuleId provided in the inputs,
589 * query AAI to get the corresponding VF Module info.
590 * A 200 response is expected with the VF Module info in the response body,
591 * Will determine VF Module's orchestration status if one exists
593 * @param execution The flow's execution instance.
595 public void queryAAIVfModuleForStatus(DelegateExecution execution) {
597 def method = getClass().getSimpleName() + '.queryAAIVfModuleForStatus(' +
598 'execution=' + execution.getId() +
600 logger.trace('Entered ' + method)
602 execution.setVariable(Prefix + 'orchestrationStatus', '')
605 def vnfId = execution.getVariable('vnfId')
606 def vfModuleId = execution.getVariable('vfModuleId')
608 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)
611 Optional<org.onap.aai.domain.yang.VfModule> vfModule = getAAIClient().get(org.onap.aai.domain.yang.VfModule.class, uri);
612 // Retrieve VF Module info and its orchestration status; if not found, do nothing
613 if (vfModule.isPresent()) {
614 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponseCode', 200)
615 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponse', vfModule.get())
616 def orchestrationStatus = vfModule.get().getOrchestrationStatus()
617 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
618 logger.debug("Received orchestration status from A&AI: " + orchestrationStatus)
620 } catch (Exception ex) {
622 logger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
623 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
625 logger.trace('Exited ' + method)
626 } catch (BpmnError e) {
628 } catch (Exception e) {
629 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
630 'Caught exception in ' + method, "BPMN",
631 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
632 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModuleForStatus(): ' + e.getMessage())