aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy
blob: 36d579c7ab5688784048bcd51fde8637548caf27 (plain)
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
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2019 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 static org.apache.commons.lang3.StringUtils.isBlank
import java.lang.reflect.Type
import javax.ws.rs.NotFoundException
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.*
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
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.beans.nsmf.NSSI
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.common.scripts.RequestDBUtil
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.db.request.beans.OperationStatus
import org.onap.so.logger.LoggingAnchor
import org.onap.so.logger.MessageEnum
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

/**
 * This groovy class supports the <class>ActivateSliceService.bpmn</class> process.
 * AlaCarte flow for 1702 slice service activate
 *
 */

class ActivateSliceService extends AbstractServiceTaskProcessor {


    String Prefix = "ACTSS_"

    ExceptionUtil exceptionUtil = new ExceptionUtil()

    JsonUtils jsonUtil = new JsonUtils()

    RequestDBUtil requestDBUtil = new RequestDBUtil()

    private static final Logger logger = LoggerFactory.getLogger(ActivateSliceService.class)

    void preProcessRequest(DelegateExecution execution) {
        logger.debug(Prefix + "preProcessRequest Start")
        execution.setVariable("prefix", Prefix)
        String msg

        try {
            // check for incoming json message/input
            String siRequest = execution.getVariable("bpmnRequest")
            logger.debug(siRequest)

            String requestId = execution.getVariable("mso-request-id")
            execution.setVariable("msoRequestId", requestId)
            logger.info("Input Request:" + siRequest + " reqId:" + requestId)

            String serviceInstanceId = execution.getVariable("serviceInstanceId")
            if (isBlank(serviceInstanceId)) {
                msg = "Input serviceInstanceId' is null"
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
            }
            String source = jsonUtil.getJsonValue(siRequest, "source")
            execution.setVariable("source", source)

            //subscriberInfo
            String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
            if (isBlank(globalSubscriberId)) {
                msg = "Input globalSubscriberId' is null"
                logger.info(msg)
                execution.setVariable("globalSubscriberId", "5GCustomer")
            } else {
                execution.setVariable("globalSubscriberId", globalSubscriberId)
            }

            //requestParameters
            String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
            if (isBlank(subscriptionServiceType)) {
                msg = "Input subscriptionServiceType is null"
                logger.debug(msg)
                execution.setVariable("subscriptionServiceType", "5G")
            } else {
                execution.setVariable("subscriptionServiceType", subscriptionServiceType)
            }
            String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
            execution.setVariable("operationId", operationId)

            String operationType = execution.getVariable("operationType")
            execution.setVariable("operationType", operationType.toUpperCase())

            logger.info("operationType is " + execution.getVariable("operationType") )
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            msg = "Exception in preProcessRequest " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "preProcessRequest Exit")
    }


    def sendSyncResponse = { DelegateExecution execution ->
        logger.debug(Prefix + "sendSyncResponse Start")
        try {
            String operationId = execution.getVariable("operationId")
            // RESTResponse for API Handler (APIH) Reply Task
            String Activate5GsliceServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
            logger.debug(" sendSyncResponse to APIH:" + "\n" + Activate5GsliceServiceRestRequest)
            sendWorkflowResponse(execution, 202, Activate5GsliceServiceRestRequest)
            execution.setVariable("sentSyncResponse", true)
        } catch (Exception ex) {
            String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "sendSyncResponse Exit")
    }


