Groovy scripts header correction
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / UpdateVfModuleVolumeInfraV1.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.bpmn.infrastructure.scripts\r
22 \r
23 import groovy.json.JsonSlurper\r
24 \r
25 import java.util.concurrent.ExecutionException;\r
26 \r
27 import org.camunda.bpm.engine.delegate.BpmnError\r
28 import org.camunda.bpm.engine.runtime.Execution\r
29 import org.apache.commons.lang3.*\r
30 import org.springframework.web.util.UriUtils\r
31 import org.openecomp.mso.bpmn.common.scripts.AaiUtil;\r
32 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;\r
33 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase;\r
34 import org.openecomp.mso.bpmn.common.scripts.VidUtils;\r
35 import org.openecomp.mso.bpmn.core.WorkflowException\r
36 import org.openecomp.mso.rest.APIResponse\r
37 import org.openecomp.mso.rest.RESTClient\r
38 import org.openecomp.mso.rest.RESTConfig\r
39 \r
40 class UpdateVfModuleVolumeInfraV1 extends VfModuleBase {\r
41         \r
42         /**\r
43          * Initialize the flow's variables.\r
44          * \r
45          * @param execution The flow's execution instance.\r
46          */\r
47         private void initProcessVariables(Execution execution) {\r
48                 execution.setVariable('prefix', 'UPDVfModVol_')\r
49                 execution.setVariable('UPDVfModVol_Request', null)\r
50                 execution.setVariable('UPDVfModVol_requestInfo', null)\r
51                 execution.setVariable('UPDVfModVol_requestId', null)\r
52                 execution.setVariable('UPDVfModVol_source', null)\r
53                 execution.setVariable('UPDVfModVol_volumeInputs', null)\r
54                 execution.setVariable('UPDVfModVol_volumeGroupId', null)\r
55                 execution.setVariable('UPDVfModVol_vnfType', null)\r
56                 execution.setVariable('UPDVfModVol_serviceId', null)\r
57                 execution.setVariable('UPDVfModVol_aicCloudRegion', null)\r
58                 execution.setVariable('UPDVfModVol_tenantId', null)\r
59                 execution.setVariable('UPDVfModVol_volumeParams', null)\r
60                 execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', null)\r
61                 execution.setVariable('UPDVfModVol_volumeGroupTenantId', null)\r
62                 execution.setVariable('UpdateVfModuleVolumeSuccessIndicator', false)\r
63         }\r
64         \r
65 \r
66         /**\r
67          * Perform initial processing, such as request validation, initialization of variables, etc.\r
68          * * @param execution\r
69          */\r
70         public void preProcessRequest (Execution execution) {\r
71                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
72                 preProcessRequest(execution, isDebugEnabled)\r
73         }\r
74         \r
75         public void preProcessRequest(Execution execution, isDebugLogEnabled) {\r
76 \r
77                 initProcessVariables(execution)\r
78                 String jsonRequest = validateRequest(execution)\r
79                 \r
80                 def request = ""\r
81                 \r
82                 try {\r
83                         def jsonSlurper = new JsonSlurper()\r
84                         Map reqMap = jsonSlurper.parseText(jsonRequest)\r
85                         \r
86                         def serviceInstanceId = execution.getVariable('serviceInstanceId')\r
87                         def volumeGroupId = execution.getVariable('volumeGroupId')\r
88                         //def vnfId = execution.getVariable('vnfId')\r
89                         \r
90                         def vidUtils = new VidUtils(this)\r
91                         request = vidUtils.createXmlVolumeRequest(reqMap, 'UPDATE_VF_MODULE_VOL', serviceInstanceId, volumeGroupId)\r
92                         \r
93                         execution.setVariable('UPDVfModVol_Request', request)\r
94                         execution.setVariable("UPDVfModVol_isVidRequest", true)\r
95                         \r
96                         //need to get persona-model-id aka model-invariantId to use later to validate vf-module relation in AAI\r
97                         \r
98                         def modelInvariantId = reqMap.requestDetails.modelInfo.modelInvariantUuid ?: ''\r
99                         execution.setVariable('UPDVfModVol_modelInvariantId', modelInvariantId)\r
100                 \r
101                         utils.log("DEBUG", "modelInvariantId from request: " + modelInvariantId, isDebugLogEnabled)\r
102                         utils.log("DEBUG", "XML request:\n" + request, isDebugLogEnabled)\r
103                 }\r
104                 catch(groovy.json.JsonException je) {\r
105                         utils.log("DEBUG", " Request is in XML format.", isDebugLogEnabled)\r
106                         // assume request is in XML format - proceed as usual to process XML request\r
107                 }\r
108                 \r
109                 def requestId = execution.getVariable('mso-request-id')\r
110                 \r
111                 def requestInfo = getRequiredNodeXml(execution, request, 'request-info')\r
112                 execution.setVariable('UPDVfModVol_requestInfo', requestInfo)\r
113                 execution.setVariable('UPDVfModVol_requestId', requestId)\r
114                 //execution.setVariable('UPDVfModVol_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))\r
115                 execution.setVariable('UPDVfModVol_source', getNodeTextForce(requestInfo, 'source'))\r
116                 \r
117                 def volumeInputs = getRequiredNodeXml(execution, request, 'volume-inputs')\r
118                 execution.setVariable('UPDVfModVol_volumeInputs', volumeInputs)\r
119                 execution.setVariable('UPDVfModVol_volumeGroupId', getRequiredNodeText(execution, volumeInputs, 'volume-group-id'))\r
120                 execution.setVariable('UPDVfModVol_vnfType', getRequiredNodeText(execution, volumeInputs, 'vnf-type'))\r
121                 execution.setVariable('UPDVfModVol_vnfVersion', getRequiredNodeText(execution, volumeInputs, 'asdc-service-model-version'))\r
122                 execution.setVariable('UPDVfModVol_serviceId', utils.getNodeText1(volumeInputs, 'service-id'))\r
123                 execution.setVariable('UPDVfModVol_aicCloudRegion', getRequiredNodeText(execution, volumeInputs, 'aic-cloud-region'))\r
124                 execution.setVariable('UPDVfModVol_tenantId', getRequiredNodeText(execution, volumeInputs, 'tenant-id'))\r
125                 //execution.setVariable('UPDVfModVol_modelCustomizationId', getRequiredNodeText(execution, volumeInputs, 'model-customization-id'))\r
126 \r
127                 setBasicDBAuthHeader(execution, isDebugLogEnabled)\r
128                 \r
129                 def volumeParams = utils.getNodeXml(request, 'volume-params')\r
130                 execution.setVariable('UPDVfModVol_volumeParams', volumeParams)\r
131         }\r
132 \r
133         /**\r
134          * Prepare and send the synchronous response.\r
135          * \r
136          * @param execution The flow's execution instance.\r
137          */\r
138         public void sendSynchResponse(Execution execution, isDebugLogEnabled) {\r
139 \r
140                 def requestInfo = execution.getVariable('UPDVfModVol_requestInfo')\r
141                 def requestId = execution.getVariable('UPDVfModVol_requestId')\r
142                 def source = execution.getVariable('UPDVfModVol_source')\r
143                 def progress = getNodeTextForce(requestInfo, 'progress')\r
144                 if (progress.isEmpty()) {\r
145                         progress = '0'\r
146                 }\r
147                 def startTime = getNodeTextForce(requestInfo, 'start-time')\r
148                 if (startTime.isEmpty()) {\r
149                         startTime = System.currentTimeMillis()\r
150                 }\r
151                 def volumeInputs = execution.getVariable('UPDVfModVol_volumeInputs')\r
152                 \r
153                 String xmlSyncResponse = """\r
154                         <volume-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
155                                 <request-info>\r
156                                         <request-id>${requestId}</request-id>\r
157                                         <action>UPDATE_VF_MODULE_VOL</action>\r
158                                         <request-status>IN_PROGRESS</request-status>\r
159                                         <progress>${progress}</progress>\r
160                                         <start-time>${startTime}</start-time>\r
161                                         <source>${source}</source>\r
162                                 </request-info>\r
163                                 ${volumeInputs}\r
164                         </volume-request>\r
165                 """\r
166 \r
167                 def syncResponse = ''\r
168                 def isVidRequest = execution.getVariable('UPDVfModVol_isVidRequest')\r
169                 \r
170                 if(isVidRequest) {\r
171                         def volumeGroupId = execution.getVariable('volumeGroupId')\r
172                         syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()\r
173                 } \r
174                 else {\r
175                         syncResponse = utils.formatXml(xmlSyncResponse)\r
176                 }\r
177                 \r
178                 logDebug('Sync response: ' + syncResponse, isDebugLogEnabled)\r
179                 execution.setVariable('UPDVfModVol_syncResponseSent', true)\r
180                 sendWorkflowResponse(execution, 200, syncResponse)\r
181         }\r
182         \r
183         /**\r
184          * Prepare a Request for querying AAI for Volume Group information using the\r
185          * Volume Group Id and Aic Cloud Region.\r
186          * @param execution The flow's execution instance.\r
187          */\r
188         public void queryAAIForVolumeGroup(Execution execution, isDebugLogEnabled) {\r
189 \r
190                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')\r
191                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')\r
192 \r
193                 AaiUtil aaiUtil = new AaiUtil(this)\r
194                 String aaiEndpoint = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(execution)\r
195                 String queryAAIVolumeGroupRequest = aaiEndpoint + '/' + URLEncoder.encode(aicCloudRegion, "UTF-8") + "/volume-groups/volume-group/" + UriUtils.encode(volumeGroupId, "UTF-8")\r
196                 \r
197                 utils.logAudit('Query AAI volume group by ID: ' + queryAAIVolumeGroupRequest)\r
198                 logDebug('Query AAI volume group by ID: ' + queryAAIVolumeGroupRequest, isDebugLogEnabled)\r
199                 \r
200                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIVolumeGroupRequest)\r
201                 \r
202                 String returnCode = response.getStatusCode()\r
203                 String aaiResponseAsString = response.getResponseBodyAsString()\r
204                 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)\r
205                 \r
206                 utils.logAudit("AAI query volume group by id return code: " + returnCode)\r
207                 utils.logAudit("AAI query volume group by id response: " + aaiResponseAsString)\r
208                 \r
209                 logDebug("AAI Volume Group return code: " + returnCode, isDebugLogEnabled)\r
210                 logDebug("AAI Volume Group response: " + aaiResponseAsString, isDebugLogEnabled)\r
211                 \r
212                 ExceptionUtil exceptionUtil = new ExceptionUtil()\r
213                 \r
214                 if ((returnCode == '200') || (returnCode == '204')) {\r
215                         \r
216                         execution.setVariable('UPDVfModVol_aaiVolumeGroupResponse', aaiResponseAsString)\r
217                         //def heatStackId = getNodeTextForce(aaiResponseAsString, 'heat-stack-id')\r
218                         //execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', heatStackId)\r
219                         \r
220                         def volumeGroupTenantId = getTenantIdFromVolumeGroup(aaiResponseAsString)\r
221                         if (volumeGroupTenantId == null) {\r
222                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Could not find Tenant Id element in Volume Group with Volume Group Id " + volumeGroupId\r
223                                         + ", AIC Cloud Region " + aicCloudRegion)\r
224                         }\r
225                         execution.setVariable('UPDVfModVol_volumeGroupTenantId', volumeGroupTenantId)\r
226                         logDebug("Received Tenant Id " + volumeGroupTenantId + " from AAI for Volume Group with Volume Group Id " + volumeGroupId + ", AIC Cloud Region " + aicCloudRegion, isDebugLogEnabled)\r
227 \r
228                         def relatedVfModuleLink = getRelatedVfModuleRelatedLink(aaiResponseAsString)\r
229                         logDebug("Related VF Module link: " + relatedVfModuleLink, isDebugLogEnabled)\r
230                         execution.setVariable('UPDVfModVol_relatedVfModuleLink', relatedVfModuleLink)\r
231                         \r
232                 } \r
233                 else if (returnCode == '404') {\r
234                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Volume Group " + volumeGroupId + " not found at AAI")\r
235                 } \r
236                 else {\r
237                         WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)\r
238                         throw new BpmnError("MSOWorkflowException")\r
239                 }\r
240         }\r
241         \r
242         /**\r
243          * Query AAI service instance\r
244          * @param execution\r
245          * @param isDebugEnabled\r
246          */\r
247         public void queryAAIForGenericVnf(Execution execution, isDebugEnabled) {\r
248                 \r
249                 def vnfId = execution.getVariable('vnfId')\r
250                 \r
251                 AaiUtil aaiUtil = new AaiUtil(this)\r
252                 String aaiEndpoint = aaiUtil.getNetworkGenericVnfEndpoint(execution)\r
253                 def String queryAAIRequest = aaiEndpoint + "/" + UriUtils.encode(vnfId, "UTF-8")\r
254                 \r
255                 utils.logAudit("AAI query generic vnf request: " + queryAAIRequest)\r
256                 \r
257                 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)\r
258                 \r
259                 String returnCode = response.getStatusCode()\r
260                 String aaiResponseAsString = response.getResponseBodyAsString()\r
261                 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)\r
262                 \r
263                 utils.logAudit("AAI query generic vnf return code: " + returnCode)\r
264                 utils.logAudit("AAI query generic vnf response: " + aaiResponseAsString)\r
265 \r
266                 ExceptionUtil exceptionUtil = new ExceptionUtil()\r
267                 \r
268                 if (returnCode=='200') {\r
269                         utils.log("DEBUG", 'Generic vnf ' + vnfId + ' found in AAI.', isDebugEnabled)\r
270                         execution.setVariable('UPDVfModVol_AAIQueryGenericVfnResponse', aaiResponseAsString)\r
271                 } else {\r
272                         if (returnCode=='404') {\r
273                                 def message = 'Generic vnf ' + vnfId + ' was not found in AAI. Return code: 404.'\r
274                                 utils.log("DEBUG", message, isDebugEnabled)\r
275                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)\r
276                         } else {\r
277                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)\r
278                                 throw new BpmnError("MSOWorkflowException")\r
279                         }\r
280                 }\r
281         }\r
282         \r
283         /**\r
284          * Query AAI for VF Module using vf-module-id\r
285          * @param execution\r
286          * @param isDebugLogEnabled\r
287          */\r
288         public void queryAAIForVfModule(Execution execution, isDebugLogEnabled) {\r
289                 \r
290                         AaiUtil aaiUtil = new AaiUtil(this)\r
291                         String queryAAIVfModuleRequest = execution.getVariable('UPDVfModVol_relatedVfModuleLink')\r
292                         execution.setVariable('UPDVfModVol_personaModelId', '')\r
293                         \r
294                         utils.logAudit('Query AAI VF Module: ' + queryAAIVfModuleRequest)\r
295                         logDebug('Query AAI VF Module: ' + queryAAIVfModuleRequest, isDebugLogEnabled)\r
296                         \r
297                         def aaiUrl = execution.getVariable("URN_aai_endpoint")\r
298                         logDebug('A&AI URL: ' + aaiUrl, isDebugLogEnabled)\r
299                         \r
300                         def requestEndpoint = aaiUrl + queryAAIVfModuleRequest\r
301                         logDebug('A&AI request endpoint: ' + requestEndpoint, isDebugLogEnabled)\r
302                         \r
303                         APIResponse response = aaiUtil.executeAAIGetCall(execution, requestEndpoint)\r
304                         \r
305                         String returnCode = response.getStatusCode()\r
306                         String aaiResponseAsString = response.getResponseBodyAsString()\r
307                         aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)\r
308                         \r
309                         utils.logAudit("AAI query vf-module: " + returnCode)\r
310                         utils.logAudit("AAI query vf-module response: " + aaiResponseAsString)\r
311                         \r
312                         logDebug("AAI query vf-module:: " + returnCode, isDebugLogEnabled)\r
313                         logDebug("AAI query vf-module response: " + aaiResponseAsString, isDebugLogEnabled)\r
314                         \r
315                         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
316                         \r
317                         if ((returnCode == '200') || (returnCode == '204')) {\r
318                                 def personaModelId =  utils.getNodeText1(aaiResponseAsString, 'model-invariant-id')\r
319                                 if(personaModelId == null) {\r
320                                         //check old attribute name\r
321                                         personaModelId =  utils.getNodeText1(aaiResponseAsString, 'persona-model-id')\r
322                                 }\r
323                                 logDebug("vfModule personaModelId: " + personaModelId, isDebugLogEnabled)\r
324                                 execution.setVariable('UPDVfModVol_personaModelId', personaModelId)\r
325                         }\r
326                         else if (returnCode == '404') {\r
327                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "VF Module not found at AAI")\r
328                         }\r
329                         else {\r
330                                 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)\r
331                                 throw new BpmnError("MSOWorkflowException")\r
332                         }\r
333                 }\r
334         /**\r
335          * \r
336          */\r
337         public String getRelatedVfModuleRelatedLink(xml) {\r
338                 def list = new XmlSlurper().parseText(xml)\r
339                 def vfModuleRelationship = list.'**'.find { node -> node.'related-to'.text() == 'vf-module'     }\r
340                 return vfModuleRelationship?.'related-link'?.text() ?: ''\r
341         }\r
342         \r
343         /**\r
344          * Prepare a Request for invoking the VnfAdapterRest subflow to do\r
345          * a Volume Group update.\r
346          *\r
347          * @param execution The flow's execution instance.\r
348          */\r
349         public void prepVnfAdapterRest(Execution execution, isDebugLogEnabled) {\r
350                 \r
351                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')\r
352                 def tenantId = execution.getVariable('UPDVfModVol_tenantId')\r
353                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')\r
354                 \r
355                 def aaiVolumeGroupResponse = execution.getVariable('UPDVfModVol_aaiVolumeGroupResponse')\r
356                 def volumeGroupHeatStackId = getNodeTextForce(aaiVolumeGroupResponse, 'heat-stack-id')\r
357                 def volumeGroupName = getNodeTextForce(aaiVolumeGroupResponse, 'volume-group-name')\r
358                 def modelCustomizationId = getNodeTextForce(aaiVolumeGroupResponse, 'vf-module-model-customization-id')\r
359                 if(modelCustomizationId == null) {\r
360                         // Check old attribute name\r
361                         modelCustomizationId = getNodeTextForce(aaiVolumeGroupResponse, 'vf-module-persona-model-customization-id')\r
362                 }\r
363                 \r
364                 def vnfType = execution.getVariable('UPDVfModVol_vnfType')\r
365                 def vnfVersion = execution.getVariable('UPDVfModVol_vnfVersion')\r
366                 \r
367                 def aaiGenericVnfResponse = execution.getVariable('UPDVfModVol_AAIQueryGenericVfnResponse')\r
368                 def vnfId = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-id')\r
369                 def vnfName = utils.getNodeText1(aaiGenericVnfResponse, 'vnf-name')\r
370 \r
371                 \r
372                 def volumeParamsXml = execution.getVariable('UPDVfModVol_volumeParams')\r
373                 def volumeGroupParams = transformVolumeParamsToEntries(volumeParamsXml)\r
374                 \r
375                 def requestId = execution.getVariable('UPDVfModVol_requestId')\r
376                 def serviceId = execution.getVariable('UPDVfModVol_serviceId')\r
377                 \r
378                 def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()\r
379                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)\r
380                 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")\r
381                 if ('true'.equals(useQualifiedHostName)) {\r
382                                 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)\r
383                 }\r
384 \r
385                 String vnfAdapterRestRequest = """\r
386                         <updateVolumeGroupRequest>\r
387                                 <cloudSiteId>${aicCloudRegion}</cloudSiteId>\r
388                                 <tenantId>${tenantId}</tenantId>\r
389                                 <vnfId>${vnfId}</vnfId>\r
390                                 <vnfName>${vnfName}</vnfName>\r
391                                 <volumeGroupId>${volumeGroupId}</volumeGroupId>\r
392                                 <volumeGroupName>${volumeGroupName}</volumeGroupName>\r
393                                 <volumeGroupStackId>${volumeGroupHeatStackId}</volumeGroupStackId>\r
394                                 <vnfType>${vnfType}</vnfType>\r
395                                 <vnfVersion>${vnfVersion}</vnfVersion>\r
396                                 <vfModuleType></vfModuleType>\r
397                                 <modelCustomizationUuid>${modelCustomizationId}</modelCustomizationUuid>\r
398                                 <volumeGroupParams>\r
399                                         <entry>\r
400                                                 <key>vnf_id</key>\r
401                                                 <value>${vnfId}</value>\r
402                                         </entry>\r
403                                         <entry>\r
404                                                 <key>vnf_name</key>\r
405                                                 <value>${vnfName}</value>\r
406                                         </entry>\r
407                                         <entry>\r
408                                                 <key>vf_module_id</key>\r
409                                                 <value>${volumeGroupId}</value>\r
410                                         </entry>\r
411                                         <entry>\r
412                                                 <key>vf_module_name</key>\r
413                                                 <value>${volumeGroupName}</value>\r
414                                         </entry>\r
415                                         ${volumeGroupParams}\r
416                             </volumeGroupParams>\r
417                                 <skipAAI>true</skipAAI>\r
418                             <msoRequest>\r
419                                 <requestId>${requestId}</requestId>\r
420                                 <serviceInstanceId>${serviceId}</serviceInstanceId>\r
421                             </msoRequest>\r
422                             <messageId>${messageId}</messageId>\r
423                             <notificationUrl>${notificationUrl}</notificationUrl>\r
424                         </updateVolumeGroupRequest>\r
425                 """\r
426                 vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)\r
427                 execution.setVariable('UPDVfModVol_vnfAdapterRestRequest', vnfAdapterRestRequest)\r
428                 logDebug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest, isDebugLogEnabled)\r
429         }\r
430         \r
431         /**\r
432          * Prepare a Request for updating the DB for this Infra request.\r
433          *\r
434          * @param execution The flow's execution instance.\r
435          */\r
436         public void prepDbInfraDbRequest(Execution execution, isDebugLogEnabled) {\r
437 \r
438                 def requestId = execution.getVariable('UPDVfModVol_requestId')\r
439                 ExceptionUtil exceptionUtil = new ExceptionUtil();\r
440                 \r
441                 String updateInfraRequest = """\r
442                         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
443                                         xmlns:req="http://org.openecomp.mso/requestsdb">\r
444                                 <soapenv:Header/>\r
445                                 <soapenv:Body>\r
446                                         <req:updateInfraRequest>\r
447                                                 <requestId>${requestId}</requestId>\r
448                                                 <lastModifiedBy>BPEL</lastModifiedBy>\r
449                                                 <requestStatus>COMPLETE</requestStatus>\r
450                                                 <progress>100</progress>\r
451                                         </req:updateInfraRequest>\r
452                                 </soapenv:Body>\r
453                         </soapenv:Envelope>\r
454                 """\r
455 \r
456                 updateInfraRequest = utils.formatXml(updateInfraRequest)\r
457                 execution.setVariable('UPDVfModVol_updateInfraRequest', updateInfraRequest)\r
458                 logDebug('Request for Update Infra Request:\n' + updateInfraRequest, isDebugLogEnabled)\r
459         }\r
460         \r
461         /**\r
462          * Build a "CompletionHandler" request.\r
463          * @param execution The flow's execution instance.\r
464          */\r
465         public void prepCompletionHandlerRequest(Execution execution, requestId, action, source, isDebugLogEnabled) {\r
466 \r
467                 String content = """\r
468                 <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
469                                         xmlns:ns="http://org.openecomp/mso/request/types/v1">\r
470                         <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
471                                 <request-id>${requestId}</request-id>\r
472                                 <action>UPDATE</action>\r
473                                 <source>${source}</source>\r
474                         </request-info>\r
475                         <aetgt:mso-bpel-name>BPMN VF Module Volume action: UPDATE</aetgt:mso-bpel-name>\r
476                 </aetgt:MsoCompletionRequest>           \r
477                 """\r
478 \r
479                 content = utils.formatXml(content)\r
480                 logDebug('Request for Completion Handler:\n' + content, isDebugLogEnabled)\r
481                 execution.setVariable('UPDVfModVol_CompletionHandlerRequest', content)\r
482         }\r
483         \r
484 \r
485         /**\r
486          * Build a "FalloutHandler" request.\r
487          * @param execution The flow's execution instance.\r
488          */\r
489         public void prepFalloutHandler(Execution execution, isDebugLogEnabled) {\r
490                 def requestId = execution.getVariable('UPDVfModVol_requestId')\r
491                 def source = execution.getVariable('UPDVfModVol_source')\r
492                 \r
493                 String requestInfo = """\r
494                 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
495                 <request-id>${requestId}</request-id>\r
496                 <action>UPDATE</action>\r
497                 <source>${source}</source>\r
498            </request-info>"""\r
499                 \r
500                 def WorkflowException workflowException = execution.getVariable("WorkflowException")\r
501                 def errorResponseCode = workflowException.getErrorCode()\r
502                 def errorResponseMsg = workflowException.getErrorMessage()\r
503                 def encErrorResponseMsg = ""\r
504                 if (errorResponseMsg != null) {\r
505                         encErrorResponseMsg = errorResponseMsg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")\r
506                 }\r
507 \r
508                 String content = """\r
509                         <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
510                                         xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
511                                         xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
512                                         xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">                           \r
513                                 ${requestInfo}\r
514                                 <sdncadapterworkflow:WorkflowException>\r
515                                         <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>\r
516                                         <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>\r
517                                 </sdncadapterworkflow:WorkflowException>        \r
518                         </sdncadapterworkflow:FalloutHandlerRequest>\r
519                 """\r
520                 content = utils.formatXml(content)\r
521                 logDebug('Request for Fallout Handler:\n' + content, isDebugLogEnabled)\r
522                 execution.setVariable('UPDVfModVol_FalloutHandlerRequest', content)\r
523         }\r
524         \r
525         /**\r
526          * Create a WorkflowException for the error case where the Tenant Id from\r
527          * AAI did not match the Tenant Id in the incoming request.\r
528          * @param execution The flow's execution instance.\r
529          */\r
530         public void handleTenantIdMismatch(Execution execution, isDebugLogEnabled) {\r
531                 \r
532                 def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')\r
533                 def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')\r
534                 def tenantId = execution.getVariable('UPDVfModVol_tenantId')\r
535                 def volumeGroupTenantId = execution.getVariable('UPDVfModVol_volumeGroupTenantId')\r
536                 \r
537                 def String errorMessage = "TenantId " + tenantId + " in incoming request does not match Tenant Id " + volumeGroupTenantId +\r
538                         " retrieved from AAI for Volume Group Id " + volumeGroupId + ", AIC Cloud Region " + aicCloudRegion \r
539                 \r
540                 ExceptionUtil exceptionUtil = new ExceptionUtil()\r
541                 logError('Error in UpdateVfModuleVol: ' + errorMessage)\r
542                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)\r
543         }\r
544         \r
545         /**\r
546          * Create a WorkflowException for the error case where the Personal Model Id from\r
547          * AAI did not match the model invariant ID in the incoming request.\r
548          * @param execution The flow's execution instance.\r
549          */\r
550         public void handlePersonaModelIdMismatch(Execution execution, isDebugLogEnabled) {\r
551                 \r
552                 def modelInvariantId = execution.getVariable('UPDVfModVol_modelInvariantId')\r
553                 def personaModelId = execution.getVariable('UPDVfModVol_personaModelId')\r
554                 \r
555                 def String errorMessage = "Model Invariant ID " + modelInvariantId + " in incoming request does not match persona model ID " + personaModelId +\r
556                         " retrieved from AAI for Volume Group Id "\r
557                 \r
558                 ExceptionUtil exceptionUtil = new ExceptionUtil()\r
559                 logError('Error in UpdateVfModuleVol: ' + errorMessage)\r
560                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)\r
561         }\r
562         \r
563 }\r