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.delegate.DelegateExecution
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(DelegateExecution 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(DelegateExecution 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 // 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 utils.log("DEBUG", " Request in XML format: " + requestInXmlFormat, isDebugLogEnabled)
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 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
125 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
129 String restFaultMessage = e.getMessage()
130 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
131 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
137 String request = validateRequest(execution)
138 execution.setVariable('DeleteVfModuleRequest', request)
139 utils.logAudit("DeleteVfModuleInfra Request: " + request)
141 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
142 execution.setVariable('DELVfModI_requestInfo', requestInfo)
143 execution.setVariable('DELVfModI_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
144 execution.setVariable('DELVfModI_source', getNodeTextForce(requestInfo, 'source'))
146 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
147 execution.setVariable('DELVfModI_vnfInputs', vnfInputs)
148 execution.setVariable('DELVfModI_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
149 execution.setVariable('DELVfModI_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
150 execution.setVariable('DELVfModI_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
151 execution.setVariable('DELVfModI_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
152 execution.setVariable('DELVfModI_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
154 def vnfParams = utils.getNodeXml(request, 'vnf-params')
155 execution.setVariable('DELVfModI_vnfParams', vnfParams)
157 logDebug('Exited ' + method, isDebugLogEnabled)
158 } catch (BpmnError e) {
160 } catch (Exception e) {
161 logError('Caught exception in ' + method, e)
162 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
167 * Sends the 'IN_PROGRESS' synchronous response.
169 * @param execution The flow's execution instance.
171 public void sendSynchResponse(DelegateExecution execution) {
172 def method = getClass().getSimpleName() + '.sendResponse(' +
173 'execution=' + execution.getId() +
175 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
176 logDebug('Entered ' + method, isDebugLogEnabled)
179 def requestInfo = execution.getVariable('DELVfModI_requestInfo')
180 def requestId = execution.getVariable('DELVfModI_requestId')
181 def source = execution.getVariable('DELVfModI_source')
182 def progress = getNodeTextForce(requestInfo, 'progress')
183 if (progress.isEmpty()) {
186 def startTime = getNodeTextForce(requestInfo, 'start-time')
187 if (startTime.isEmpty()) {
188 startTime = System.currentTimeMillis()
191 // RESTResponse (for API Handler (APIH) Reply Task)
192 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
193 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
195 utils.logAudit("DeleteVfModuleInfra Synch Response: " + synchResponse)
196 sendWorkflowResponse(execution, 200, synchResponse)
198 logDebug('Exited ' + method, isDebugLogEnabled)
199 } catch (BpmnError e) {
201 } catch (Exception e) {
202 logError('Caught exception in ' + method, e)
203 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
208 * Currently passing the entire DELETE_VF_MODULE vnf-request to DoDeleteVfModule.
209 * 'DeleteVfModuleRequest' is now being set in preProcessRequest().
210 * TBD: may want to eventually create a specific request that only contains the needed fields.
212 * @param execution The flow's execution instance.
214 public void prepDoDeleteVfModule(DelegateExecution execution) {
215 def method = getClass().getSimpleName() + '.prepDoDeleteVfModule(' +
216 'execution=' + execution.getId() +
218 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
219 logDebug('Entered ' + method, isDebugLogEnabled)
223 logDebug('Exited ' + method, isDebugLogEnabled)
224 } catch (BpmnError e) {
226 } catch (Exception e) {
227 logError('Caught exception in ' + method, e)
228 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoDeleteVfModule(): ' + e.getMessage())
233 * Prepare the DB update to add an entry for the Vf Module request.
235 * @param execution The flow's execution instance.
237 public void prepUpdateInfraRequest(DelegateExecution execution) {
238 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
239 'execution=' + execution.getId() +
241 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
242 logDebug('Entered ' + method, isDebugLogEnabled)
245 def requestId = execution.getVariable('DELVfModI_requestId')
246 def vnfId = execution.getVariable('DELVfModI_vnfId')
247 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
248 def tenantId = execution.getVariable('DELVfModI_tenantId')
249 def volumeGroupId = execution.getVariable('DELVfModI_volumeGroupId')
251 String updateInfraRequest = """
252 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
253 xmlns:req="http://org.openecomp.mso/requestsdb">
256 <req:updateInfraRequest>
257 <requestId>${requestId}</requestId>
258 <lastModifiedBy>BPMN</lastModifiedBy>
259 <requestStatus>COMPLETED</requestStatus>
260 <progress>100</progress>
261 </req:updateInfraRequest>
266 updateInfraRequest = utils.formatXml(updateInfraRequest)
267 execution.setVariable('DELVfModI_updateInfraRequest', updateInfraRequest)
268 utils.logAudit("DeleteAAIVfModuleInfra Update Request: " + updateInfraRequest)
269 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
271 logDebug('Exited ' + method, isDebugLogEnabled)
272 } catch (BpmnError e) {
274 } catch (Exception e) {
275 logError('Caught exception in ' + method, e)
276 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepInfraRequest(): ' + e.getMessage())
281 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
283 * @param execution the execution
284 * @param resultVar the execution variable in which the result will be stored
286 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
287 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
288 'execution=' + execution.getId() +
289 ', resultVar=' + resultVar +
291 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
292 logDebug('Entered ' + method, isDebugLogEnabled)
295 def request = execution.getVariable("DeleteVfModuleRequest")
296 def requestInfo = utils.getNodeXml(request, 'request-info', false)
297 def action = utils.getNodeText1(requestInfo, "action")
300 """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
301 xmlns:ns="http://org.openecomp/mso/request/types/v1"
302 xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">
303 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
306 <ns8:status-message>Vf Module has been deleted successfully.</ns8:status-message>
307 <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
308 </aetgt:MsoCompletionRequest>"""
310 content = utils.formatXml(content)
311 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
312 utils.logAudit("DeleteVfModule Infra Completion Handler Request: " + content)
313 execution.setVariable(resultVar, content)
315 logDebug('Exited ' + method, isDebugLogEnabled)
316 } catch (BpmnError e) {
318 } catch (Exception e) {
319 logError('Caught exception in ' + method, e)
320 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
325 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
327 * @param execution the execution
328 * @param resultVar the execution variable in which the result will be stored
330 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
331 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
332 'execution=' + execution.getId() +
333 ', resultVar=' + resultVar +
335 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
336 logDebug('Entered ' + method, isDebugLogEnabled)
339 def prefix = execution.getVariable('prefix')
340 def request = execution.getVariable("DeleteVfModuleRequest")
341 def requestInfo = utils.getNodeXml(request, 'request-info', false)
342 def WorkflowException workflowException = execution.getVariable("WorkflowException")
343 def errorResponseCode = workflowException.getErrorCode()
344 def errorResponseMsg = workflowException.getErrorMessage()
345 def encErrorResponseMsg = ""
346 if (errorResponseMsg != null) {
347 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
351 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
352 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
353 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
354 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
356 <sdncadapterworkflow:WorkflowException>
357 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
358 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
359 </sdncadapterworkflow:WorkflowException>
360 </sdncadapterworkflow:FalloutHandlerRequest>
362 content = utils.formatXml(content)
363 utils.logAudit("DeleteVfModuleInfra Fallout Handler Request: " + content)
364 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
365 execution.setVariable(resultVar, content)
367 logDebug('Exited ' + method, isDebugLogEnabled)
368 } catch (BpmnError e) {
370 } catch (Exception e) {
371 logError('Caught exception in ' + method, e)
372 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')