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
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
32 import org.openecomp.mso.bpmn.core.WorkflowException
33 import org.openecomp.mso.bpmn.core.json.JsonUtils;
34 import org.openecomp.mso.rest.APIResponse
35 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.openecomp.mso.bpmn.core.RollbackData
39 public class UpdateVfModule extends AbstractServiceTaskProcessor {
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() +
73 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
74 logDebug('Entered ' + method, isDebugLogEnabled)
77 initProcessVariables(execution)
78 String request = validateRequest(execution)
80 utils.logAudit("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 logDebug('Exited ' + method, isDebugLogEnabled)
97 } catch (BpmnError e) {
99 } catch (Exception e) {
100 logError('Caught exception in ' + method, e)
101 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
106 * Prepare and send the synchronous response for this flow.
108 * @param execution The flow's execution instance.
110 public void sendSynchResponse(DelegateExecution execution) {
111 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
112 'execution=' + execution.getId() +
114 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
115 logDebug('Entered ' + method, isDebugLogEnabled)
118 def requestInfo = execution.getVariable('UPDVfMod_requestInfo')
119 def requestId = execution.getVariable('UPDVfMod_requestId')
120 def source = execution.getVariable('UPDVfMod_source')
121 def progress = getNodeTextForce(requestInfo, 'progress')
122 if (progress.isEmpty()) {
125 def startTime = getNodeTextForce(requestInfo, 'start-time')
126 if (startTime.isEmpty()) {
127 startTime = System.currentTimeMillis()
129 def vnfInputs = execution.getVariable('UPDVfMod_vnfInputs')
131 String synchResponse = """
132 <vnf-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
134 <request-id>${requestId}</request-id>
135 <action>UPDATE_VF_MODULE</action>
136 <request-status>IN_PROGRESS</request-status>
137 <progress>${progress}</progress>
138 <start-time>${startTime}</start-time>
139 <source>${source}</source>
145 synchResponse = utils.formatXml(synchResponse)
146 sendWorkflowResponse(execution, 200, synchResponse)
148 utils.logAudit("UpdateVfModule Synch Response: " + synchResponse)
149 logDebug('Exited ' + method, isDebugLogEnabled)
150 } catch (BpmnError e) {
152 } catch (Exception e) {
153 logError('Caught exception in ' + method, e)
154 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendSynchResponse(): ' + e.getMessage())
159 * Prepare the Request for invoking the DoUpdateVfModule subflow.
161 * NOTE: Currently, the method just logs passing through as the
162 * incoming Request to this main flow is used as the Request to
163 * the DoUpdateVfModule subflow. No preparation processing is
166 * @param execution The flow's execution instance.
168 public void prepDoUpdateVfModule(DelegateExecution execution) {
169 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
170 'execution=' + execution.getId() +
172 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
173 logDebug('Entered ' + method, isDebugLogEnabled)
177 logDebug('Exited ' + method, isDebugLogEnabled)
178 } catch (BpmnError e) {
180 } catch (Exception e) {
181 logError('Caught exception in ' + method, e)
182 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
187 * Prepare the Request for updating the DB for this Infra Request.
189 * @param execution The flow's execution instance.
191 public void prepUpdateInfraRequest(DelegateExecution execution) {
192 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
193 'execution=' + execution.getId() +
195 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
196 logDebug('Entered ' + method, isDebugLogEnabled)
199 def requestId = execution.getVariable('UPDVfMod_requestId')
200 def vnfId = execution.getVariable('UPDVfMod_vnfId')
201 def vfModuleId = execution.getVariable('UPDVfMod_vfModuleId')
202 def tenantId = execution.getVariable('UPDVfMod_tenantId')
203 def volumeGroupId = execution.getVariable('UPDVfMod_volumeGroupId')
205 String updateInfraRequest = """
206 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
207 xmlns:req="http://org.openecomp.mso/requestsdb">
210 <req:updateInfraRequest>
211 <requestId>${requestId}</requestId>
212 <lastModifiedBy>BPEL</lastModifiedBy>
213 <requestStatus>COMPLETE</requestStatus>
214 <progress>100</progress>
216 <vnf-id>${vnfId}</vnf-id>
217 <vf-module-id>${vfModuleId}</vf-module-id>
218 <tenant-id>${tenantId}</tenant-id>
219 <volume-group-id>${volumeGroupId}</volume-group-id>
221 </req:updateInfraRequest>
226 updateInfraRequest = utils.formatXml(updateInfraRequest)
227 execution.setVariable('UPDVfMod_updateInfraRequest', updateInfraRequest)
228 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
230 utils.logAudit("UpdateVfModule Infra Request: " + updateInfraRequest)
231 logDebug('Exited ' + method, isDebugLogEnabled)
232 } catch (BpmnError e) {
234 } catch (Exception e) {
235 logError('Caught exception in ' + method, e)
236 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateInfraRequest(): ' + e.getMessage())
241 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
243 * @param execution the execution
244 * @param resultVar the execution variable in which the result will be stored
246 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
247 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
248 'execution=' + execution.getId() +
249 ', resultVar=' + resultVar +
251 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
252 logDebug('Entered ' + method, isDebugLogEnabled)
255 def requestInfo = getVariable(execution, 'UPDVfMod_requestInfo')
258 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
259 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
261 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
262 </sdncadapterworkflow:MsoCompletionRequest>
265 content = utils.formatXml(content)
266 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
267 execution.setVariable(resultVar, content)
269 utils.logAudit("UpdateVfModule CompletionHandler Request: " + content)
270 logDebug('Exited ' + method, isDebugLogEnabled)
271 } catch (BpmnError e) {
273 } catch (Exception e) {
274 logError('Caught exception in ' + method, e)
275 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
280 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
282 * @param execution the execution
283 * @param resultVar the execution variable in which the result will be stored
285 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
286 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
287 'execution=' + execution.getId() +
288 ', resultVar=' + resultVar +
290 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
291 logDebug('Entered ' + method, isDebugLogEnabled)
294 def prefix = execution.getVariable('prefix')
295 def request = getVariable(execution, prefix+'Request')
296 def requestInformation = utils.getNodeXml(request, 'request-information', false)
298 def WorkflowException workflowException = execution.getVariable("WorkflowException")
299 def errorResponseCode = workflowException.getErrorCode()
300 def errorResponseMsg = workflowException.getErrorMessage()
301 def encErrorResponseMsg = ""
302 if (errorResponseMsg != null) {
303 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
307 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
308 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
309 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
310 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
311 ${requestInformation}
312 <sdncadapterworkflow:WorkflowException>
313 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
314 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
315 </sdncadapterworkflow:WorkflowException>
316 </sdncadapterworkflow:FalloutHandlerRequest>
318 content = utils.formatXml(content)
319 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
320 execution.setVariable(resultVar, content)
322 utils.logAudit("UpdateVfModule fallOutHandler Request: " + content)
323 logDebug('Exited ' + method, isDebugLogEnabled)
324 } catch (BpmnError e) {
326 } catch (Exception e) {
327 logError('Caught exception in ' + method, e)
328 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')