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 com.att.bpm.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.runtime.Execution
31 import org.w3c.dom.Document
32 import org.w3c.dom.Element
33 import org.w3c.dom.Node
34 import org.w3c.dom.NodeList
36 import org.xml.sax.InputSource
39 import org.openecomp.mso.bpmn.core.WorkflowException
40 import org.openecomp.mso.bpmn.core.json.JsonUtils;
44 * This class supports the DeleteVnfInfra Flow
45 * with the Deletion of a generic vnf for
48 class DeleteVnfInfra extends AbstractServiceTaskProcessor {
50 String Prefix="DELVI_"
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
53 VidUtils vidUtils = new VidUtils(this)
56 * This method gets and validates the incoming
61 public void preProcessRequest(Execution execution) {
62 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
63 execution.setVariable("prefix",Prefix)
64 utils.log("DEBUG", " *** STARTED DeleteVnfInfra PreProcessRequest Process*** ", isDebugEnabled)
66 execution.setVariable("DELVI_SuccessIndicator", false)
67 execution.setVariable("DELVI_vnfInUse", false)
71 String deleteVnfRequest = execution.getVariable("bpmnRequest")
72 execution.setVariable("DELVI_DeleteVnfRequest", deleteVnfRequest)
73 utils.logAudit("Incoming DeleteVnfInfra Request is: \n" + deleteVnfRequest)
75 if(deleteVnfRequest != null){
77 String requestId = execution.getVariable("att-mso-request-id")
78 execution.setVariable("DELVI_requestId", requestId)
80 String serviceInstanceId = execution.getVariable("serviceInstanceId")
81 execution.setVariable("DELVI_serviceInstanceId", serviceInstanceId)
82 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
84 String vnfId = execution.getVariable("vnfId")
85 execution.setVariable("DELVI_vnfId", vnfId)
86 utils.log("DEBUG", "Incoming Vnf(Instance) Id is: " + vnfId, isDebugEnabled)
88 String source = jsonUtil.getJsonValue(deleteVnfRequest, "requestDetails.requestInfo.source")
89 execution.setVariable("DELVI_source", source)
90 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
92 //For Completion Handler & Fallout Handler
94 """<request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
95 <request-id>${requestId}</request-id>
96 <action>DELETE</action>
97 <source>${source}</source>
100 execution.setVariable("DELVI_requestInfo", requestInfo)
102 // Setting for sub flow calls
103 execution.setVariable("DELVI_type", "generic-vnf")
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
110 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
113 utils.log("DEBUG", " Error Occured in DeleteVnfInfra PreProcessRequest method!" + e, isDebugEnabled)
114 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PreProcessRequest")
117 utils.log("DEBUG", "*** COMPLETED DeleteVnfInfra PreProcessRequest Process ***", isDebugEnabled)
120 public void sendSyncResponse (Execution execution) {
121 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
122 execution.setVariable("prefix",Prefix)
124 utils.log("DEBUG", " *** STARTED DeleteVnfInfra SendSyncResponse Process *** ", isDebugEnabled)
127 String requestId = execution.getVariable("DELVI_requestId")
128 String vnfId = execution.getVariable("DELVI_vnfId")
130 String DeleteVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
132 utils.log("DEBUG", " DeleteVnfInfra Sync Response is: \n" + DeleteVnfResponse, isDebugEnabled)
133 execution.setVariable("DELVI_sentSyncResponse", true)
135 sendWorkflowResponse(execution, 202, DeleteVnfResponse)
137 } catch (Exception ex) {
138 utils.log("DEBUG", "Error Occured in DeleteVnfInfra SendSyncResponse Process " + ex.getMessage(), isDebugEnabled)
139 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra SendSyncResponse Process")
142 utils.log("DEBUG", "*** COMPLETED DeleteVnfInfra SendSyncResponse Process ***", isDebugEnabled)
145 public void processGetVnfResponse(Execution execution){
146 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
147 execution.setVariable("prefix",Prefix)
148 utils.log("DEBUG", " *** STARTED DeleteVnfInfra processGetVnfResponse Process *** ", isDebugEnabled)
150 String vnf = execution.getVariable("DELVI_genericVnf")
151 String resourceVersion = utils.getNodeText1(vnf, "resource-version")
152 execution.setVariable("DELVI_resourceVersion", resourceVersion)
154 if(utils.nodeExists(vnf, "relationship")){
155 InputSource source = new InputSource(new StringReader(vnf));
156 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
157 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
158 Document vnfXml = docBuilder.parse(source)
160 NodeList nodeList = vnfXml.getElementsByTagName("relationship")
161 for (int x = 0; x < nodeList.getLength(); x++) {
162 Node node = nodeList.item(x)
163 if (node.getNodeType() == Node.ELEMENT_NODE) {
164 Element eElement = (Element) node
165 def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()
166 if(e.equals("volume-group") || e.equals("l3-network") || e.equals("vserver")){
167 utils.log("DEBUG", "Generic Vnf still has relationship to OpenStack.", isDebugEnabled)
168 execution.setVariable("DELVI_vnfInUse", true)
170 utils.log("DEBUG", "Relationship NOT related to OpenStack", isDebugEnabled)
176 if(utils.nodeExists(vnf, "vf-module")){
177 execution.setVariable("DELVI_vnfInUse", true)
178 utils.log("DEBUG", "Generic Vnf still has vf-modules.", isDebugEnabled)
182 } catch (Exception ex) {
183 utils.log("DEBUG", "Error Occured in DeleteVnfInfra processGetVnfResponse Process " + ex.getMessage(), isDebugEnabled)
184 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra processGetVnfResponse Process")
187 utils.log("DEBUG", "*** COMPLETED DeleteVnfInfra processGetVnfResponse Process ***", isDebugEnabled)
190 public void prepareCompletionHandlerRequest(Execution execution){
191 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
192 execution.setVariable("prefix",Prefix)
194 utils.log("DEBUG", " *** STARTED DeleteVnfInfra PrepareCompletionHandlerRequest Process *** ", isDebugEnabled)
197 String requestInfo = execution.getVariable("DELVI_requestInfo")
198 requestInfo = utils.removeXmlPreamble(requestInfo)
199 String vnfId = execution.getVariable("DELVI_vnfId")
202 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
203 xmlns:ns="http://ecomp.att.com/mso/request/types/v1">
205 <status-message>Vnf has been deleted successfully.</status-message>
206 <vnfId>${vnfId}</vnfId>
207 <mso-bpel-name>DeleteVnfInfra</mso-bpel-name>
208 </aetgt:MsoCompletionRequest>"""
210 execution.setVariable("DELVI_completionHandlerRequest", request)
211 utils.log("DEBUG", "Completion Handler Request is: " + request, isDebugEnabled)
213 execution.setVariable("WorkflowResponse", "Success") // for junits
215 } catch (Exception ex) {
216 utils.log("DEBUG", "Error Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage(), isDebugEnabled)
217 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process")
220 utils.log("DEBUG", "*** COMPLETED DeleteVnfInfra PrepareCompletionHandlerRequest Process ***", isDebugEnabled)
223 public void sendErrorResponse(Execution execution){
224 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
225 execution.setVariable("prefix",Prefix)
227 utils.log("DEBUG", " *** STARTED DeleteVnfInfra sendErrorResponse Process *** ", isDebugEnabled)
229 def sentSyncResponse = execution.getVariable("DELVI_sentSyncResponse")
230 if(sentSyncResponse == false){
231 utils.log("DEBUG", "Sending a Sync Error Response", isDebugEnabled)
232 WorkflowException wfex = execution.getVariable("WorkflowException")
233 String response = exceptionUtil.buildErrorResponseXml(wfex)
235 utils.logAudit(response)
236 sendWorkflowResponse(execution, 500, response)
238 utils.log("DEBUG", "A Sync Response has already been sent. Skipping Send Sync Error Response.", isDebugEnabled)
241 } catch(Exception ex) {
242 utils.log("DEBUG", "Error Occured in DeleteVnfInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
243 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra sendErrorResponse Process")
245 utils.log("DEBUG", "*** COMPLETED DeleteVnfInfra sendErrorResponse Process ***", isDebugEnabled)