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.runtime.Execution
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 {
42 * Initialize the flow's variables.
44 * @param execution The flow's execution instance.
46 public void initProcessVariables(Execution execution) {
47 execution.setVariable('prefix', 'UPDVfMod_')
48 execution.setVariable('UPDVfMod_Request', null)
49 execution.setVariable('UPDVfMod_requestInfo', null)
50 execution.setVariable('UPDVfMod_requestId', null)
51 execution.setVariable('UPDVfMod_source', null)
52 execution.setVariable('UPDVfMod_vnfInputs', null)
53 execution.setVariable('UPDVfMod_vnfId', null)
54 execution.setVariable('UPDVfMod_vfModuleId', null)
55 execution.setVariable('UPDVfMod_tenantId', null)
56 execution.setVariable('UPDVfMod_volumeGroupId', null)
57 execution.setVariable('UPDVfMod_vnfParams', null)
58 execution.setVariable('UPDVfMod_updateInfraRequest', null)
59 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
63 * Check for missing elements in the received request.
65 * @param execution The flow's execution instance.
67 public void preProcessRequest(Execution execution) {
68 def method = getClass().getSimpleName() + '.preProcessRequest(' +
69 'execution=' + execution.getId() +
71 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
72 logDebug('Entered ' + method, isDebugLogEnabled)
75 initProcessVariables(execution)
76 String request = validateRequest(execution)
78 utils.logAudit("UpdateVfModule request: " + request)
79 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
80 execution.setVariable('UPDVfMod_requestInfo', requestInfo)
81 execution.setVariable('UPDVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
82 execution.setVariable('UPDVfMod_source', getNodeTextForce(requestInfo, 'source'))
84 def vnfInputs = getRequiredNodeXml(execution, request, 'vnf-inputs')
85 execution.setVariable('UPDVfMod_vnfInputs', vnfInputs)
86 execution.setVariable('UPDVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
87 execution.setVariable('UPDVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
88 execution.setVariable('UPDVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
89 execution.setVariable('UPDVfMod_volumeGroupId', getNodeTextForce(vnfInputs, 'volume-group-id'))
91 def vnfParams = utils.getNodeXml(request, 'vnf-params')
92 execution.setVariable('UPDVfMod_vnfParams', vnfParams)
94 logDebug('Exited ' + method, isDebugLogEnabled)
95 } catch (BpmnError e) {
97 } catch (Exception e) {
98 logError('Caught exception in ' + method, e)
99 createWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
104 * Prepare and send the synchronous response for this flow.
106 * @param execution The flow's execution instance.
108 public void sendSynchResponse(Execution execution) {
109 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
110 'execution=' + execution.getId() +
112 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
113 logDebug('Entered ' + method, isDebugLogEnabled)
116 def requestInfo = execution.getVariable('UPDVfMod_requestInfo')
117 def requestId = execution.getVariable('UPDVfMod_requestId')
118 def source = execution.getVariable('UPDVfMod_source')
119 def progress = getNodeTextForce(requestInfo, 'progress')
120 if (progress.isEmpty()) {
123 def startTime = getNodeTextForce(requestInfo, 'start-time')
124 if (startTime.isEmpty()) {
125 startTime = System.currentTimeMillis()
127 def vnfInputs = execution.getVariable('UPDVfMod_vnfInputs')
129 String synchResponse = """
130 <vnf-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
132 <request-id>${requestId}</request-id>
133 <action>UPDATE_VF_MODULE</action>
134 <request-status>IN_PROGRESS</request-status>
135 <progress>${progress}</progress>
136 <start-time>${startTime}</start-time>
137 <source>${source}</source>
143 synchResponse = utils.formatXml(synchResponse)
144 sendWorkflowResponse(execution, 200, synchResponse)
146 utils.logAudit("UpdateVfModule Synch Response: " + synchResponse)
147 logDebug('Exited ' + method, isDebugLogEnabled)
148 } catch (BpmnError e) {
150 } catch (Exception e) {
151 logError('Caught exception in ' + method, e)
152 createWorkflowException(execution, 1002, 'Error in sendSynchResponse(): ' + e.getMessage())
157 * Prepare the Request for invoking the DoUpdateVfModule subflow.
159 * NOTE: Currently, the method just logs passing through as the
160 * incoming Request to this main flow is used as the Request to
161 * the DoUpdateVfModule subflow. No preparation processing is
164 * @param execution The flow's execution instance.
166 public void prepDoUpdateVfModule(Execution execution) {
167 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
168 'execution=' + execution.getId() +
170 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
171 logDebug('Entered ' + method, isDebugLogEnabled)
175 logDebug('Exited ' + method, isDebugLogEnabled)
176 } catch (BpmnError e) {
178 } catch (Exception e) {
179 logError('Caught exception in ' + method, e)
180 createWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
185 * Prepare the Request for updating the DB for this Infra Request.
187 * @param execution The flow's execution instance.
189 public void prepUpdateInfraRequest(Execution execution) {
190 def method = getClass().getSimpleName() + '.prepUpdateInfraRequest(' +
191 'execution=' + execution.getId() +
193 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
194 logDebug('Entered ' + method, isDebugLogEnabled)
197 def requestId = execution.getVariable('UPDVfMod_requestId')
198 def vnfId = execution.getVariable('UPDVfMod_vnfId')
199 def vfModuleId = execution.getVariable('UPDVfMod_vfModuleId')
200 def tenantId = execution.getVariable('UPDVfMod_tenantId')
201 def volumeGroupId = execution.getVariable('UPDVfMod_volumeGroupId')
203 String updateInfraRequest = """
204 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
205 xmlns:req="http://org.openecomp.mso/requestsdb">
208 <req:updateInfraRequest>
209 <requestId>${requestId}</requestId>
210 <lastModifiedBy>BPEL</lastModifiedBy>
211 <requestStatus>COMPLETE</requestStatus>
212 <progress>100</progress>
214 <vnf-id>${vnfId}</vnf-id>
215 <vf-module-id>${vfModuleId}</vf-module-id>
216 <tenant-id>${tenantId}</tenant-id>
217 <volume-group-id>${volumeGroupId}</volume-group-id>
219 </req:updateInfraRequest>
224 updateInfraRequest = utils.formatXml(updateInfraRequest)
225 execution.setVariable('UPDVfMod_updateInfraRequest', updateInfraRequest)
226 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)
228 utils.logAudit("UpdateVfModule Infra Request: " + updateInfraRequest)
229 logDebug('Exited ' + method, isDebugLogEnabled)
230 } catch (BpmnError e) {
232 } catch (Exception e) {
233 logError('Caught exception in ' + method, e)
234 createWorkflowException(execution, 1002, 'Error in prepUpdateInfraRequest(): ' + e.getMessage())
239 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
241 * @param execution the execution
242 * @param resultVar the execution variable in which the result will be stored
244 public void completionHandlerPrep(Execution execution, String resultVar) {
245 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
246 'execution=' + execution.getId() +
247 ', resultVar=' + resultVar +
249 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
250 logDebug('Entered ' + method, isDebugLogEnabled)
253 def requestInfo = getVariable(execution, 'UPDVfMod_requestInfo')
256 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
257 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
259 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
260 </sdncadapterworkflow:MsoCompletionRequest>
263 content = utils.formatXml(content)
264 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
265 execution.setVariable(resultVar, content)
267 utils.logAudit("UpdateVfModule CompletionHandler Request: " + content)
268 logDebug('Exited ' + method, isDebugLogEnabled)
269 } catch (BpmnError e) {
271 } catch (Exception e) {
272 logError('Caught exception in ' + method, e)
273 createWorkflowException(execution, 2000, 'Internal Error')
278 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
280 * @param execution the execution
281 * @param resultVar the execution variable in which the result will be stored
283 public void falloutHandlerPrep(Execution execution, String resultVar) {
284 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
285 'execution=' + execution.getId() +
286 ', resultVar=' + resultVar +
288 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
289 logDebug('Entered ' + method, isDebugLogEnabled)
292 def prefix = execution.getVariable('prefix')
293 def request = getVariable(execution, prefix+'Request')
294 def requestInformation = utils.getNodeXml(request, 'request-information', false)
296 def WorkflowException workflowException = execution.getVariable("WorkflowException")
297 def errorResponseCode = workflowException.getErrorCode()
298 def errorResponseMsg = workflowException.getErrorMessage()
299 def encErrorResponseMsg = ""
300 if (errorResponseMsg != null) {
301 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
305 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
306 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
307 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
308 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
309 ${requestInformation}
310 <sdncadapterworkflow:WorkflowException>
311 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
312 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
313 </sdncadapterworkflow:WorkflowException>
314 </sdncadapterworkflow:FalloutHandlerRequest>
316 content = utils.formatXml(content)
317 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
318 execution.setVariable(resultVar, content)
320 utils.logAudit("UpdateVfModule fallOutHandler Request: " + content)
321 logDebug('Exited ' + method, isDebugLogEnabled)
322 } catch (BpmnError e) {
324 } catch (Exception e) {
325 logError('Caught exception in ' + method, e)
326 createWorkflowException(execution, 2000, 'Internal Error')