2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2020  Telecom Italia
 
   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.fasterxml.jackson.databind.ObjectMapper
 
  24 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  25 import org.onap.aai.domain.yang.CloudRegion
 
  26 import org.onap.aai.domain.yang.GenericVnf
 
  27 import org.onap.aai.domain.yang.ModelVer
 
  28 import org.onap.aai.domain.yang.ServiceInstance
 
  29 import org.onap.aai.domain.yang.ServiceSubscription
 
  30 import org.onap.aai.domain.yang.SliceProfile
 
  31 import org.onap.aai.domain.yang.Tenant
 
  32 import org.onap.aai.domain.yang.VfModule
 
  33 import org.onap.aaiclient.client.aai.AAIObjectType
 
  34 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  35 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
 
  36 import org.onap.aaiclient.client.aai.entities.Relationships
 
  37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  38 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  39 import org.onap.logging.filter.base.ONAPComponents
 
  40 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  41 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  42 import org.onap.so.bpmn.common.scripts.RequestDBUtil
 
  43 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  44 import org.onap.so.bpmn.core.json.JsonUtils
 
  45 import org.onap.so.client.HttpClient
 
  46 import org.onap.so.db.request.beans.OperationStatus
 
  47 import org.onap.so.requestsdb.RequestsDbConstant
 
  48 import org.onap.so.serviceinstancebeans.CloudConfiguration
 
  49 import org.onap.so.serviceinstancebeans.LineOfBusiness
 
  50 import org.onap.so.serviceinstancebeans.ModelInfo
 
  51 import org.onap.so.serviceinstancebeans.ModelType
 
  52 import org.onap.so.serviceinstancebeans.OwningEntity
 
  53 import org.onap.so.serviceinstancebeans.Project
 
  54 import org.onap.so.serviceinstancebeans.RequestDetails
 
  55 import org.onap.so.serviceinstancebeans.RequestInfo
 
  56 import org.onap.so.serviceinstancebeans.RequestParameters
 
  57 import org.onap.so.serviceinstancebeans.Resources
 
  58 import org.onap.so.serviceinstancebeans.Service
 
  59 import org.onap.so.serviceinstancebeans.SubscriberInfo
 
  60 import org.onap.so.serviceinstancebeans.VfModules
 
  61 import org.onap.so.serviceinstancebeans.Vnfs
 
  62 import org.slf4j.Logger
 
  63 import org.slf4j.LoggerFactory
 
  65 import javax.ws.rs.core.Response
 
  68  class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
  70     private final String PREFIX ="DoCommonCoreNSSI"
 
  72     private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class)
 
  74     private JsonUtils jsonUtil = new JsonUtils()
 
  75     private ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  76     private RequestDBUtil requestDBUtil = new RequestDBUtil()
 
  79     void preProcessRequest(DelegateExecution execution) {
 
  80         LOGGER.trace("${getPrefix()} Start preProcessRequest")
 
  82         def currentNSSI = execution.getVariable("currentNSSI")
 
  84             String msg = "currentNSSI is null"
 
  86             exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  89         LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest")
 
  94      * Queries Network Service Instance in AAI
 
  97     void getNetworkServiceInstance(DelegateExecution execution) {
 
  98         LOGGER.trace("${getPrefix()} Start getNetworkServiceInstance")
 
 100         AAIResourcesClient client = getAAIClient()
 
 102         def currentNSSI = execution.getVariable("currentNSSI")
 
 104         String nssiId = currentNSSI['nssiId']
 
 106         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
 
 107         Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
 
 109         if (nssiOpt.isPresent()) {
 
 110             ServiceInstance nssi = nssiOpt.get()
 
 111             currentNSSI['nssi'] = nssi
 
 113             ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client)
 
 114             currentNSSI['networkServiceInstance'] = networkServiceInstance
 
 117             String msg = String.format("NSSI %s not found in AAI", nssiId)
 
 119             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 122         LOGGER.trace("${getPrefix()} Exit getNetworkServiceInstance")
 
 127      * Handles Network Service
 
 131      * @return Network Service Instance
 
 133     private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
 
 134         ServiceInstance networkServiceInstance = null
 
 136         def currentNSSI = execution.getVariable("currentNSSI")
 
 138         AAIResultWrapper wrapper = client.get(nssiUri)
 
 139         Optional<Relationships> relationships = wrapper.getRelationships()
 
 141         if (relationships.isPresent()) {
 
 142             for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)) {
 
 143                 Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri)
 
 144                 if (networkServiceInstanceOpt.isPresent()) {
 
 145                     networkServiceInstance = networkServiceInstanceOpt.get()
 
 147                     if (networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
 
 148                         currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
 
 153                     String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
 
 155                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 160             String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
 
 162             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 165         if(networkServiceInstance == null) {
 
 166             String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId)
 
 168             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 171         return networkServiceInstance
 
 176      * Queries constitute VNF from Network Service Instance
 
 179     void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
 
 180         LOGGER.trace("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
 
 182         def currentNSSI = execution.getVariable("currentNSSI")
 
 184         AAIResourcesClient client = getAAIClient()
 
 186         AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
 
 187         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
 
 188         Optional<Relationships> relationships = wrapper.getRelationships()
 
 189         if (relationships.isPresent()) {
 
 190             for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) {
 
 191                 currentNSSI['constituteVnfUri'] = constituteVnfUri
 
 192                 Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri)
 
 193                 if(constituteVnfOpt.isPresent()) {
 
 194                     GenericVnf constituteVnf = constituteVnfOpt.get()
 
 195                     currentNSSI['constituteVnf'] = constituteVnf
 
 198                     String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
 
 200                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 203                 break  // Should be only one constitute VNF
 
 207             String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
 
 209             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 212         LOGGER.trace("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
 
 218      * Retrieves NSSI associated profiles from AAI
 
 221     void getNSSIAssociatedProfiles(DelegateExecution execution) {
 
 222         LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles")
 
 224         def currentNSSI = execution.getVariable("currentNSSI")
 
 226         ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
 
 228         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
 
 230         if(associatedProfiles.isEmpty()) {
 
 231             String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
 
 233             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 236             currentNSSI['associatedProfiles'] =  associatedProfiles
 
 239         LOGGER.trace("${getPrefix()} Exit getNSSIAssociatedProfiles")
 
 244      * Calculates a final list of S-NSSAI
 
 247     void calculateSNSSAI(DelegateExecution execution) {
 
 248         LOGGER.trace("${getPrefix()} Start calculateSNSSAI")
 
 250         def currentNSSI = execution.getVariable("currentNSSI")
 
 252         List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
 
 254         String currentSNSSAI = currentNSSI['S-NSSAI']
 
 256         List<String> snssais = new ArrayList<>()
 
 258         String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" )
 
 260         boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
 
 262         if(isCreateSliceProfileInstance) { // Slice Profile Instance has to be created
 
 263             for (SliceProfile associatedProfile : associatedProfiles) {
 
 264                 snssais.add(associatedProfile.getSNssai())
 
 267             snssais.add(currentSNSSAI)
 
 269         else { // Slice profile instance has to be deleted
 
 270             for (SliceProfile associatedProfile : associatedProfiles) {
 
 271                 if (!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI
 
 272                     snssais.add(associatedProfile.getSNssai())
 
 274                     currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
 
 279         currentNSSI['S-NSSAIs'] = snssais
 
 281         LOGGER.trace("${getPrefix()} Exit calculateSNSSAI")
 
 286      * Invoke PUT Service Instance API
 
 289     void invokePUTServiceInstance(DelegateExecution execution) {
 
 290         LOGGER.trace("${getPrefix()} Start invokePUTServiceInstance")
 
 292         def currentNSSI = execution.getVariable("currentNSSI")
 
 295             //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}"
 
 296             def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ???
 
 298             ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
 
 300             GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
 
 302             String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
 
 304             String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
 
 305             String basicAuth =  UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
 
 308             String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
 
 309             String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
 
 311             String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
 
 312             if(errorCode == null || errorCode.isEmpty()) { // No error
 
 313                 authHeader = responseAuthHeader
 
 316                 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
 
 319             def requestDetails = ""
 
 320             String prepareRequestDetailsResponse = prepareRequestDetails(execution)
 
 321             errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
 
 322             if(errorCode == null || errorCode.isEmpty()) { // No error
 
 323                 requestDetails = prepareRequestDetailsResponse
 
 326                 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage"))
 
 329             String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
 
 330             String putServiceInstanceResponse = ""
 
 332             if(errorCode == null || errorCode.isEmpty()) { // No error
 
 333                 putServiceInstanceResponse = callPUTServiceInstanceResponse // check the response ???
 
 336                 LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
 
 337                 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
 
 341             String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
 
 343             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 346         LOGGER.trace("${getPrefix()} Exit invokePUTServiceInstance")
 
 350     String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
 
 351         String errorCode = ""
 
 352         String errorMessage = ""
 
 356             HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
 
 357             httpClient.addAdditionalHeader("Authorization", authHeader)
 
 358             httpClient.addAdditionalHeader("Accept", "application/json")
 
 360             Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
 
 363             if (httpResponse.hasEntity()) {
 
 364                 response = httpResponse.readEntity(String.class)
 
 368                 errorMessage = "No response received."
 
 371                         " \"errorCode\": \"${errorCode}\",\n" +
 
 372                         " \"errorMessage\": \"${errorMessage}\"\n" +
 
 377             String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
 
 381                     " \"errorCode\": \"7000\",\n" +
 
 382                     " \"errorMessage\": \"${msg}\"\n" +
 
 395      * @param requestDetails
 
 398     ModelInfo prepareModelInfo(DelegateExecution execution) {
 
 400         def currentNSSI = execution.getVariable("currentNSSI")
 
 401         ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
 
 403         ModelInfo modelInfo = new ModelInfo()
 
 405         modelInfo.setModelType(ModelType.service)
 
 406         modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
 
 408         AAIResourcesClient client = getAAIClient()
 
 410         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId())
 
 411         Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl)
 
 413         if (modelVerOpt.isPresent()) {
 
 414             modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId())
 
 415             modelInfo.setModelName(modelVerOpt.get().getModelName())
 
 416             modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
 
 424      * Prepares subscriber info
 
 426      * @return SubscriberInfo
 
 428     SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
 
 429         def currentNSSI = execution.getVariable("currentNSSI")
 
 431         String globalSubscriberId = currentNSSI['globalSubscriberId']
 
 433         String subscriberName = currentNSSI['subscriberName']
 
 435         SubscriberInfo subscriberInfo = new SubscriberInfo()
 
 436         subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
 
 437         subscriberInfo.setSubscriberName(subscriberName)
 
 440         AAIResourcesClient client = getAAIClient()
 
 442         Customer customer = null
 
 444         AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
 
 445         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
 
 446         Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships()
 
 447         if(serviceSubscriptionRelationshipsOps.isPresent()) {
 
 448             List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)
 
 449             if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) {
 
 450                 AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation
 
 451                 Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri)
 
 453                 if(serviceSubscriptionOpt.isPresent()) {
 
 454                     currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get()
 
 457                 wrapper = client.get(serviceSubscriptionUri)
 
 458                 Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships()
 
 459                 if(customerRelationshipsOps.isPresent()) {
 
 460                     List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER)
 
 461                     if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) {
 
 462                         Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation
 
 463                         if(customerOpt.isPresent()) {
 
 464                             customer = customerOpt.get()
 
 465                             subscriberInfo.setSubscriberName(customer.getSubscriberName())
 
 473         return subscriberInfo
 
 478      * Prepares Request Info
 
 480      * @return RequestInfo
 
 482     RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
 
 483         def currentNSSI = execution.getVariable("currentNSSI")
 
 485         String serviceId = currentNSSI['serviceId']
 
 487         RequestInfo requestInfo = new RequestInfo()
 
 489         requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
 
 490         requestInfo.setSource("VID")
 
 491         requestInfo.setProductFamilyId(serviceId)
 
 492         requestInfo.setRequestorId("NBI")
 
 499      * Prepares Model Info
 
 500      * @param networkServiceInstance
 
 504     ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
 
 506         ModelInfo serviceModelInfo = new ModelInfo()
 
 507         serviceModelInfo.setModelType(ModelType.service)
 
 508         serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId())
 
 510         serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId())
 
 511         serviceModelInfo.setModelName(modelInfo.getModelName())
 
 512         serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
 
 514         return serviceModelInfo
 
 519      * Prepares Cloud configuration
 
 521      * @return CloudConfiguration
 
 523     CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
 
 524         def currentNSSI = execution.getVariable("currentNSSI")
 
 526         CloudConfiguration cloudConfiguration = new CloudConfiguration()
 
 528         AAIResourcesClient client = getAAIClient()
 
 530         AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
 
 531         AAIResultWrapper wrapper = client.get(constituteVnfUri)
 
 532         Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
 
 534         if(cloudRegionRelationshipsOps.isPresent()) {
 
 535             List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION)
 
 536             if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) {
 
 537                 AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0)
 
 538                 currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri
 
 540                 Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0))
 
 541                 CloudRegion cloudRegion = null
 
 542                 if (cloudRegionrOpt.isPresent()) {
 
 543                     cloudRegion = cloudRegionrOpt.get()
 
 544                     cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
 
 545                     for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
 
 546                         cloudConfiguration.setTenantId(tenant.getTenantId())
 
 547                         break // only one is required
 
 550                     cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
 
 555         return cloudConfiguration
 
 560      * Prepares a list of VF Modules
 
 562      * @param constituteVnf
 
 563      * @return List<VfModules>
 
 565     List<VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
 
 567         AAIResourcesClient client = getAAIClient()
 
 569         List<VfModules> vfModuless = new ArrayList<>()
 
 570         for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
 
 571             VfModules vfmodules = new VfModules()
 
 573             ModelInfo vfModuleModelInfo = new ModelInfo()
 
 574             vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
 
 575             vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
 
 577             AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId())
 
 579             Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
 
 581             if (vfModuleModelVerOpt.isPresent()) {
 
 582                 vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
 
 583                 vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
 
 584                 vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
 
 586             vfmodules.setModelInfo(vfModuleModelInfo)
 
 588             vfmodules.setInstanceName(vfModule.getVfModuleName())
 
 590             vfModuless.add(vfmodules)
 
 598      * prepares VNF Model Info
 
 600      * @param constituteVnf
 
 603     ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
 
 604         ModelInfo vnfModelInfo = new ModelInfo()
 
 606         AAIResourcesClient client = getAAIClient()
 
 608         vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId())
 
 609         vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId())
 
 610         vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName())
 
 612         AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId(), constituteVnf.getModelVersionId())
 
 614         Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl)
 
 616         if (vnfModelVerOpt.isPresent()) {
 
 617             vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId())
 
 618             vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
 
 619             vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
 
 626     List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
 
 627         def currentNSSI = execution.getVariable("currentNSSI")
 
 629         List<Map<String, Object>> instanceParams = new ArrayList<>()
 
 630         Map<String, Object> instanceParamsMap = new HashMap<>()
 
 633         List<String> snssais = (List<String>) currentNSSI['S-NSSAIs']
 
 635         ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
 
 637         String orchStatus = nssi.getOrchestrationStatus()
 
 640         List<Map<String, String>> snssaiList = new ArrayList<>()
 
 642         for(String snssai:snssais) {
 
 643             Map<String, String> snssaisMap = new HashMap<>()
 
 644             snssaisMap.put("snssai", snssai)
 
 645             snssaisMap.put("status", orchStatus)
 
 646             snssaiList.add(snssaisMap)
 
 649         //    Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>()
 
 650         //    supportedNssaiDetails.put("sNssai", supportedNssaiDetails)
 
 652         ObjectMapper mapper = new ObjectMapper()
 
 654         String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList)
 
 657         instanceParamsMap.put("k8s-rb-profile-name", "default") // ???
 
 658         instanceParamsMap.put("config-type", "day2") // ???
 
 659         instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr)
 
 660         instanceParams.add(instanceParamsMap)
 
 662         return instanceParams
 
 670     Resources prepareResources(DelegateExecution execution) {
 
 671         def currentNSSI = execution.getVariable("currentNSSI")
 
 673         Resources resources = new Resources()
 
 676         List<Vnfs> vnfs = new ArrayList<>()
 
 678         Vnfs vnf = new Vnfs()
 
 681         LineOfBusiness lob = new LineOfBusiness()
 
 682         lob.setLineOfBusinessName("VNF")
 
 683         vnf.setLineOfBusiness(lob)
 
 686         GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
 
 687         vnf.setProductFamilyId(constituteVnf.getServiceId())
 
 689         // Cloud configuration
 
 690         vnf.setCloudConfiguration(prepareCloudConfiguration(execution))
 
 693         vnf.setVfModules(prepareVfModules(execution, constituteVnf))
 
 696         vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf))
 
 699         vnf.setInstanceName(constituteVnf.getVnfName())
 
 702         vnf.setInstanceParams(prepareInstanceParams(execution))
 
 707         resources.setVnfs(vnfs)
 
 717     Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
 
 718         Service service = new Service()
 
 721         service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo))
 
 723         service.setInstanceName(networkServiceInstance.getServiceInstanceName())
 
 726         service.setResources(prepareResources(execution))
 
 734      * Prepares request parameters
 
 736      * @return RequestParameters
 
 738     RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
 
 739         def currentNSSI = execution.getVariable("currentNSSI")
 
 741         RequestParameters requestParameters = new RequestParameters()
 
 743         ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription']
 
 745         if(serviceSubscription != null) {
 
 746             requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
 
 750         List<Map<String, Object>> userParams = new ArrayList<>()
 
 752         Map<String, Object> userParam = new HashMap<>()
 
 753         userParam.put("Homing_Solution", "none")
 
 754         userParams.add(userParam)
 
 757         Map<String, Object> serviceMap = new HashMap<>()
 
 758         serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo))
 
 759         userParams.add(serviceMap)
 
 760         requestParameters.setUserParams(userParams)
 
 762         return requestParameters
 
 767      * Prepare Owning Entity
 
 769      * @return OwningEntity
 
 771     OwningEntity prepareOwningEntity(DelegateExecution execution) {
 
 772         def currentNSSI = execution.getVariable("currentNSSI")
 
 774         AAIResourcesClient client = getAAIClient()
 
 776         AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
 
 778         OwningEntity owningEntity = new OwningEntity()
 
 779         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
 
 780         Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
 
 781         if (owningEntityRelationshipsOps.isPresent()) {
 
 782             List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)
 
 784             if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
 
 785                 Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation
 
 786                 if (owningEntityOpt.isPresent()) {
 
 787                     owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
 
 788                     owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
 
 803     Project prepareProject(DelegateExecution execution) {
 
 804         def currentNSSI = execution.getVariable("currentNSSI")
 
 806         AAIResourcesClient client = getAAIClient()
 
 808         Project project = new Project()
 
 810         AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri']
 
 812         if (cloudRegionRelatedAAIUri != null) {
 
 813             AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri)
 
 814             Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
 
 815             if (cloudRegionOps.isPresent()) {
 
 816                 List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT)
 
 817                 if (!(projectAAIUris == null || projectAAIUris.isEmpty())) {
 
 818                     Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0))
 
 819                     if (projectOpt.isPresent()) {
 
 820                         project.setProjectName(projectOpt.get().getProjectName())
 
 831      * Prepares RequestDetails object
 
 835     String prepareRequestDetails(DelegateExecution execution) {
 
 836         String errorCode = ""
 
 837         String errorMessage = ""
 
 840         RequestDetails requestDetails = new RequestDetails()
 
 842         def currentNSSI = execution.getVariable("currentNSSI")
 
 844         ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
 
 848             ModelInfo modelInfo = prepareModelInfo(execution)
 
 849             requestDetails.setModelInfo(modelInfo)
 
 852             requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution))
 
 855             requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance))
 
 857             // Request Parameters
 
 858             requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo))
 
 860             // Cloud configuration
 
 861             requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution))
 
 864             requestDetails.setOwningEntity(prepareOwningEntity(execution))
 
 867             requestDetails.setProject(prepareProject(execution))
 
 869             ObjectMapper mapper = new ObjectMapper()
 
 871             response = mapper.writeValueAsString(requestDetails)
 
 874             String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
 
 878                     " \"errorCode\": \"7000\",\n" +
 
 879                     " \"errorMessage\": \"${msg}\"\n" +
 
 888     String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) {
 
 890         String errorCode = ""
 
 891         String errorMessage = ""
 
 893         LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue)
 
 895             response = utils.getBasicAuth(basicAuthValue, msokey)
 
 896         } catch (Exception ex) {
 
 897             LOGGER.error("Unable to encode username and password string: ", ex)
 
 900             errorMessage = "Internal Error - Unable to encode username and password string"
 
 903                     " \"errorCode\": \"${errorCode}\",\n" +
 
 904                     " \"errorMessage\": \"${errorMessage}\"\n" +
 
 912     String encryptBasicAuth(String basicAuth, String msoKey) {
 
 913         return utils.encrypt(basicAuth, msoKey)
 
 918      * Removes Slice Profile association with NSSI
 
 921     void removeSPAssociationWithNSSI(DelegateExecution execution) {
 
 922         LOGGER.trace("${getPrefix()} Start removeSPAssociationWithNSSI")
 
 924         AAIResourcesClient client = getAAIClient()
 
 926         def currentNSSI = execution.getVariable("currentNSSI")
 
 928         ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
 
 930         String nssiId = currentNSSI['nssiId']
 
 931         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
 
 933         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
 
 935         String currentSNSSAI = currentNSSI['S-NSSAI']
 
 937         associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
 
 940             getAAIClient().update(nssiUri, nssi)
 
 942             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
 
 945         LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI")
 
 950      * Deletes Slice Profile Instance
 
 953     void deleteSliceProfileInstance(DelegateExecution execution) {
 
 954         LOGGER.trace("${getPrefix()} Start deleteSliceProfileInstance")
 
 956         AAIResourcesClient client = getAAIClient()
 
 958         def currentNSSI = execution.getVariable("currentNSSI")
 
 960         SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI']
 
 962         String globalSubscriberId = currentNSSI['globalSubscriberId']
 
 963         String serviceType = currentNSSI['serviceType']
 
 964         String nssiId = currentNSSI['nssiId']
 
 966         // global-customer-id, service-type, service-instance-id, profile-id
 
 967         AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileContainsSNSSAI.getProfileId())
 
 970             getAAIClient().delete(sliceProfileUri)
 
 972             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
 
 975         LOGGER.trace("${getPrefix()} Exit deleteSliceProfileInstance")
 
 980      * Updates operation status
 
 983     void updateServiceOperationStatus(DelegateExecution execution) {
 
 984         LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus")
 
 986         def currentNSSI = execution.getVariable("currentNSSI")
 
 988         OperationStatus operationStatus = new OperationStatus()
 
 989         operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String)
 
 990         operationStatus.setOperationId(currentNSSI['operationId'] as String)
 
 991         operationStatus.setOperation(currentNSSI['operationType'] as String)
 
 992         operationStatus.setResult(RequestsDbConstant.Status.FINISHED)
 
 994         requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus)
 
 996         LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus")
 
1001      * Returns AAI client
 
1002      * @return AAI client
 
1004     AAIResourcesClient getAAIClient() {
 
1005         return new AAIResourcesClient()
 
1009     String getPrefix() {