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.openecomp.mso.bpmn.infrastructure.scripts
23 import groovy.util.Node
24 import groovy.util.XmlParser;
25 import groovy.xml.QName
27 import java.io.Serializable;
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.runtime.Execution
32 import groovy.json.JsonSlurper
34 import org.openecomp.mso.rest.APIResponse
35 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
36 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
37 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
38 import org.openecomp.mso.bpmn.core.RollbackData
39 import org.openecomp.mso.bpmn.core.WorkflowException
40 import org.openecomp.mso.bpmn.core.json.JsonUtils;
43 public class DeleteVfModuleInfra extends AbstractServiceTaskProcessor {
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
48 * Initialize the flow's variables.
50 * @param execution The flow's execution instance.
52 public void initProcessVariables(Execution execution) {
53 execution.setVariable('prefix', 'DELVfModI_')
54 execution.setVariable('DELVfModI_requestInfo', null)
55 execution.setVariable('DELVfModI_requestId', null)
56 execution.setVariable('DELVfModI_source', null)
57 execution.setVariable('DELVfModI_vnfInputs', null)
58 execution.setVariable('DELVfModI_vnfId', null)
59 execution.setVariable('DELVfModI_vfModuleId', null)
60 execution.setVariable('DELVfModI_tenantId', null)
61 execution.setVariable('DELVfModI_volumeGroupId', null)
62 execution.setVariable('DELVfModI_vnfParams', null)
63 execution.setVariable('DELVfModI_updateInfraRequest', null)
64 execution.setVariable('DeleteVfModuleRequest', null)
65 execution.setVariable('DeleteVfModuleSuccessIndicator', false)
69 * Process the incoming DELETE_VF_MODULE vnf-request.
71 * @param execution The flow's execution instance.
73 public void preProcessRequest(Execution execution) {
74 def method = getClass().getSimpleName() + '.preProcessRequest(' +
75 'execution=' + execution.getId() +
77 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
78 logDebug('Entered ' + method, isDebugLogEnabled)
79 execution.setVariable("isVidRequest", "false")
80 initProcessVariables(execution)
82 def prefix = execution.getVariable('prefix')
84 def incomingRequest = execution.getVariable('bpmnRequest')
86 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
87 utils.logAudit("DeleteVfModule Infra incoming Request: " + incomingRequest)
89 // check if request is xml or json
91 def jsonSlurper = new JsonSlurper()
92 Map reqMap = jsonSlurper.parseText(incomingRequest)
93 utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
95 def serviceInstanceId = execution.getVariable('serviceInstanceId')
96 utils.log("DEBUG", "serviceInstanceId is: " + serviceInstanceId, isDebugLogEnabled)
97 def vnfId = execution.getVariable('vnfId')
98 utils.log("DEBUG", "vnfId is: " + vnfId, isDebugLogEnabled)
99 def cloudConfiguration = jsonUtil.getJsonValue(incomingRequest, "requestDetails.cloudConfiguration")
100 execution.setVariable("cloudConfiguration", cloudConfiguration)
101 utils.log("DEBUG", "CloudConfiguration is: " + cloudConfiguration, isDebugLogEnabled)
102 def vfModuleModelInfo = jsonUtil.getJsonValue(incomingRequest, "requestDetails.modelInfo")
104 execution.setVariable("vfModuleModelInfo", vfModuleModelInfo)
105 utils.log("DEBUG", "VfModuleModelInfo is: " + vfModuleModelInfo, isDebugLogEnabled)
107 def vidUtils = new VidUtils(this)
109 String requestInXmlFormat = vidUtils.createXmlVfModuleRequest(execution, reqMap, 'DELETE_VF_MODULE', serviceInstanceId)
111 utils.log("DEBUG", " Request in XML format: " + requestInXmlFormat, isDebugLogEnabled)
113 setBasicDBAuthHeader(execution, isDebugLogEnabled)
115 execution.setVariable(prefix + 'Request', requestInXmlFormat)
116 execution.setVariable(prefix+'vnfId', vnfId)
117 execution.setVariable("isVidRequest", "true")
120 catch(groovy.json.JsonException je) {
121 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
122 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
126 String restFaultMessage = e.getMessage()
127 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
128 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
134 String request = validateRequest(execution)
135 execution.setVariable('DeleteVfModuleRequest', request)
136 utils.logAudit("DeleteVfModuleInfra Request: " + request)
138 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
139 execution.setVariable('DELVfModI_requestInfo', requestInfo)
140 execution.setVariable('DELVfModI_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
141 execution.setVariable('DELVfModI_source', getNodeTextForce(requestInfo, 'source'))
143 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
144 execution.setVariable('DELVfModI_vnfInputs', vnfInputs)
145 execution.setVariable('DELVfModI_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
146 execution.setVariable('DELVfModI_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
147 execution.setVariable('DELVfModI_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
148 execution.setVariable('DELVfModI_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
149 execution.setVariable('DELVfModI_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
151 def vnfParams = utils.getNodeXml(request, 'vnf-params')
152 execution.setVariable('DELVfModI_vnfParams', vnfParams)
154 logDebug('Exited ' + method, isDebugLogEnabled)
155 } catch (BpmnError e) {
157 } catch (Exception e) {
158 logError('Caught exception in ' + method, e)
159 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
164 * Sends the 'IN_PROGRESS' synchronous response.
166 * @param execution The flow's execution instance.
168 public void sendSynchResponse(Execution execution) {
169 def method = getClass().getSimpleName() + '.sendResponse(' +
170 'execution=' + execution.getId() +
172 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
173 logDebug('Entered ' + method, isDebugLogEnabled)
176 def requestInfo = execution.getVariable('DELVfModI_requestInfo')
177 def requestId = execution.getVariable('DELVfModI_requestId')
178 def source = execution.getVariable('DELVfModI_source')
179 def progress = getNodeTextForce(requestInfo, 'progress')
180 if (progress.isEmpty()) {
183 def startTime = getNodeTextForce(requestInfo, 'start-time')
184 if (startTime.isEmpty()) {
185 startTime = System.currentTimeMillis()
188 // RESTResponse (for API Handler (APIH) Reply Task)
189 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
190 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
192 utils.logAudit("DeleteVfModuleInfra Synch Response: " + synchResponse)
193 sendWorkflowResponse(execution, 200, synchResponse)
195 logDebug('Exited ' + method, isDebugLogEnabled)
196 } catch (BpmnError e) {
198 } catch (Exception e) {
199 logError('Caught exception in ' + method, e)
200 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
205 * Currently passing the entire DELETE_VF_MODULE vnf-request to DoDeleteVfModule.
206 * 'DeleteVfModuleRequest' is now being set in preProcessRequest().
207 * TBD: may want to eventually create a specific request that only contains the needed fields.
209 * @param execution The flow's execution instance.
211 public void prepDoDeleteVfModule(Execution execution) {
212 def method = getClass().getSimpleName() + '.prepDoDeleteVfModule(' +
213 'execution=' + execution.getId() +
215 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
216 logDebug('Entered ' + method, isDebugLogEnabled)
220 logDebug('Exited ' + method, isDebugLogEnabled)
221 } catch (BpmnError e) {
223 } catch (Exception e) {
224 logError('Caught exception in ' + method, e)
225 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoDeleteVfModule(): ' + e.getMessage())
230 * Prepare the DB update to add an entry for the Vf Module request.
232 * @param execution The flow's execution instance.
234 public void prepUpdateInfraRequest(Execution execution) {
235 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
236 'execution=' + execution.getId() +
238 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
239 logDebug('Entered ' + method, isDebugLogEnabled)
242 def requestId = execution.getVariable('DELVfModI_requestId')
243 def vnfId = execution.getVariable('DELVfModI_vnfId')
244 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
245 def tenantId = execution.getVariable('DELVfModI_tenantId')
246 def volumeGroupId = execution.getVariable('DELVfModI_volumeGroupId')
248 String updateInfraRequest = """
249 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
250 xmlns:req="http://org.openecomp.mso/requestsdb">
253 <req:updateInfraRequest>
254 <requestId>${requestId}</requestId>
255 <lastModifiedBy>BPMN</lastModifiedBy>
256 <requestStatus>COMPLETED</requestStatus>
257 <progress>100</progress>
258 </req:updateInfraRequest>
263 updateInfraRequest = utils.formatXml(updateInfraRequest)
264 execution.setVariable('DELVfModI_updateInfraRequest', updateInfraRequest)
265 utils.logAudit("DeleteAAIVfModuleInfra Update Request: " + updateInfraRequest)
266 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
268 logDebug('Exited ' + method, isDebugLogEnabled)
269 } catch (BpmnError e) {
271 } catch (Exception e) {
272 logError('Caught exception in ' + method, e)
273 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepInfraRequest(): ' + e.getMessage())
278 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
280 * @param execution the execution
281 * @param resultVar the execution variable in which the result will be stored
283 public void completionHandlerPrep(Execution execution, String resultVar) {
284 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
285 'execution=' + execution.getId() +
286 ', resultVar=' + resultVar +
288 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
289 logDebug('Entered ' + method, isDebugLogEnabled)
292 def request = execution.getVariable("DeleteVfModuleRequest")
293 def requestInfo = utils.getNodeXml(request, 'request-info', false)
294 def action = utils.getNodeText1(requestInfo, "action")
297 """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
298 xmlns:ns="http://org.openecomp/mso/request/types/v1"
299 xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">
300 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
303 <ns8:status-message>Vf Module has been deleted successfully.</ns8:status-message>
304 <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
305 </aetgt:MsoCompletionRequest>"""
307 content = utils.formatXml(content)
308 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
309 utils.logAudit("DeleteVfModule Infra Completion Handler Request: " + content)
310 execution.setVariable(resultVar, content)
312 logDebug('Exited ' + method, isDebugLogEnabled)
313 } catch (BpmnError e) {
315 } catch (Exception e) {
316 logError('Caught exception in ' + method, e)
317 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
322 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
324 * @param execution the execution
325 * @param resultVar the execution variable in which the result will be stored
327 public void falloutHandlerPrep(Execution execution, String resultVar) {
328 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
329 'execution=' + execution.getId() +
330 ', resultVar=' + resultVar +
332 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
333 logDebug('Entered ' + method, isDebugLogEnabled)
336 def prefix = execution.getVariable('prefix')
337 def request = execution.getVariable("DeleteVfModuleRequest")
338 def requestInfo = utils.getNodeXml(request, 'request-info', false)
339 def WorkflowException workflowException = execution.getVariable("WorkflowException")
340 def errorResponseCode = workflowException.getErrorCode()
341 def errorResponseMsg = workflowException.getErrorMessage()
342 def encErrorResponseMsg = ""
343 if (errorResponseMsg != null) {
344 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
348 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
349 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
350 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
351 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
353 <sdncadapterworkflow:WorkflowException>
354 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
355 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
356 </sdncadapterworkflow:WorkflowException>
357 </sdncadapterworkflow:FalloutHandlerRequest>
359 content = utils.formatXml(content)
360 utils.logAudit("DeleteVfModuleInfra Fallout Handler Request: " + content)
361 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
362 execution.setVariable(resultVar, content)
364 logDebug('Exited ' + method, isDebugLogEnabled)
365 } catch (BpmnError e) {
367 } catch (Exception e) {
368 logError('Caught exception in ' + method, e)
369 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')