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.json.JsonSlurper
24 import groovy.util.Node
25 import groovy.util.XmlParser;
26 import groovy.xml.QName
28 import java.io.Serializable;
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.runtime.Execution
33 import org.openecomp.mso.rest.APIResponse
34 import org.openecomp.mso.rest.RESTClient
35 import org.openecomp.mso.rest.RESTConfig
36 import org.openecomp.mso.bpmn.core.RollbackData
37 import org.openecomp.mso.bpmn.core.WorkflowException
40 public class UpdateVfModuleInfra extends AbstractServiceTaskProcessor {
43 * Initialize the flow's variables.
45 * @param execution The flow's execution instance.
47 public void initProcessVariables(Execution execution) {
48 execution.setVariable('prefix', 'UPDVfModI_')
49 execution.setVariable('UPDVfModI_Request', null)
50 execution.setVariable('UPDVfModI_requestInfo', null)
51 execution.setVariable('UPDVfModI_requestId', null)
52 execution.setVariable('UPDVfModI_source', null)
53 execution.setVariable('UPDVfModI_vnfInputs', null)
54 execution.setVariable('UPDVfModI_vnfId', null)
55 execution.setVariable('UPDVfModI_vfModuleId', null)
56 execution.setVariable('UPDVfModI_tenantId', null)
57 execution.setVariable('UPDVfModI_volumeGroupId', null)
58 execution.setVariable('UPDVfModI_vnfParams', null)
59 execution.setVariable('UPDVfModI_updateInfraRequest', null)
60 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
64 * Check for missing elements in the received request.
66 * @param execution The flow's execution instance.
68 public void preProcessRequest(Execution execution) {
69 def method = getClass().getSimpleName() + '.preProcessRequest(' +
70 'execution=' + execution.getId() +
72 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
73 logDebug('Entered ' + method, isDebugLogEnabled)
75 initProcessVariables(execution)
77 def prefix = "UPDVfModI_"
79 execution.setVariable("isVidRequest", "false")
81 def incomingRequest = execution.getVariable('bpmnRequest')
83 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
85 // check if request is xml or json
87 def jsonSlurper = new JsonSlurper()
88 Map reqMap = jsonSlurper.parseText(incomingRequest)
89 utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
91 def serviceInstanceId = execution.getVariable('serviceInstanceId')
92 def vnfId = execution.getVariable('vnfId')
94 def vidUtils = new VidUtils(this)
96 String requestInXmlFormat = vidUtils.createXmlVfModuleRequest(execution, reqMap, 'UPDATE_VF_MODULE', serviceInstanceId)
98 utils.log("DEBUG", " Request in XML format: " + requestInXmlFormat, isDebugLogEnabled)
100 execution.setVariable(prefix + 'Request', requestInXmlFormat)
101 execution.setVariable(prefix+'vnfId', vnfId)
102 execution.setVariable("isVidRequest", "true")
105 catch(groovy.json.JsonException je) {
106 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
107 workflowException(execution, "Invalid request format", 400)
111 String restFaultMessage = e.getMessage()
112 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
113 workflowException(execution, restFaultMessage, 400)
119 String request = validateInfraRequest(execution)
121 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
122 execution.setVariable('UPDVfModI_requestInfo', requestInfo)
123 execution.setVariable('UPDVfModI_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
124 execution.setVariable('UPDVfModI_source', getNodeTextForce(requestInfo, 'source'))
126 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
127 execution.setVariable('UPDVfModI_vnfInputs', vnfInputs)
128 execution.setVariable('UPDVfModI_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
129 execution.setVariable('UPDVfModI_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
130 execution.setVariable('UPDVfModI_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
131 execution.setVariable('UPDVfModI_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
133 def vnfParams = utils.getNodeXml(request, 'vnf-params')
134 execution.setVariable('UPDVfModI_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 * Prepare and send the sychronous response for this flow.
148 * @param execution The flow's execution instance.
150 public void sendSynchResponse(Execution execution) {
151 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
152 'execution=' + execution.getId() +
154 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
155 logDebug('Entered ' + method, isDebugLogEnabled)
159 def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
160 def requestId = execution.getVariable('UPDVfModI_requestId')
161 def source = execution.getVariable('UPDVfModI_source')
162 def progress = getNodeTextForce(requestInfo, 'progress')
163 if (progress.isEmpty()) {
166 def startTime = getNodeTextForce(requestInfo, 'start-time')
167 if (startTime.isEmpty()) {
168 startTime = System.currentTimeMillis()
171 // RESTResponse (for API Handler (APIH) Reply Task)
172 def vfModuleId = execution.getVariable("vfModuleId")
173 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
175 sendWorkflowResponse(execution, 200, synchResponse)
177 logDebug('Exited ' + method, isDebugLogEnabled)
178 } catch (BpmnError e) {
180 } catch (Exception e) {
181 logError('Caught exception in ' + method, e)
182 createWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
187 * Prepare the Request for invoking the DoUpdateVfModule subflow.
189 * NOTE: Currently, the method just logs passing through as the
190 * incoming Request to this main flow is used as the Request to
191 * the DoUpdateVfModule subflow. No preparation processing is
194 * @param execution The flow's execution instance.
196 public void prepDoUpdateVfModule(Execution execution) {
197 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
198 'execution=' + execution.getId() +
200 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
201 logDebug('Entered ' + method, isDebugLogEnabled)
205 logDebug('Exited ' + method, isDebugLogEnabled)
206 } catch (BpmnError e) {
208 } catch (Exception e) {
209 logError('Caught exception in ' + method, e)
210 createWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
215 * Prepare the Request for updating the DB for this Infra Request.
217 * @param execution The flow's execution instance.
219 public void prepUpdateInfraRequest(Execution execution) {
220 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
221 'execution=' + execution.getId() +
223 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
224 logDebug('Entered ' + method, isDebugLogEnabled)
227 def requestId = execution.getVariable('UPDVfModI_requestId')
228 def vnfId = execution.getVariable('UPDVfModI_vnfId')
229 def vfModuleId = execution.getVariable('UPDVfModI_vfModuleId')
230 def tenantId = execution.getVariable('UPDVfModI_tenantId')
231 def volumeGroupId = execution.getVariable('UPDVfModI_volumeGroupId')
233 String updateInfraRequest = """
234 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
235 xmlns:req="http://com.att.mso/requestsdb">
238 <req:updateInfraRequest>
239 <requestId>${requestId}</requestId>
240 <lastModifiedBy>BPEL</lastModifiedBy>
241 <requestStatus>COMPLETE</requestStatus>
242 <progress>100</progress>
244 <vnf-id>${vnfId}</vnf-id>
245 <vf-module-id>${vfModuleId}</vf-module-id>
246 <tenant-id>${tenantId}</tenant-id>
247 <volume-group-id>${volumeGroupId}</volume-group-id>
249 </req:updateInfraRequest>
254 updateInfraRequest = utils.formatXml(updateInfraRequest)
255 execution.setVariable('UPDVfModI_updateInfraRequest', updateInfraRequest)
256 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
258 logDebug('Exited ' + method, isDebugLogEnabled)
259 } catch (BpmnError e) {
261 } catch (Exception e) {
262 logError('Caught exception in ' + method, e)
263 createWorkflowException(execution, 1002, 'Error in prepUpdateInfraRequest(): ' + e.getMessage())
268 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
270 * @param execution the execution
271 * @param resultVar the execution variable in which the result will be stored
273 public void completionHandlerPrep(Execution execution, String resultVar) {
274 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
275 'execution=' + execution.getId() +
276 ', resultVar=' + resultVar +
278 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
279 logDebug('Entered ' + method, isDebugLogEnabled)
282 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
285 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
286 xmlns:reqtype="http://ecomp.att.com/mso/request/types/v1">
288 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
289 </sdncadapterworkflow:MsoCompletionRequest>
292 content = utils.formatXml(content)
293 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
294 execution.setVariable(resultVar, content)
296 logDebug('Exited ' + method, isDebugLogEnabled)
297 } catch (BpmnError e) {
299 } catch (Exception e) {
300 logError('Caught exception in ' + method, e)
301 createWorkflowException(execution, 2000, 'Internal Error')
306 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
308 * @param execution the execution
309 * @param resultVar the execution variable in which the result will be stored
311 public void falloutHandlerPrep(Execution execution, String resultVar) {
312 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
313 'execution=' + execution.getId() +
314 ', resultVar=' + resultVar +
316 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
317 logDebug('Entered ' + method, isDebugLogEnabled)
320 def prefix = execution.getVariable('prefix')
321 def request = getVariable(execution, prefix+'Request')
322 def requestInformation = utils.getNodeXml(request, 'request-info', false)
324 def WorkflowException workflowException = execution.getVariable("WorkflowException")
325 def errorResponseCode = workflowException.getErrorCode()
326 def errorResponseMsg = workflowException.getErrorMessage()
327 def encErrorResponseMsg = ""
328 if (errorResponseMsg != null) {
329 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
333 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
334 xmlns:reqtype="http://ecomp.att.com/mso/request/types/v1"
335 xmlns:msoservtypes="http://ecomp.att.com/mso/request/types/v1"
336 xmlns:structuredtypes="http://ecomp.att.com/mso/structured/types/v1">
337 ${requestInformation}
338 <sdncadapterworkflow:WorkflowException>
339 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
340 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
341 </sdncadapterworkflow:WorkflowException>
342 </sdncadapterworkflow:FalloutHandlerRequest>
344 content = utils.formatXml(content)
345 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
346 execution.setVariable(resultVar, content)
348 logDebug('Exited ' + method, isDebugLogEnabled)
349 } catch (BpmnError e) {
351 } catch (Exception e) {
352 logError('Caught exception in ' + method, e)
353 createWorkflowException(execution, 2000, 'Internal Error')
358 * Validates the request, request id and service instance id. If a problem is found,
359 * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
360 * method also sets up the log context for the workflow.
361 * @param execution the execution
362 * @return the validated request
364 public String validateInfraRequest(Execution execution) {
365 def method = getClass().getSimpleName() + '.validateInfraRequest(' +
366 'execution=' + execution.getId() +
368 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
369 logDebug('Entered ' + method, isDebugLogEnabled)
371 String processKey = getProcessKey(execution);
372 def prefix = execution.getVariable("prefix")
374 if (prefix == null) {
375 createWorkflowException(execution, 1002, processKey + " prefix is null")
379 def request = execution.getVariable(prefix + 'Request')
381 if (request == null) {
382 request = execution.getVariable(processKey + 'Request')
384 if (request == null) {
385 request = execution.getVariable('bpmnRequest')
388 setVariable(execution, processKey + 'Request', null);
389 setVariable(execution, 'bpmnRequest', null);
390 setVariable(execution, prefix + 'Request', request);
393 if (request == null) {
394 createWorkflowException(execution, 1002, processKey + " request is null")
399 def requestId = execution.getVariable("att-mso-request-id")
401 if (requestId == null) {
402 createWorkflowException(execution, 1002, processKey + " request has no att-mso-request-id")
405 setVariable(execution, prefix + 'requestId', requestId)
407 def serviceInstanceId = execution.getVariable("att-mso-service-instance-id")
409 if (serviceInstanceId == null) {
410 createWorkflowException(execution, 1002, processKey + " request message has no att-mso-service-instance-id")
413 utils.logContext(requestId, serviceInstanceId)
415 logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
416 logDebug('Exited ' + method, isDebugLogEnabled)
418 } catch (BpmnError e) {
420 } catch (Exception e) {
421 logError('Caught exception in ' + method, e)
422 createWorkflowException(execution, 1002, "Invalid Message")