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
459
460
461
462
463
464
465
466
467
468
469
470
471
|
/*-
* ============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 groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.client.aai.AAIValidatorImpl
import org.onap.so.client.appc.ApplicationControllerClient
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public class UpdateVfModuleInfraV2 {
private static final Logger logger = LoggerFactory.getLogger(UpdateVfModuleInfraV2.class)
ExceptionUtil exceptionUtil = new ExceptionUtil()
boolean preProcessRequestCheck = true;
boolean sendSynchResponseCheck = true;
boolean checkPserverFlagCheck = true;
boolean vfFlagCheckSetCheck = true;
boolean lockAppCCheck = true;
boolean healthDiagnosticSDNOCheck = true;
boolean healthCheckAppCCheck = true;
boolean stopVfModuleControllerCheck = true;
boolean healthCheckControllerCheck = true;
boolean doUpdateVfModulePrepCheck = true;
boolean completionHandlerPrepCheck = true;
boolean startVfModuleControllerCheck = true;
boolean vFFlagUnsetCheck = true;
boolean unlockAppCCheck = true;
boolean postUpgradeHealthCheckControllerCheck = true;
public void initProcessVariables(DelegateExecution execution) {
execution.setVariable('prefix', 'UPDVfModI_')
execution.setVariable('UPDVfModI_Request', null)
execution.setVariable('UPDVfModI_requestInfo', null)
execution.setVariable('UPDVfModI_requestId', null)
execution.setVariable('UPDVfModI_source', null)
execution.setVariable('UPDVfModI_vnfInputs', null)
execution.setVariable('UPDVfModI_vnfId', null)
execution.setVariable('UPDVFModI_moduleUuid', null)
execution.setVariable('UPDVfModI_vfModuleId', null)
execution.setVariable('UPDVfModI_tenantId', null)
execution.setVariable('UPDVfModI_volumeGroupId', null)
execution.setVariable('UPDVfModI_vnfParams', null)
execution.setVariable('UPDVfModI_updateInfraRequest', null)
execution.setVariable('UpdateVfModuleSuccessIndicator', false)
}
/**
* Check for missing elements in the received request.
*
* @param execution The flow's execution instance.
*/
public void preProcessRequest(DelegateExecution execution) {
logger.debug("*****************************PreProcessRequest**************************")
def method = getClass().getSimpleName() + '.preProcessRequest(' +
'execution=' + execution.getId() +
')'
//logger.trace('Entered ' + method)
initProcessVariables(execution)
def prefix = "UPDVfModI_"
def incomingRequest = execution.getVariable('bpmnRequest')
//logger.debug("Incoming Infra Request: " + incomingRequest)
try {
def jsonSlurper = new JsonSlurper()
def jsonOutput = new JsonOutput()
Map reqMap = jsonSlurper.parseText(incomingRequest)
//logger.debug(" Request is in JSON format.")
def serviceInstanceId = execution.getVariable('serviceInstanceId')
def vnfId = execution.getVariable('vnfId')
def moduleUuid = execution.getVariable('moduleUuid')
execution.setVariable(prefix + 'moduleUuid',moduleUuid)
execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
execution.setVariable(prefix+'vnfId', vnfId)
execution.setVariable("isVidRequest", "true")
def vnfName = ''
def asdcServiceModelVersion = ''
def serviceModelInfo = null
def vnfModelInfo = null
def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
if (relatedInstanceList != null) {
relatedInstanceList.each {
if (it.relatedInstance.modelInfo?.modelType == 'service') {
asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
}
if (it.relatedInstance.modelInfo.modelType == 'vnf') {
vnfName = it.relatedInstance.instanceName ?: ''
vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
}
}
}
execution.setVariable(prefix + 'vnfName', vnfName)
execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
def vnfType = execution.getVariable('vnfType')
execution.setVariable(prefix + 'vnfType', vnfType)
def vfModuleId = execution.getVariable('vfModuleId')
execution.setVariable(prefix + 'vfModuleId', vfModuleId)
def volumeGroupId = execution.getVariable('volumeGroupId')
execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
def userParams = reqMap.requestDetails?.requestParameters?.userParams
Map<String, String> userParamsMap = [:]
if (userParams != null) {
userParams.each { userParam ->
userParamsMap.put(userParam.name, userParam.value.toString())
}
}
//logger.debug('Processed user params: ' + userParamsMap)
execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
def isBaseVfModule = "false"
if (execution.getVariable('isBaseVfModule') == true) {
isBaseVfModule = "true"
}
execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
def requestId = execution.getVariable("mso-request-id")
execution.setVariable(prefix + 'requestId', requestId)
def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
def backoutOnFailure = ""
if(suppressRollback != null){
if ( suppressRollback == true) {
backoutOnFailure = "false"
} else if ( suppressRollback == false) {
backoutOnFailure = "true"
}
}
execution.setVariable('disableRollback', suppressRollback)
def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
execution.setVariable(prefix + 'vfModuleName', vfModuleName)
def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
execution.setVariable(prefix + 'serviceId', serviceId)
def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
execution.setVariable(prefix + 'usePreload', usePreload)
def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
def cloudOwner = cloudConfiguration.cloudOwner
execution.setVariable(prefix + 'cloudOwner', cloudOwner)
def tenantId = cloudConfiguration.tenantId
execution.setVariable(prefix + 'tenantId', tenantId)
def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
execution.setVariable(prefix + 'sdncVersion', '1702')
execution.setVariable("UpdateVfModuleInfraSuccessIndicator", false)
def source = reqMap.requestDetails?.requestInfo?.source
execution.setVariable(prefix + "source", source)
//For Completion Handler & Fallout Handler
String requestInfo =
"""<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
<request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
<action>UPDATE</action>
<source>${MsoUtils.xmlEscape(source)}</source>
</request-info>"""
execution.setVariable(prefix + "requestInfo", requestInfo)
//backoutOnFailure
//logger.debug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"))
//logger.trace('Exited ' + method)
}
catch(groovy.json.JsonException je) {
//logger.debug(" Request is not in JSON format.")
exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
}
catch(Exception e) {
String restFaultMessage = e.getMessage()
//logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
}
}
/**
* Prepare and send the synchronous response for this flow.
*
* @param execution The flow's execution instance.
*/
public void sendSynchResponse(DelegateExecution execution) {
logger.debug("*****************************SendSynchResponse**************************")
def method = getClass().getSimpleName() + '.sendSynchResponse(' +
'execution=' + execution.getId() +
')'
//logger.trace('Entered ' + method)
try {
def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
def requestId = execution.getVariable('UPDVfModI_requestId')
def source = execution.getVariable('UPDVfModI_source')
def progress = getNodeTextForce(requestInfo, 'progress')
if (progress.isEmpty()) {
progress = '0'
}
def startTime = getNodeTextForce(requestInfo, 'start-time')
if (startTime.isEmpty()) {
startTime = System.currentTimeMillis()
}
// RESTResponse (for API Handler (APIH) Reply Task)
def vfModuleId = execution.getVariable("vfModuleId")
String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
sendWorkflowResponse(execution, 200, synchResponse)
//logger.trace('Exited ' + method)
} catch (BpmnError e) {
throw e;
} catch (Exception e) {
//logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
}
}
//check to see if the Pserver Flag is locked
public void checkPserverFlag(DelegateExecution execution) {
logger.debug("*****************************CheckingPserverFlag*************************")
String vnfId = (String)execution.getVariable('vnfId')
AAIValidatorImpl aaiVI = new AAIValidatorImpl()
boolean flag = aaiVI.isPhysicalServerLocked(vnfId)
}
//check to see if the VFFlag is locked
public void vfFlagCheck(DelegateExecution execution) {
logger.debug("*****************************VfFlagCheck*************************")
String vnfId = (String)execution.getVariable('vnfId')
AAIValidatorImpl aaiVI = new AAIValidatorImpl()
boolean flag = aaiVI.isVNFLocked(vnfId)
}
//lock the VF Flag
public void vfFlagSet(DelegateExecution execution) {
logger.debug("*****************************VfFlagSet*************************")
String vnfId = (String)execution.getVariable('vnfId')
String uuid = (String)execution.getVariable('moduleUuid')
AAIValidatorImpl aaiVI = new AAIValidatorImpl()
aaiVI.updateVnfToLocked(vnfId,uuid);
}
//Lock AppC
public void lockAppC(DelegateExecution execution) {
logger.debug("*****************************lockAppC*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("Lock",vfModuleId)
}
//run health check
public void healthCheckAppC(DelegateExecution execution) {
logger.debug("*****************************healthCheckAppC*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("HealthCheck",vfModuleId)
}
//SDNO health diagnostic
public void healthDiagnosticSDNO(DelegateExecution execution) {
logger.debug("*****************************healthDiagnosticSDNO is currently ignored*************************")
//SDNOValidatorImpl.healthDiagnostic("","");
}
//stop VF module controller
public void stopVfModuleController(DelegateExecution execution) {
logger.debug("*****************************stopVfModuleController*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("Stop",vfModuleId)
}
public void doUpdateVfModulePrep(DelegateExecution execution) {
logger.debug("*****************************doUpdateVfModulePrep*************************")
def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
'execution=' + execution.getId() +
')'
//logger.trace('Entered ' + method)
try {
//logger.trace('Exited ' + method)
} catch (BpmnError e) {
throw e;
} catch (Exception e) {
//logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
}
}
public void completionHandlerPrep(DelegateExecution execution,String resultVar) {
logger.debug("*****************************completionHandlerPrep*************************")
def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
'execution=' + execution.getId() +
', resultVar=' + resultVar +
')'
//logger.trace('Entered ' + method)
try {
def requestInfo = getVariable(execution, 'UPDVfModI_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(resultVar + ' = ' + System.lineSeparator() + content)
execution.setVariable(resultVar, content)
//logger.trace('Exited ' + method)
} catch (BpmnError e) {
throw e;
} catch (Exception e) {
//logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
}
}
public void healthCheckController(DelegateExecution execution) {
logger.debug("*****************************healthCheckController*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("HealthCheck",vfModuleId)
}
public void startVfModuleController(DelegateExecution execution) {
logger.debug("*****************************startVfModuleController*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("Start",vfModuleId)
}
public void vFFlagUnset(DelegateExecution execution) {
logger.debug("*****************************vFFlagUnset*************************")
String vnfId = (String)execution.getVariable('vnfId')
String uuid = (String)execution.getVariable('moduleUuid')
AAIValidatorImpl aaiVI = new AAIValidatorImpl()
aaiVI.updateVnfToUnLocked(vnfId,uuid);
}
public void unlockAppC(DelegateExecution execution) {
logger.debug("*****************************unlockAppC*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("Unlock",vfModuleId)
}
public void postUpgradeHealthCheckController(DelegateExecution execution) {
logger.debug("*****************************postUpgradeHealthCheckController*************************")
def vfModuleId = ""
ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
def status = aCC.runCommand("HealthCheck",vfModuleId)
}
Properties getLCMProperties() {
Properties properties = new Properties()
properties.put("topic.read", UrnPropertiesReader.getVariable("appc.client.topic.read.name"))
properties.put("topic.read.timeout", UrnPropertiesReader.getVariable("appc.client.topic.read.timeout"))
properties.put("client.response.timeout", UrnPropertiesReader.getVariable("appc.client.response.timeout"))
properties.put("topic.write", UrnPropertiesReader.getVariable("appc.client.topic.write"))
properties.put("poolMembers", UrnPropertiesReader.getVariable("appc.client.poolMembers"))
properties.put("client.key", UrnPropertiesReader.getVariable("appc.client.key"))
properties.put("client.secret", UrnPropertiesReader.getVariable("appc.client.secret"))
properties.put("client.name", "MSO")
properties.put("service", UrnPropertiesReader.getVariable("appc.client.service"))
return properties
}
}
|