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 static org.apache.commons.lang3.StringUtils.isBlank
 
  24 import java.lang.reflect.Type
 
  25 import javax.ws.rs.NotFoundException
 
  26 import org.camunda.bpm.engine.delegate.BpmnError
 
  27 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  28 import org.onap.aai.domain.yang.*
 
  29 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  30 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
 
  31 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
 
  32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
 
  35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
 
  36 import org.onap.logging.filter.base.ErrorCode
 
  37 import org.onap.so.beans.nsmf.NSSI
 
  38 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  39 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  40 import org.onap.so.bpmn.common.scripts.MsoUtils
 
  41 import org.onap.so.bpmn.common.scripts.RequestDBUtil
 
  42 import org.onap.so.bpmn.core.WorkflowException
 
  43 import org.onap.so.bpmn.core.json.JsonUtils
 
  44 import org.onap.so.db.request.beans.OperationStatus
 
  45 import org.onap.so.logger.LoggingAnchor
 
  46 import org.onap.so.logger.MessageEnum
 
  47 import org.slf4j.Logger
 
  48 import org.slf4j.LoggerFactory
 
  49 import com.google.gson.Gson
 
  50 import com.google.gson.reflect.TypeToken
 
  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(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIServiceId))
 
 252         if (!client.exists(uri)) {
 
 253             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
 
 255         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 256         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 257         if (si.isPresent()) {
 
 259             List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
 
 260             for (Relationship relationship : relatedList) {
 
 261                 String relatedTo = relationship.getRelatedTo()
 
 262                 if (relatedTo.toLowerCase() == "allotted-resource") {
 
 263                     //get snssi from allotted resource in list by nsi
 
 264                     List<String> SNSSIList = new ArrayList<>()
 
 265                     List<RelationshipData> relationshipDataList = relationship.getRelationshipData()
 
 266                     for (RelationshipData relationshipData : relationshipDataList) {
 
 267                         if (relationshipData.getRelationshipKey() == "service-instance.service-instance-id") {
 
 268                             SNSSIList.add(relationshipData.getRelationshipValue())
 
 271                     for (String snssi : SNSSIList) {
 
 272                         AAIResourcesClient client01 = new AAIResourcesClient()
 
 273                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(snssi))
 
 274                         if (!client.exists(uri01)) {
 
 275                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
 
 276                                     "Service Instance was not found in aai")
 
 278                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
 
 279                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
 
 280                         if (nssiSi.isPresent()) {
 
 281                             return nssiSi.get().getOrchestrationStatus() == "deactivated"
 
 289         logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
 
 293     def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
 
 294         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
 
 295         logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
 
 296         String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
 
 297         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
 
 299         String globalCustId = execution.getVariable("globalSubscriberId")
 
 300         String serviceType = execution.getVariable("serviceType")
 
 301         String operationType = execution.getVariable("operationType")
 
 303         String nssiMap = execution.getVariable("nssiMap")
 
 304         Type type = new TypeToken<HashMap<String, NSSI>>() {}.getType()
 
 305         Map<String, NSSI> activateNssiMap = new Gson().fromJson(nssiMap, type)
 
 306         //update tn/cn/an nssi
 
 307         for (Map.Entry<String, NSSI> entry : activateNssiMap.entrySet()) {
 
 308             NSSI nssi = entry.getValue()
 
 309             String nssiid = nssi.getNssiId()
 
 310             updateStratus(execution, globalCustId, serviceType, nssiid, operationType)
 
 312         if (operationType.equalsIgnoreCase("activation")) {
 
 314             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
 
 316             updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
 
 319             updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
 
 320             boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
 
 323                 updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
 
 325                 logger.error("Service's status update failed")
 
 326                 String msg = "Service's status update failed"
 
 327                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 330         logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
 
 334     def updateStratus = { DelegateExecution execution, String globalCustId,
 
 335                           String serviceType, String serviceId, String operationType ->
 
 336         logger.debug(Prefix + "updateStratus Start")
 
 339             AAIResourcesClient client = new AAIResourcesClient()
 
 340             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(serviceId))
 
 341             if (!client.exists(uri)) {
 
 342                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
 
 344             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 345             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 347             if (si.isPresent()) {
 
 348                 if (operationType.equalsIgnoreCase("activation")) {
 
 349                     if (si.get().getOrchestrationStatus() == "deactivated") {
 
 350                         si.get().setOrchestrationStatus("activated")
 
 351                         client.update(uri, si.get())
 
 354                     if (si.get().getOrchestrationStatus() == "activated") {
 
 355                         si.get().setOrchestrationStatus("deactivated")
 
 356                         client.update(uri, si.get())
 
 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)
 
 367         logger.debug(Prefix + "updateStratus Exit")
 
 371     def prepareActivation = { DelegateExecution execution ->
 
 372         logger.debug(Prefix + "prepareActivation Start")
 
 374         logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
 
 375         String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
 
 377         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 378         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 380         Map<String, NSSI> nssiMap = new HashMap<>()
 
 382         List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))
 
 384         def activationCount = activationSequence.size()
 
 386         execution.setVariable("activationIndex", "0")
 
 388         execution.setVariable("activationCount", activationCount)
 
 390             //get the TN NSSI id by NSI id, active NSSI TN slicing
 
 391             AAIResourcesClient client = new AAIResourcesClient()
 
 392             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIserviceInstanceId))
 
 393             if (!client.exists(uri)) {
 
 394                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
 
 396             AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 397             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 398             if (si.isPresent()) {
 
 400                 List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
 
 401                 for (Relationship relationship : relatedList) {
 
 402                     String relatedTo = relationship.getRelatedTo()
 
 403                     if (relatedTo.toLowerCase() == "service-instance") {
 
 404                         String relatioshipurl = relationship.getRelatedLink()
 
 405                         String nssiserviceid =
 
 406                                 relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
 
 408                         AAIResourcesClient client01 = new AAIResourcesClient()
 
 409                         AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiserviceid))
 
 410                         if (!client.exists(uri01)) {
 
 411                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
 
 412                                     "Service Instance was not found in aai")
 
 414                         AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
 
 415                         Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
 
 416                         if (nssiSi.isPresent()) {
 
 417                             if (nssiSi.get().getEnvironmentContext().toLowerCase().contains("an")
 
 418                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("cn")
 
 419                                     || nssiSi.get().getEnvironmentContext().toLowerCase().contains("tn")) {
 
 420                                 nssiMap.put(nssiSi.get().getEnvironmentContext(),
 
 421                                         new NSSI(nssiSi.get().getServiceInstanceId(),
 
 422                                                 nssiSi.get().getModelInvariantId(), nssiSi.get().getModelVersionId()))
 
 430         } catch (Exception e) {
 
 431             String msg = "Requested service does not exist:" + e.getMessage()
 
 432             logger.info("Service doesnt exist")
 
 433             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 436         if (nssiMap.size() > 0) {
 
 437             execution.setVariable("isNSSIActivate", "true")
 
 438             String nssiMap01 = mapToJsonStr(nssiMap)
 
 439             execution.setVariable("nssiMap", nssiMap01)
 
 440             execution.setVariable("operation_type", "activate")
 
 441             execution.setVariable("activationCount", nssiMap.size())
 
 442             logger.info("the nssiMap01 is :" + nssiMap01)
 
 444             execution.setVariable("isNSSIActivate", "false")
 
 447         logger.debug(Prefix + "prepareActivation Exit")
 
 451     private mapToJsonStr = { HashMap<String, NSSI> stringNSSIHashMap ->
 
 452         HashMap<String, NSSI> map = new HashMap<String, NSSI>()
 
 453         for (Map.Entry<String, NSSI> child : stringNSSIHashMap.entrySet()) {
 
 454             map.put(child.getKey(), child.getValue())
 
 456         return new Gson().toJson(map)
 
 460     def checkAAIOrchStatusofslice = { DelegateExecution execution ->
 
 461         logger.debug(Prefix + "CheckAAIOrchStatus Start")
 
 464         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 465         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 466         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 467         String operationType = execution.getVariable("operationType")
 
 469         logger.debug("serviceInstanceId: " + serviceInstanceId)
 
 471         //check the e2e slice status
 
 474                 AAIResourcesClient client = new AAIResourcesClient()
 
 475                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
 
 476                 if (!client.exists(uri)) {
 
 477                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
 
 478                             "Service Instance was not found in aai")
 
 480                 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 481                 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 482                 if (si.isPresent()) {
 
 483                     if (si.get().getOrchestrationStatus().toLowerCase() == "activated" &&
 
 484                             operationType.equalsIgnoreCase("deactivation")) {
 
 485                         logger.info("Service is in active state")
 
 486                         execution.setVariable("e2eservicestatus", "activated")
 
 487                         execution.setVariable("isContinue", "true")
 
 488                         String snssai = si.get().getEnvironmentContext()
 
 489                         execution.setVariable("snssai", snssai)
 
 490                     } else if (si.get().getOrchestrationStatus().toLowerCase() == "deactivated" &&
 
 491                             operationType.equalsIgnoreCase("activation")) {
 
 492                         logger.info("Service is  in de-activated state")
 
 493                         execution.setVariable("e2eservicestatus", "deactivated")
 
 494                         execution.setVariable("isContinue", "true")
 
 495                         String snssai = si.get().getEnvironmentContext()
 
 496                         execution.setVariable("snssai", snssai)
 
 498                         execution.setVariable("isContinue", "false")
 
 501             } catch (Exception e) {
 
 502                 msg = "Requested e2eservice does not exist"
 
 503                 logger.info("e2eservice doesnt exist")
 
 504                 execution.setVariable("isContinue", "false")
 
 505                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 508             //check the NSI is exist or the status of NSI is active or de-active
 
 511                 //get the allotted-resources by e2e slice id
 
 512                 AAIResourcesClient client_allotted = new AAIResourcesClient()
 
 513                 AAIPluralResourceUri uri_allotted = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId).allottedResources()
 
 515                 if (!client_allotted.exists(uri_allotted)) {
 
 516                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
 
 518                 AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
 
 519                 Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)
 
 521                 if (all_allotted.isPresent() && all_allotted.get().getAllottedResource()) {
 
 522                     List<AllottedResource> AllottedResourceList = all_allotted.get().getAllottedResource()
 
 523                     AllottedResource ar = AllottedResourceList.first()
 
 524                     String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
 
 525                     String nsiserviceid = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
 
 526                     execution.setVariable("NSIserviceid", nsiserviceid)
 
 527                     logger.info("the NSI ID is:" + nsiserviceid)
 
 529                     //Query nsi by nsi id
 
 531                         //get the NSI id by e2e slice id
 
 532                         AAIResourcesClient client = new AAIResourcesClient()
 
 533                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nsiserviceid))
 
 534                         if (!client.exists(uri)) {
 
 535                             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
 
 536                                     "Service Instance was not found in aai")
 
 538                         AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
 
 539                         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
 
 541                         if (si.isPresent()) {
 
 542                             if (si.get().getServiceRole().toLowerCase() == "nsi") {
 
 543                                 if (si.get().getOrchestrationStatus() == "activated") {
 
 544                                     logger.info("NSI services is  in activated state")
 
 545                                     execution.setVariable("NSIservicestatus", "activated")
 
 547                                     logger.info("NSI services is  in deactivated state")
 
 548                                     execution.setVariable("NSIservicestatus", "deactivated")
 
 551                                 logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
 
 552                                         si.get().getServiceRole())
 
 553                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 556                     } catch (Exception e) {
 
 557                         msg = "Requested NSI service does not exist:" + e.getMessage()
 
 558                         logger.info("NSI service doesnt exist")
 
 559                         execution.setVariable("isContinue", "false")
 
 560                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 563             } catch (Exception e) {
 
 564                 msg = "Requested service does not exist: " + e.getMessage()
 
 565                 logger.info("NSI Service doesnt exist")
 
 566                 execution.setVariable("isActivate", "false")
 
 567                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 569         } catch (BpmnError e) {
 
 571         } catch (Exception ex) {
 
 572             msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
 
 574             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 577         logger.debug(Prefix + "CheckAAIOrchStatus Exit")