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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
/*-
* ============LICENSE_START=======================================================
* OPENECOMP - SO
* ================================================================================
* Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
* ================================================================================
* 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.json.JSONArray
import org.json.JSONObject
import org.json.XML
import static org.apache.commons.lang3.StringUtils.*
import groovy.xml.XmlUtil
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
import org.onap.so.bpmn.common.scripts.AaiUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.aai.domain.yang.SpPartner
import org.onap.so.bpmn.common.recipe.ResourceInput
import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
import org.onap.so.client.aai.AAIObjectType
import org.onap.so.client.aai.AAIResourcesClient
import org.onap.so.client.aai.entities.uri.AAIResourceUri
import org.onap.so.client.aai.entities.uri.AAIUriFactory
import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
import java.util.Map
import java.util.UUID
import javax.ws.rs.core.Response
import org.onap.so.logger.MsoLogger
import org.camunda.bpm.engine.runtime.Execution
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.apache.commons.lang3.*
import org.apache.commons.codec.binary.Base64
import org.springframework.web.util.UriUtils
/**
* This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
* flow for Create E2EServiceInstance in 3rdONAP
*/
public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
String Prefix = "CRE3rdONAPESI_"
ExceptionUtil exceptionUtil = new ExceptionUtil()
JsonUtils jsonUtil = new JsonUtils()
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, Create3rdONAPE2EServiceInstance.class)
public void checkSPPartnerInfo (DelegateExecution execution) {
msoLogger.info(" ***** Started checkSPPartnerInfo *****")
try {
//get bpmn inputs from resource request.
String requestId = execution.getVariable("mso-request-id")
String requestAction = execution.getVariable("requestAction")
msoLogger.info("The requestAction is: " + requestAction)
String recipeParamsFromRequest = execution.getVariable("recipeParams")
msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
String resourceInput = execution.getVariable("resourceInput")
msoLogger.info("The resourceInput is: " + resourceInput)
//Get ResourceInput Object
ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
String resourceInputPrameters = resourceInputObj.getResourceParameters()
String inputParametersJson = JsonUtils.getJsonValue(resourceInputPrameters, "requestInputs")
JSONObject inputParameters = new JSONObject(inputParametersJson)
// set local resourceInput
execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
boolean is3rdONAPExist = false
if(inputParameters.has("sppartner_url"))
{
String sppartnerUrl = inputParameters.get("sppartner_url")
if(!isBlank(sppartnerUrl)) {
execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
is3rdONAPExist = true
}
else {
is3rdONAPExist = false
String msg = "sppartner Url is blank."
msoLogger.debug(msg)
}
}
if(inputParameters.has("sppartner_providingServiceUuid"))
{
String sppartnerUUID= inputParameters.get("sppartner_providingServiceUuid")
execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
is3rdONAPExist = true
}
else {
is3rdONAPExist = false
String msg = "sppartner providingServiceUuid is blank."
msoLogger.debug(msg)
}
if(inputParameters.has("sppartner_providingServiceInvariantUuid"))
{
String sppartnerInvarianteUUID = inputParameters.get("sppartner_providingServiceInvariantUuid")
execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
is3rdONAPExist = true
}
else {
is3rdONAPExist = false
String msg = "sppartner providingServiceInvarianteUuid is blank."
msoLogger.debug(msg)
}
if(inputParameters.has("sppartner_handoverMode"))
{
String handoverMode = inputParameters.get("sppartner_handoverMode")
execution.setVariable(Prefix + "HandoverMode", handoverMode)
is3rdONAPExist = true
}
else {
is3rdONAPExist = false
String msg = "sppartner handoverMode is blank."
msoLogger.debug(msg)
}
execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
execution.setVariable("mso-request-id", requestId)
execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
} catch (BpmnError e) {
throw e
} catch (Exception ex){
String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
msoLogger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
}
public void checkLocallCall (DelegateExecution execution) {
msoLogger.info(" ***** Started checkLocallCall *****")
try {
//Get ResourceInput Object
ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
//uuiRequest
String incomingRequest = resourceInputObj.getRequestsInputs()
String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
JSONObject inputParameters = new JSONObject(requestInputs)
execution.setVariable(Prefix + "ServiceParameters", inputParameters)
// CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
boolean isLocalCall = true
String callSource = "UUI"
if(inputParameters.has("CallSource"))
{
callSource = inputParameters.get("CallSource")
if("ExternalAPI".equalsIgnoreCase(callSource)) {
String sppartnerId = inputParameters.get("SppartnerServiceId")
execution.setVariable(Prefix + "SppartnerServiceId", sppartnerId)
isLocalCall = false
}
}
execution.setVariable(Prefix + "CallSource", callSource)
msoLogger.debug("callSource is: " + callSource )
execution.setVariable("IsLocalCall", isLocalCall)
} catch (Exception ex){
String msg = "Exception in checkLocallCall " + ex.getMessage()
msoLogger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
}
public void preProcessRequest(DelegateExecution execution){
msoLogger.info(" ***** Started preProcessRequest *****")
String msg = ""
try {
ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
if (isBlank(globalSubscriberId)) {
msg = "Input globalSubscriberId is null"
msoLogger.error(msg)
}
//set local variable
execution.setVariable("globalSubscriberId", globalSubscriberId)
msoLogger.info("globalSubscriberId:" + globalSubscriberId)
String serviceType = resourceInputObj.getServiceType()
if (isBlank(serviceType)) {
msg = "Input serviceType is null"
msoLogger.error(msg)
}
execution.setVariable("serviceType", serviceType)
msoLogger.info("serviceType:" + serviceType)
String resourceName = resourceInputObj.getResourceInstanceName()
if (isBlank(resourceName)) {
msg = "Input resourceName is null"
msoLogger.error(msg)
}
execution.setVariable("resourceName", resourceName)
msoLogger.info("resourceName:" + resourceName)
int beginIndex = resourceName.indexOf("_") + 1
String serviceInstanceName = resourceName.substring(beginIndex)
execution.setVariable("serviceInstanceName", serviceInstanceName)
String serviceInstanceId = resourceInputObj.getServiceInstanceId()
if (isBlank(serviceInstanceId)) {
msg = "Input serviceInstanceId is null"
msoLogger.error(msg)
}
execution.setVariable(Prefix + "ServiceInstanceId", serviceInstanceId)
msoLogger.info("serviceInstanceId:" + serviceInstanceId)
String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
if (isBlank(resourceModelInvariantUuid)) {
msg = "Input resourceModelInvariantUuid is null"
msoLogger.error(msg)
}
execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
msoLogger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
if (isBlank(resourceModelUuid)) {
msg = "Input resourceModelUuid is null"
msoLogger.error(msg)
}
execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
msoLogger.info("resourceModelUuid:" + resourceModelUuid)
String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
if (isBlank(resourceModelCustomizationUuid)) {
msg = "Input resourceModelCustomizationUuid is null"
msoLogger.error(msg)
}
execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
msoLogger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
} catch (BpmnError e) {
throw e
} catch (Exception ex){
msg = "Exception in preProcessRequest " + ex.getMessage()
msoLogger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
}
public void prepareUpdateProgress(DelegateExecution execution) {
msoLogger.info(" ***** Started prepareUpdateProgress *****")
ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
String operType = resourceInputObj.getOperationType()
String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
String modelName = resourceInputObj.getResourceModelInfo().getModelName()
String operationId = resourceInputObj.getOperationId()
String progress = execution.getVariable("progress")
String status = execution.getVariable("status")
String statusDescription = execution.getVariable("statusDescription")
String body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://org.openecomp.mso/requestsdb">
<soapenv:Header/>
<soapenv:Body>
<ns:updateResourceOperationStatus>
<operType>${operType}</operType>
<operationId>${operationId}</operationId>
<progress>${progress}</progress>
<resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
<serviceId>${ServiceInstanceId}</serviceId>
<status>${status}</status>
<statusDescription>${statusDescription}</statusDescription>
</ns:updateResourceOperationStatus>
</soapenv:Body>
</soapenv:Envelope>"""
setProgressUpdateVariables(execution, body)
msoLogger.info(" ***** Exit prepareUpdateProgress *****")
}
public void allocateCrossONAPResource(DelegateExecution execution) {
msoLogger.info(" ***** Started allocateCrossONAPResource *****")
//get TP links from AAI for SOTN handoverMode only
String handoverMode = execution.getVariable(Prefix + "HandoverMode")
if("SOTN".equalsIgnoreCase(handoverMode)) {
// Put TP Link info into serviceParameters
JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
if(inputParameters.has("remote-access-provider-id")) {
Map<String, Object> crossTPs = new HashMap<String, Object>();
crossTPs.put("local-access-provider-id", inputParameters.get("remote-access-provider-id"));
crossTPs.put("local-access-client-id", inputParameters.get("remote-access-client-id"));
crossTPs.put("local-access-topology-id", inputParameters.get("remote-access-topology-id"));
crossTPs.put("local-access-node-id", inputParameters.get("remote-access-node-id"));
crossTPs.put("local-access-ltp-id", inputParameters.get("remote-access-ltp-id"));
crossTPs.put("remote-access-provider-id", inputParameters.get("local-access-provider-id"));
crossTPs.put("remote-access-client-id", inputParameters.get("local-access-client-id"));
crossTPs.put("remote-access-topology-id", inputParameters.get("local-access-topology-id"));
crossTPs.put("remote-access-node-id", inputParameters.get("local-access-node-id"));
crossTPs.put("remote-access-ltp-id", inputParameters.get("local-access-ltp-id"));
inputParameters.put("local-access-provider-id", crossTPs.get("local-access-provider-id"));
inputParameters.put("local-access-client-id", crossTPs.get("local-access-client-id"));
inputParameters.put("local-access-topology-id", crossTPs.get("local-access-topology-id"));
inputParameters.put("local-access-node-id", crossTPs.get("local-access-node-id"));
inputParameters.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id"));
inputParameters.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id"));
inputParameters.put("remote-access-client-id", crossTPs.get("remote-access-client-id"));
inputParameters.put("remote-access-topology-id", crossTPs.get("remote-access-topology-id"));
inputParameters.put("remote-access-node-id", crossTPs.get("remote-access-node-id"));
inputParameters.put("remote-access-ltp-id", crossTPs.get("remote-access-ltp-id"));
execution.setVariable(Prefix + "ServiceParameters", inputParameters)
}
else {
msoLogger.error("No allocated CrossONAPResource found in ServiceParameters")
}
}
msoLogger.info("Exit " + allocateCrossONAPResource)
}
public void prepare3rdONAPRequest(DelegateExecution execution) {
msoLogger.info(" ***** Started prepare3rdONAPRequest *****")
String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
String extAPIPath = sppartnerUrl + '/serviceOrder'
execution.setVariable("ExternalAPIURL", extAPIPath)
// ExternalAPI message format
String externalId = execution.getVariable("resourceName")
String category = "E2E Service"
String description = "Service Order from SPPartner"
String requestedStartDate = utils.generateCurrentTimeInUtc()
String requestedCompletionDate = utils.generateCurrentTimeInUtc()
String priority = "1" // 0-4 0:highest
String subscriberId = execution.getVariable("globalSubscriberId")
String customerRole = "ONAPcustomer"
String subscriberName = subscriberId
String referredType = "Consumer"
String orderItemId = "1"
String action = "add" //for create
String serviceState = "active"
String serviceName = execution.getVariable("serviceInstanceName")
String serviceUuId = execution.getVariable(Prefix + "SppartnerUUID")
Map<String, String> valueMap = new HashMap<>()
valueMap.put("externalId", '"' + externalId + '"')
valueMap.put("category", '"' + category + '"')
valueMap.put("description", '"' + description + '"')
valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
valueMap.put("priority", '"'+ priority + '"')
valueMap.put("subscriberId", '"' + subscriberId + '"')
valueMap.put("customerRole", '"' + customerRole + '"')
valueMap.put("subscriberName", '"' + subscriberName + '"')
valueMap.put("referredType", '"' + referredType + '"')
valueMap.put("orderItemId", '"' + orderItemId + '"')
valueMap.put("action", '"' + action + '"')
valueMap.put("serviceState", '"' + serviceState + '"')
valueMap.put("serviceId", "null") //null for add
valueMap.put("serviceName", '"' + serviceName + '"')
valueMap.put("serviceUuId", '"' + serviceUuId + '"')
ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
// insert CallSource='ExternalAPI' to uuiRequest
Map<String, String> requestInputsMap = new HashMap<>()
requestInputsMap.put("inputName", '"CallSource"')
requestInputsMap.put("inputValue", '"ExternalAPI"')
String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
requestInputsMap.clear()
String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
requestInputsMap.put("inputName", '"SppartnerServiceId"')
requestInputsMap.put("inputValue", '"' + serviceInstanceId + '"')
_requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
requestInputsMap.clear()
String serviceType = execution.getVariable("serviceType")
requestInputsMap.put("inputName", '"serviceType"')
requestInputsMap.put("inputValue", '"' + serviceType + '"')
_requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
// Transfer all uuiRequest incomeParameters to ExternalAPI format
JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
for(String key : inputParameters.keySet()) {
String inputName = key
String inputValue = inputParameters.opt(key)
requestInputsMap.clear()
requestInputsMap.put("inputName", '"' + inputName+ '"')
requestInputsMap.put("inputValue", '"' + inputValue + '"')
_requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
}
valueMap.put("_requestInputs_", _requestInputs_)
String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
execution.setVariable(Prefix + "Payload", payload)
msoLogger.info("Exit " + prepare3rdONAPRequest)
}
public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
msoLogger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
String extAPIPath = execution.getVariable("ExternalAPIURL")
String payload = execution.getVariable(Prefix + "Payload")
msoLogger.debug("doCreateE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
msoLogger.debug("doCreateE2ESIin3rdONAP payload is: " + payload)
ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
int responseCode = response.getStatus()
execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
msoLogger.debug("Post ServiceOrder response code is: " + responseCode)
String extApiResponse = response.readEntity(String.class)
JSONObject responseObj = new JSONObject(extApiResponse)
execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
msoLogger.debug("doCreateE2ESIin3rdONAP response body is: " + extApiResponse)
//Process Response
if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
//200 OK 201 CREATED 202 ACCEPTED
{
msoLogger.debug("Post ServiceOrder Received a Good Response")
String serviceOrderId = responseObj.get("id")
execution.setVariable(Prefix + "SuccessIndicator", true)
execution.setVariable("ServiceOrderId", serviceOrderId)
msoLogger.info("Post ServiceOrderid is: " + serviceOrderId)
}
else{
msoLogger.error("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
// exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
}
msoLogger.info("Exit " + doCreateE2ESIin3rdONAP)
}
public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
msoLogger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
String extAPIPath = execution.getVariable("ExternalAPIURL")
extAPIPath += "/" + execution.getVariable("ServiceOrderId")
utils.log("DEBUG", "getE2ESIProgressin3rdONAP create externalAPIURL is: " + extAPIPath, isDebugEnabled)
ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
int responseCode = response.getStatus()
execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
msoLogger.debug("Get ServiceOrder response code is: " + responseCode)
String extApiResponse = response.readEntity(String.class)
JSONObject responseObj = new JSONObject(extApiResponse)
execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
msoLogger.debug("getE2ESIProgressin3rdONAP create response body is: " + extApiResponse)
//Process Response //200 OK 201 CREATED 202 ACCEPTED
if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
{
msoLogger.debug("Get Create ServiceOrder Received a Good Response")
String orderState = responseObj.get("state")
if("REJECTED".equalsIgnoreCase(orderState)) {
execution.setVariable("progress", 100)
execution.setVariable("status", "error")
execution.setVariable("statusDescription", "Create Service Order Status is REJECTED")
return
}
JSONArray items = responseObj.getJSONArray("orderItem")
JSONObject item = items[0]
JSONObject service = item.get("service")
String sppartnerServiceId = service.get("id")
if(sppartnerServiceId == null || sppartnerServiceId.equals("null")) {
execution.setVariable("progress", 100)
execution.setVariable("status", "error")
execution.setVariable("statusDescription", "Create Service Order Status get null sppartnerServiceId")
msoLogger.error("null sppartnerServiceId while getting progress from externalAPI")
return
}
execution.setVariable(Prefix + "SppartnerServiceId", sppartnerServiceId)
String serviceOrderState = item.get("state")
execution.setVariable(Prefix + "SuccessIndicator", true)
execution.setVariable("ServiceOrderState", serviceOrderState)
// Get serviceOrder State and process progress
if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
execution.setVariable("progress", 15)
execution.setVariable("status", "processing")
execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
}
else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
execution.setVariable("progress", 40)
execution.setVariable("status", "processing")
execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
}
else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
execution.setVariable("progress", 100)
execution.setVariable("status", "finished")
execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
}
else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
execution.setVariable("progress", 100)
execution.setVariable("status", "error")
execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
}
else {
execution.setVariable("progress", 100)
execution.setVariable("status", "error")
execution.setVariable("statusDescription", "Create Service Order Status is unknown")
}
}
else{
msoLogger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
execution.setVariable("progress", 100)
execution.setVariable("status", "error")
execution.setVariable("statusDescription", "Get Create ServiceOrder Received a bad response")
exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get Create ServiceOrder Received a bad response from 3rdONAP External API")
}
msoLogger.info("Exit " + getE2ESIProgressin3rdONAP)
}
/**
* delay 5 sec
*/
public void timeDelay(DelegateExecution execution) {
try {
Thread.sleep(5000)
} catch(InterruptedException e) {
msoLogger.error("Time Delay exception" + e)
}
}
public void saveSPPartnerInAAI(DelegateExecution execution) {
msoLogger.info(" ***** Started saveSPPartnerInAAI *****")
String sppartnerId = execution.getVariable(Prefix + "SppartnerServiceId")
String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
String callSource = execution.getVariable(Prefix + "CallSource")
String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String serviceType = execution.getVariable("serviceType")
String resourceModelInvariantUuid = execution.getVariable(Prefix + "ResourceModelInvariantUuid")
String resourceModelUuid = execution.getVariable(Prefix + "ResourceModelUuid")
String resourceModelCustomizationUuid = execution.getVariable(Prefix + "ResourceModelCustomizationUuid")
SpPartner partner = new SpPartner()
partner.setSpPartnerId(sppartnerId)
partner.setUrl(sppartnerUrl)
partner.setCallsource(callSource)
partner.setModelInvariantId(resourceModelInvariantUuid)
partner.setModelVersionId(resourceModelUuid)
partner.setModelCustomizationId(resourceModelCustomizationUuid)
AAIResourcesClient client = new AAIResourcesClient()
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SP_PARTNER, sppartnerId)
client.create(uri, partner)
AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
client.connect(uri, siUri)
msoLogger.info("Exit " + saveSPPartnerInAAI)
}
private void setProgressUpdateVariables(DelegateExecution execution, String body) {
def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
execution.setVariable("CVFMI_updateResOperStatusRequest", body)
}
public void postProcess(DelegateExecution execution){
msoLogger.info(" ***** Started postProcess *****")
String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")
msoLogger.info("response from AAI for put sppartner, response code :" + responseCode + " response object :" + responseObj)
msoLogger.info(" ***** Exit postProcess *****")
}
public void sendSyncResponse (DelegateExecution execution) {
msoLogger.debug(" *** sendSyncResponse *** ")
try {
String operationStatus = "finished"
// RESTResponse for main flow
String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
sendWorkflowResponse(execution, 202, resourceOperationResp)
execution.setVariable("sentSyncResponse", true)
} catch (Exception ex) {
String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
msoLogger.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
msoLogger.debug(" ***** Exit sendSyncResopnse *****")
}
}
|