2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.scripts
 
  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
 
  47 import javax.ws.rs.NotFoundException
 
  48 import java.lang.reflect.Type
 
  50 import static org.apache.commons.lang3.StringUtils.isBlank
 
  53  * This groovy class supports the <class>ActivateSliceService.bpmn</class> process.
 
  54  * AlaCarte flow for 1702 slice service activate
 
  58 class ActivateSliceService extends AbstractServiceTaskProcessor {
 
  61     String Prefix = "ACTSS_"
 
  63     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  65     JsonUtils jsonUtil = new JsonUtils()
 
  67     RequestDBUtil requestDBUtil = new RequestDBUtil()
 
  69     private static final Logger logger = LoggerFactory.getLogger(ActivateSliceService.class)
 
  71     void preProcessRequest(DelegateExecution execution) {
 
  72         logger.debug(Prefix + "preProcessRequest Start")
 
  73         execution.setVariable("prefix", Prefix)
 
  77             // check for incoming json message/input
 
  78             String siRequest = execution.getVariable("bpmnRequest")
 
  79             logger.debug(siRequest)
 
  81             String requestId = execution.getVariable("mso-request-id")
 
  82             execution.setVariable("msoRequestId", requestId)
 
  83             logger.info("Input Request:" + siRequest + " reqId:" + requestId)
 
  85             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
  86             if (isBlank(serviceInstanceId)) {
 
  87                 msg = "Input serviceInstanceId' is null"
 
  88                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  90             String source = jsonUtil.getJsonValue(siRequest, "source")
 
  91             execution.setVariable("source", source)
 
  94             String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
 
  95             if (isBlank(globalSubscriberId)) {
 
  96                 msg = "Input globalSubscriberId' is null"
 
  98                 execution.setVariable("globalSubscriberId", "5GCustomer")
 
 100                 execution.setVariable("globalSubscriberId", globalSubscriberId)
 
 104             String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
 
 105             if (isBlank(subscriptionServiceType)) {
 
 106                 msg = "Input subscriptionServiceType is null"
 
 108                 execution.setVariable("subscriptionServiceType", "5G")
 
 110                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
 
 112             String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
 
 113             execution.setVariable("operationId", operationId)
 
 115             String operationType = execution.getVariable("operationType")
 
 116             execution.setVariable("operationType", operationType.toUpperCase())
 
 118             logger.info("operationType is " + execution.getVariable("operationType") )
 
 119         } catch (BpmnError e) {
 
 121         } catch (Exception ex) {
 
 122             msg = "Exception in preProcessRequest " + ex.getMessage()
 
 124             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 126         logger.debug(Prefix + "preProcessRequest Exit")
 
 130     def sendSyncResponse = { DelegateExecution execution ->
 
 131         logger.debug(Prefix + "sendSyncResponse Start")
 
 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()
 
 142             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 144         logger.debug(Prefix + "sendSyncResponse Exit")
 
 148     public sendSyncError = { DelegateExecution execution ->
 
 149         logger.debug("sendSyncError Start")
 
 152             if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
 
 153                 WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
 
 154                 errorMessage = wfe.getErrorMessage()
 
 156                 errorMessage = "Sending Sync Error."
 
 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>"""
 
 165             logger.debug(buildWorkflowException)
 
 166             sendWorkflowResponse(execution, 500, buildWorkflowException)
 
 168         } catch (Exception ex) {
 
 169             logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
 
 171         logger.debug(Prefix + "sendSyncError Exit")
 
 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"
 
 184         String operationContent = execution.getVariable("operationContent")
 
 185         String operationType = execution.getVariable("operationType")
 
 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)
 
 197         requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
 
 199         logger.debug(Prefix + "prepareCompletionRequest Exit")
 
 204      * Init the service Operation Status
 
 206     def prepareInitServiceOperationStatus = { DelegateExecution execution ->
 
 207         logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
 
 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"
 
 216             String operationContent = "Prepare service activation"
 
 218             execution.setVariable("e2eserviceInstanceId", serviceId)
 
 219             execution.setVariable("operationType", operationType)
 
 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)
 
 231             requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
 
 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())
 
 240         logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
 
 244     private getSNSSIStatusByNsi = { DelegateExecution execution, String NSIServiceId ->
 
 246         logger.debug(Prefix + "getSNSSIStatusByNsi Start")
 
 247         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 248         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 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")
 
 256         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 257         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 258         if (si.isPresent()) {
 
 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())
 
 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")
 
 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"
 
 291         logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
 
 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")
 
 301         String globalCustId = execution.getVariable("globalSubscriberId")
 
 302         String serviceType = execution.getVariable("serviceType")
 
 303         String operationType = execution.getVariable("operationType")
 
 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)
 
 314         if (operationType.equalsIgnoreCase("activation")) {
 
 316             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
 
 318             updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
 
 321             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
 
 322             boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
 
 325                 updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
 
 327                 logger.error("Service's status update failed")
 
 328                 String msg = "Service's status update failed"
 
 329                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 332         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
 
 336     def updateStratus = { DelegateExecution execution, String globalCustId,
 
 337                           String serviceType, String serviceId, String operationType ->
 
 338         logger.debug(Prefix + "updateStratus Start")
 
 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")
 
 347             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 348             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 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())
 
 357                     if (si.get().getOrchestrationStatus() == "activated") {
 
 358                         si.get().setOrchestrationStatus("deactivated")
 
 359                         client.update(uri, si.get())
 
 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)
 
 370         logger.debug(Prefix + "updateStratus Exit")
 
 374     def prepareActivation = { DelegateExecution execution ->
 
 375         logger.debug(Prefix + "prepareActivation Start")
 
 377         logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
 
 378         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
 
 380         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 381         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 383         Map<String, NSSI> nssiMap = new HashMap<>()
 
 385         List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))
 
 387         def activationCount = activationSequence.size()
 
 389         execution.setVariable("activationIndex", "0")
 
 391         execution.setVariable("activationCount", activationCount)
 
 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")
 
 400             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 401             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 402             if (si.isPresent()) {
 
 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())
 
 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")
 
 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()))
 
 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)
 
 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)
 
 449             execution.setVariable("isNSSIActivate", "false")
 
 452         logger.debug(Prefix + "prepareActivation Exit")
 
 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())
 
 461         return new Gson().toJson(map)
 
 465     def checkAAIOrchStatusofslice = { DelegateExecution execution ->
 
 466         logger.debug(Prefix + "CheckAAIOrchStatus Start")
 
 469         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 470         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 471         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 472         String operationType = execution.getVariable("operationType")
 
 474         logger.debug("serviceInstanceId: " + serviceInstanceId)
 
 476         //check the e2e slice status
 
 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")
 
 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)
 
 504                         execution.setVariable("isContinue", "false")
 
 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)
 
 514             //check the NSI is exist or the status of NSI is active or de-active
 
 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")
 
 524                 AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
 
 525                 Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)
 
 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)
 
 535                     //Query nsi by nsi id
 
 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")
 
 545                         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 546                         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 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")
 
 554                                     logger.info("NSI services is  in deactivated state")
 
 555                                     execution.setVariable("NSIservicestatus", "deactivated")
 
 558                                 logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
 
 559                                         si.get().getServiceRole())
 
 560                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 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)
 
 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)
 
 576         } catch (BpmnError e) {
 
 578         } catch (Exception ex) {
 
 579             msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
 
 581             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 584         logger.debug(Prefix + "CheckAAIOrchStatus Exit")