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
24 import javax.xml.parsers.DocumentBuilder
25 import javax.xml.parsers.DocumentBuilderFactory
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.VidUtils
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.client.aai.AAIResourcesClient
35 import org.onap.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.entities.uri.AAIResourceUri
37 import org.onap.so.client.aai.entities.uri.AAIUriFactory
38 import org.w3c.dom.Document
39 import org.w3c.dom.Element
40 import org.w3c.dom.Node
41 import org.w3c.dom.NodeList
42 import org.xml.sax.InputSource
44 import org.onap.so.logger.MessageEnum
45 import org.onap.so.logger.MsoLogger
48 * This class supports the DoDeleteVnf subFlow
49 * with the Deletion of a generic vnf for
53 class DoDeleteVnf extends AbstractServiceTaskProcessor {
54 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVnf.class);
56 String Prefix="DoDVNF_"
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
59 VidUtils vidUtils = new VidUtils(this)
62 * This method gets and validates the incoming
68 public void preProcessRequest(DelegateExecution execution) {
70 execution.setVariable("prefix",Prefix)
71 msoLogger.trace("STARTED DoDeleteVnf PreProcessRequest Process")
73 execution.setVariable("DoDVNF_SuccessIndicator", false)
74 execution.setVariable("DoDVNF_vnfInUse", false)
79 String vnfId = execution.getVariable("vnfId")
80 execution.setVariable("DoDVNF_vnfId", vnfId)
81 msoLogger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
83 // Setting for sub flow calls
84 execution.setVariable("DoDVNF_type", "generic-vnf")
86 msoLogger.debug("Rethrowing MSOWorkflowException")
89 msoLogger.debug(" Error Occured in DoDeleteVnf PreProcessRequest method!" + e)
90 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
93 msoLogger.trace("COMPLETED DoDeleteVnf PreProcessRequest Process ")
97 public void processGetVnfResponse(DelegateExecution execution){
99 execution.setVariable("prefix",Prefix)
100 msoLogger.trace("STARTED DoDeleteVnf processGetVnfResponse Process ")
102 String vnf = execution.getVariable("DoDVNF_genericVnf")
103 String resourceVersion = utils.getNodeText(vnf, "resource-version")
104 execution.setVariable("DoDVNF_resourceVersion", resourceVersion)
106 if(utils.nodeExists(vnf, "relationship")){
107 InputSource source = new InputSource(new StringReader(vnf));
108 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
109 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
110 Document vnfXml = docBuilder.parse(source)
112 NodeList nodeList = vnfXml.getElementsByTagName("relationship")
113 for (int x = 0; x < nodeList.getLength(); x++) {
114 Node node = nodeList.item(x)
115 if (node.getNodeType() == Node.ELEMENT_NODE) {
116 Element eElement = (Element) node
117 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
118 if(e.equals("volume-group") || e.equals("l3-network")){
119 msoLogger.debug("Generic Vnf still has relationship to OpenStack.")
120 execution.setVariable("DoDVNF_vnfInUse", true)
122 msoLogger.debug("Relationship NOT related to OpenStack")
128 if(utils.nodeExists(vnf, "vf-module")){
129 execution.setVariable("DoDVNF_vnfInUse", true)
130 msoLogger.debug("Generic Vnf still has vf-modules.")
134 } catch (Exception ex) {
135 msoLogger.debug("Error Occured in DoDeleteVnf processGetVnfResponse Process " + ex.getMessage())
136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf processGetVnfResponse Process")
139 msoLogger.trace("COMPLETED DoDeleteVnf processGetVnfResponse Process ")
143 * Deletes the generic vnf from aai
145 public void deleteVnf(DelegateExecution execution) {
146 msoLogger.trace("STARTED deleteVnf")
148 String vnfId = execution.getVariable("DoDVNF_vnfId")
150 AAIResourcesClient resourceClient = new AAIResourcesClient();
151 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
152 resourceClient.delete(uri)
154 msoLogger.trace("COMPLETED deleteVnf")
155 } catch (Exception ex) {
156 msoLogger.debug("Error Occured in DoDeleteVnf deleteVnf Process " + ex.getMessage())
157 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf deleteVnf Process")