2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.logging.filter.base.ErrorCode
33 import org.onap.so.logger.MessageEnum
34 import org.slf4j.Logger
35 import org.slf4j.LoggerFactory
38 public class UpdateVfModule extends AbstractServiceTaskProcessor {
39 private static final Logger logger = LoggerFactory.getLogger( UpdateVfModule.class);
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
44 * Initialize the flow's variables.
46 * @param execution The flow's execution instance.
48 public void initProcessVariables(DelegateExecution execution) {
49 execution.setVariable('prefix', 'UPDVfMod_')
50 execution.setVariable('UPDVfMod_Request', null)
51 execution.setVariable('UPDVfMod_requestInfo', null)
52 execution.setVariable('UPDVfMod_requestId', null)
53 execution.setVariable('UPDVfMod_source', null)
54 execution.setVariable('UPDVfMod_vnfInputs', null)
55 execution.setVariable('UPDVfMod_vnfId', null)
56 execution.setVariable('UPDVfMod_vfModuleId', null)
57 execution.setVariable('UPDVfMod_tenantId', null)
58 execution.setVariable('UPDVfMod_volumeGroupId', null)
59 execution.setVariable('UPDVfMod_vnfParams', null)
60 execution.setVariable('UPDVfMod_updateInfraRequest', null)
61 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
65 * Check for missing elements in the received request.
67 * @param execution The flow's execution instance.
69 public void preProcessRequest(DelegateExecution execution) {
70 def method = getClass().getSimpleName() + '.preProcessRequest(' +
71 'execution=' + execution.getId() +
74 logger.trace('Entered ' + method)
77 initProcessVariables(execution)
78 String request = validateRequest(execution)
80 logger.debug("UpdateVfModule request: " + request)
81 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
82 execution.setVariable('UPDVfMod_requestInfo', requestInfo)
83 execution.setVariable('UPDVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
84 execution.setVariable('UPDVfMod_source', getNodeTextForce(requestInfo, 'source'))
86 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
87 execution.setVariable('UPDVfMod_vnfInputs', vnfInputs)
88 execution.setVariable('UPDVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
89 execution.setVariable('UPDVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
90 execution.setVariable('UPDVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
91 execution.setVariable('UPDVfMod_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
93 def vnfParams = utils.getNodeXml(request, 'vnf-params')
94 execution.setVariable('UPDVfMod_vnfParams', vnfParams)
96 logger.trace('Exited ' + method)
97 } catch (BpmnError e) {
99 } catch (Exception e) {
100 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
101 'Caught exception in ' + method, "BPMN",
102 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
103 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
108 * Prepare and send the synchronous response for this flow.
110 * @param execution The flow's execution instance.
112 public void sendSynchResponse(DelegateExecution execution) {
113 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
114 'execution=' + execution.getId() +
117 logger.trace('Entered ' + method)
120 def requestInfo = execution.getVariable('UPDVfMod_requestInfo')
121 def requestId = execution.getVariable('UPDVfMod_requestId')
122 def source = execution.getVariable('UPDVfMod_source')
123 def progress = getNodeTextForce(requestInfo, 'progress')
124 if (progress.isEmpty()) {
127 def startTime = getNodeTextForce(requestInfo, 'start-time')
128 if (startTime.isEmpty()) {
129 startTime = System.currentTimeMillis()
131 def vnfInputs = execution.getVariable('UPDVfMod_vnfInputs')
133 String synchResponse = """
134 <vnf-request xmlns="http://org.onap/so/infra/vnf-request/v1">
136 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
137 <action>UPDATE_VF_MODULE</action>
138 <request-status>IN_PROGRESS</request-status>
139 <progress>${MsoUtils.xmlEscape(progress)}</progress>
140 <start-time>${MsoUtils.xmlEscape(startTime)}</start-time>
141 <source>${MsoUtils.xmlEscape(source)}</source>
147 synchResponse = utils.formatXml(synchResponse)
148 sendWorkflowResponse(execution, 200, synchResponse)
150 logger.debug("UpdateVfModule Synch Response: " + synchResponse)
151 logger.trace('Exited ' + method)
152 } catch (BpmnError e) {
154 } catch (Exception e) {
155 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
156 'Caught exception in ' + method, "BPMN",
157 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
158 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendSynchResponse(): ' + e.getMessage())
163 * Prepare the Request for invoking the DoUpdateVfModule subflow.
165 * NOTE: Currently, the method just logs passing through as the
166 * incoming Request to this main flow is used as the Request to
167 * the DoUpdateVfModule subflow. No preparation processing is
170 * @param execution The flow's execution instance.
172 public void prepDoUpdateVfModule(DelegateExecution execution) {
173 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
174 'execution=' + execution.getId() +
177 logger.trace('Entered ' + method)
181 logger.trace('Exited ' + method)
182 } catch (BpmnError e) {
184 } catch (Exception e) {
185 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
186 'Caught exception in ' + method, "BPMN",
187 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
188 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
193 * Prepare the Request for updating the DB for this Infra Request.
195 * @param execution The flow's execution instance.
197 public void prepUpdateInfraRequest(DelegateExecution execution) {
198 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
199 'execution=' + execution.getId() +
202 logger.trace('Entered ' + method)
205 def requestId = execution.getVariable('UPDVfMod_requestId')
206 def vnfId = execution.getVariable('UPDVfMod_vnfId')
207 def vfModuleId = execution.getVariable('UPDVfMod_vfModuleId')
208 def tenantId = execution.getVariable('UPDVfMod_tenantId')
209 def volumeGroupId = execution.getVariable('UPDVfMod_volumeGroupId')
211 String updateInfraRequest = """
212 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
213 xmlns:req="http://org.onap.so/requestsdb">
216 <req:updateInfraRequest>
217 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
218 <lastModifiedBy>BPEL</lastModifiedBy>
219 <requestStatus>COMPLETE</requestStatus>
220 <progress>100</progress>
222 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
223 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
224 <tenant-id>${MsoUtils.xmlEscape(tenantId)}</tenant-id>
225 <volume-group-id>${MsoUtils.xmlEscape(volumeGroupId)}</volume-group-id>
227 </req:updateInfraRequest>
232 updateInfraRequest = utils.formatXml(updateInfraRequest)
233 execution.setVariable('UPDVfMod_updateInfraRequest', updateInfraRequest)
234 logger.debug('Request for Update Infra Request:\n' + updateInfraRequest)
236 logger.debug("UpdateVfModule Infra Request: " + updateInfraRequest)
237 logger.trace('Exited ' + method)
238 } catch (BpmnError e) {
240 } catch (Exception e) {
241 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
242 'Caught exception in ' + method, "BPMN",
243 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
244 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateInfraRequest(): ' + e.getMessage())
249 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
251 * @param execution the execution
252 * @param resultVar the execution variable in which the result will be stored
254 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
255 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
256 'execution=' + execution.getId() +
257 ', resultVar=' + resultVar +
260 logger.trace('Entered ' + method)
263 def requestInfo = getVariable(execution, 'UPDVfMod_requestInfo')
266 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
267 xmlns:reqtype="http://org.onap/so/request/types/v1">
269 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
270 </sdncadapterworkflow:MsoCompletionRequest>
273 content = utils.formatXml(content)
274 logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
275 execution.setVariable(resultVar, content)
277 logger.debug("UpdateVfModule CompletionHandler Request: " + content)
278 logger.trace('Exited ' + method)
279 } catch (BpmnError e) {
281 } catch (Exception e) {
282 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
283 'Caught exception in ' + method, "BPMN",
284 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
285 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
290 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
292 * @param execution the execution
293 * @param resultVar the execution variable in which the result will be stored
295 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
296 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
297 'execution=' + execution.getId() +
298 ', resultVar=' + resultVar +
301 logger.trace('Entered ' + method)
304 def prefix = execution.getVariable('prefix')
305 def request = getVariable(execution, prefix+'Request')
306 def requestInformation = utils.getNodeXml(request, 'request-information', false)
308 def WorkflowException workflowException = execution.getVariable("WorkflowException")
309 def errorResponseCode = workflowException.getErrorCode()
310 def errorResponseMsg = workflowException.getErrorMessage()
311 def encErrorResponseMsg = ""
312 if (errorResponseMsg != null) {
313 encErrorResponseMsg = errorResponseMsg
317 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
318 xmlns:reqtype="http://org.onap/so/request/types/v1"
319 xmlns:msoservtypes="http://org.onap/so/request/types/v1"
320 xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
321 ${requestInformation}
322 <sdncadapterworkflow:WorkflowException>
323 <sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
324 <sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
325 </sdncadapterworkflow:WorkflowException>
326 </sdncadapterworkflow:FalloutHandlerRequest>
328 content = utils.formatXml(content)
329 logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
330 execution.setVariable(resultVar, content)
332 logger.debug("UpdateVfModule fallOutHandler Request: " + content)
333 logger.trace('Exited ' + method)
334 } catch (BpmnError e) {
336 } catch (Exception e) {
337 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
338 'Caught exception in ' + method, "BPMN",
339 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
340 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')