1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.so.bpmn.infrastructure.scripts
import static org.apache.commons.lang.StringUtils.isEmpty
import org.apache.commons.collections.CollectionUtils
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.VolumeGroup
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.Relationships
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.logging.filter.base.ErrorCode
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.common.scripts.VfModuleBase
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.constants.Defaults
import org.onap.so.logger.MessageEnum
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class UpdateVfModuleVolume extends VfModuleBase {
private static final Logger logger = LoggerFactory.getLogger(UpdateVfModuleVolume.class)
ExceptionUtil exceptionUtil = new ExceptionUtil()
/**
* Initialize the flow's variables.
*
* @param execution The flow's execution instance.
*/
private void initProcessVariables(DelegateExecution execution) {
execution.setVariable('prefix', 'UPDVfModVol_')
execution.setVariable('UPDVfModVol_Request', null)
execution.setVariable('UPDVfModVol_requestInfo', null)
execution.setVariable('UPDVfModVol_requestId', null)
execution.setVariable('UPDVfModVol_source', null)
execution.setVariable('UPDVfModVol_volumeInputs', null)
execution.setVariable('UPDVfModVol_volumeGroupId', null)
execution.setVariable('UPDVfModVol_vnfType', null)
execution.setVariable('UPDVfModVol_serviceId', null)
execution.setVariable('UPDVfModVol_aicCloudRegion', null)
execution.setVariable('UPDVfModVol_tenantId', null)
execution.setVariable('UPDVfModVol_volumeParams', null)
execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', null)
execution.setVariable('UPDVfModVol_volumeGroupTenantId', null)
execution.setVariable('UpdateVfModuleVolumeSuccessIndicator', false)
}
/**
* Check for missing elements in the received request.
*
* @param execution The flow's execution instance.
*/
@Override
public void preProcessRequest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.preProcessRequest(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
initProcessVariables(execution)
String request = validateRequest(execution)
def requestInfo = getRequiredNodeXml(execution, request, 'request-info')
execution.setVariable('UPDVfModVol_requestInfo', requestInfo)
execution.setVariable('UPDVfModVol_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
execution.setVariable('UPDVfModVol_source', getNodeTextForce(requestInfo, 'source'))
def volumeInputs = getRequiredNodeXml(execution, request, 'volume-inputs')
execution.setVariable('UPDVfModVol_volumeInputs', volumeInputs)
execution.setVariable('UPDVfModVol_volumeGroupId', getRequiredNodeText(execution, volumeInputs, 'volume-group-id'))
execution.setVariable('UPDVfModVol_vnfType', getRequiredNodeText(execution, volumeInputs, 'vnf-type'))
execution.setVariable('UPDVfModVol_serviceId', getRequiredNodeText(execution, volumeInputs, 'service-id'))
execution.setVariable('UPDVfModVol_aicCloudRegion', getRequiredNodeText(execution, volumeInputs, 'aic-cloud-region'))
execution.setVariable('UPDVfModVol_cloudOwner', getRequiredNodeText(execution, volumeInputs, 'cloud-owner'))
execution.setVariable('UPDVfModVol_tenantId', getRequiredNodeText(execution, volumeInputs, 'tenant-id'))
def volumeParams = utils.getNodeXml(request, 'volume-params')
execution.setVariable('UPDVfModVol_volumeParams', volumeParams)
logger.trace('Exited {}', method)
logger.debug("UpdateVfModuleVolume request: {}", request)
} catch (BpmnError bpmnError) {
throw bpmnError
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
}
}
/**
* Prepare and send the synchronous response.
*
* @param execution The flow's execution instance.
*/
public void sendSynchResponse(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.sendSynchResponse(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def requestInfo = execution.getVariable('UPDVfModVol_requestInfo')
def requestId = execution.getVariable('UPDVfModVol_requestId')
def source = execution.getVariable('UPDVfModVol_source')
def progress = getNodeTextForce(requestInfo, 'progress')
if (progress.isEmpty()) {
progress = '0'
}
def startTime = getNodeTextForce(requestInfo, 'start-time')
if (startTime.isEmpty()) {
startTime = System.currentTimeMillis()
}
def volumeInputs = execution.getVariable('UPDVfModVol_volumeInputs')
String synchResponse = """
<volume-request xmlns="http://org.onap/so/infra/vnf-request/v1">
<request-info>
<request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
<action>UPDATE_VF_MODULE_VOL</action>
<request-status>IN_PROGRESS</request-status>
<progress>${MsoUtils.xmlEscape(progress)}</progress>
<start-time>${MsoUtils.xmlEscape(startTime)}</start-time>
<source>${MsoUtils.xmlEscape(source)}</source>
</request-info>
${volumeInputs}
</volume-request>
"""
synchResponse = utils.formatXml(synchResponse)
sendWorkflowResponse(execution, 200, synchResponse)
logger.debug("UpdateVfModuleVolume Synch Response: {}", synchResponse)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendSynchResponse(): ' + e.getMessage())
}
}
/**
* Prepare a Request for querying AAI for Volume Group information using the
* Volume Group Id and Aic Cloud Region.
*
* @param execution The flow's execution instance.
*/
public void queryAAIForVolumeGroup(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.queryAAIForVolumeGroup(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), aicCloudRegion).volumeGroup(volumeGroupId))
AAIResultWrapper wrapper = getAAIClient().get(uri)
Optional<VolumeGroup> volumeGroup = wrapper.asBean(VolumeGroup.class)
if(volumeGroup.isPresent()){
def heatStackId = volumeGroup.get().getHeatStackId()
execution.setVariable('UPDVfModVol_volumeGroupHeatStackId', heatStackId)
Optional<Relationships> relationships = wrapper.getRelationships()
if(relationships.isPresent()){
List<AAIResourceUri> resourceUriList = relationships.get().getRelatedUris(Types.TENANT)
if(CollectionUtils.isNotEmpty(resourceUriList)){
AAIResourceUri tenantUri = resourceUriList.get(0)
String volumeGroupTenantId = tenantUri.getURIKeys().get(AAIFluentTypeBuilder.Types.TENANT.getUriParams().tenantId)
if( isEmpty(volumeGroupTenantId)){
exceptionUtil.buildAndThrowWorkflowException(execution,2500,"Could not find Tenant Id element in Volume Group with Volume Group Id" + volumeGroupId + ", AIC Cloud Region" + aicCloudRegion)
}
execution.setVariable('UPDVfModVol_volumeGroupTenantId', volumeGroupTenantId)
logger.debug("Received Tenant Id: {} from AAI for Volume Group with Volume Group Id: {}, AIC Cloud Region",
volumeGroupTenantId, volumeGroupId, aicCloudRegion)
}else{
exceptionUtil.buildAndThrowWorkflowException(execution,2500,"Could not find Tenant Id element in Volume Group with Volume Group Id" + volumeGroupId + ", AIC Cloud Region" + aicCloudRegion)
}
}
}else{
exceptionUtil.buildAndThrowWorkflowException(execution,2500,"Volume Group" + volumeGroupId + " not found at AAI")
}
logger.trace('Exited {}', method)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVolumeGroup(): ' + e.getMessage())
}
}
/**
* Prepare a Request for invoking the VnfAdapterRest subflow to do
* a Volume Group update.
*
* @param execution The flow's execution instance.
*/
public void prepVnfAdapterRest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
def tenantId = execution.getVariable('UPDVfModVol_tenantId')
def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
def volumeGroupHeatStackId = execution.getVariable('UPDVfModVol_volumeGroupHeatStackId')
def vnfType = execution.getVariable('UPDVfModVol_vnfType')
def volumeParamsXml = execution.getVariable('UPDVfModVol_volumeParams')
def volumeGroupParams = transformParamsToEntries(volumeParamsXml)
def requestId = execution.getVariable('UPDVfModVol_requestId')
def serviceId = execution.getVariable('UPDVfModVol_serviceId')
def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
if ('true'.equals(useQualifiedHostName)) {
notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
}
String vnfAdapterRestRequest = """
<updateVolumeGroupRequest>
<cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
<cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
<tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
<volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
<volumeGroupStackId>${MsoUtils.xmlEscape(volumeGroupHeatStackId)}</volumeGroupStackId>
<vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
<vnfVersion></vnfVersion>
<vfModuleType></vfModuleType>
<volumeGroupParams>
${volumeGroupParams}
</volumeGroupParams>
<skipAAI>true</skipAAI>
<msoRequest>
<requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
<serviceInstanceId>${MsoUtils.xmlEscape(serviceId)}</serviceInstanceId>
</msoRequest>
<messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
<notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
</updateVolumeGroupRequest>
"""
vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
execution.setVariable('UPDVfModVol_vnfAdapterRestRequest', vnfAdapterRestRequest)
logger.debug('Request for VNFAdapter Rest:\n{}', vnfAdapterRestRequest)
logger.debug("UpdateVfModuleVolume Request for VNFAdapter Rest: {}", vnfAdapterRestRequest)
logger.trace('Exited {}', method)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
}
}
/**
* Prepare a Request for updating the DB for this Infra request.
*
* @param execution The flow's execution instance.
*/
public void prepDbInfraDbRequest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.prepDbInfraDbRequest(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def requestId = execution.getVariable('UPDVfMod_requestId')
String updateInfraRequest = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:req="http://org.onap.so/requestsdb">
<soapenv:Header/>
<soapenv:Body>
<req:updateInfraRequest>
<requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
<lastModifiedBy>BPEL</lastModifiedBy>
<requestStatus>COMPLETE</requestStatus>
<progress>100</progress>
</req:updateInfraRequest>
</soapenv:Body>
</soapenv:Envelope>
"""
updateInfraRequest = utils.formatXml(updateInfraRequest)
execution.setVariable('UPDVfModVol_updateInfraRequest', updateInfraRequest)
logger.debug('Request for Update Infra Request:\n{}', updateInfraRequest)
logger.debug("UpdateVfModuleVolume Request for Updating DB for Infra: {}", updateInfraRequest)
logger.trace('Exited {}', method)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildWorkflowException(execution, 1002, 'Error in prepDbInfraDbRequest(): ' + e.getMessage())
}
}
/**
* Build a "CompletionHandler" request.
*
* @param execution The flow's execution instance.
*/
public void prepCompletionHandlerRequest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.prepCompletionHandlerRequest(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def requestInfo = execution.getVariable('UPDVfModVol_requestInfo')
String content = """
<sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
xmlns:reqtype="http://org.onap/so/request/types/v1">
${requestInfo}
<sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
</sdncadapterworkflow:MsoCompletionRequest>
"""
content = utils.formatXml(content)
logger.debug('Request for Completion Handler:\n{}', content)
logger.debug("UpdateVfModuleVolume Completion Handler request: {}", content)
execution.setVariable('UPDVfModVol_CompletionHandlerRequest', content)
logger.trace('Exited {}', method)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepCompletionHandlerRequest(): ' + e.getMessage())
}
}
/**
* Build a "FalloutHandler" request.
*
* @param execution The flow's execution instance.
*/
public void prepFalloutHandler(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.prepFalloutHandler(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
try {
def requestInfo = execution.getVariable('UPDVfModVol_requestInfo')
def WorkflowException workflowException = execution.getVariable("WorkflowException")
def errorResponseCode = workflowException.getErrorCode()
def errorResponseMsg = workflowException.getErrorMessage()
def encErrorResponseMsg = ""
if (errorResponseMsg != null) {
encErrorResponseMsg = errorResponseMsg
}
String content = """
<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
xmlns:reqtype="http://org.onap/so/request/types/v1"
xmlns:msoservtypes="http://org.onap/so/request/types/v1"
xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
${requestInfo}
<sdncadapterworkflow:WorkflowException>
<sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
<sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
</sdncadapterworkflow:WorkflowException>
</sdncadapterworkflow:FalloutHandlerRequest>
"""
content = utils.formatXml(content)
logger.debug('Request for Fallout Handler:\n{}', content)
logger.debug("UpdateVfModuleVolume Fallout request: {}", content)
execution.setVariable('UPDVfModVol_FalloutHandlerRequest', content)
logger.trace('Exited {}', method)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
logger.error("{} {} Caught exception in {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), method, e)
exceptionUtil.buildWorkflowException(execution, 1002, 'Error in prepFalloutHandler(): ' + e.getMessage())
}
}
/**
* Create a WorkflowException for the error case where the Tenant Id from
* AAI did not match the Tenant Id in the incoming request.
*
* @param execution The flow's execution instance.
*/
public void handleTenantIdMismatch(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.handleTenantIdMismatch(' +
'execution=' + execution.getId() +
')'
logger.trace('Entered {}', method)
String processKey = getProcessKey(execution)
def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId')
def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion')
def tenantId = execution.getVariable('UPDVfModVol_tenantId')
def volumeGroupTenantId = execution.getVariable('UPDVfModVol_volumeGroupTenantId')
def String errorMessage = 'TenantId \'' + tenantId + '\' in incoming request does not match Tenant Id \'' + volumeGroupTenantId +
'\' retrieved from AAI for Volume Group Id \'' + volumeGroupId + '\', AIC Cloud Region \'' + aicCloudRegion + '\''
logger.error("{} {} Error in UpdateVfModuleVol: {}\n ", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
ErrorCode.UnknownError.getValue(), errorMessage)
WorkflowException exception = new WorkflowException(processKey, 5000, errorMessage)
execution.setVariable("WorkflowException", exception)
logger.trace('Exited ' + method)
logger.debug("UpdateVfModuleVolume workflowException in Tenant Mismatch: " + errorMessage)
}
}
|