2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.VidUtils;
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils;
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
40 * This class supports the DeleteVnfInfra Flow
41 * with the Deletion of a generic vnf for
44 class DeleteVnfInfra extends AbstractServiceTaskProcessor {
46 private static final Logger logger = LoggerFactory.getLogger( DeleteVnfInfra.class);
48 String Prefix="DELVI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils(this)
54 * This method gets and validates the incoming
59 public void preProcessRequest(DelegateExecution execution) {
60 execution.setVariable("prefix",Prefix)
61 logger.trace("STARTED DeleteVnfInfra PreProcessRequest Process")
63 execution.setVariable("DELVI_SuccessIndicator", false)
64 execution.setVariable("DELVI_vnfInUse", false)
68 String deleteVnfRequest = execution.getVariable("bpmnRequest")
69 execution.setVariable("DELVI_DeleteVnfRequest", deleteVnfRequest)
70 logger.debug("Incoming DeleteVnfInfra Request is: \n" + deleteVnfRequest)
72 if(deleteVnfRequest != null){
74 String requestId = execution.getVariable("mso-request-id")
75 execution.setVariable("DELVI_requestId", requestId)
77 String serviceInstanceId = execution.getVariable("serviceInstanceId")
78 execution.setVariable("DELVI_serviceInstanceId", serviceInstanceId)
79 logger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
81 String vnfId = execution.getVariable("vnfId")
82 execution.setVariable("DELVI_vnfId", vnfId)
83 logger.debug("Incoming Vnf(Instance) Id is: " + vnfId)
85 String source = jsonUtil.getJsonValue(deleteVnfRequest, "requestDetails.requestInfo.source")
86 execution.setVariable("DELVI_source", source)
87 logger.debug("Incoming Source is: " + source)
89 def cloudConfiguration = jsonUtil.getJsonValue(deleteVnfRequest, "requestDetails.cloudConfiguration")
90 execution.setVariable("DELVI_cloudConfiguration", cloudConfiguration)
92 boolean cascadeDelete = false
93 Boolean cascadeDeleteObj = jsonUtil.getJsonRawValue(deleteVnfRequest, "requestDetails.requestParameters.cascadeDelete")
94 if(cascadeDeleteObj!=null){
95 cascadeDelete = cascadeDeleteObj.booleanValue()
97 execution.setVariable("DELVI_cascadeDelete", cascadeDelete)
98 logger.debug("Incoming cascadeDelete is: " + cascadeDelete)
100 //For Completion Handler & Fallout Handler
102 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
103 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
104 <action>DELETE</action>
105 <source>${MsoUtils.xmlEscape(source)}</source>
108 execution.setVariable("DELVI_requestInfo", requestInfo)
110 // Setting for sub flow calls
111 execution.setVariable("DELVI_type", "generic-vnf")
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
118 logger.debug("Rethrowing MSOWorkflowException")
121 logger.debug(" Error Occured in DeleteVnfInfra PreProcessRequest method!" + e)
122 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PreProcessRequest")
125 logger.trace("COMPLETED DeleteVnfInfra PreProcessRequest Process")
128 public void sendSyncResponse (DelegateExecution execution) {
129 execution.setVariable("prefix",Prefix)
131 logger.trace("STARTED DeleteVnfInfra SendSyncResponse Process")
134 String requestId = execution.getVariable("DELVI_requestId")
135 String vnfId = execution.getVariable("DELVI_vnfId")
137 String DeleteVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
139 logger.debug("DeleteVnfInfra Sync Response is: \n" + DeleteVnfResponse)
140 execution.setVariable("DELVI_sentSyncResponse", true)
142 sendWorkflowResponse(execution, 202, DeleteVnfResponse)
144 } catch (Exception ex) {
145 logger.debug("Error Occured in DeleteVnfInfra SendSyncResponse Process " + ex.getMessage())
146 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra SendSyncResponse Process")
149 logger.trace("COMPLETED DeleteVnfInfra SendSyncResponse Process")
152 public void prepareCompletionHandlerRequest(DelegateExecution execution){
153 execution.setVariable("prefix",Prefix)
155 logger.trace("STARTED DeleteVnfInfra PrepareCompletionHandlerRequest Process")
158 String requestInfo = execution.getVariable("DELVI_requestInfo")
159 requestInfo = utils.removeXmlPreamble(requestInfo)
160 String vnfId = execution.getVariable("DELVI_vnfId")
163 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
164 xmlns:ns="http://org.onap/so/request/types/v1">
166 <status-message>Vnf has been deleted successfully.</status-message>
167 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
168 <mso-bpel-name>DeleteVnfInfra</mso-bpel-name>
169 </aetgt:MsoCompletionRequest>"""
171 execution.setVariable("DELVI_completionHandlerRequest", request)
172 logger.debug("Completion Handler Request is: " + request)
174 execution.setVariable("WorkflowResponse", "Success") // for junits
176 } catch (Exception ex) {
177 logger.debug("Error Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage())
178 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra PrepareCompletionHandlerRequest Process")
181 logger.trace("COMPLETED DeleteVnfInfra PrepareCompletionHandlerRequest Process")
184 public void sendErrorResponse(DelegateExecution execution){
185 execution.setVariable("prefix",Prefix)
187 logger.trace("STARTED DeleteVnfInfra sendErrorResponse Process")
189 def sentSyncResponse = execution.getVariable("DELVI_sentSyncResponse")
190 if(sentSyncResponse == false){
191 logger.debug("Sending a Sync Error Response")
192 WorkflowException wfex = execution.getVariable("WorkflowException")
193 String response = exceptionUtil.buildErrorResponseXml(wfex)
195 logger.debug(response)
196 sendWorkflowResponse(execution, 500, response)
198 logger.debug("A Sync Response has already been sent. Skipping Send Sync Error Response.")
201 } catch(Exception ex) {
202 logger.debug("Error Occured in DeleteVnfInfra sendErrorResponse Process " + ex.getMessage())
203 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVnfInfra sendErrorResponse Process")
205 logger.trace("COMPLETED DeleteVnfInfra sendErrorResponse Process")