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 org.apache.commons.lang3.*
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.VidUtils;
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.bpmn.core.json.JsonUtils;
33 import org.onap.so.logger.MsoLogger
37 * This class supports the DeleteVnfInfra Flow
38 * with the Deletion of a generic vnf for
41 class DeleteVnfInfra extends AbstractServiceTaskProcessor {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteVnfInfra.class);
45 String Prefix="DELVI_"
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
48 VidUtils vidUtils = new VidUtils(this)
51 * This method gets and validates the incoming
56 public void preProcessRequest(DelegateExecution execution) {
57 execution.setVariable("prefix",Prefix)
58 msoLogger.trace("STARTED DeleteVnfInfra PreProcessRequest Process")
60 execution.setVariable("DELVI_SuccessIndicator", false)
61 execution.setVariable("DELVI_vnfInUse", false)
65 String deleteVnfRequest = execution.getVariable("bpmnRequest")
66 execution.setVariable("DELVI_DeleteVnfRequest", deleteVnfRequest)
67 msoLogger.debug("Incoming DeleteVnfInfra Request is: \n" + deleteVnfRequest)
69 if(deleteVnfRequest != null){
71 String requestId = execution.getVariable("mso-request-id")
72 execution.setVariable("DELVI_requestId", requestId)
74 String serviceInstanceId = execution.getVariable("serviceInstanceId")
75 execution.setVariable("DELVI_serviceInstanceId", serviceInstanceId)
76 msoLogger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
78 String vnfId = execution.getVariable("vnfId")
79 execution.setVariable("DELVI_vnfId", vnfId)
80 msoLogger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
82 String source = jsonUtil.getJsonValue(deleteVnfRequest, "requestDetails.requestInfo.source")
83 execution.setVariable("DELVI_source", source)
84 msoLogger.debug("Incoming Source is: " + source)
86 def cloudConfiguration = jsonUtil.getJsonValue(deleteVnfRequest, "requestDetails.cloudConfiguration")
87 execution.setVariable("DELVI_cloudConfiguration", cloudConfiguration)
89 boolean cascadeDelete = false
90 Boolean cascadeDeleteObj = jsonUtil.getJsonRawValue(deleteVnfRequest, "requestDetails.requestParameters.cascadeDelete")
91 if(cascadeDeleteObj!=null){
92 cascadeDelete = cascadeDeleteObj.booleanValue()
94 execution.setVariable("DELVI_cascadeDelete", cascadeDelete)
95 msoLogger.debug("Incoming cascadeDelete is: " + cascadeDelete)
97 //For Completion Handler & Fallout Handler
99 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
100 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
101 <action>DELETE</action>
102 <source>${MsoUtils.xmlEscape(source)}</source>
105 execution.setVariable("DELVI_requestInfo", requestInfo)
107 // Setting for sub flow calls
108 execution.setVariable("DELVI_type", "generic-vnf")
111 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
115 msoLogger.debug("Rethrowing MSOWorkflowException")
118 msoLogger.debug(" Error Occured in DeleteVnfInfra PreProcessRequest method!" + e)
119 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PreProcessRequest")
122 msoLogger.trace("COMPLETED DeleteVnfInfra PreProcessRequest Process")
125 public void sendSyncResponse (DelegateExecution execution) {
126 execution.setVariable("prefix",Prefix)
128 msoLogger.trace("STARTED DeleteVnfInfra SendSyncResponse Process")
131 String requestId = execution.getVariable("DELVI_requestId")
132 String vnfId = execution.getVariable("DELVI_vnfId")
134 String DeleteVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
136 msoLogger.debug("DeleteVnfInfra Sync Response is: \n" + DeleteVnfResponse)
137 execution.setVariable("DELVI_sentSyncResponse", true)
139 sendWorkflowResponse(execution, 202, DeleteVnfResponse)
141 } catch (Exception ex) {
142 msoLogger.debug("Error Occured in DeleteVnfInfra SendSyncResponse Process " + ex.getMessage())
143 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra SendSyncResponse Process")
146 msoLogger.trace("COMPLETED DeleteVnfInfra SendSyncResponse Process")
149 public void prepareCompletionHandlerRequest(DelegateExecution execution){
150 execution.setVariable("prefix",Prefix)
152 msoLogger.trace("STARTED DeleteVnfInfra PrepareCompletionHandlerRequest Process")
155 String requestInfo = execution.getVariable("DELVI_requestInfo")
156 requestInfo = utils.removeXmlPreamble(requestInfo)
157 String vnfId = execution.getVariable("DELVI_vnfId")
160 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
161 xmlns:ns="http://org.onap/so/request/types/v1">
163 <status-message>Vnf has been deleted successfully.</status-message>
164 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
165 <mso-bpel-name>DeleteVnfInfra</mso-bpel-name>
166 </aetgt:MsoCompletionRequest>"""
168 execution.setVariable("DELVI_completionHandlerRequest", request)
169 msoLogger.debug("Completion Handler Request is: " + request)
171 execution.setVariable("WorkflowResponse", "Success") // for junits
173 } catch (Exception ex) {
174 msoLogger.debug("Error Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage())
175 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process")
178 msoLogger.trace("COMPLETED DeleteVnfInfra PrepareCompletionHandlerRequest Process")
181 public void sendErrorResponse(DelegateExecution execution){
182 execution.setVariable("prefix",Prefix)
184 msoLogger.trace("STARTED DeleteVnfInfra sendErrorResponse Process")
186 def sentSyncResponse = execution.getVariable("DELVI_sentSyncResponse")
187 if(sentSyncResponse == false){
188 msoLogger.debug("Sending a Sync Error Response")
189 WorkflowException wfex = execution.getVariable("WorkflowException")
190 String response = exceptionUtil.buildErrorResponseXml(wfex)
192 msoLogger.debug(response)
193 sendWorkflowResponse(execution, 500, response)
195 msoLogger.debug("A Sync Response has already been sent. Skipping Send Sync Error Response.")
198 } catch(Exception ex) {
199 msoLogger.debug("Error Occured in DeleteVnfInfra sendErrorResponse Process " + ex.getMessage())
200 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra sendErrorResponse Process")
202 msoLogger.trace("COMPLETED DeleteVnfInfra sendErrorResponse Process")