2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.onap.aai.domain.yang.NetworkPolicies
24 import org.onap.aai.domain.yang.NetworkPolicy
26 import javax.xml.parsers.DocumentBuilder
27 import javax.xml.parsers.DocumentBuilderFactory
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
36 import org.onap.so.bpmn.common.scripts.VfModule
37 import org.onap.so.bpmn.core.UrnPropertiesReader
38 import org.onap.so.bpmn.core.WorkflowException
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.so.client.aai.AAIObjectPlurals
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.logger.MessageEnum
45 import org.onap.so.logger.MsoLogger
46 import org.onap.so.rest.APIResponse
47 import org.onap.so.rest.RESTClient
48 import org.onap.so.rest.RESTConfig
49 import org.springframework.web.util.UriUtils
50 import org.w3c.dom.Document
51 import org.w3c.dom.Element
52 import org.w3c.dom.Node
53 import org.w3c.dom.NodeList;
54 import org.xml.sax.InputSource
56 /* Subflow for Delete VF Module. When no DoDeleteVfModuleRequest is specified on input,
57 * functions as a building block subflow
59 * Inputs for building block interface:
61 * @param - isDebugLogEnabled
64 * @param - serviceInstanceId
65 * @param - vfModuleName O
66 * @param - vfModuleModelInfo
67 * @param - cloudConfiguration*
68 * @param - sdncVersion ("1610")
69 * @param - retainResources
73 * @param - WorkflowException
76 public class DoDeleteVfModule extends AbstractServiceTaskProcessor{
77 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVfModule.class);
79 def Prefix="DoDVfMod_"
81 ExceptionUtil exceptionUtil = new ExceptionUtil()
82 JsonUtils jsonUtil = new JsonUtils()
84 public void initProcessVariables(DelegateExecution execution) {
85 execution.setVariable("prefix",Prefix)
86 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", null)
87 execution.setVariable("DoDVfMod_oamManagementV4Address", null)
88 execution.setVariable("DoDVfMod_oamManagementV6Address", null)
92 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
93 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
94 public void preProcessRequest(DelegateExecution execution) {
96 initProcessVariables(execution)
99 def xml = execution.getVariable("DoDeleteVfModuleRequest")
101 String vfModuleId = ""
103 if (xml == null || xml.isEmpty()) {
104 // Building Block-type request
106 // Set mso-request-id to request-id for VNF Adapter interface
107 String requestId = execution.getVariable("requestId")
108 execution.setVariable("mso-request-id", requestId)
110 String cloudConfiguration = execution.getVariable("cloudConfiguration")
111 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
112 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
113 execution.setVariable("tenantId", tenantId)
114 String cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
115 execution.setVariable("cloudSiteId", cloudSiteId)
116 // Source is HARDCODED
117 String source = "VID"
118 execution.setVariable("source", source)
119 // SrvInstId is hardcoded to empty
120 execution.setVariable("srvInstId", "")
121 // ServiceId is hardcoded to empty
122 execution.setVariable("serviceId", "")
123 String serviceInstanceId = execution.getVariable("serviceInstanceId")
124 vnfId = execution.getVariable("vnfId")
125 vfModuleId = execution.getVariable("vfModuleId")
126 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
127 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
130 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
133 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
134 execution.setVariable("vfModuleModelName", vfModuleModelName)
136 def retainResources = execution.getVariable("retainResources")
137 if (retainResources == null) {
138 retainResources = false
140 execution.setVariable("retainResources", retainResources)
144 msoLogger.debug("DoDeleteVfModule Request: " + xml)
146 msoLogger.debug("input request xml: " + xml)
148 vnfId = utils.getNodeText(xml,"vnf-id")
149 execution.setVariable("vnfId", vnfId)
150 vfModuleId = utils.getNodeText(xml,"vf-module-id")
151 execution.setVariable("vfModuleId", vfModuleId)
152 def srvInstId = execution.getVariable("mso-service-instance-id")
153 execution.setVariable("srvInstId", srvInstId)
154 String requestId = ""
156 requestId = execution.getVariable("mso-request-id")
157 } catch (Exception ex) {
158 requestId = utils.getNodeText(xml, "request-id")
160 execution.setVariable("requestId", requestId)
161 String source = utils.getNodeText(xml, "source")
162 execution.setVariable("source", source)
163 String serviceId = utils.getNodeText(xml, "service-id")
164 execution.setVariable("serviceId", serviceId)
165 String tenantId = utils.getNodeText(xml, "tenant-id")
166 execution.setVariable("tenantId", tenantId)
168 String serviceInstanceIdToSdnc = ""
169 if (xml.contains("service-instance-id")) {
170 serviceInstanceIdToSdnc = utils.getNodeText(xml, "service-instance-id")
172 serviceInstanceIdToSdnc = vfModuleId
174 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceIdToSdnc)
175 String vfModuleName = utils.getNodeText(xml, "vf-module-name")
176 execution.setVariable("vfModuleName", vfModuleName)
177 String vfModuleModelName = utils.getNodeText(xml, "vf-module-model-name")
178 execution.setVariable("vfModuleModelName", vfModuleModelName)
179 String cloudSiteId = utils.getNodeText(xml, "aic-cloud-region")
180 execution.setVariable("cloudSiteId", cloudSiteId)
183 // formulate the request for PrepareUpdateAAIVfModule
184 String request = """<PrepareUpdateAAIVfModuleRequest>
185 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
186 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
187 <orchestration-status>pending-delete</orchestration-status>
188 </PrepareUpdateAAIVfModuleRequest>""" as String
189 msoLogger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
190 msoLogger.debug("UpdateAAIVfModule Request: " + request)
191 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
192 execution.setVariable("vfModuleFromAAI", null)
196 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
200 // build a SDNC vnf-topology-operation request for the specified action
201 // (note: the action passed is expected to be 'changedelete' or 'delete')
202 public void prepSDNCAdapterRequest(DelegateExecution execution, String action) {
205 String uuid = execution.getVariable('testReqId') // for junits
207 uuid = execution.getVariable("requestId") + "-" + System.currentTimeMillis()
210 def srvInstId = execution.getVariable("srvInstId")
211 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
212 String requestId = execution.getVariable("requestId")
213 String source = execution.getVariable("source")
214 String serviceId = execution.getVariable("serviceId")
215 String vnfId = execution.getVariable("vnfId")
216 String tenantId = execution.getVariable("tenantId")
217 String vfModuleId = execution.getVariable("vfModuleId")
218 String serviceInstanceIdToSdnc = execution.getVariable(Prefix + "serviceInstanceIdToSdnc")
219 String vfModuleName = execution.getVariable("vfModuleName")
220 // Get vfModuleName from AAI response if it was not specified on the request
221 if (vfModuleName == null || vfModuleName.isEmpty()) {
222 if (execution.getVariable("vfModuleFromAAI") != null) {
223 org.onap.aai.domain.yang.VfModule vfModuleFromAAI = execution.getVariable("vfModuleFromAAI")
224 vfModuleName = vfModuleFromAAI.getVfModuleName()
227 String vfModuleModelName = execution.getVariable("vfModuleModelName")
228 String cloudSiteId = execution.getVariable("cloudSiteId")
229 boolean retainResources = execution.getVariable("retainResources")
230 String requestSubActionString = ""
231 if (retainResources) {
232 requestSubActionString = "<request-sub-action>RetainResource</request-sub-action>"
234 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
235 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
236 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
237 <sdncadapter:RequestHeader>
238 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
239 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
240 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
241 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
242 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
243 </sdncadapter:RequestHeader>
244 <sdncadapterworkflow:SDNCRequestData>
245 <request-information>
246 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
247 <request-action>DisconnectVNFRequest</request-action>
248 ${requestSubActionString}
249 <source>${MsoUtils.xmlEscape(source)}</source>
253 </request-information>
254 <service-information>
255 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
256 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
257 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
258 <subscriber-name>notsurewecare</subscriber-name>
259 </service-information>
260 <vnf-request-information>
261 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
262 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
263 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
264 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
265 <generic-vnf-name></generic-vnf-name>
266 <generic-vnf-type></generic-vnf-type>
267 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
268 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
269 </vnf-request-information>
270 </sdncadapterworkflow:SDNCRequestData>
271 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
273 msoLogger.debug("sdncAdapterWorkflowRequest: " + request)
274 msoLogger.debug("DoDeleteVfModule - SDNCAdapterWorkflowRequest: " + request)
275 execution.setVariable("sdncAdapterWorkflowRequest", request)
278 // parse the incoming DELETE_VF_MODULE request
279 // and formulate the outgoing VnfAdapterDeleteV1 request
280 public void prepVNFAdapterRequest(DelegateExecution execution) {
282 def requestId = UUID.randomUUID().toString()
283 def origRequestId = execution.getVariable('requestId')
284 def srvInstId = execution.getVariable("serviceInstanceId")
285 def aicCloudRegion = execution.getVariable("cloudSiteId")
286 def vnfId = execution.getVariable("vnfId")
287 def vfModuleId = execution.getVariable("vfModuleId")
288 def vfModuleStackId = execution.getVariable('DoDVfMod_heatStackId')
289 def tenantId = execution.getVariable("tenantId")
290 def messageId = execution.getVariable('requestId') + '-' +
291 System.currentTimeMillis()
292 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
293 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
294 if ('true'.equals(useQualifiedHostName)) {
295 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
299 <deleteVfModuleRequest>
300 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
301 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
302 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
303 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
304 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
305 <skipAAI>true</skipAAI>
307 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
308 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
310 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
311 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
312 </deleteVfModuleRequest>
315 msoLogger.debug("vnfAdapterRestV1Request: " + request)
316 msoLogger.debug("deleteVfModuleRequest: " + request)
317 execution.setVariable("vnfAdapterRestV1Request", request)
320 // parse the incoming DELETE_VF_MODULE request
321 // and formulate the outgoing UpdateAAIVfModuleRequest request
322 public void prepUpdateAAIVfModule(DelegateExecution execution) {
324 def vnfId = execution.getVariable("vnfId")
325 def vfModuleId = execution.getVariable("vfModuleId")
326 // formulate the request for UpdateAAIVfModule
327 String request = """<UpdateAAIVfModuleRequest>
328 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
329 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
330 <heat-stack-id>DELETE</heat-stack-id>
331 <orchestration-status>deleted</orchestration-status>
332 </UpdateAAIVfModuleRequest>""" as String
333 msoLogger.debug("UpdateAAIVfModuleRequest :" + request)
334 msoLogger.debug("UpdateAAIVfModuleRequest: " + request)
335 execution.setVariable("UpdateAAIVfModuleRequest", request)
338 // parse the incoming DELETE_VF_MODULE request
339 // and formulate the outgoing DeleteAAIVfModuleRequest request
340 public void prepDeleteAAIVfModule(DelegateExecution execution) {
343 def vnfId = execution.getVariable("vnfId")
344 def vfModuleId = execution.getVariable("vfModuleId")
345 // formulate the request for UpdateAAIVfModule
346 String request = """<DeleteAAIVfModuleRequest>
347 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
348 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
349 </DeleteAAIVfModuleRequest>""" as String
350 msoLogger.debug("DeleteAAIVfModuleRequest :" + request)
351 msoLogger.debug("DeleteAAIVfModuleRequest: " + request)
352 execution.setVariable("DeleteAAIVfModuleRequest", request)
355 // generates a WorkflowException if
357 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
358 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
359 String processKey = getProcessKey(execution);
360 WorkflowException exception = new WorkflowException(processKey, 5000,
361 execution.getVariable("DoDVfMod_deleteGenericVnfResponse"))
362 execution.setVariable("WorkflowException", exception)
365 public void sdncValidateResponse(DelegateExecution execution, String response){
367 execution.setVariable("prefix",Prefix)
369 WorkflowException workflowException = execution.getVariable("WorkflowException")
370 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
372 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
373 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
375 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
376 msoLogger.debug("Successfully Validated SDNC Response")
378 throw new BpmnError("MSOWorkflowException")
382 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
383 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
384 'execution=' + execution.getId() +
387 msoLogger.trace('Entered ' + method)
388 execution.setVariable("prefix",Prefix)
390 msoLogger.trace("STARTED postProcessVNFAdapterRequest Process")
392 String vnfResponse = execution.getVariable("DoDVfMod_doDeleteVfModuleResponse")
393 msoLogger.debug("VNF Adapter Response is: " + vnfResponse)
394 msoLogger.debug("deleteVnfAResponse is: \n" + vnfResponse)
396 if(vnfResponse != null){
398 if(vnfResponse.contains("deleteVfModuleResponse")){
399 msoLogger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
400 execution.setVariable("DoDVfMod_vnfVfModuleDeleteCompleted", true)
402 // Parse vnfOutputs for contrail network polcy FQDNs
403 if (vnfResponse.contains("vfModuleOutputs")) {
404 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
405 InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
406 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
407 docFactory.setNamespaceAware(true)
408 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
409 Document outputsXml = docBuilder.parse(source)
411 NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
412 List contrailNetworkPolicyFqdnList = []
413 for (int i = 0; i< entries.getLength(); i++) {
414 Node node = entries.item(i)
415 if (node.getNodeType() == Node.ELEMENT_NODE) {
416 Element element = (Element) node
417 String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
418 if (key.endsWith("contrail_network_policy_fqdn")) {
419 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
420 msoLogger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
421 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
423 else if (key.equals("oam_management_v4_address")) {
424 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
425 msoLogger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
426 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
428 else if (key.equals("oam_management_v6_address")) {
429 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
430 msoLogger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
431 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
436 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
437 msoLogger.debug("Setting the fqdn list")
438 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
442 msoLogger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
443 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
446 msoLogger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
447 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
453 msoLogger.debug("Internal Error Occured in PostProcess Method")
454 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
456 msoLogger.trace("COMPLETED postProcessVnfAdapterResponse Process")
459 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
460 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
461 'execution=' + execution.getId() +
464 msoLogger.trace('Entered ' + method)
465 execution.setVariable("prefix", Prefix)
466 msoLogger.trace("STARTED deleteNetworkPoliciesFromAAI ")
470 List fqdnList = execution.getVariable("DoDVfMod_contrailNetworkPolicyFqdnList")
471 if (fqdnList == null) {
472 msoLogger.debug("No network policies to delete")
475 int fqdnCount = fqdnList.size()
477 execution.setVariable("DoDVfMod_networkPolicyFqdnCount", fqdnCount)
478 msoLogger.debug("DoDVfMod_networkPolicyFqdnCount - " + fqdnCount)
481 // AII loop call over contrail network policy fqdn list
482 for (i in 0..fqdnCount-1) {
483 String fqdn = fqdnList[i]
484 // Query AAI for this network policy FQDN
485 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
486 uri.queryParam("network-policy-fqdn", fqdn)
488 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
489 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
490 // This network policy FQDN exists in AAI - need to delete it now
491 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
492 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
493 // Retrieve the network policy id for this FQDN
494 def networkPolicyId = networkPolicy.getNetworkPolicyId()
495 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
497 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
498 getAAIClient().delete(delUri)
499 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 200)
500 } catch (Exception e) {
501 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 500)
502 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
503 msoLogger.debug(delErrorMessage)
504 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
507 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
508 // This network policy FQDN is not in AAI. No need to delete.
509 msoLogger.debug("The return code is: " + 404)
510 msoLogger.debug("This network policy FQDN is not in AAI: " + fqdn)
511 msoLogger.debug("Network policy FQDN is not in AAI")
513 }catch(Exception e ) {
515 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
516 msoLogger.debug(dataErrorMessage)
520 msoLogger.debug("No contrail network policies to query/create")
522 } catch (BpmnError e) {
524 } catch (Exception ex) {
525 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
526 msoLogger.debug(exceptionMessage)
527 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
533 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
535 * @param execution The flow's execution instance.
537 public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
538 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
539 'execution=' + execution.getId() +
542 msoLogger.trace('Entered ' + method)
545 def vnfId = execution.getVariable('vnfId')
546 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
547 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
548 def ipv4OamAddressElement = ''
549 def managementV6AddressElement = ''
551 if (oamManagementV4Address != null) {
552 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
555 if (oamManagementV6Address != null) {
556 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
560 String updateAAIGenericVnfRequest = """
561 <UpdateAAIGenericVnfRequest>
562 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
563 ${ipv4OamAddressElement}
564 ${managementV6AddressElement}
565 </UpdateAAIGenericVnfRequest>
567 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
568 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
569 msoLogger.debug("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
570 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
573 msoLogger.trace('Exited ' + method)
574 } catch (BpmnError e) {
576 } catch (Exception e) {
577 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
578 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
583 * Using the vnfId and vfModuleId provided in the inputs,
584 * query AAI to get the corresponding VF Module info.
585 * A 200 response is expected with the VF Module info in the response body,
586 * Will determine VF Module's orchestration status if one exists
588 * @param execution The flow's execution instance.
590 public void queryAAIVfModuleForStatus(DelegateExecution execution) {
592 def method = getClass().getSimpleName() + '.queryAAIVfModuleForStatus(' +
593 'execution=' + execution.getId() +
595 msoLogger.trace('Entered ' + method)
597 execution.setVariable(Prefix + 'orchestrationStatus', '')
600 def vnfId = execution.getVariable('vnfId')
601 def vfModuleId = execution.getVariable('vfModuleId')
603 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)
606 Optional<org.onap.aai.domain.yang.VfModule> vfModule = getAAIClient().get(org.onap.aai.domain.yang.VfModule.class, uri);
607 // Retrieve VF Module info and its orchestration status; if not found, do nothing
608 if (vfModule.isPresent()) {
609 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponseCode', 200)
610 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponse', vfModule.get())
611 def orchestrationStatus = vfModule.get().getOrchestrationStatus()
612 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
613 msoLogger.debug("Received orchestration status from A&AI: " + orchestrationStatus)
615 } catch (Exception ex) {
617 msoLogger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
618 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
620 msoLogger.trace('Exited ' + method)
621 } catch (BpmnError e) {
623 } catch (Exception e) {
624 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
625 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModuleForStatus(): ' + e.getMessage())