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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
23 import javax.xml.parsers.DocumentBuilder
24 import javax.xml.parsers.DocumentBuilderFactory
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.runtime.Execution
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
31 import org.openecomp.mso.bpmn.common.scripts.VidUtils
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
33 import org.w3c.dom.Document
34 import org.w3c.dom.Element
35 import org.w3c.dom.Node
36 import org.w3c.dom.NodeList
37 import org.xml.sax.InputSource
41 * This class supports the DoDeleteVnf subFlow
42 * with the Deletion of a generic vnf for
46 class DoDeleteVnf extends AbstractServiceTaskProcessor {
48 String Prefix="DoDVNF_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils(this)
54 * This method gets and validates the incoming
60 public void preProcessRequest(Execution execution) {
61 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
62 execution.setVariable("prefix",Prefix)
63 utils.log("DEBUG", " *** STARTED DoDeleteVnf PreProcessRequest Process*** ", isDebugEnabled)
65 execution.setVariable("DoDVNF_SuccessIndicator", false)
66 execution.setVariable("DoDVNF_vnfInUse", false)
71 String vnfId = execution.getVariable("vnfId")
72 execution.setVariable("DoDVNF_vnfId", vnfId)
73 utils.log("DEBUG", "Incoming Vnf(Instance) Id is: " + vnfId, isDebugEnabled)
75 // Setting for sub flow calls
76 execution.setVariable("DoDVNF_type", "generic-vnf")
78 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
81 utils.log("DEBUG", " Error Occured in DoDeleteVnf PreProcessRequest method!" + e, isDebugEnabled)
82 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
85 utils.log("DEBUG", "*** COMPLETED DoDeleteVnf PreProcessRequest Process ***", isDebugEnabled)
89 public void processGetVnfResponse(Execution execution){
90 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
91 execution.setVariable("prefix",Prefix)
92 utils.log("DEBUG", " *** STARTED DoDeleteVnf processGetVnfResponse Process *** ", isDebugEnabled)
94 String vnf = execution.getVariable("DoDVNF_genericVnf")
95 String resourceVersion = utils.getNodeText1(vnf, "resource-version")
96 execution.setVariable("DoDVNF_resourceVersion", resourceVersion)
98 if(utils.nodeExists(vnf, "relationship")){
99 InputSource source = new InputSource(new StringReader(vnf));
100 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
101 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
102 Document vnfXml = docBuilder.parse(source)
104 NodeList nodeList = vnfXml.getElementsByTagName("relationship")
105 for (int x = 0; x < nodeList.getLength(); x++) {
106 Node node = nodeList.item(x)
107 if (node.getNodeType() == Node.ELEMENT_NODE) {
108 Element eElement = (Element) node
109 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
110 if(e.equals("volume-group") || e.equals("l3-network")){
111 utils.log("DEBUG", "Generic Vnf still has relationship to OpenStack.", isDebugEnabled)
112 execution.setVariable("DoDVNF_vnfInUse", true)
114 utils.log("DEBUG", "Relationship NOT related to OpenStack", isDebugEnabled)
120 if(utils.nodeExists(vnf, "vf-module")){
121 execution.setVariable("DoDVNF_vnfInUse", true)
122 utils.log("DEBUG", "Generic Vnf still has vf-modules.", isDebugEnabled)
126 } catch (Exception ex) {
127 utils.log("DEBUG", "Error Occured in DoDeleteVnf processGetVnfResponse Process " + ex.getMessage(), isDebugEnabled)
128 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf processGetVnfResponse Process")
131 utils.log("DEBUG", "*** COMPLETED DoDeleteVnf processGetVnfResponse Process ***", isDebugEnabled)