334f5b4e4fa64a4e96dcfc1f33f530aaf291db8b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License")
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import com.google.gson.Gson
24 import com.google.gson.reflect.TypeToken
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.*
28 import org.onap.so.beans.nsmf.NSSI
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.RequestDBUtil
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.aaiclient.client.aai.AAIObjectType
36 import org.onap.aaiclient.client.aai.AAIResourcesClient
37 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
39 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
40 import org.onap.so.db.request.beans.OperationStatus
41 import org.onap.logging.filter.base.ErrorCode
42 import org.onap.so.logger.LoggingAnchor
43 import org.onap.so.logger.MessageEnum
44 import org.slf4j.Logger
45 import org.slf4j.LoggerFactory
46
47 import javax.ws.rs.NotFoundException
48 import java.lang.reflect.Type
49
50 import static org.apache.commons.lang3.StringUtils.isBlank
51
52 /**
53  * This groovy class supports the <class>ActivateSliceService.bpmn</class> process.
54  * AlaCarte flow for 1702 slice service activate
55  *
56  */
57
58 class ActivateSliceService extends AbstractServiceTaskProcessor {
59
60
61     String Prefix = "ACTSS_"
62
63     ExceptionUtil exceptionUtil = new ExceptionUtil()
64
65     JsonUtils jsonUtil = new JsonUtils()
66
67     RequestDBUtil requestDBUtil = new RequestDBUtil()
68
69     private static final Logger logger = LoggerFactory.getLogger(ActivateSliceService.class)
70
71     void preProcessRequest(DelegateExecution execution) {
72         logger.debug(Prefix + "preProcessRequest Start")
73         execution.setVariable("prefix", Prefix)
74         String msg
75
76         try {
77             // check for incoming json message/input
78             String siRequest = execution.getVariable("bpmnRequest")
79             logger.debug(siRequest)
80
81             String requestId = execution.getVariable("mso-request-id")
82             execution.setVariable("msoRequestId", requestId)
83             logger.info("Input Request:" + siRequest + " reqId:" + requestId)
84
85             String serviceInstanceId = execution.getVariable("serviceInstanceId")
86             if (isBlank(serviceInstanceId)) {
87                 msg = "Input serviceInstanceId' is null"
88                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
89             }
90             String source = jsonUtil.getJsonValue(siRequest, "source")
91             execution.setVariable("source", source)
92
93             //subscriberInfo
94             String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
95             if (isBlank(globalSubscriberId)) {
96                 msg = "Input globalSubscriberId' is null"
97                 logger.info(msg)
98                 execution.setVariable("globalSubscriberId", "5GCustomer")
99             } else {
100                 execution.setVariable("globalSubscriberId", globalSubscriberId)
101             }
102
103             //requestParameters
104             String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
105             if (isBlank(subscriptionServiceType)) {
106                 msg = "Input subscriptionServiceType is null"
107                 logger.debug(msg)
108                 execution.setVariable("subscriptionServiceType", "5G")
109             } else {
110                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
111             }
112             String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
113             execution.setVariable("operationId", operationId)
114
115             String operationType = execution.getVariable("operationType")
116             execution.setVariable("operationType", operationType.toUpperCase())
117
118             logger.info("operationType is " + execution.getVariable("operationType") )
119         } catch (BpmnError e) {
120             throw e
121         } catch (Exception ex) {
122             msg = "Exception in preProcessRequest " + ex.getMessage()
123             logger.info(msg)
124             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
125         }
126         logger.debug(Prefix + "preProcessRequest Exit")
127     }
128
129
130     def sendSyncResponse = { DelegateExecution execution ->
131         logger.debug(Prefix + "sendSyncResponse Start")
132         try {
133             String operationId = execution.getVariable("operationId")
134             // RESTResponse for API Handler (APIH) Reply Task
135             String Activate5GsliceServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
136             logger.debug(" sendSyncResponse to APIH:" + "\n" + Activate5GsliceServiceRestRequest)
137             sendWorkflowResponse(execution, 202, Activate5GsliceServiceRestRequest)
138             execution.setVariable("sentSyncResponse", true)
139         } catch (Exception ex) {
140             String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
141             logger.debug(msg)
142             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
143         }
144         logger.debug(Prefix + "sendSyncResponse Exit")
145     }
146
147
148     public sendSyncError = { DelegateExecution execution ->
149         logger.debug("sendSyncError Start")
150         try {
151             String errorMessage
152             if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
153                 WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
154                 errorMessage = wfe.getErrorMessage()
155             } else {
156                 errorMessage = "Sending Sync Error."
157             }
158
159             String buildWorkflowException =
160                     """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
161                                         <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
162                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>
163                                    </aetgt:WorkflowException>"""
164
165             logger.debug(buildWorkflowException)
166             sendWorkflowResponse(execution, 500, buildWorkflowException)
167
168         } catch (Exception ex) {
169             logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
170         }
171         logger.debug(Prefix + "sendSyncError Exit")
172     }
173
174
175     def prepareCompletionRequest = { DelegateExecution execution ->
176         logger.debug(Prefix + "prepareCompletionRequest Start")
177         String serviceId = execution.getVariable("serviceInstanceId")
178         String operationId = execution.getVariable("operationId")
179         String userId = execution.getVariable("globalSubscriberId")
180         //String result = execution.getVariable("result")
181         String result = "finished"
182         String progress = "100"
183         String reason = ""
184         String operationContent = execution.getVariable("operationContent")
185         String operationType = execution.getVariable("operationType")
186
187         OperationStatus initStatus = new OperationStatus()
188         initStatus.setServiceId(serviceId)
189         initStatus.setOperationId(operationId)
190         initStatus.setOperation(operationType)
191         initStatus.setUserId(userId)
192         initStatus.setResult(result)
193         initStatus.setProgress(progress)
194         initStatus.setReason(reason)
195         initStatus.setOperationContent(operationContent)
196
197         requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
198
199         logger.debug(Prefix + "prepareCompletionRequest Exit")
200     }
201
202
203     /**
204      * Init the service Operation Status
205      */
206     def prepareInitServiceOperationStatus = { DelegateExecution execution ->
207         logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
208         try {
209             String serviceId = execution.getVariable("serviceInstanceId")
210             String operationId = execution.getVariable("operationId")
211             String operationType = execution.getVariable("operationType")
212             String userId = execution.getVariable("globalSubscriberId")
213             String result = "processing"
214             String progress = "0"
215             String reason = ""
216             String operationContent = "Prepare service activation"
217
218             execution.setVariable("e2eserviceInstanceId", serviceId)
219             execution.setVariable("operationType", operationType)
220
221             OperationStatus initStatus = new OperationStatus()
222             initStatus.setServiceId(serviceId)
223             initStatus.setOperationId(operationId)
224             initStatus.setOperation(operationType)
225             initStatus.setUserId(userId)
226             initStatus.setResult(result)
227             initStatus.setProgress(progress)
228             initStatus.setReason(reason)
229             initStatus.setOperationContent(operationContent)
230
231             requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
232
233         } catch (Exception e) {
234             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
235                     "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
236                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
237             execution.setVariable("CVFMI_ErrorResponse",
238                     "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
239         }
240         logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
241     }
242
243
244     private getSNSSIStatusByNsi = { DelegateExecution execution, String NSIServiceId ->
245
246         logger.debug(Prefix + "getSNSSIStatusByNsi Start")
247         String globalSubscriberId = execution.getVariable("globalSubscriberId")
248         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
249
250         AAIResourcesClient client = new AAIResourcesClient()
251         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
252                 globalSubscriberId, subscriptionServiceType, NSIServiceId)
253         if (!client.exists(uri)) {
254             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
255         }
256         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
257         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
258         if (si.isPresent()) {
259
260             List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
261             for (Relationship relationship : relatedList) {
262                 String relatedTo = relationship.getRelatedTo()
263                 if (relatedTo.toLowerCase() == "allotted-resource") {
264                     //get snssi from allotted resource in list by nsi
265                     List<String> SNSSIList = new ArrayList<>()
266                     List<RelationshipData> relationshipDataList = relationship.getRelationshipData()
267                     for (RelationshipData relationshipData : relationshipDataList) {
268                         if (relationshipData.getRelationshipKey() == "service-instance.service-instance-id") {
269                             SNSSIList.add(relationshipData.getRelationshipValue())
270                         }
271                     }
272                     for (String snssi : SNSSIList) {
273                         AAIResourcesClient client01 = new AAIResourcesClient()
274                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
275                                 globalSubscriberId, subscriptionServiceType, snssi)
276                         if (!client.exists(uri01)) {
277                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
278                                     "Service Instance was not found in aai")
279                         }
280                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
281                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
282                         if (nssiSi.isPresent()) {
283                             return nssiSi.get().getOrchestrationStatus() == "deactivated"
284                         }
285                     }
286
287                 }
288             }
289
290         }
291         logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
292     }
293
294
295     def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
296         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
297         logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
298         String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
299         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
300
301         String globalCustId = execution.getVariable("globalSubscriberId")
302         String serviceType = execution.getVariable("serviceType")
303         String operationType = execution.getVariable("operationType")
304
305         String nssiMap = execution.getVariable("nssiMap")
306         Type type = new TypeToken<HashMap<String, NSSI>>() {}.getType()
307         Map<String, NSSI> activateNssiMap = new Gson().fromJson(nssiMap, type)
308         //update tn/cn/an nssi
309         for (Map.Entry<String, NSSI> entry : activateNssiMap.entrySet()) {
310             NSSI nssi = entry.getValue()
311             String nssiid = nssi.getNssiId()
312             updateStratus(execution, globalCustId, serviceType, nssiid, operationType)
313         }
314         if (operationType.equalsIgnoreCase("activation")) {
315             //update the s-nssai
316             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
317             //update the nsi
318             updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
319         } else {
320             //update the s-nssai
321             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
322             boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
323             if (flag) {
324                 //update the nsi
325                 updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
326             } else {
327                 logger.error("Service's status update failed")
328                 String msg = "Service's status update failed"
329                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
330             }
331         }
332         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
333     }
334
335
336     def updateStratus = { DelegateExecution execution, String globalCustId,
337                           String serviceType, String serviceId, String operationType ->
338         logger.debug(Prefix + "updateStratus Start")
339
340         try {
341             AAIResourcesClient client = new AAIResourcesClient()
342             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
343                     globalCustId, serviceType, serviceId)
344             if (!client.exists(uri)) {
345                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
346             }
347             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
348             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
349
350             if (si.isPresent()) {
351                 if (operationType.equalsIgnoreCase("activation")) {
352                     if (si.get().getOrchestrationStatus() == "deactivated") {
353                         si.get().setOrchestrationStatus("activated")
354                         client.update(uri, si.get())
355                     }
356                 } else {
357                     if (si.get().getOrchestrationStatus() == "activated") {
358                         si.get().setOrchestrationStatus("deactivated")
359                         client.update(uri, si.get())
360                     }
361                 }
362
363             }
364         } catch (Exception e) {
365             logger.info("Service is already in active state")
366             String msg = "Service is already in active state, " + e.getMessage()
367             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
368         }
369
370         logger.debug(Prefix + "updateStratus Exit")
371     }
372
373
374     def prepareActivation = { DelegateExecution execution ->
375         logger.debug(Prefix + "prepareActivation Start")
376
377         logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
378         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
379
380         String globalSubscriberId = execution.getVariable("globalSubscriberId")
381         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
382
383         Map<String, NSSI> nssiMap = new HashMap<>()
384
385         List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))
386
387         def activationCount = activationSequence.size()
388
389         execution.setVariable("activationIndex", "0")
390
391         execution.setVariable("activationCount", activationCount)
392         try {
393             //get the TN NSSI id by NSI id, active NSSI TN slicing
394             AAIResourcesClient client = new AAIResourcesClient()
395             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
396                     globalSubscriberId, subscriptionServiceType, NSIserviceInstanceId)
397             if (!client.exists(uri)) {
398                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
399             }
400             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
401             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
402             if (si.isPresent()) {
403
404                 List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
405                 for (Relationship relationship : relatedList) {
406                     String relatedTo = relationship.getRelatedTo()
407                     if (relatedTo.toLowerCase() == "service-instance") {
408                         String relatioshipurl = relationship.getRelatedLink()
409                         String nssiserviceid =
410                                 relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
411
412                         AAIResourcesClient client01 = new AAIResourcesClient()
413                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
414                                 globalSubscriberId, subscriptionServiceType, nssiserviceid)
415                         if (!client.exists(uri01)) {
416                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
417                                     "Service Instance was not found in aai")
418                         }
419                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
420                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
421                         if (nssiSi.isPresent()) {
422                             if (nssiSi.get().getEnvironmentContext().toLowerCase().contains("an")
423                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("cn")
424                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("tn")) {
425                                 nssiMap.put(nssiSi.get().getEnvironmentContext(),
426                                         new NSSI(nssiSi.get().getServiceInstanceId(),
427                                                 nssiSi.get().getModelInvariantId(), nssiSi.get().getModelVersionId()))
428                             }
429                         }
430                     }
431                 }
432
433
434             }
435         } catch (Exception e) {
436             String msg = "Requested service does not exist:" + e.getMessage()
437             logger.info("Service doesnt exist")
438             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
439         }
440
441         if (nssiMap.size() > 0) {
442             execution.setVariable("isNSSIActivate", "true")
443             String nssiMap01 = mapToJsonStr(nssiMap)
444             execution.setVariable("nssiMap", nssiMap01)
445             execution.setVariable("operation_type", "activate")
446             execution.setVariable("activationCount", nssiMap.size())
447             logger.info("the nssiMap01 is :" + nssiMap01)
448         } else {
449             execution.setVariable("isNSSIActivate", "false")
450         }
451
452         logger.debug(Prefix + "prepareActivation Exit")
453     }
454
455
456     private mapToJsonStr = { HashMap<String, NSSI> stringNSSIHashMap ->
457         HashMap<String, NSSI> map = new HashMap<String, NSSI>()
458         for (Map.Entry<String, NSSI> child : stringNSSIHashMap.entrySet()) {
459             map.put(child.getKey(), child.getValue())
460         }
461         return new Gson().toJson(map)
462     }
463
464
465     def checkAAIOrchStatusofslice = { DelegateExecution execution ->
466         logger.debug(Prefix + "CheckAAIOrchStatus Start")
467
468         String msg = ""
469         String serviceInstanceId = execution.getVariable("serviceInstanceId")
470         String globalSubscriberId = execution.getVariable("globalSubscriberId")
471         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
472         String operationType = execution.getVariable("operationType")
473
474         logger.debug("serviceInstanceId: " + serviceInstanceId)
475
476         //check the e2e slice status
477         try {
478             try {
479                 AAIResourcesClient client = new AAIResourcesClient()
480                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
481                         globalSubscriberId, subscriptionServiceType, serviceInstanceId)
482                 if (!client.exists(uri)) {
483                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
484                             "Service Instance was not found in aai")
485                 }
486                 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
487                 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
488                 if (si.isPresent()) {
489                     if (si.get().getOrchestrationStatus().toLowerCase() == "activated" &&
490                             operationType.equalsIgnoreCase("deactivation")) {
491                         logger.info("Service is in active state")
492                         execution.setVariable("e2eservicestatus", "activated")
493                         execution.setVariable("isContinue", "true")
494                         String snssai = si.get().getEnvironmentContext()
495                         execution.setVariable("snssai", snssai)
496                     } else if (si.get().getOrchestrationStatus().toLowerCase() == "deactivated" &&
497                             operationType.equalsIgnoreCase("activation")) {
498                         logger.info("Service is  in de-activated state")
499                         execution.setVariable("e2eservicestatus", "deactivated")
500                         execution.setVariable("isContinue", "true")
501                         String snssai = si.get().getEnvironmentContext()
502                         execution.setVariable("snssai", snssai)
503                     } else {
504                         execution.setVariable("isContinue", "false")
505                     }
506                 }
507             } catch (Exception e) {
508                 msg = "Requested e2eservice does not exist"
509                 logger.info("e2eservice doesnt exist")
510                 execution.setVariable("isContinue", "false")
511                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
512             }
513
514             //check the NSI is exist or the status of NSI is active or de-active
515             try {
516
517                 //get the allotted-resources by e2e slice id
518                 AAIResourcesClient client_allotted = new AAIResourcesClient()
519                 AAIResourceUri uri_allotted = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE_ALL,
520                         globalSubscriberId, subscriptionServiceType, serviceInstanceId)
521                 if (!client_allotted.exists(uri_allotted)) {
522                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
523                 }
524                 AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
525                 Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)
526
527                 if (all_allotted.isPresent() && all_allotted.get().getAllottedResource()) {
528                     List<AllottedResource> AllottedResourceList = all_allotted.get().getAllottedResource()
529                     AllottedResource ar = AllottedResourceList.first()
530                     String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
531                     String nsiserviceid = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
532                     execution.setVariable("NSIserviceid", nsiserviceid)
533                     logger.info("the NSI ID is:" + nsiserviceid)
534
535                     //Query nsi by nsi id
536                     try {
537                         //get the NSI id by e2e slice id
538                         AAIResourcesClient client = new AAIResourcesClient()
539                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
540                                 globalSubscriberId, subscriptionServiceType, nsiserviceid)
541                         if (!client.exists(uri)) {
542                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
543                                     "Service Instance was not found in aai")
544                         }
545                         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
546                         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
547
548                         if (si.isPresent()) {
549                             if (si.get().getServiceRole().toLowerCase() == "nsi") {
550                                 if (si.get().getOrchestrationStatus() == "activated") {
551                                     logger.info("NSI services is  in activated state")
552                                     execution.setVariable("NSIservicestatus", "activated")
553                                 } else {
554                                     logger.info("NSI services is  in deactivated state")
555                                     execution.setVariable("NSIservicestatus", "deactivated")
556                                 }
557                             } else {
558                                 logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
559                                         si.get().getServiceRole())
560                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
561                             }
562                         }
563                     } catch (Exception e) {
564                         msg = "Requested NSI service does not exist:" + e.getMessage()
565                         logger.info("NSI service doesnt exist")
566                         execution.setVariable("isContinue", "false")
567                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
568                     }
569                 }
570             } catch (Exception e) {
571                 msg = "Requested service does not exist: " + e.getMessage()
572                 logger.info("NSI Service doesnt exist")
573                 execution.setVariable("isActivate", "false")
574                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
575             }
576         } catch (BpmnError e) {
577             throw e
578         } catch (Exception ex) {
579             msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
580             logger.info(msg)
581             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
582         }
583
584         logger.debug(Prefix + "CheckAAIOrchStatus Exit")
585     }
586
587 }