2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
23 import javax.xml.parsers.DocumentBuilder
\r
24 import javax.xml.parsers.DocumentBuilderFactory
\r
26 import org.apache.commons.lang3.*
\r
27 import org.camunda.bpm.engine.delegate.BpmnError
\r
28 import org.camunda.bpm.engine.runtime.Execution
\r
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
31 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
33 import org.w3c.dom.Document
\r
34 import org.w3c.dom.Element
\r
35 import org.w3c.dom.Node
\r
36 import org.w3c.dom.NodeList
\r
37 import org.xml.sax.InputSource
\r
41 * This class supports the DoDeleteVnf subFlow
\r
42 * with the Deletion of a generic vnf for
\r
46 class DoDeleteVnf extends AbstractServiceTaskProcessor {
\r
48 String Prefix="DoDVNF_"
\r
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
50 JsonUtils jsonUtil = new JsonUtils()
\r
51 VidUtils vidUtils = new VidUtils(this)
\r
54 * This method gets and validates the incoming
\r
57 * @param - execution
\r
60 public void preProcessRequest(Execution execution) {
\r
61 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
62 execution.setVariable("prefix",Prefix)
\r
63 utils.log("DEBUG", " *** STARTED DoDeleteVnf PreProcessRequest Process*** ", isDebugEnabled)
\r
65 execution.setVariable("DoDVNF_SuccessIndicator", false)
\r
66 execution.setVariable("DoDVNF_vnfInUse", false)
\r
71 String vnfId = execution.getVariable("vnfId")
\r
72 execution.setVariable("DoDVNF_vnfId", vnfId)
\r
73 utils.log("DEBUG", "Incoming Vnf(Instance) Id is: " + vnfId, isDebugEnabled)
\r
75 // Setting for sub flow calls
\r
76 execution.setVariable("DoDVNF_type", "generic-vnf")
\r
77 }catch(BpmnError b){
\r
78 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
80 }catch(Exception e){
\r
81 utils.log("DEBUG", " Error Occured in DoDeleteVnf PreProcessRequest method!" + e, isDebugEnabled)
\r
82 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf PreProcessRequest")
\r
85 utils.log("DEBUG", "*** COMPLETED DoDeleteVnf PreProcessRequest Process ***", isDebugEnabled)
\r
89 public void processGetVnfResponse(Execution execution){
\r
90 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
91 execution.setVariable("prefix",Prefix)
\r
92 utils.log("DEBUG", " *** STARTED DoDeleteVnf processGetVnfResponse Process *** ", isDebugEnabled)
\r
94 String vnf = execution.getVariable("DoDVNF_genericVnf")
\r
95 String resourceVersion = utils.getNodeText1(vnf, "resource-version")
\r
96 execution.setVariable("DoDVNF_resourceVersion", resourceVersion)
\r
98 if(utils.nodeExists(vnf, "relationship")){
\r
99 InputSource source = new InputSource(new StringReader(vnf));
\r
100 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
\r
101 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
\r
102 Document vnfXml = docBuilder.parse(source)
\r
104 NodeList nodeList = vnfXml.getElementsByTagName("relationship")
\r
105 for (int x = 0; x < nodeList.getLength(); x++) {
\r
106 Node node = nodeList.item(x)
\r
107 if (node.getNodeType() == Node.ELEMENT_NODE) {
\r
108 Element eElement = (Element) node
\r
109 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
\r
110 if(e.equals("volume-group") || e.equals("l3-network")){
\r
111 utils.log("DEBUG", "Generic Vnf still has relationship to OpenStack.", isDebugEnabled)
\r
112 execution.setVariable("DoDVNF_vnfInUse", true)
\r
114 utils.log("DEBUG", "Relationship NOT related to OpenStack", isDebugEnabled)
\r
120 if(utils.nodeExists(vnf, "vf-module")){
\r
121 execution.setVariable("DoDVNF_vnfInUse", true)
\r
122 utils.log("DEBUG", "Generic Vnf still has vf-modules.", isDebugEnabled)
\r
126 } catch (Exception ex) {
\r
127 utils.log("DEBUG", "Error Occured in DoDeleteVnf processGetVnfResponse Process " + ex.getMessage(), isDebugEnabled)
\r
128 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoDeleteVnf processGetVnfResponse Process")
\r
131 utils.log("DEBUG", "*** COMPLETED DoDeleteVnf processGetVnfResponse Process ***", isDebugEnabled)
\r