2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.onap.so.logger.LoggingAnchor
26 import org.onap.aai.domain.yang.NetworkPolicies
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.so.logger.ErrorCode
30 import javax.xml.parsers.DocumentBuilder
31 import javax.xml.parsers.DocumentBuilderFactory
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
39 import org.onap.so.bpmn.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.slf4j.Logger
48 import org.slf4j.LoggerFactory
49 import org.w3c.dom.Document
50 import org.w3c.dom.Element
51 import org.w3c.dom.Node
52 import org.w3c.dom.NodeList;
53 import org.xml.sax.InputSource
55 /* Subflow for Delete VF Module. When no DoDeleteVfModuleRequest is specified on input,
56 * functions as a building block subflow
58 * Inputs for building block interface:
60 * @param - isDebugLogEnabled
63 * @param - serviceInstanceId
64 * @param - vfModuleName O
65 * @param - vfModuleModelInfo
66 * @param - cloudConfiguration*
67 * @param - sdncVersion ("1610")
68 * @param - retainResources
72 * @param - WorkflowException
75 public class DoDeleteVfModule extends AbstractServiceTaskProcessor{
76 private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModule.class);
78 def Prefix="DoDVfMod_"
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
81 JsonUtils jsonUtil = new JsonUtils()
83 public void initProcessVariables(DelegateExecution execution) {
84 execution.setVariable("prefix",Prefix)
85 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", null)
86 execution.setVariable("DoDVfMod_oamManagementV4Address", null)
87 execution.setVariable("DoDVfMod_oamManagementV6Address", null)
91 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
92 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
93 public void preProcessRequest(DelegateExecution execution) {
95 initProcessVariables(execution)
98 def xml = execution.getVariable("DoDeleteVfModuleRequest")
100 String vfModuleId = ""
102 if (xml == null || xml.isEmpty()) {
103 // Building Block-type request
105 // Set mso-request-id to request-id for VNF Adapter interface
106 String requestId = execution.getVariable("requestId")
107 execution.setVariable("mso-request-id", requestId)
109 String cloudConfiguration = execution.getVariable("cloudConfiguration")
110 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
111 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
112 execution.setVariable("tenantId", tenantId)
113 String cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
114 execution.setVariable("cloudSiteId", cloudSiteId)
115 String cloudOwner = jsonUtil.getJsonValue(cloudConfiguration, "cloudOwner")
116 execution.setVariable("cloudOwner", cloudOwner)
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)
182 String cloudOwner = utils.getNodeText(xml, "cloud-owner")
183 execution.setVariable("cloudOwner", cloudOwner)
186 // formulate the request for PrepareUpdateAAIVfModule
187 String request = """<PrepareUpdateAAIVfModuleRequest>
188 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
189 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
190 <orchestration-status>pending-delete</orchestration-status>
191 </PrepareUpdateAAIVfModuleRequest>""" as String
192 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
193 logger.debug("UpdateAAIVfModule Request: " + request)
194 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
195 execution.setVariable("vfModuleFromAAI", null)
199 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
203 // build a SDNC vnf-topology-operation request for the specified action
204 // (note: the action passed is expected to be 'changedelete' or 'delete')
205 public void prepSDNCAdapterRequest(DelegateExecution execution, String action) {
208 String uuid = execution.getVariable('testReqId') // for junits
210 uuid = execution.getVariable("requestId") + "-" + System.currentTimeMillis()
213 def srvInstId = execution.getVariable("srvInstId")
214 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
215 String requestId = execution.getVariable("requestId")
216 String source = execution.getVariable("source")
217 String serviceId = execution.getVariable("serviceId")
218 String vnfId = execution.getVariable("vnfId")
219 String tenantId = execution.getVariable("tenantId")
220 String vfModuleId = execution.getVariable("vfModuleId")
221 String serviceInstanceIdToSdnc = execution.getVariable(Prefix + "serviceInstanceIdToSdnc")
222 String vfModuleName = execution.getVariable("vfModuleName")
223 // Get vfModuleName from AAI response if it was not specified on the request
224 if (vfModuleName == null || vfModuleName.isEmpty()) {
225 if (execution.getVariable("vfModuleFromAAI") != null) {
226 org.onap.aai.domain.yang.VfModule vfModuleFromAAI = execution.getVariable("vfModuleFromAAI")
227 vfModuleName = vfModuleFromAAI.getVfModuleName()
230 String vfModuleModelName = execution.getVariable("vfModuleModelName")
231 String cloudSiteId = execution.getVariable("cloudSiteId")
232 boolean retainResources = execution.getVariable("retainResources")
233 String requestSubActionString = ""
234 if (retainResources) {
235 requestSubActionString = "<request-sub-action>RetainResource</request-sub-action>"
237 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
238 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
239 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
240 <sdncadapter:RequestHeader>
241 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
242 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
243 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
244 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
245 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
246 </sdncadapter:RequestHeader>
247 <sdncadapterworkflow:SDNCRequestData>
248 <request-information>
249 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
250 <request-action>DisconnectVNFRequest</request-action>
251 ${requestSubActionString}
252 <source>${MsoUtils.xmlEscape(source)}</source>
256 </request-information>
257 <service-information>
258 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
259 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
260 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
261 <subscriber-name>notsurewecare</subscriber-name>
262 </service-information>
263 <vnf-request-information>
264 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
265 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
266 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
267 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
268 <generic-vnf-name></generic-vnf-name>
269 <generic-vnf-type></generic-vnf-type>
270 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
271 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
272 </vnf-request-information>
273 </sdncadapterworkflow:SDNCRequestData>
274 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
276 logger.debug("sdncAdapterWorkflowRequest: " + request)
277 logger.debug("DoDeleteVfModule - SDNCAdapterWorkflowRequest: " + request)
278 execution.setVariable("sdncAdapterWorkflowRequest", request)
281 // parse the incoming DELETE_VF_MODULE request
282 // and formulate the outgoing VnfAdapterDeleteV1 request
283 public void prepVNFAdapterRequest(DelegateExecution execution) {
285 def requestId = UUID.randomUUID().toString()
286 def origRequestId = execution.getVariable('requestId')
287 def srvInstId = execution.getVariable("serviceInstanceId")
288 def aicCloudRegion = execution.getVariable("cloudSiteId")
289 def cloudOwner = execution.getVariable("cloudOwner")
290 def vnfId = execution.getVariable("vnfId")
291 def vfModuleId = execution.getVariable("vfModuleId")
292 def vfModuleStackId = execution.getVariable('DoDVfMod_heatStackId')
293 def tenantId = execution.getVariable("tenantId")
294 def messageId = execution.getVariable('requestId') + '-' +
295 System.currentTimeMillis()
296 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
297 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
298 if ('true'.equals(useQualifiedHostName)) {
299 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
303 <deleteVfModuleRequest>
304 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
305 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
306 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
307 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
308 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
309 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
310 <skipAAI>true</skipAAI>
312 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
313 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
315 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
316 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
317 </deleteVfModuleRequest>
320 logger.debug("vnfAdapterRestV1Request: " + request)
321 logger.debug("deleteVfModuleRequest: " + request)
322 execution.setVariable("vnfAdapterRestV1Request", request)
325 // parse the incoming DELETE_VF_MODULE request
326 // and formulate the outgoing UpdateAAIVfModuleRequest request
327 public void prepUpdateAAIVfModule(DelegateExecution execution) {
329 def vnfId = execution.getVariable("vnfId")
330 def vfModuleId = execution.getVariable("vfModuleId")
331 // formulate the request for UpdateAAIVfModule
332 String request = """<UpdateAAIVfModuleRequest>
333 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
334 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
335 <heat-stack-id>DELETE</heat-stack-id>
336 <orchestration-status>deleted</orchestration-status>
337 </UpdateAAIVfModuleRequest>""" as String
338 logger.debug("UpdateAAIVfModuleRequest :" + request)
339 logger.debug("UpdateAAIVfModuleRequest: " + request)
340 execution.setVariable("UpdateAAIVfModuleRequest", request)
343 // parse the incoming DELETE_VF_MODULE request
344 // and formulate the outgoing DeleteAAIVfModuleRequest request
345 public void prepDeleteAAIVfModule(DelegateExecution execution) {
348 def vnfId = execution.getVariable("vnfId")
349 def vfModuleId = execution.getVariable("vfModuleId")
350 // formulate the request for UpdateAAIVfModule
351 String request = """<DeleteAAIVfModuleRequest>
352 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
353 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
354 </DeleteAAIVfModuleRequest>""" as String
355 logger.debug("DeleteAAIVfModuleRequest :" + request)
356 logger.debug("DeleteAAIVfModuleRequest: " + request)
357 execution.setVariable("DeleteAAIVfModuleRequest", request)
360 // generates a WorkflowException if
362 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
363 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
364 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
365 "BPMN", ErrorCode.UnknownError.getValue(), "Exception");
366 String processKey = getProcessKey(execution);
367 WorkflowException exception = new WorkflowException(processKey, 5000,
368 execution.getVariable("DoDVfMod_deleteGenericVnfResponse"))
369 execution.setVariable("WorkflowException", exception)
372 public void sdncValidateResponse(DelegateExecution execution, String response){
374 execution.setVariable("prefix",Prefix)
376 WorkflowException workflowException = execution.getVariable("WorkflowException")
377 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
379 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
380 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
382 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
383 logger.debug("Successfully Validated SDNC Response")
385 throw new BpmnError("MSOWorkflowException")
389 public void postProcessVNFAdapterRequest(DelegateExecution execution) {
390 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
391 'execution=' + execution.getId() +
394 logger.trace('Entered ' + method)
395 execution.setVariable("prefix",Prefix)
397 logger.trace("STARTED postProcessVNFAdapterRequest Process")
399 String vnfResponse = execution.getVariable("DoDVfMod_doDeleteVfModuleResponse")
400 logger.debug("VNF Adapter Response is: " + vnfResponse)
401 logger.debug("deleteVnfAResponse is: \n" + vnfResponse)
403 if(vnfResponse != null){
405 if(vnfResponse.contains("deleteVfModuleResponse")){
406 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
407 execution.setVariable("DoDVfMod_vnfVfModuleDeleteCompleted", true)
409 // Parse vnfOutputs for contrail network polcy FQDNs
410 if (vnfResponse.contains("vfModuleOutputs")) {
411 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
412 InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
413 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
414 docFactory.setNamespaceAware(true)
415 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
416 Document outputsXml = docBuilder.parse(source)
418 NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
419 List contrailNetworkPolicyFqdnList = []
420 for (int i = 0; i< entries.getLength(); i++) {
421 Node node = entries.item(i)
422 if (node.getNodeType() == Node.ELEMENT_NODE) {
423 Element element = (Element) node
424 String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
425 if (key.endsWith("contrail_network_policy_fqdn")) {
426 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
427 logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
428 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
430 else if (key.equals("oam_management_v4_address")) {
431 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
432 logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
433 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
435 else if (key.equals("oam_management_v6_address")) {
436 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
437 logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
438 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
443 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
444 logger.debug("Setting the fqdn list")
445 execution.setVariable("DoDVfMod_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
449 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
450 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
453 logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
454 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
460 logger.debug("Internal Error Occured in PostProcess Method")
461 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
463 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
466 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
467 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
468 'execution=' + execution.getId() +
471 logger.trace('Entered ' + method)
472 execution.setVariable("prefix", Prefix)
473 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
477 List fqdnList = execution.getVariable("DoDVfMod_contrailNetworkPolicyFqdnList")
478 if (fqdnList == null) {
479 logger.debug("No network policies to delete")
482 int fqdnCount = fqdnList.size()
484 execution.setVariable("DoDVfMod_networkPolicyFqdnCount", fqdnCount)
485 logger.debug("DoDVfMod_networkPolicyFqdnCount - " + fqdnCount)
488 // AII loop call over contrail network policy fqdn list
489 for (i in 0..fqdnCount-1) {
490 String fqdn = fqdnList[i]
491 // Query AAI for this network policy FQDN
492 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
493 uri.queryParam("network-policy-fqdn", fqdn)
495 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
496 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
497 // This network policy FQDN exists in AAI - need to delete it now
498 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
499 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
500 // Retrieve the network policy id for this FQDN
501 def networkPolicyId = networkPolicy.getNetworkPolicyId()
502 logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
504 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
505 getAAIClient().delete(delUri)
506 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 200)
507 } catch (Exception e) {
508 execution.setVariable("DoDVfMod_aaiDeleteNetworkPolicyReturnCode", 500)
509 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
510 logger.debug(delErrorMessage)
511 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
514 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
515 // This network policy FQDN is not in AAI. No need to delete.
516 logger.debug("The return code is: " + 404)
517 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
518 logger.debug("Network policy FQDN is not in AAI")
520 }catch(Exception e ) {
522 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
523 logger.debug(dataErrorMessage)
527 logger.debug("No contrail network policies to query/create")
529 } catch (BpmnError e) {
531 } catch (Exception ex) {
532 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
533 logger.debug(exceptionMessage)
534 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
540 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
542 * @param execution The flow's execution instance.
544 public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
545 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
546 'execution=' + execution.getId() +
549 logger.trace('Entered ' + method)
552 def vnfId = execution.getVariable('vnfId')
553 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
554 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
555 def ipv4OamAddressElement = ''
556 def managementV6AddressElement = ''
558 if (oamManagementV4Address != null) {
559 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
562 if (oamManagementV6Address != null) {
563 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
567 String updateAAIGenericVnfRequest = """
568 <UpdateAAIGenericVnfRequest>
569 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
570 ${ipv4OamAddressElement}
571 ${managementV6AddressElement}
572 </UpdateAAIGenericVnfRequest>
574 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
575 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
576 logger.debug("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
577 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
580 logger.trace('Exited ' + method)
581 } catch (BpmnError e) {
583 } catch (Exception e) {
584 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
585 'Caught exception in ' + method, "BPMN",
586 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
587 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
592 * Using the vnfId and vfModuleId provided in the inputs,
593 * query AAI to get the corresponding VF Module info.
594 * A 200 response is expected with the VF Module info in the response body,
595 * Will determine VF Module's orchestration status if one exists
597 * @param execution The flow's execution instance.
599 public void queryAAIVfModuleForStatus(DelegateExecution execution) {
601 def method = getClass().getSimpleName() + '.queryAAIVfModuleForStatus(' +
602 'execution=' + execution.getId() +
604 logger.trace('Entered ' + method)
606 execution.setVariable(Prefix + 'orchestrationStatus', '')
609 def vnfId = execution.getVariable('vnfId')
610 def vfModuleId = execution.getVariable('vfModuleId')
612 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)
615 Optional<org.onap.aai.domain.yang.VfModule> vfModule = getAAIClient().get(org.onap.aai.domain.yang.VfModule.class, uri);
616 // Retrieve VF Module info and its orchestration status; if not found, do nothing
617 if (vfModule.isPresent()) {
618 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponseCode', 200)
619 execution.setVariable(Prefix + 'queryAAIVfModuleForStatusResponse', vfModule.get())
620 def orchestrationStatus = vfModule.get().getOrchestrationStatus()
621 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
622 logger.debug("Received orchestration status from A&AI: " + orchestrationStatus)
624 } catch (Exception ex) {
625 logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
626 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
628 logger.trace('Exited ' + method)
629 } catch (BpmnError e) {
631 } catch (Exception e) {
632 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
633 'Caught exception in ' + method, "BPMN",
634 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
635 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModuleForStatus(): ' + e.getMessage())