    public sendSyncError = { DelegateExecution execution ->
        logger.debug("sendSyncError Start")
        try {
            String errorMessage
            if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
                WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
                errorMessage = wfe.getErrorMessage()
            } else {
                errorMessage = "Sending Sync Error."
            }

            String buildWorkflowException =
                    """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
					<aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
					<aetgt:ErrorCode>7000</aetgt:ErrorCode>
				   </aetgt:WorkflowException>"""

            logger.debug(buildWorkflowException)
            sendWorkflowResponse(execution, 500, buildWorkflowException)

        } catch (Exception ex) {
            logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
        }
        logger.debug(Prefix + "sendSyncError Exit")
    }


    def prepareCompletionRequest = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareCompletionRequest Start")
        String serviceId = execution.getVariable("serviceInstanceId")
        String operationId = execution.getVariable("operationId")
        String userId = execution.getVariable("globalSubscriberId")
        //String result = execution.getVariable("result")
        String result = "finished"
        String progress = "100"
        String reason = ""
        String operationContent = execution.getVariable("operationContent")
        String operationType = execution.getVariable("operationType")

        OperationStatus initStatus = new OperationStatus()
        initStatus.setServiceId(serviceId)
        initStatus.setOperationId(operationId)
        initStatus.setOperation(operationType)
        initStatus.setUserId(userId)
        initStatus.setResult(result)
        initStatus.setProgress(progress)
        initStatus.setReason(reason)
        initStatus.setOperationContent(operationContent)

        requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)

        logger.debug(Prefix + "prepareCompletionRequest Exit")
    }


    /**
     * Init the service Operation Status
     */
    def prepareInitServiceOperationStatus = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
        try {
            String serviceId = execution.getVariable("serviceInstanceId")
            String operationId = execution.getVariable("operationId")
            String operationType = execution.getVariable("operationType")
            String userId = execution.getVariable("globalSubscriberId")
            String result = "processing"
            String progress = "0"
            String reason = ""
            String operationContent = "Prepare service activation"

            execution.setVariable("e2eserviceInstanceId", serviceId)
            execution.setVariable("operationType", operationType)

            OperationStatus initStatus = new OperationStatus()
            initStatus.setServiceId(serviceId)
            initStatus.setOperationId(operationId)
            initStatus.setOperation(operationType)
            initStatus.setUserId(userId)
            initStatus.setResult(result)
            initStatus.setProgress(progress)
            initStatus.setReason(reason)
            initStatus.setOperationContent(operationContent)

            requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)

        } catch (Exception e) {
            logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                    "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
                    ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
            execution.setVariable("CVFMI_ErrorResponse",
                    "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
        }
        logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
    }


    private getSNSSIStatusByNsi = { DelegateExecution execution, String NSIServiceId ->

        logger.debug(Prefix + "getSNSSIStatusByNsi Start")
        String globalSubscriberId = execution.getVariable("globalSubscriberId")
        String subscriptionServiceType = execution.getVariable("subscriptionServiceType")

        AAIResourcesClient client = new AAIResourcesClient()
        AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIServiceId))
        if (!client.exists(uri)) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
        }
        AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
        Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
        if (si.isPresent()) {

            List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
            for (Relationship relationship : relatedList) {
                String relatedTo = relationship.getRelatedTo()
                if (relatedTo.toLowerCase() == "allotted-resource") {
                    //get snssi from allotted resource in list by nsi
                    List<String> SNSSIList = new ArrayList<>()
                    List<RelationshipData> relationshipDataList = relationship.getRelationshipData()
                    for (RelationshipData relationshipData : relationshipDataList) {
                        if (relationshipData.getRelationshipKey() == "service-instance.service-instance-id") {
                            SNSSIList.add(relationshipData.getRelationshipValue())
                        }
                    }
                    for (String snssi : SNSSIList) {
                        AAIResourcesClient client01 = new AAIResourcesClient()
                        AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(snssi))
                        if (!client.exists(uri01)) {
                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                                    "Service Instance was not found in aai")
                        }
                        AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
                        Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
                        if (nssiSi.isPresent()) {
                            return nssiSi.get().getOrchestrationStatus() == "deactivated"
                        }
                    }

                }
            }

        }
        logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
    }


    def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
        logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
        logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
        String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
        String NSIserviceInstanceId = execution.getVariable("NSIserviceid")

        String globalCustId = execution.getVariable("globalSubscriberId")
        String serviceType = execution.getVariable("serviceType")
        String operationType = execution.getVariable("operationType")

        String nssiMap = execution.getVariable("nssiMap")
        Type type = new TypeToken<HashMap<String, NSSI>>() {}.getType()
        Map<String, NSSI> activateNssiMap = new Gson().fromJson(nssiMap, type)
        //update tn/cn/an nssi
        for (Map.Entry<String, NSSI> entry : activateNssiMap.entrySet()) {
            NSSI nssi = entry.getValue()
            String nssiid = nssi.getNssiId()
            updateStratus(execution, globalCustId, serviceType, nssiid, operationType)
        }
        if (operationType.equalsIgnoreCase("activation")) {
            //update the s-nssai
            updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
            //update the nsi
            updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
        } else {
            //update the s-nssai
            updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
            boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
            if (flag) {
                //update the nsi
                updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
            } else {
                logger.error("Service's status update failed")
                String msg = "Service's status update failed"
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }
        }
        logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
    }


    def updateStratus = { DelegateExecution execution, String globalCustId,
                          String serviceType, String serviceId, String operationType ->
        logger.debug(Prefix + "updateStratus Start")

        try {
            AAIResourcesClient client = new AAIResourcesClient()
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(serviceId))
            if (!client.exists(uri)) {
                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
            }
            AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
            Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)

            if (si.isPresent()) {
                if (operationType.equalsIgnoreCase("activation")) {
                    if (si.get().getOrchestrationStatus() == "deactivated") {
                        si.get().setOrchestrationStatus("activated")
                        client.update(uri, si.get())
                    }
                } else {
                    if (si.get().getOrchestrationStatus() == "activated") {
                        si.get().setOrchestrationStatus("deactivated")
                        client.update(uri, si.get())
                    }
                }

            }
        } catch (Exception e) {
            logger.info("Service is already in active state")
            String msg = "Service is already in active state, " + e.getMessage()
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        logger.debug(Prefix + "updateStratus Exit")
    }


    def prepareActivation = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareActivation Start")

        logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
        String NSIserviceInstanceId = execution.getVariable("NSIserviceid")

        String globalSubscriberId = execution.getVariable("globalSubscriberId")
        String subscriptionServiceType = execution.getVariable("subscriptionServiceType")

        Map<String, NSSI> nssiMap = new HashMap<>()

        List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))

        def activationCount = activationSequence.size()

        execution.setVariable("activationIndex", "0")

        execution.setVariable("activationCount", activationCount)
        try {
            //get the TN NSSI id by NSI id, active NSSI TN slicing
            AAIResourcesClient client = new AAIResourcesClient()
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIserviceInstanceId))
            if (!client.exists(uri)) {
                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
            }
            AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
            Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
            if (si.isPresent()) {

                List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
                for (Relationship relationship : relatedList) {
                    String relatedTo = relationship.getRelatedTo()
                    if (relatedTo.toLowerCase() == "service-instance") {
                        String relatioshipurl = relationship.getRelatedLink()
                        String nssiserviceid =
                                relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())

                        AAIResourcesClient client01 = new AAIResourcesClient()
                        AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiserviceid))
                        if (!client.exists(uri01)) {
                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                                    "Service Instance was not found in aai")
                        }
                        AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
                        Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
                        if (nssiSi.isPresent()) {
                            if (nssiSi.get().getEnvironmentContext().toLowerCase().contains("an")
                                    || nssiSi.get().getEnvironmentContext().toLowerCase().contains("cn")
                                    || nssiSi.get().getEnvironmentContext().toLowerCase().contains("tn")) {
                                nssiMap.put(nssiSi.get().getEnvironmentContext(),
                                        new NSSI(nssiSi.get().getServiceInstanceId(),
                                                nssiSi.get().getModelInvariantId(), nssiSi.get().getModelVersionId()))
                            }
                        }
                    }
                }


            }
        } catch (Exception e) {
            String msg = "Requested service does not exist:" + e.getMessage()
            logger.info("Service doesnt exist")
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        if (nssiMap.size() > 0) {
            execution.setVariable("isNSSIActivate", "true")
            String nssiMap01 = mapToJsonStr(nssiMap)
            execution.setVariable("nssiMap", nssiMap01)
            execution.setVariable("operation_type", "activate")
            execution.setVariable("activationCount", nssiMap.size())
            logger.info("the nssiMap01 is :" + nssiMap01)
        } else {
            execution.setVariable("isNSSIActivate", "false")
        }

        logger.debug(Prefix + "prepareActivation Exit")
    }


    private mapToJsonStr = { HashMap<String, NSSI> stringNSSIHashMap ->
        HashMap<String, NSSI> map = new HashMap<String, NSSI>()
        for (Map.Entry<String, NSSI> child : stringNSSIHashMap.entrySet()) {
            map.put(child.getKey(), child.getValue())
        }
        return new Gson().toJson(map)
    }


    def checkAAIOrchStatusofslice = { DelegateExecution execution ->
        logger.debug(Prefix + "CheckAAIOrchStatus Start")

        String msg = ""
        String serviceInstanceId = execution.getVariable("serviceInstanceId")
        String globalSubscriberId = execution.getVariable("globalSubscriberId")
        String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
        String operationType = execution.getVariable("operationType")

        logger.debug("serviceInstanceId: " + serviceInstanceId)

        //check the e2e slice status
        try {
            try {
                AAIResourcesClient client = new AAIResourcesClient()
                AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
                if (!client.exists(uri)) {
                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                            "Service Instance was not found in aai")
                }
                AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
                Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
                if (si.isPresent()) {
                    if (si.get().getOrchestrationStatus().toLowerCase() == "activated" &&
                            operationType.equalsIgnoreCase("deactivation")) {
                        logger.info("Service is in active state")
                        execution.setVariable("e2eservicestatus", "activated")
                        execution.setVariable("isContinue", "true")
                        String snssai = si.get().getEnvironmentContext()
                        execution.setVariable("snssai", snssai)
                    } else if (si.get().getOrchestrationStatus().toLowerCase() == "deactivated" &&
                            operationType.equalsIgnoreCase("activation")) {
                        logger.info("Service is  in de-activated state")
                        execution.setVariable("e2eservicestatus", "deactivated")
                        execution.setVariable("isContinue", "true")
                        String snssai = si.get().getEnvironmentContext()
                        execution.setVariable("snssai", snssai)
                    } else {
                        execution.setVariable("isContinue", "false")
                    }
                }
            } catch (Exception e) {
                msg = "Requested e2eservice does not exist"
                logger.info("e2eservice doesnt exist")
                execution.setVariable("isContinue", "false")
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }

            //check the NSI is exist or the status of NSI is active or de-active
            try {

                //get the allotted-resources by e2e slice id
                AAIResourcesClient client_allotted = new AAIResourcesClient()
                AAIPluralResourceUri uri_allotted = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId).allottedResources()
                        )
                if (!client_allotted.exists(uri_allotted)) {
                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
                }
                AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
                Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)

                if (all_allotted.isPresent() && all_allotted.get().getAllottedResource()) {
                    List<AllottedResource> AllottedResourceList = all_allotted.get().getAllottedResource()
                    AllottedResource ar = AllottedResourceList.first()
                    String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
                    String nsiserviceid = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
                    execution.setVariable("NSIserviceid", nsiserviceid)
                    logger.info("the NSI ID is:" + nsiserviceid)

                    //Query nsi by nsi id
                    try {
                        //get the NSI id by e2e slice id
                        AAIResourcesClient client = new AAIResourcesClient()
                        AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nsiserviceid))
                        if (!client.exists(uri)) {
                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                                    "Service Instance was not found in aai")
                        }
                        AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
                        Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)

                        if (si.isPresent()) {
                            if (si.get().getServiceRole().toLowerCase() == "nsi") {
                                if (si.get().getOrchestrationStatus() == "activated") {
                                    logger.info("NSI services is  in activated state")
                                    execution.setVariable("NSIservicestatus", "activated")
                                } else {
                                    logger.info("NSI services is  in deactivated state")
                                    execution.setVariable("NSIservicestatus", "deactivated")
                                }
                            } else {
                                logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
                                        si.get().getServiceRole())
                                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                            }
                        }
                    } catch (Exception e) {
                        msg = "Requested NSI service does not exist:" + e.getMessage()
                        logger.info("NSI service doesnt exist")
                        execution.setVariable("isContinue", "false")
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                    }
                }
            } catch (Exception e) {
                msg = "Requested service does not exist: " + e.getMessage()
                logger.info("NSI Service doesnt exist")
                execution.setVariable("isActivate", "false")
                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
            }
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        logger.debug(Prefix + "CheckAAIOrchStatus Exit")
    }

}