630148e899ce7a09f41b941c714b26e86c992e44
[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.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.AAIResourcesClient
37 import org.onap.so.client.aai.entities.AAIResultWrapper
38 import org.onap.so.client.aai.entities.uri.AAIResourceUri
39 import org.onap.so.client.aai.entities.uri.AAIUriFactory
40 import org.onap.so.db.request.beans.OperationStatus
41 import org.onap.so.logger.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             } else {
99                 execution.setVariable("globalSubscriberId", globalSubscriberId)
100             }
101
102             //requestParameters
103             String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
104             if (isBlank(subscriptionServiceType)) {
105                 msg = "Input subscriptionServiceType is null"
106                 logger.debug(msg)
107                 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108             } else {
109                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
110             }
111             String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
112             execution.setVariable("operationId", operationId)
113
114             execution.getVariable("operationType")
115             logger.info("operationType is " + execution.getVariable("operationType") )
116         } catch (BpmnError e) {
117             throw e
118         } catch (Exception ex) {
119             msg = "Exception in preProcessRequest " + ex.getMessage()
120             logger.info(msg)
121             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
122         }
123         logger.debug(Prefix + "preProcessRequest Exit")
124     }
125
126
127     def sendSyncResponse = { DelegateExecution execution ->
128         logger.debug(Prefix + "sendSyncResponse Start")
129         try {
130             String operationId = execution.getVariable("operationId")
131             // RESTResponse for API Handler (APIH) Reply Task
132             String Activate5GsliceServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
133             logger.debug(" sendSyncResponse to APIH:" + "\n" + Activate5GsliceServiceRestRequest)
134             sendWorkflowResponse(execution, 202, Activate5GsliceServiceRestRequest)
135             execution.setVariable("sentSyncResponse", true)
136         } catch (Exception ex) {
137             String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
138             logger.debug(msg)
139             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140         }
141         logger.debug(Prefix + "sendSyncResponse Exit")
142     }
143
144
145     public sendSyncError = { DelegateExecution execution ->
146         logger.debug("sendSyncError Start")
147         try {
148             String errorMessage
149             if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
150                 WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
151                 errorMessage = wfe.getErrorMessage()
152             } else {
153                 errorMessage = "Sending Sync Error."
154             }
155
156             String buildWorkflowException =
157                     """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
158                                         <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
159                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>
160                                    </aetgt:WorkflowException>"""
161
162             logger.debug(buildWorkflowException)
163             sendWorkflowResponse(execution, 500, buildWorkflowException)
164
165         } catch (Exception ex) {
166             logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
167         }
168         logger.debug(Prefix + "sendSyncError Exit")
169     }
170
171
172     def prepareCompletionRequest = { DelegateExecution execution ->
173         logger.debug(Prefix + "prepareCompletionRequest Start")
174         String serviceId = execution.getVariable("serviceInstanceId")
175         String operationId = execution.getVariable("operationId")
176         String userId = execution.getVariable("globalSubscriberId")
177         //String result = execution.getVariable("result")
178         String result = "finished"
179         String progress = "100"
180         String reason = ""
181         String operationContent = execution.getVariable("operationContent")
182         String operationType = execution.getVariable("operationType")
183
184         OperationStatus initStatus = new OperationStatus()
185         initStatus.setServiceId(serviceId)
186         initStatus.setOperationId(operationId)
187         initStatus.setOperation(operationType)
188         initStatus.setUserId(userId)
189         initStatus.setResult(result)
190         initStatus.setProgress(progress)
191         initStatus.setReason(reason)
192         initStatus.setOperationContent(operationContent)
193
194         requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
195
196         logger.debug(Prefix + "prepareCompletionRequest Exit")
197     }
198
199
200     /**
201      * Init the service Operation Status
202      */
203     def prepareInitServiceOperationStatus = { DelegateExecution execution ->
204         logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
205         try {
206             String serviceId = execution.getVariable("serviceInstanceId")
207             String operationId = execution.getVariable("operationId")
208             String operationType = execution.getVariable("operationType")
209             String userId = execution.getVariable("globalSubscriberId")
210             String result = "processing"
211             String progress = "0"
212             String reason = ""
213             String operationContent = "Prepare service activation"
214
215             execution.setVariable("e2eserviceInstanceId", serviceId)
216             execution.setVariable("operationType", operationType)
217
218             OperationStatus initStatus = new OperationStatus()
219             initStatus.setServiceId(serviceId)
220             initStatus.setOperationId(operationId)
221             initStatus.setOperation(operationType)
222             initStatus.setUserId(userId)
223             initStatus.setResult(result)
224             initStatus.setProgress(progress)
225             initStatus.setReason(reason)
226             initStatus.setOperationContent(operationContent)
227
228             requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
229
230         } catch (Exception e) {
231             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
232                     "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
233                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
234             execution.setVariable("CVFMI_ErrorResponse",
235                     "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
236         }
237         logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
238     }
239
240
241     private getSNSSIStatusByNsi = { DelegateExecution execution, String NSIServiceId ->
242
243         logger.debug(Prefix + "getSNSSIStatusByNsi Start")
244         String globalSubscriberId = execution.getVariable("globalSubscriberId")
245         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
246
247         AAIResourcesClient client = new AAIResourcesClient()
248         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
249                 globalSubscriberId, subscriptionServiceType, NSIServiceId)
250         if (!client.exists(uri)) {
251             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
252         }
253         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
254         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
255         if (si.isPresent()) {
256
257             List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
258             for (Relationship relationship : relatedList) {
259                 String relatedTo = relationship.getRelatedTo()
260                 if (relatedTo.toLowerCase() == "allotted-resource") {
261                     //get snssi from allotted resource in list by nsi
262                     List<String> SNSSIList = new ArrayList<>()
263                     List<RelationshipData> relationshipDataList = relationship.getRelationshipData()
264                     for (RelationshipData relationshipData : relationshipDataList) {
265                         if (relationshipData.getRelationshipKey() == "service-instance.service-instance-id") {
266                             SNSSIList.add(relationshipData.getRelationshipValue())
267                         }
268                     }
269                     for (String snssi : SNSSIList) {
270                         AAIResourcesClient client01 = new AAIResourcesClient()
271                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
272                                 globalSubscriberId, subscriptionServiceType, snssi)
273                         if (!client.exists(uri01)) {
274                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
275                                     "Service Instance was not found in aai")
276                         }
277                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
278                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
279                         if (nssiSi.isPresent()) {
280                             return nssiSi.get().getOrchestrationStatus() == "deactivated"
281                         }
282                     }
283
284                 }
285             }
286
287         }
288         logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
289     }
290
291
292     def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
293         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
294         logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
295         String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
296         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
297
298         String globalCustId = execution.getVariable("globalSubscriberId")
299         String serviceType = execution.getVariable("serviceType")
300         String operationType = execution.getVariable("operationType")
301
302         String nssiMap = execution.getVariable("nssiMap")
303         Type type = new TypeToken<HashMap<String, NSSI>>() {}.getType()
304         Map<String, NSSI> activateNssiMap = new Gson().fromJson(nssiMap, type)
305         //update tn/cn/an nssi
306         for (Map.Entry<String, NSSI> entry : activateNssiMap.entrySet()) {
307             NSSI nssi = entry.getValue()
308             String nssiid = nssi.getNssiId()
309             updateStratus(execution, globalCustId, serviceType, nssiid, operationType)
310         }
311         if (operationType == "activation") {
312             //update the s-nssai
313             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
314             //update the nsi
315             updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
316         } else {
317             //update the s-nssai
318             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
319             boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
320             if (flag) {
321                 //update the nsi
322                 updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
323             } else {
324                 logger.error("Service's status update failed")
325                 String msg = "Service's status update failed"
326                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
327             }
328         }
329         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
330     }
331
332
333     def updateStratus = { DelegateExecution execution, String globalCustId,
334                           String serviceType, String serviceId, String operationType ->
335         logger.debug(Prefix + "updateStratus Start")
336
337         try {
338             AAIResourcesClient client = new AAIResourcesClient()
339             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
340                     globalCustId, serviceType, serviceId)
341             if (!client.exists(uri)) {
342                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
343             }
344             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
345             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
346
347             if (si.isPresent()) {
348                 if (operationType == "activation") {
349                     if (si.get().getOrchestrationStatus() == "deactivated") {
350                         si.get().setOrchestrationStatus("activated")
351                         client.update(uri, si.get())
352                     }
353                 } else {
354                     if (si.get().getOrchestrationStatus() == "activated") {
355                         si.get().setOrchestrationStatus("deactivated")
356                         client.update(uri, si.get())
357                     }
358                 }
359
360             }
361         } catch (Exception e) {
362             logger.info("Service is already in active state")
363             String msg = "Service is already in active state, " + e.getMessage()
364             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
365         }
366
367         logger.debug(Prefix + "updateStratus Exit")
368     }
369
370
371     def prepareActivation = { DelegateExecution execution ->
372         logger.debug(Prefix + "prepareActivation Start")
373
374         logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
375         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
376
377         String globalSubscriberId = execution.getVariable("globalSubscriberId")
378         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
379
380         Map<String, NSSI> nssiMap = new HashMap<>()
381
382         List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))
383
384         def activationCount = activationSequence.size()
385
386         execution.setVariable("activationIndex", "0")
387
388         execution.setVariable("activationCount", activationCount)
389         try {
390             //get the TN NSSI id by NSI id, active NSSI TN slicing
391             AAIResourcesClient client = new AAIResourcesClient()
392             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
393                     globalSubscriberId, subscriptionServiceType, NSIserviceInstanceId)
394             if (!client.exists(uri)) {
395                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
396             }
397             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
398             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
399             if (si.isPresent()) {
400
401                 List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
402                 for (Relationship relationship : relatedList) {
403                     String relatedTo = relationship.getRelatedTo()
404                     if (relatedTo.toLowerCase() == "service-instance") {
405                         String relatioshipurl = relationship.getRelatedLink()
406                         String nssiserviceid =
407                                 relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
408
409                         AAIResourcesClient client01 = new AAIResourcesClient()
410                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
411                                 globalSubscriberId, subscriptionServiceType, nssiserviceid)
412                         if (!client.exists(uri01)) {
413                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
414                                     "Service Instance was not found in aai")
415                         }
416                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
417                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
418                         if (nssiSi.isPresent()) {
419                             if (nssiSi.get().getEnvironmentContext().toLowerCase().contains("an")
420                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("cn")
421                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("tn")) {
422                                 nssiMap.put(nssiSi.get().getEnvironmentContext(),
423                                         new NSSI(nssiSi.get().getServiceInstanceId(),
424                                                 nssiSi.get().getModelInvariantId(), nssiSi.get().getModelVersionId()))
425                             }
426                         }
427                     }
428                 }
429
430
431             }
432         } catch (Exception e) {
433             String msg = "Requested service does not exist:" + e.getMessage()
434             logger.info("Service doesnt exist")
435             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
436         }
437
438         if (nssiMap.size() > 0) {
439             execution.setVariable("isNSSIActivate", "true")
440             String nssiMap01 = mapToJsonStr(nssiMap)
441             execution.setVariable("nssiMap", nssiMap01)
442             execution.setVariable("operation_type", "activate")
443             execution.setVariable("activationCount", nssiMap.size())
444             logger.info("the nssiMap01 is :" + nssiMap01)
445         } else {
446             execution.setVariable("isNSSIActivate", "false")
447         }
448
449         logger.debug(Prefix + "prepareActivation Exit")
450     }
451
452
453     private mapToJsonStr = { HashMap<String, NSSI> stringNSSIHashMap ->
454         HashMap<String, NSSI> map = new HashMap<String, NSSI>()
455         for (Map.Entry<String, NSSI> child : stringNSSIHashMap.entrySet()) {
456             map.put(child.getKey(), child.getValue())
457         }
458         return new Gson().toJson(map)
459     }
460
461
462     def checkAAIOrchStatusofslice = { DelegateExecution execution ->
463         logger.debug(Prefix + "CheckAAIOrchStatus Start")
464
465         String msg = ""
466         String serviceInstanceId = execution.getVariable("serviceInstanceId")
467         String globalSubscriberId = execution.getVariable("globalSubscriberId")
468         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
469         String operationType = execution.getVariable("operationType")
470
471         logger.debug("serviceInstanceId: " + serviceInstanceId)
472
473         //check the e2e slice status
474         try {
475             try {
476                 AAIResourcesClient client = new AAIResourcesClient()
477                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
478                         globalSubscriberId, subscriptionServiceType, serviceInstanceId)
479                 if (!client.exists(uri)) {
480                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
481                             "Service Instance was not found in aai")
482                 }
483                 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
484                 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
485                 if (si.isPresent()) {
486                     if (si.get().getOrchestrationStatus().toLowerCase() == "activated" &&
487                             operationType == "deactivation") {
488                         logger.info("Service is in active state")
489                         execution.setVariable("e2eservicestatus", "activated")
490                         execution.setVariable("isContinue", "true")
491                         String snssai = si.get().getEnvironmentContext()
492                         execution.setVariable("snssai", snssai)
493                     } else if ((si.get().getOrchestrationStatus().toLowerCase() == "deactivated" ||
494                             si.get().getOrchestrationStatus().toLowerCase() == "created") &&
495                             operationType == "activation") {
496                         logger.info("Service is  in de-activated state")
497                         execution.setVariable("e2eservicestatus", "deactivated")
498                         execution.setVariable("isContinue", "true")
499                         String snssai = si.get().getEnvironmentContext()
500                         execution.setVariable("snssai", snssai)
501                     } else {
502                         execution.setVariable("isContinue", "false")
503                     }
504                 }
505             } catch (Exception e) {
506                 msg = "Requested e2eservice does not exist"
507                 logger.info("e2eservice doesnt exist")
508                 execution.setVariable("isContinue", "false")
509                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
510             }
511
512             //check the NSI is exist or the status of NSI is active or de-active
513             try {
514
515                 //get the allotted-resources by e2e slice id
516                 AAIResourcesClient client_allotted = new AAIResourcesClient()
517                 AAIResourceUri uri_allotted = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE_ALL,
518                         globalSubscriberId, subscriptionServiceType, serviceInstanceId)
519                 if (!client_allotted.exists(uri_allotted)) {
520                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
521                 }
522                 AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
523                 Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)
524
525                 if (all_allotted.isPresent() && all_allotted.get().getAllottedResource()) {
526                     List<AllottedResource> AllottedResourceList = all_allotted.get().getAllottedResource()
527                     AllottedResource ar = AllottedResourceList.first()
528                     String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
529                     String nsiserviceid = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
530                     execution.setVariable("NSIserviceid", nsiserviceid)
531                     logger.info("the NSI ID is:" + nsiserviceid)
532
533                     //Query nsi by nsi id
534                     try {
535                         //get the NSI id by e2e slice id
536                         AAIResourcesClient client = new AAIResourcesClient()
537                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
538                                 globalSubscriberId, subscriptionServiceType, nsiserviceid)
539                         if (!client.exists(uri)) {
540                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
541                                     "Service Instance was not found in aai")
542                         }
543                         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
544                         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
545
546                         if (si.isPresent()) {
547                             if (si.get().getServiceRole().toLowerCase() == "nsi") {
548                                 if (si.get().getOrchestrationStatus() == "activated") {
549                                     logger.info("NSI services is  in activated state")
550                                     execution.setVariable("NSIservicestatus", "activated")
551                                 } else {
552                                     logger.info("NSI services is  in deactivated state")
553                                     execution.setVariable("NSIservicestatus", "deactivated")
554                                 }
555                             } else {
556                                 logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
557                                         si.get().getServiceRole())
558                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
559                             }
560                         }
561                     } catch (Exception e) {
562                         msg = "Requested NSI service does not exist:" + e.getMessage()
563                         logger.info("NSI service doesnt exist")
564                         execution.setVariable("isContinue", "false")
565                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
566                     }
567                 }
568             } catch (Exception e) {
569                 msg = "Requested service does not exist: " + e.getMessage()
570                 logger.info("NSI Service doesnt exist")
571                 execution.setVariable("isActivate", "false")
572                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
573             }
574         } catch (BpmnError e) {
575             throw e
576         } catch (Exception ex) {
577             msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
578             logger.info(msg)
579             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
580         }
581
582         logger.debug(Prefix + "CheckAAIOrchStatus Exit")
583     }
584
585 }