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 com.att.bpm.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.rest.RESTClient
36 import org.openecomp.mso.rest.RESTConfig
37 import org.openecomp.mso.bpmn.core.RollbackData
38 import org.openecomp.mso.bpmn.core.WorkflowException
41 public class DeleteVfModuleInfra extends AbstractServiceTaskProcessor {
44 * Initialize the flow's variables.
46 * @param execution The flow's execution instance.
48 public void initProcessVariables(Execution execution) {
49 execution.setVariable('prefix', 'DELVfModI_')
50 execution.setVariable('DELVfModI_requestInfo', null)
51 execution.setVariable('DELVfModI_requestId', null)
52 execution.setVariable('DELVfModI_source', null)
53 execution.setVariable('DELVfModI_vnfInputs', null)
54 execution.setVariable('DELVfModI_vnfId', null)
55 execution.setVariable('DELVfModI_vfModuleId', null)
56 execution.setVariable('DELVfModI_tenantId', null)
57 execution.setVariable('DELVfModI_volumeGroupId', null)
58 execution.setVariable('DELVfModI_vnfParams', null)
59 execution.setVariable('DELVfModI_updateInfraRequest', null)
60 execution.setVariable('DeleteVfModuleRequest', null)
61 execution.setVariable('DeleteVfModuleSuccessIndicator', false)
65 * Process the incoming DELETE_VF_MODULE vnf-request.
67 * @param execution The flow's execution instance.
69 public void preProcessRequest(Execution execution) {
70 def method = getClass().getSimpleName() + '.preProcessRequest(' +
71 'execution=' + execution.getId() +
73 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
74 logDebug('Entered ' + method, isDebugLogEnabled)
75 execution.setVariable("isVidRequest", "false")
76 initProcessVariables(execution)
78 def prefix = execution.getVariable('prefix')
80 def incomingRequest = execution.getVariable('bpmnRequest')
82 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
84 // check if request is xml or json
86 def jsonSlurper = new JsonSlurper()
87 Map reqMap = jsonSlurper.parseText(incomingRequest)
88 utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
90 def serviceInstanceId = execution.getVariable('serviceInstanceId')
91 def vnfId = execution.getVariable('vnfId')
93 def vidUtils = new VidUtils(this)
95 String requestInXmlFormat = vidUtils.createXmlVfModuleRequest(execution, reqMap, 'DELETE_VF_MODULE', serviceInstanceId)
97 utils.log("DEBUG", " Request in XML format: " + requestInXmlFormat, isDebugLogEnabled)
99 execution.setVariable(prefix + 'Request', requestInXmlFormat)
100 execution.setVariable(prefix+'vnfId', vnfId)
101 execution.setVariable("isVidRequest", "true")
104 catch(groovy.json.JsonException je) {
105 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
106 workflowException(execution, "Invalid request format", 400)
110 String restFaultMessage = e.getMessage()
111 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
112 workflowException(execution, restFaultMessage, 400)
118 String request = validateRequest(execution)
119 execution.setVariable('DeleteVfModuleRequest', request)
121 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
122 execution.setVariable('DELVfModI_requestInfo', requestInfo)
123 execution.setVariable('DELVfModI_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
124 execution.setVariable('DELVfModI_source', getNodeTextForce(requestInfo, 'source'))
126 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
127 execution.setVariable('DELVfModI_vnfInputs', vnfInputs)
128 execution.setVariable('DELVfModI_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
129 execution.setVariable('DELVfModI_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
130 execution.setVariable('DELVfModI_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
131 execution.setVariable('DELVfModI_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
133 def vnfParams = utils.getNodeXml(request, 'vnf-params')
134 execution.setVariable('DELVfModI_vnfParams', vnfParams)
136 logDebug('Exited ' + method, isDebugLogEnabled)
137 } catch (BpmnError e) {
139 } catch (Exception e) {
140 logError('Caught exception in ' + method, e)
141 createWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
146 * Sends the 'IN_PROGRESS' synchronous response.
148 * @param execution The flow's execution instance.
150 public void sendSynchResponse(Execution execution) {
151 def method = getClass().getSimpleName() + '.sendResponse(' +
152 'execution=' + execution.getId() +
154 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
155 logDebug('Entered ' + method, isDebugLogEnabled)
158 def requestInfo = execution.getVariable('DELVfModI_requestInfo')
159 def requestId = execution.getVariable('DELVfModI_requestId')
160 def source = execution.getVariable('DELVfModI_source')
161 def progress = getNodeTextForce(requestInfo, 'progress')
162 if (progress.isEmpty()) {
165 def startTime = getNodeTextForce(requestInfo, 'start-time')
166 if (startTime.isEmpty()) {
167 startTime = System.currentTimeMillis()
170 // RESTResponse (for API Handler (APIH) Reply Task)
171 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
172 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
174 sendWorkflowResponse(execution, 200, synchResponse)
176 logDebug('Exited ' + method, isDebugLogEnabled)
177 } catch (BpmnError e) {
179 } catch (Exception e) {
180 logError('Caught exception in ' + method, e)
181 createWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
186 * Currently passing the entire DELETE_VF_MODULE vnf-request to DoDeleteVfModule.
187 * 'DeleteVfModuleRequest' is now being set in preProcessRequest().
188 * TBD: may want to eventually create a specific request that only contains the needed fields.
190 * @param execution The flow's execution instance.
192 public void prepDoDeleteVfModule(Execution execution) {
193 def method = getClass().getSimpleName() + '.prepDoDeleteVfModule(' +
194 'execution=' + execution.getId() +
196 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
197 logDebug('Entered ' + method, isDebugLogEnabled)
201 logDebug('Exited ' + method, isDebugLogEnabled)
202 } catch (BpmnError e) {
204 } catch (Exception e) {
205 logError('Caught exception in ' + method, e)
206 createWorkflowException(execution, 1002, 'Error in prepDoDeleteVfModule(): ' + e.getMessage())
211 * Prepare the DB update to add an entry for the Vf Module request.
213 * @param execution The flow's execution instance.
215 public void prepUpdateInfraRequest(Execution execution) {
216 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
217 'execution=' + execution.getId() +
219 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
220 logDebug('Entered ' + method, isDebugLogEnabled)
223 def requestId = execution.getVariable('DELVfModI_requestId')
224 def vnfId = execution.getVariable('DELVfModI_vnfId')
225 def vfModuleId = execution.getVariable('DELVfModI_vfModuleId')
226 def tenantId = execution.getVariable('DELVfModI_tenantId')
227 def volumeGroupId = execution.getVariable('DELVfModI_volumeGroupId')
229 String updateInfraRequest = """
230 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
231 xmlns:req="http://com.att.mso/requestsdb">
234 <req:updateInfraRequest>
235 <requestId>${requestId}</requestId>
236 <lastModifiedBy>BPMN</lastModifiedBy>
237 <requestStatus>COMPLETED</requestStatus>
238 <progress>100</progress>
239 </req:updateInfraRequest>
244 updateInfraRequest = utils.formatXml(updateInfraRequest)
245 execution.setVariable('DELVfModI_updateInfraRequest', updateInfraRequest)
246 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
248 logDebug('Exited ' + method, isDebugLogEnabled)
249 } catch (BpmnError e) {
251 } catch (Exception e) {
252 logError('Caught exception in ' + method, e)
253 createWorkflowException(execution, 1002, 'Error in prepInfraRequest(): ' + e.getMessage())
258 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
260 * @param execution the execution
261 * @param resultVar the execution variable in which the result will be stored
263 public void completionHandlerPrep(Execution execution, String resultVar) {
264 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
265 'execution=' + execution.getId() +
266 ', resultVar=' + resultVar +
268 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
269 logDebug('Entered ' + method, isDebugLogEnabled)
272 def request = execution.getVariable("DeleteVfModuleRequest")
273 def requestInfo = utils.getNodeXml(request, 'request-info', false)
274 def action = utils.getNodeText1(requestInfo, "action")
277 """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
278 xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
279 xmlns:ns8="http://ecomp.att.com/mso/workflow/schema/v1">
280 <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
283 <ns8:status-message>Vf Module has been deleted successfully.</ns8:status-message>
284 <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
285 </aetgt:MsoCompletionRequest>"""
287 content = utils.formatXml(content)
288 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
289 execution.setVariable(resultVar, content)
291 logDebug('Exited ' + method, isDebugLogEnabled)
292 } catch (BpmnError e) {
294 } catch (Exception e) {
295 logError('Caught exception in ' + method, e)
296 createWorkflowException(execution, 2000, 'Internal Error')
301 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
303 * @param execution the execution
304 * @param resultVar the execution variable in which the result will be stored
306 public void falloutHandlerPrep(Execution execution, String resultVar) {
307 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
308 'execution=' + execution.getId() +
309 ', resultVar=' + resultVar +
311 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
312 logDebug('Entered ' + method, isDebugLogEnabled)
315 def prefix = execution.getVariable('prefix')
316 def request = execution.getVariable("DeleteVfModuleRequest")
317 def requestInfo = utils.getNodeXml(request, 'request-info', false)
318 def WorkflowException workflowException = execution.getVariable("WorkflowException")
319 def errorResponseCode = workflowException.getErrorCode()
320 def errorResponseMsg = workflowException.getErrorMessage()
321 def encErrorResponseMsg = ""
322 if (errorResponseMsg != null) {
323 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
327 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
328 xmlns:reqtype="http://ecomp.att.com/mso/request/types/v1"
329 xmlns:msoservtypes="http://ecomp.att.com/mso/request/types/v1"
330 xmlns:structuredtypes="http://ecomp.att.com/mso/structured/types/v1">
332 <sdncadapterworkflow:WorkflowException>
333 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
334 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
335 </sdncadapterworkflow:WorkflowException>
336 </sdncadapterworkflow:FalloutHandlerRequest>
338 content = utils.formatXml(content)
339 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
340 execution.setVariable(resultVar, content)
342 logDebug('Exited ' + method, isDebugLogEnabled)
343 } catch (BpmnError e) {
345 } catch (Exception e) {
346 logError('Caught exception in ' + method, e)
347 createWorkflowException(execution, 2000, 'Internal Error')