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.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.MsoUtils
28 import org.onap.so.bpmn.core.WorkflowException
29 import org.onap.so.logger.MessageEnum
30 import org.onap.so.logger.MsoLogger
33 public class UpdateVfModule extends AbstractServiceTaskProcessor {
34 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UpdateVfModule.class);
36 ExceptionUtil exceptionUtil = new ExceptionUtil()
39 * Initialize the flow's variables.
41 * @param execution The flow's execution instance.
43 public void initProcessVariables(DelegateExecution execution) {
44 execution.setVariable('prefix', 'UPDVfMod_')
45 execution.setVariable('UPDVfMod_Request', null)
46 execution.setVariable('UPDVfMod_requestInfo', null)
47 execution.setVariable('UPDVfMod_requestId', null)
48 execution.setVariable('UPDVfMod_source', null)
49 execution.setVariable('UPDVfMod_vnfInputs', null)
50 execution.setVariable('UPDVfMod_vnfId', null)
51 execution.setVariable('UPDVfMod_vfModuleId', null)
52 execution.setVariable('UPDVfMod_tenantId', null)
53 execution.setVariable('UPDVfMod_volumeGroupId', null)
54 execution.setVariable('UPDVfMod_vnfParams', null)
55 execution.setVariable('UPDVfMod_updateInfraRequest', null)
56 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
60 * Check for missing elements in the received request.
62 * @param execution The flow's execution instance.
64 public void preProcessRequest(DelegateExecution execution) {
65 def method = getClass().getSimpleName() + '.preProcessRequest(' +
66 'execution=' + execution.getId() +
69 msoLogger.trace('Entered ' + method)
72 initProcessVariables(execution)
73 String request = validateRequest(execution)
75 msoLogger.debug("UpdateVfModule request: " + request)
76 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
77 execution.setVariable('UPDVfMod_requestInfo', requestInfo)
78 execution.setVariable('UPDVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
79 execution.setVariable('UPDVfMod_source', getNodeTextForce(requestInfo, 'source'))
81 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
82 execution.setVariable('UPDVfMod_vnfInputs', vnfInputs)
83 execution.setVariable('UPDVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
84 execution.setVariable('UPDVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
85 execution.setVariable('UPDVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
86 execution.setVariable('UPDVfMod_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
88 def vnfParams = utils.getNodeXml(request, 'vnf-params')
89 execution.setVariable('UPDVfMod_vnfParams', vnfParams)
91 msoLogger.trace('Exited ' + method)
92 } catch (BpmnError e) {
94 } catch (Exception e) {
95 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
96 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
101 * Prepare and send the synchronous response for this flow.
103 * @param execution The flow's execution instance.
105 public void sendSynchResponse(DelegateExecution execution) {
106 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
107 'execution=' + execution.getId() +
110 msoLogger.trace('Entered ' + method)
113 def requestInfo = execution.getVariable('UPDVfMod_requestInfo')
114 def requestId = execution.getVariable('UPDVfMod_requestId')
115 def source = execution.getVariable('UPDVfMod_source')
116 def progress = getNodeTextForce(requestInfo, 'progress')
117 if (progress.isEmpty()) {
120 def startTime = getNodeTextForce(requestInfo, 'start-time')
121 if (startTime.isEmpty()) {
122 startTime = System.currentTimeMillis()
124 def vnfInputs = execution.getVariable('UPDVfMod_vnfInputs')
126 String synchResponse = """
127 <vnf-request xmlns="http://org.onap/so/infra/vnf-request/v1">
129 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
130 <action>UPDATE_VF_MODULE</action>
131 <request-status>IN_PROGRESS</request-status>
132 <progress>${MsoUtils.xmlEscape(progress)}</progress>
133 <start-time>${MsoUtils.xmlEscape(startTime)}</start-time>
134 <source>${MsoUtils.xmlEscape(source)}</source>
140 synchResponse = utils.formatXml(synchResponse)
141 sendWorkflowResponse(execution, 200, synchResponse)
143 msoLogger.debug("UpdateVfModule Synch Response: " + synchResponse)
144 msoLogger.trace('Exited ' + method)
145 } catch (BpmnError e) {
147 } catch (Exception e) {
148 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
149 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendSynchResponse(): ' + e.getMessage())
154 * Prepare the Request for invoking the DoUpdateVfModule subflow.
156 * NOTE: Currently, the method just logs passing through as the
157 * incoming Request to this main flow is used as the Request to
158 * the DoUpdateVfModule subflow. No preparation processing is
161 * @param execution The flow's execution instance.
163 public void prepDoUpdateVfModule(DelegateExecution execution) {
164 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
165 'execution=' + execution.getId() +
168 msoLogger.trace('Entered ' + method)
172 msoLogger.trace('Exited ' + method)
173 } catch (BpmnError e) {
175 } catch (Exception e) {
176 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
177 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
182 * Prepare the Request for updating the DB for this Infra Request.
184 * @param execution The flow's execution instance.
186 public void prepUpdateInfraRequest(DelegateExecution execution) {
187 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
188 'execution=' + execution.getId() +
191 msoLogger.trace('Entered ' + method)
194 def requestId = execution.getVariable('UPDVfMod_requestId')
195 def vnfId = execution.getVariable('UPDVfMod_vnfId')
196 def vfModuleId = execution.getVariable('UPDVfMod_vfModuleId')
197 def tenantId = execution.getVariable('UPDVfMod_tenantId')
198 def volumeGroupId = execution.getVariable('UPDVfMod_volumeGroupId')
200 String updateInfraRequest = """
201 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
202 xmlns:req="http://org.onap.so/requestsdb">
205 <req:updateInfraRequest>
206 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
207 <lastModifiedBy>BPEL</lastModifiedBy>
208 <requestStatus>COMPLETE</requestStatus>
209 <progress>100</progress>
211 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
212 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
213 <tenant-id>${MsoUtils.xmlEscape(tenantId)}</tenant-id>
214 <volume-group-id>${MsoUtils.xmlEscape(volumeGroupId)}</volume-group-id>
216 </req:updateInfraRequest>
221 updateInfraRequest = utils.formatXml(updateInfraRequest)
222 execution.setVariable('UPDVfMod_updateInfraRequest', updateInfraRequest)
223 msoLogger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
225 msoLogger.debug("UpdateVfModule Infra Request: " + updateInfraRequest)
226 msoLogger.trace('Exited ' + method)
227 } catch (BpmnError e) {
229 } catch (Exception e) {
230 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
231 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateInfraRequest(): ' + e.getMessage())
236 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
238 * @param execution the execution
239 * @param resultVar the execution variable in which the result will be stored
241 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
242 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
243 'execution=' + execution.getId() +
244 ', resultVar=' + resultVar +
247 msoLogger.trace('Entered ' + method)
250 def requestInfo = getVariable(execution, 'UPDVfMod_requestInfo')
253 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
254 xmlns:reqtype="http://org.onap/so/request/types/v1">
256 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
257 </sdncadapterworkflow:MsoCompletionRequest>
260 content = utils.formatXml(content)
261 msoLogger.debug(resultVar + ' = ' + System.lineSeparator() + content)
262 execution.setVariable(resultVar, content)
264 msoLogger.debug("UpdateVfModule CompletionHandler Request: " + content)
265 msoLogger.trace('Exited ' + method)
266 } catch (BpmnError e) {
268 } catch (Exception e) {
269 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
270 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
275 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
277 * @param execution the execution
278 * @param resultVar the execution variable in which the result will be stored
280 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
281 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
282 'execution=' + execution.getId() +
283 ', resultVar=' + resultVar +
286 msoLogger.trace('Entered ' + method)
289 def prefix = execution.getVariable('prefix')
290 def request = getVariable(execution, prefix+'Request')
291 def requestInformation = utils.getNodeXml(request, 'request-information', false)
293 def WorkflowException workflowException = execution.getVariable("WorkflowException")
294 def errorResponseCode = workflowException.getErrorCode()
295 def errorResponseMsg = workflowException.getErrorMessage()
296 def encErrorResponseMsg = ""
297 if (errorResponseMsg != null) {
298 encErrorResponseMsg = errorResponseMsg
302 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
303 xmlns:reqtype="http://org.onap/so/request/types/v1"
304 xmlns:msoservtypes="http://org.onap/so/request/types/v1"
305 xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
306 ${requestInformation}
307 <sdncadapterworkflow:WorkflowException>
308 <sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
309 <sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
310 </sdncadapterworkflow:WorkflowException>
311 </sdncadapterworkflow:FalloutHandlerRequest>
313 content = utils.formatXml(content)
314 msoLogger.debug(resultVar + ' = ' + System.lineSeparator() + content)
315 execution.setVariable(resultVar, content)
317 msoLogger.debug("UpdateVfModule fallOutHandler Request: " + content)
318 msoLogger.trace('Exited ' + method)
319 } catch (BpmnError e) {
321 } catch (Exception e) {
322 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
323 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')