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
25 import org.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.common.scripts.VidUtils;
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.logger.ErrorCode;
35 import org.onap.so.logger.MessageEnum
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 import groovy.json.JsonSlurper
43 public class DeleteVfModuleInfra extends AbstractServiceTaskProcessor {
45 private static final Logger logger = LoggerFactory.getLogger( DeleteVfModuleInfra.class);
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
49 * Initialize the flow's variables.
51 * @param execution The flow's execution instance.
53 public void initProcessVariables(DelegateExecution execution) {
54 execution.setVariable('prefix', 'DELVfModI_')
55 execution.setVariable('DELVfModI_requestInfo', null)
56 execution.setVariable('DELVfModI_requestId', null)
57 execution.setVariable('DELVfModI_source', null)
58 execution.setVariable('DELVfModI_vnfInputs', null)
59 execution.setVariable('DELVfModI_vnfId', null)
60 execution.setVariable('DELVfModI_vfModuleId', null)
61 execution.setVariable('DELVfModI_tenantId', null)
62 execution.setVariable('DELVfModI_volumeGroupId', null)
63 execution.setVariable('DELVfModI_vnfParams', null)
64 execution.setVariable('DELVfModI_updateInfraRequest', null)
65 execution.setVariable('DeleteVfModuleRequest', null)
66 execution.setVariable('DeleteVfModuleSuccessIndicator', false)
70 * Process the incoming DELETE_VF_MODULE vnf-request.
72 * @param execution The flow's execution instance.
74 public void preProcessRequest(DelegateExecution execution) {
75 def method = getClass().getSimpleName() + '.preProcessRequest(' +
76 'execution=' + execution.getId() +
78 logger.trace('Entered ' + method)
79 execution.setVariable("isVidRequest", "false")
80 initProcessVariables(execution)
82 def prefix = execution.getVariable('prefix')
84 def incomingRequest = execution.getVariable('bpmnRequest')
85 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
87 logger.debug("Incoming Infra Request: " + incomingRequest)
89 // check if request is xml or json
91 def jsonSlurper = new JsonSlurper()
92 Map reqMap = jsonSlurper.parseText(incomingRequest)
93 logger.debug(" Request is in JSON format.")
95 def serviceInstanceId = execution.getVariable('serviceInstanceId')
96 logger.debug("serviceInstanceId is: " + serviceInstanceId)
97 def vnfId = execution.getVariable('vnfId')
98 logger.debug("vnfId is: " + vnfId)
99 def cloudConfiguration = jsonUtil.getJsonValue(incomingRequest, "requestDetails.cloudConfiguration")
100 execution.setVariable("cloudConfiguration", cloudConfiguration)
101 logger.debug("CloudConfiguration is: " + cloudConfiguration)
102 def vfModuleModelInfo = jsonUtil.getJsonValue(incomingRequest, "requestDetails.modelInfo")
104 execution.setVariable("vfModuleModelInfo", vfModuleModelInfo)
105 logger.debug("VfModuleModelInfo is: " + vfModuleModelInfo)
107 // This is aLaCarte flow, so aLaCarte flag is always on
108 execution.setVariable('aLaCarte', true)
110 def vidUtils = new VidUtils(this)
112 String requestInXmlFormat = vidUtils.createXmlVfModuleRequest(execution, reqMap, 'DELETE_VF_MODULE', serviceInstanceId)
114 logger.debug(" Request in XML format: " + requestInXmlFormat)
116 setBasicDBAuthHeader(execution, isDebugLogEnabled)
118 execution.setVariable(prefix + 'Request', requestInXmlFormat)
119 execution.setVariable(prefix+'vnfId', vnfId)
120 execution.setVariable("isVidRequest", "true")
123 catch(groovy.json.JsonException je) {
124 logger.debug(" Request is not in JSON format.")
125 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
129 String restFaultMessage = e.getMessage()
130 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Caught exception",
131 "BPMN", ErrorCode.UnknownError.getValue(),
132 "Exception is:\n" + e);
133 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
139 String request = validateRequest(execution)
140 execution.setVariable('DeleteVfModuleRequest', request)
141 logger.debug("DeleteVfModuleInfra Request: " + request)
143 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
144 execution.setVariable('DELVfModI_requestInfo', requestInfo)
145 execution.setVariable('DELVfModI_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
146 execution.setVariable('DELVfModI_source', getNodeTextForce(requestInfo, 'source'))
148 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
149 execution.setVariable('DELVfModI_vnfInputs', vnfInputs)
150 execution.setVariable('DELVfModI_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
151 execution.setVariable('DELVfModI_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
152 execution.setVariable('DELVfModI_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
153 execution.setVariable('DELVfModI_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
154 execution.setVariable('DELVfModI_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
156 def vnfParams = utils.getNodeXml(request, 'vnf-params')
157 execution.setVariable('DELVfModI_vnfParams', vnfParams)
159 logger.trace('Exited ' + method)
160 } catch (BpmnError e) {
162 } catch (Exception e) {
163 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
164 "Caught exception in " + method, "BPMN",
165 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
166 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
171 * Sends the 'IN_PROGRESS' synchronous response.
173 * @param execution The flow's execution instance.
175 public void sendSynchResponse(DelegateExecution execution) {
176 def method = getClass().getSimpleName() + '.sendResponse(' +
177 'execution=' + execution.getId() +
179 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
180 logger.trace('Entered ' + method)
183 def requestInfo = execution.getVariable('DELVfModI_requestInfo')
184 def requestId = execution.getVariable('DELVfModI_requestId')
185 def source = execution.getVariable('DELVfModI_source')
186 def progress = getNodeTextForce(requestInfo, 'progress')
187 if (progress.isEmpty()) {
190 def startTime = getNodeTextForce(requestInfo, 'start-time')
191 if (startTime.isEmpty()) {
192 startTime = System.currentTimeMillis()
195 // RESTResponse (for API Handler (APIH) Reply Task)
196 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
197 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
199 logger.debug("DeleteVfModuleInfra Synch Response: " + synchResponse)
200 sendWorkflowResponse(execution, 200, synchResponse)
202 logger.trace('Exited ' + method)
203 } catch (BpmnError e) {
205 } catch (Exception e) {
206 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
207 "Caught exception in " + method, "BPMN",
208 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
209 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
214 * Currently passing the entire DELETE_VF_MODULE vnf-request to DoDeleteVfModule.
215 * 'DeleteVfModuleRequest' is now being set in preProcessRequest().
216 * TBD: may want to eventually create a specific request that only contains the needed fields.
218 * @param execution The flow's execution instance.
220 public void prepDoDeleteVfModule(DelegateExecution execution) {
221 def method = getClass().getSimpleName() + '.prepDoDeleteVfModule(' +
222 'execution=' + execution.getId() +
224 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
225 logger.trace('Entered ' + method)
229 logger.trace('Exited ' + method)
230 } catch (BpmnError e) {
232 } catch (Exception e) {
233 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in '
234 + method, "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
235 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoDeleteVfModule(): ' + e.getMessage())
240 * Prepare the DB update to add an entry for the Vf Module request.
242 * @param execution The flow's execution instance.
244 public void prepUpdateInfraRequest(DelegateExecution execution) {
245 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
246 'execution=' + execution.getId() +
248 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
249 logger.trace('Entered ' + method)
252 def requestId = execution.getVariable('DELVfModI_requestId')
253 def vnfId = execution.getVariable('DELVfModI_vnfId')
254 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
255 def tenantId = execution.getVariable('DELVfModI_tenantId')
256 def volumeGroupId = execution.getVariable('DELVfModI_volumeGroupId')
258 String updateInfraRequest = """
259 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
260 xmlns:req="http://org.onap.so/requestsdb">
263 <req:updateInfraRequest>
264 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
265 <lastModifiedBy>BPMN</lastModifiedBy>
266 <requestStatus>COMPLETED</requestStatus>
267 <progress>100</progress>
268 </req:updateInfraRequest>
273 updateInfraRequest = utils.formatXml(updateInfraRequest)
274 execution.setVariable('DELVfModI_updateInfraRequest', updateInfraRequest)
275 logger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
277 logger.trace('Exited ' + method)
278 } catch (BpmnError e) {
280 } catch (Exception e) {
281 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
282 'Caught exception in ' + method, "BPMN",
283 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
284 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepInfraRequest(): ' + e.getMessage())
289 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
291 * @param execution the execution
292 * @param resultVar the execution variable in which the result will be stored
294 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
295 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
296 'execution=' + execution.getId() +
297 ', resultVar=' + resultVar +
299 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
300 logger.trace('Entered ' + method)
303 def request = execution.getVariable("DeleteVfModuleRequest")
304 def requestInfo = utils.getNodeXml(request, 'request-info', false)
305 def action = utils.getNodeText(requestInfo, "action")
308 """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
309 xmlns:ns="http://org.onap/so/request/types/v1"
310 xmlns:ns8="http://org.onap/so/workflow/schema/v1">
311 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
314 <ns8:status-message>Vf Module has been deleted successfully.</ns8:status-message>
315 <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
316 </aetgt:MsoCompletionRequest>"""
318 content = utils.formatXml(content)
319 logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
320 execution.setVariable(resultVar, content)
322 logger.trace('Exited ' + method)
323 } catch (BpmnError e) {
325 } catch (Exception e) {
326 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
327 'Caught exception in ' + method, "BPMN",
328 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
329 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
334 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
336 * @param execution the execution
337 * @param resultVar the execution variable in which the result will be stored
339 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
340 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
341 'execution=' + execution.getId() +
342 ', resultVar=' + resultVar +
344 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
345 logger.trace('Entered ' + method)
348 def prefix = execution.getVariable('prefix')
349 def request = execution.getVariable("DeleteVfModuleRequest")
350 def requestInfo = utils.getNodeXml(request, 'request-info', false)
351 def WorkflowException workflowException = execution.getVariable("WorkflowException")
352 def errorResponseCode = workflowException.getErrorCode()
353 def errorResponseMsg = workflowException.getErrorMessage()
354 def encErrorResponseMsg = ""
355 if (errorResponseMsg != null) {
356 encErrorResponseMsg = errorResponseMsg
360 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
361 xmlns:reqtype="http://org.onap/so/request/types/v1"
362 xmlns:msoservtypes="http://org.onap/so/request/types/v1"
363 xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
365 <sdncadapterworkflow:WorkflowException>
366 <sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
367 <sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
368 </sdncadapterworkflow:WorkflowException>
369 </sdncadapterworkflow:FalloutHandlerRequest>
371 content = utils.formatXml(content)
372 logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
373 execution.setVariable(resultVar, content)
375 logger.trace('Exited ' + method)
376 } catch (BpmnError e) {
378 } catch (Exception e) {
379 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
380 'Caught exception in ' + method, "BPMN",
381 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
382 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')