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
|
/*-
* ============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 org.onap.so.logger.LoggingAnchor
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
import org.onap.so.bpmn.common.scripts.ExceptionUtil;
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.client.aai.AAIObjectType
import org.onap.so.client.aai.entities.uri.AAIResourceUri
import org.onap.so.client.aai.entities.uri.AAIUriFactory
import org.onap.so.logger.ErrorCode
import org.onap.so.logger.MessageEnum
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
class CreateVfModuleVolumeInfraV1 extends AbstractServiceTaskProcessor {
private static final Logger logger = LoggerFactory.getLogger( CreateVfModuleVolumeInfraV1.class);
public static final String prefix='CVMVINFRAV1_'
/**
* Perform initial processing, such as request validation, initialization of variables, etc.
* * @param execution
*/
public void preProcessRequest (DelegateExecution execution) {
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
setBasicDBAuthHeader(execution, isDebugEnabled)
preProcessRequest(execution, isDebugEnabled)
}
/**
* Perform initial processing, such as request validation, initialization of variables, etc.
* @param execution
* @param isDebugEnabled
*/
public void preProcessRequest (DelegateExecution execution, isDebugEnabled) {
execution.setVariable("prefix",prefix)
setSuccessIndicator(execution, false)
execution.setVariable(prefix+'syncResponseSent', false)
String createVolumeIncoming = validateRequest(execution, 'vnfId')
logger.debug(createVolumeIncoming)
try {
def jsonSlurper = new JsonSlurper()
Map reqMap = jsonSlurper.parseText(createVolumeIncoming)
setupVariables(execution, reqMap, isDebugEnabled)
logger.debug("XML request:\n" + createVolumeIncoming)
}
catch(groovy.json.JsonException je) {
(new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, 'Request is not a valid JSON document')
}
// For rollback in this flow
setBasicDBAuthHeader(execution, isDebugEnabled)
setRollbackEnabled(execution, isDebugEnabled)
}
/**
* Set up variables that will be passed to the BB DoCreatevfModuleVolume flow
* @param execution
* @param requestMap
* @param serviceInstanceId
* @param isDebugLogEnabled
*/
public void setupVariables(DelegateExecution execution, Map requestMap, isDebugLogEnabled) {
def jsonOutput = new JsonOutput()
// volumeGroupId - is generated
String volumeGroupId = UUID.randomUUID()
execution.setVariable('volumeGroupId', volumeGroupId)
logger.debug("Generated volumeGroupId: " + volumeGroupId)
// volumeGroupName
def volGrpName = requestMap.requestDetails.requestInfo?.instanceName ?: ''
execution.setVariable('volumeGroupName', volGrpName)
// vfModuleModelInfo
def vfModuleModelInfo = jsonOutput.toJson(requestMap.requestDetails?.modelInfo)
execution.setVariable('vfModuleModelInfo', vfModuleModelInfo)
// lcpCloudRegonId
def lcpCloudRegionId = requestMap.requestDetails.cloudConfiguration.lcpCloudRegionId
execution.setVariable('lcpCloudRegionId', lcpCloudRegionId)
// cloudOwner
def cloudOwner = requestMap.requestDetails.cloudConfiguration.cloudOwner
execution.setVariable('cloudOwner', cloudOwner)
// tenant
def tenantId = requestMap.requestDetails.cloudConfiguration.tenantId
execution.setVariable('tenantId', tenantId)
// source
def source = requestMap.requestDetails.requestInfo.source
execution.setVariable(prefix+'source', source)
// vnfType and asdcServiceModelVersion
def serviceName = ''
def asdcServiceModelVersion = ''
def modelCustomizationName = ''
def relatedInstanceList = requestMap.requestDetails.relatedInstanceList
relatedInstanceList.each {
if (it.relatedInstance.modelInfo?.modelType == 'service') {
serviceName = it.relatedInstance.modelInfo?.modelName
asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
}
if (it.relatedInstance.modelInfo?.modelType == 'vnf') {
modelCustomizationName = it.relatedInstance.modelInfo?.modelCustomizationName
}
}
def vnfType = serviceName + '/' + modelCustomizationName
execution.setVariable('vnfType', vnfType)
execution.setVariable('asdcServiceModelVersion', asdcServiceModelVersion)
// vfModuleInputParams
def userParams = requestMap.requestDetails?.requestParameters?.userParams
Map<String, String> vfModuleInputMap = [:]
userParams.each { userParam ->
vfModuleInputMap.put(userParam.name, userParam.value.toString())
}
execution.setVariable('vfModuleInputParams', vfModuleInputMap)
// disableRollback (true or false)
def disableRollback = requestMap.requestDetails.requestInfo.suppressRollback
execution.setVariable('disableRollback', disableRollback)
logger.debug('disableRollback (suppressRollback) from request: ' + disableRollback)
}
public void sendSyncResponse (DelegateExecution execution, isDebugEnabled) {
def volumeGroupId = execution.getVariable('volumeGroupId')
def requestId = execution.getVariable("mso-request-id")
def serviceInstanceId = execution.getVariable("serviceInstanceId")
String syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()
logger.debug("Sync Response: " + "\n" + syncResponse)
sendWorkflowResponse(execution, 200, syncResponse)
execution.setVariable(prefix+'syncResponseSent', true)
}
public void sendSyncError (DelegateExecution execution, isDebugEnabled) {
WorkflowException we = execution.getVariable('WorkflowException')
def errorCode = we?.getErrorCode()
def errorMessage = we?.getErrorMessage()
//default to 400 since only invalid request will trigger this method
sendWorkflowResponse(execution, 400, errorMessage)
}
/**
* Create a WorkflowException
* @param execution
* @param isDebugEnabled
*/
public void buildWorkflowException(DelegateExecution execution, int errorCode, errorMessage, isDebugEnabled) {
logger.debug(errorMessage)
(new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
}
/**
* Build Infra DB Request
* @param execution
* @param isDebugEnabled
*/
public void prepareDbInfraSuccessRequest(DelegateExecution execution, isDebugEnabled) {
def dbVnfOutputs = execution.getVariable(prefix+'volumeOutputs')
def requestId = execution.getVariable('mso-request-id')
def statusMessage = "VolumeGroup successfully created."
def requestStatus = "COMPLETED"
def progress = "100"
/*
from: $gVolumeGroup/aai:volume-group-id/text()
to: vnfreq:volume-outputs/vnfreq:volume-group-id
*/
// for now assume, generated volumeGroupId is accepted
def volumeGroupId = execution.getVariable(prefix+'volumeGroupId')
String dbRequest =
"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
<requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
<lastModifiedBy>BPMN</lastModifiedBy>
<statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
<responseBody></responseBody>
<requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
<progress>${MsoUtils.xmlEscape(progress)}</progress>
<vnfOutputs>${MsoUtils.xmlEscape(dbVnfOutputs)}</vnfOutputs>
<volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
</ns:updateInfraRequest>
</soapenv:Body>
</soapenv:Envelope>"""
String buildDBRequestAsString = utils.formatXml(dbRequest)
execution.setVariable(prefix+"createDBRequest", buildDBRequestAsString)
logger.debug("DB Infra Request: " + buildDBRequestAsString)
}
/**
* Build CommpleteMsoProcess request
* @param execution
* @param isDebugEnabled
*/
public void postProcessResponse (DelegateExecution execution, isDebugEnabled) {
def dbReturnCode = execution.getVariable(prefix+'dbReturnCode')
def createDBResponse = execution.getVariable(prefix+'createDBResponse')
logger.debug('DB return code: ' + dbReturnCode)
logger.debug('DB response: ' + createDBResponse)
def requestId = execution.getVariable("mso-request-id")
def source = execution.getVariable(prefix+'source')
String msoCompletionRequest =
"""<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
xmlns:ns="http://org.onap/so/request/types/v1">
<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
<request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
<action>CREATE</action>
<source>${MsoUtils.xmlEscape(source)}</source>
</request-info>
<aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
<aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
</aetgt:MsoCompletionRequest>"""
String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
execution.setVariable(prefix+'Success', true)
execution.setVariable(prefix+'CompleteMsoProcessRequest', xmlMsoCompletionRequest)
logger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
}
public void prepareFalloutHandlerRequest(DelegateExecution execution, isDebugEnabled) {
WorkflowException we = execution.getVariable('WorkflowException')
def errorCode = we?.getErrorCode()
def errorMessage = we?.getErrorMessage()
def requestId = execution.getVariable("mso-request-id")
def source = execution.getVariable(prefix+'source')
String falloutHandlerRequest =
"""<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
xmlns:ns="http://org.onap/so/request/types/v1"
xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
<request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
<action>CREATE</action>
<source>${MsoUtils.xmlEscape(source)}</source>
</request-info>
<aetgt:WorkflowException>
<aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
<aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
</aetgt:WorkflowException>
</aetgt:FalloutHandlerRequest>"""
// Format Response
String xmlHandlerRequest = utils.formatXml(falloutHandlerRequest)
execution.setVariable(prefix+'FalloutHandlerRequest', xmlHandlerRequest)
logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Overall Error Response " +
"going to FalloutHandler", "BPMN", ErrorCode.UnknownError.getValue(), "\n" + xmlHandlerRequest);
}
/**
* Query AAI service instance
* @param execution
* @param isDebugEnabled
*/
public void callRESTQueryAAIServiceInstance(DelegateExecution execution, isDebugEnabled) {
def request = execution.getVariable(prefix+"Request")
def serviceInstanceId = utils.getNodeText(request, "service-instance-id")
ExceptionUtil exceptionUtil = new ExceptionUtil()
try {
AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE,serviceInstanceId)
if(getAAIClient().exists(uri)){
logger.debug('Service instance ' + serviceInstanceId + ' found in AAI.')
}else{
def message = 'Service instance ' + serviceInstanceId + ' was not found in AAI. Return code: 404.'
logger.debug(message)
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
}
}catch(BpmnError bpmnError){
throw bpmnError
}catch(Exception ex){
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, ex.getMessage())
}
}
public void logAndSaveOriginalException(DelegateExecution execution, isDebugLogEnabled) {
logWorkflowException(execution, 'CreateVfModuleVolumeInfraV1 caught an event')
saveWorkflowException(execution, 'CVMVINFRAV1_originalWorkflowException')
}
public void validateRollbackResponse(DelegateExecution execution, isDebugLogEnabled) {
def originalException = execution.getVariable("CVMVINFRAV1_originalWorkflowException")
execution.setVariable("WorkflowException", originalException)
execution.setVariable("RollbackCompleted", true)
}
}
|