2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  # Copyright (c) 2020, CMCC Technologies Co., Ltd.
 
   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.ServiceInstance
 
  26 import org.onap.so.beans.nsmf.EsrInfo
 
  27 import org.onap.so.beans.nsmf.NetworkType
 
  28 import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest
 
  29 import org.onap.so.beans.nsmf.QuerySubnetCapability
 
  30 import org.onap.so.beans.nsmf.SliceProfileAdapter
 
  31 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
 
  32 import org.onap.so.beans.nsmf.oof.SubnetCapability
 
  33 import org.onap.so.beans.nsmf.oof.SubnetType
 
  34 import org.onap.so.beans.nsmf.oof.TemplateInfo
 
  35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  37 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
 
  38 import org.onap.so.bpmn.common.scripts.OofUtils
 
  39 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  40 import org.onap.so.bpmn.core.domain.AllottedResource
 
  41 import org.onap.so.bpmn.core.domain.ModelInfo
 
  42 import org.onap.so.bpmn.core.domain.ServiceDecomposition
 
  43 import org.onap.so.bpmn.core.json.JsonUtils
 
  44 import org.slf4j.Logger
 
  45 import org.slf4j.LoggerFactory
 
  46 import org.springframework.util.StringUtils
 
  49 class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{
 
  51     private static final Logger logger = LoggerFactory.getLogger(DoCreateSliceServiceOption.class)
 
  53     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  55     JsonUtils jsonUtil = new JsonUtils()
 
  57     OofUtils oofUtils = new OofUtils()
 
  59     AAISliceUtil aaiSliceUtil = new AAISliceUtil()
 
  61     private static final ObjectMapper objectMapper = new ObjectMapper()
 
  63     private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
 
  65     private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
 
  67     private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
 
  69     void preProcessRequest (DelegateExecution execution) {
 
  73      * prepare the params for decompose nst
 
  76     void prepareDecomposeNST(DelegateExecution execution) {
 
  78         SliceTaskParamsAdapter sliceTaskParams =
 
  79                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
  81         String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
 
  82         String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()
 
  84         String serviceModelInfo = """{
 
  85             "modelInvariantUuid":"${modelInvariantUuid}",
 
  86             "modelUuid":"${modelUuid}",
 
  89         execution.setVariable("nstServiceModelInfo", serviceModelInfo)
 
  93      * process the result of NST Decomposition
 
  96     public void processDecompositionNST(DelegateExecution execution) {
 
  98         List<TemplateInfo> nsstInfos = new ArrayList<>()
 
  99         ServiceDecomposition nstServiceDecomposition =
 
 100                 execution.getVariable("nstServiceDecomposition") as ServiceDecomposition
 
 102         List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
 
 103         for (AllottedResource allottedResource : allottedResources) {
 
 104             TemplateInfo nsstInfo = new TemplateInfo()
 
 105             nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
 
 106             nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
 
 107             nsstInfo.setName(allottedResource.getProvidingServiceModelName())
 
 108             nsstInfos.add(nsstInfo)
 
 110         execution.setVariable("nsstInfos", nsstInfos)
 
 112         execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
 
 113         execution.setVariable("currentNsstIndex", 0)
 
 115         List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
 
 116         execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
 
 120      * prepare the params for decompose nsst
 
 123     public void prepareDecomposeNSST(DelegateExecution execution) {
 
 125         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
 
 126         int index = execution.getVariable("currentNsstIndex") as Integer
 
 128         String modelUuid = nsstInfos.get(index).getUUID()
 
 129         String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()
 
 131         String serviceModelInfo = """{
 
 132             "modelInvariantUuid":"${modelInvariantUuid}",
 
 133             "modelUuid":"${modelUuid}",
 
 136         execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
 
 141      * process the result of NSST Decomposition
 
 144     public void processDecompositionNSST(DelegateExecution execution) {
 
 145         List<ServiceDecomposition> nsstServiceDecompositions =
 
 146                 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
 
 148         ServiceDecomposition nsstServiceDecomposition =
 
 149                 execution.getVariable("nsstServiceDecomposition") as ServiceDecomposition
 
 151         nsstServiceDecompositions.add(nsstServiceDecomposition)
 
 153         execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
 
 155         int num = execution.getVariable("maxNsstIndex") as Integer
 
 156         int index = execution.getVariable("currentNsstIndex") as Integer
 
 158         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
 
 159         nsstInfos.get(index).name = nsstServiceDecomposition.modelInfo.modelName
 
 160         execution.setVariable("nsstInfos", nsstInfos)
 
 161         execution.setVariable("currentNsstIndex", index + 1)
 
 164             execution.setVariable("nsstHandleContinue", false)
 
 166             execution.setVariable("nsstHandleContinue", true)
 
 172      * set nsst info to sliceTaskParams by type
 
 175     public void handleNsstByType(DelegateExecution execution) {
 
 177         SliceTaskParamsAdapter sliceParams =
 
 178                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
 180         List<ServiceDecomposition> nsstServiceDecompositions =
 
 181                 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
 
 183         List<SubnetCapability> subnetCapabilities = new ArrayList<>()
 
 185         for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
 
 186             handleByType(execution, serviceDecomposition, sliceParams, subnetCapabilities)
 
 189         execution.setVariable("sliceTaskParams", sliceParams)
 
 190         execution.setVariable("subnetCapabilities", subnetCapabilities)
 
 191         execution.setVariable("queryNsiFirst", true)
 
 192         logger.debug("sliceTaskParams= " + sliceParams.toString())
 
 195     private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
 
 196                               SliceTaskParamsAdapter sliceParams, List<SubnetCapability> subnetCapabilities) {
 
 197         ModelInfo modelInfo = serviceDecomposition.getModelInfo()
 
 198         String vendor = serviceDecomposition.getServiceRole()
 
 199         SubnetType subnetType = convertServiceCategory(serviceDecomposition.getServiceCategory())
 
 201         switch (subnetType) {
 
 202             case SubnetType.TN_BH:
 
 203                 sliceParams.tnBHSliceTaskInfo.vendor = vendor
 
 204                 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
 
 205                 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
 
 206                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
 
 207                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
 
 208                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
 
 210             case SubnetType.TN_MH:
 
 211                 sliceParams.tnMHSliceTaskInfo.vendor = vendor
 
 212                 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
 
 213                 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
 
 214                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
 
 215                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
 
 216                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
 
 219                 sliceParams.anSliceTaskInfo.vendor = vendor
 
 220                 sliceParams.anSliceTaskInfo.subnetType = subnetType
 
 221                 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
 
 222                 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
 
 223                 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
 
 224                 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
 
 227                 sliceParams.cnSliceTaskInfo.vendor = vendor
 
 228                 sliceParams.cnSliceTaskInfo.subnetType = subnetType
 
 229                 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
 
 230                 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
 
 231                 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
 
 232                 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
 
 238         if (null == subnetType) {
 
 239             def msg = "Get subnetType failed, modelUUId=" + modelInfo.getModelUuid()
 
 241             exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 243         String response = querySubnetCapability(execution, vendor, subnetType)
 
 244         if (!StringUtils.isEmpty(response)) {
 
 245             SubnetCapability subnetCapability = new SubnetCapability()
 
 246             Map<String, Object> result = objectMapper.readValue(response, Map.class)
 
 247             for (Map.Entry<String, Object> entry : result.entrySet()) {
 
 248                 subnetCapability.setDomainType(entry.getKey())
 
 249                 subnetCapability.setCapabilityDetails(entry.getValue())
 
 251             subnetCapabilities.add(subnetCapability)
 
 256      * get subnetType from serviceCategory
 
 259     private SubnetType convertServiceCategory(String serviceCategory){
 
 260         if(serviceCategory ==~ /CN.*/){
 
 263         if (serviceCategory ==~ /AN.*NF.*/){
 
 266         if (serviceCategory ==~ /TN.*BH.*/){
 
 267             return SubnetType.TN_BH
 
 269         if(serviceCategory ==~ /TN.*MH.*/){
 
 270             return SubnetType.TN_MH
 
 276      * query Subnet Capability of TN AN CN
 
 279     private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
 
 281         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY,
 
 282                 buildQuerySubnetCapRequest(vendor, subnetType))
 
 287      * build request body for querying Subnet Capability
 
 293     private static NssmfAdapterNBIRequest buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
 
 294         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
 
 296         List<String> subnetTypes =  new ArrayList<>()
 
 297         subnetTypes.add(subnetType.subnetType)
 
 299         QuerySubnetCapability req = new QuerySubnetCapability()
 
 300         req.setSubnetTypes(subnetTypes)
 
 302         request.setSubnetCapabilityQuery(req)
 
 304         EsrInfo esrInfo = new EsrInfo()
 
 305         esrInfo.setVendor(vendor)
 
 306         esrInfo.setNetworkType(subnetType.networkType)
 
 307         request.setEsrInfo(esrInfo)
 
 314      * prepare select nsi request
 
 317     public void preNSIRequest(DelegateExecution execution) {
 
 318         boolean preferReuse = execution.getVariable("needQuerySliceProfile") ? false : true
 
 320         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
 
 321         logger.debug( "get NSI option OOF Url: " + urlString)
 
 323         String requestId = execution.getVariable("msoRequestId")
 
 324         String messageType = "NSISelectionResponse"
 
 326         execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
 
 327         execution.setVariable("nsiSelection_messageType", messageType)
 
 328         execution.setVariable("nsiSelection_correlator", requestId)
 
 329         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
 
 330         execution.setVariable("nsiSelection_timeout", timeout)
 
 332         SliceTaskParamsAdapter sliceParams =
 
 333                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
 335         Map<String, Object> profileInfo = sliceParams.getServiceProfile()
 
 336         profileInfo.remove("profileId")
 
 337         TemplateInfo nstInfo = sliceParams.getNSTInfo()
 
 339         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
 
 341         List<SubnetCapability> subnetCapabilities =
 
 342                 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
 
 344         String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
 
 345                 messageType, profileInfo, subnetCapabilities, 600, preferReuse)
 
 347         execution.setVariable("nsiSelection_oofRequest", oofRequest)
 
 348         logger.debug("Sending request to OOF: " + oofRequest)
 
 352      * process select nsi response
 
 355     public void processNSIResp(DelegateExecution execution) {
 
 357         SliceTaskParamsAdapter sliceTaskParams =
 
 358                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
 360         String oofResponse = execution.getVariable("nsiSelection_oofResponse")
 
 361         logger.debug("NSI oofResponse is: " + oofResponse)
 
 362         execution.setVariable("oofResponse", oofResponse)
 
 363         //This needs to be changed to derive a value when we add policy to decide the solution options.
 
 365         Map<String, Object> resMap = objectMapper.readValue(oofResponse, Map.class)
 
 366         String requestStatus = resMap.get("requestStatus")
 
 367         if (!StringUtils.isEmpty(requestStatus) && requestStatus == "error") {
 
 368             exceptionUtil.buildWorkflowException(execution, 7000, "get nsi from oof error: " + oofResponse)
 
 372         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
 
 374         Map<String, Object> solution = nsiSolutions?.get(0)
 
 376         if (solution != null) {
 
 377             if (execution.getVariable("queryNsiFirst")) {
 
 378                 if (solution.get("existingNSI")) {
 
 379                     execution.setVariable("needQuerySliceProfile", true)
 
 381                     processNewNSI(solution, sliceTaskParams)
 
 382                     execution.setVariable("needQuerySliceProfile", false)
 
 384                 execution.setVariable("queryNsiFirst", false)
 
 386                 processSharedNSI(solution, sliceTaskParams, execution)
 
 387                 execution.setVariable("needQuerySliceProfile", false)
 
 390         execution.setVariable("sliceTaskParams", sliceTaskParams)
 
 391         logger.debug("after req to oof for nis select, sliceTaskParams = " + sliceTaskParams)
 
 392         logger.debug("*** Completed options Call to OOF ***")
 
 395     private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams, DelegateExecution execution) {
 
 396         Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
 
 397         String nsiId = sharedNSISolution.get("NSIId")
 
 398         String nsiName = sharedNSISolution.get("NSIName")
 
 399         sliceParams.setSuggestNsiId(nsiId)
 
 400         sliceParams.setSuggestNsiName(nsiName)
 
 402         List<String> nssiId = aaiSliceUtil.getNSSIIdList(execution,nsiId)
 
 403         List<ServiceInstance> nssiInstances = aaiSliceUtil.getNSSIListFromAAI(execution, nssiId)
 
 405         List<Map> sliceProfiles = sharedNSISolution.get("sliceProfiles") as List<Map>
 
 406         handleSliceProfiles(sliceProfiles, sliceParams)
 
 407         Map<String, Object> nssiSolution = new HashMap<>()
 
 408         for(ServiceInstance instance: nssiInstances){
 
 409             nssiSolution.put("NSSIId", instance.getServiceInstanceId())
 
 410             nssiSolution.put("NSSIName", instance.getServiceInstanceName())
 
 411             processNssiResult(sliceParams, instance.getEnvironmentContext(), nssiSolution)
 
 416     private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
 
 417         Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
 
 418         List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
 
 419         handleSliceProfiles(sliceProfiles, sliceParams)
 
 422     static def handleSliceProfiles(List<Map> sliceProfiles, SliceTaskParamsAdapter sliceParams) {
 
 423         for (Map sliceProfile : sliceProfiles) {
 
 424             String domainType = sliceProfile.get("domainType")
 
 425             sliceProfile.remove("domainType")
 
 426             SliceProfileAdapter adapter = objectMapper.readValue(objectMapper.writeValueAsString(sliceProfile), SliceProfileAdapter.class)
 
 427             switch (domainType.toLowerCase()) {
 
 429                     sliceParams.tnBHSliceTaskInfo.sliceProfile = adapter
 
 433                     sliceParams.anSliceTaskInfo.sliceProfile = adapter
 
 436                     sliceParams.cnSliceTaskInfo.sliceProfile = adapter
 
 445      * get NSSI Selection Capability for AN
 
 448     void getNSSISelectionCap4AN(DelegateExecution execution) {
 
 450         def vendor = execution.getVariable("vendor") as String
 
 452         String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
 
 454         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
 
 456         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
 
 458         String selection = resMap.get("selection")
 
 461         if ("NSMF".equalsIgnoreCase(selection)) {
 
 462             execution.setVariable("NEED_AN_NSSI_SELECTION", true)
 
 467      * get NSSI Selection Capability for TN
 
 470     void getNSSISelectionCap4TN(DelegateExecution execution) {
 
 472         def vendor = execution.getVariable("vendor") as String
 
 474         String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
 
 476         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
 
 478         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
 
 480         String selection = resMap.get("selection")
 
 482         if ("NSMF".equalsIgnoreCase(selection)) {
 
 483             execution.setVariable("NEED_TN_NSSI_SELECTION", true)
 
 488      * get NSSI Selection Capability for CN
 
 491     void getNSSISelectionCap4CN(DelegateExecution execution) {
 
 493         def vendor = execution.getVariable("vendor") as String
 
 495         String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
 
 497         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
 
 499         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
 
 501         String selection = resMap.get("selection")
 
 503         if ("NSMF".equalsIgnoreCase(selection)) {
 
 504             //execution.setVariable("NEED_CN_NSSI_SELECTION", true)
 
 509      * build NSSI Selection Capability Request body to nssmf adapter
 
 514     private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
 
 515         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
 
 516         EsrInfo esrInfo = new EsrInfo()
 
 517         esrInfo.setVendor(vendor)
 
 518         esrInfo.setNetworkType(networkType)
 
 519         request.setEsrInfo(esrInfo)
 
 521         return objectMapper.writeValueAsString(request)
 
 525      * if exist nssi need to select
 
 528     public void handleNssiSelect(DelegateExecution execution) {
 
 530         SliceTaskParamsAdapter sliceTaskParams =
 
 531                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
 534         boolean needCnNssiSelection = execution.getVariable("NEED_CN_NSSI_SELECTION") as Boolean
 
 535         boolean needAnNssiSelection = execution.getVariable("NEED_AN_NSSI_SELECTION") as Boolean
 
 536         boolean needTnNssiSelection = execution.getVariable("NEED_TN_NSSI_SELECTION") as Boolean
 
 541          *           "subType":  subtype,
 
 542          *           "nsstInfo": object,
 
 543          *           "sliceProfile": object
 
 546          *          "subType":  subtype,
 
 547          *          "nsstInfo": object,
 
 548          *          "sliceProfile": object
 
 552         List<Map> nssiNeedHandlerInfos = new ArrayList<>()
 
 553         Map<String, Object> nssiNeedHandlerMap = new HashMap()
 
 555         //List<TemplateInfo> nssiNeedHandlers = new ArrayList<>()
 
 556         //List<Object> nssiProfileNeedHandlers = new ArrayList<>()
 
 557         if (needCnNssiSelection) {
 
 558             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.cnSliceTaskInfo.subnetType)
 
 559             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.cnSliceTaskInfo.NSSTInfo)
 
 560             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.cnSliceTaskInfo.sliceProfile)
 
 561             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
 
 563         if (needAnNssiSelection) {
 
 564             nssiNeedHandlerMap.clear()
 
 565             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.anSliceTaskInfo.subnetType)
 
 566             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.anSliceTaskInfo.NSSTInfo)
 
 567             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.anSliceTaskInfo.sliceProfile)
 
 568             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
 
 570         if (needTnNssiSelection) {
 
 571             nssiNeedHandlerMap.clear()
 
 572             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnBHSliceTaskInfo.subnetType)
 
 573             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnBHSliceTaskInfo.NSSTInfo)
 
 574             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnBHSliceTaskInfo.sliceProfile)
 
 575             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
 
 577             nssiNeedHandlerMap.clear()
 
 578             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnMHSliceTaskInfo.subnetType)
 
 579             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnMHSliceTaskInfo.NSSTInfo)
 
 580             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnMHSliceTaskInfo.sliceProfile)
 
 581             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
 
 583             nssiNeedHandlerMap.clear()
 
 584             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnFHSliceTaskInfo.subnetType)
 
 585             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnFHSliceTaskInfo.NSSTInfo)
 
 586             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnFHSliceTaskInfo.sliceProfile)
 
 587             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
 
 591         if (nssiNeedHandlerInfos.size() > 0) {
 
 592             execution.setVariable("needSelectNssi", true)
 
 593             execution.setVariable("currNssiIndex", 0)
 
 594             execution.setVariable("nssiNeedHandlerInfos", nssiNeedHandlerInfos)
 
 596             execution.setVariable("needSelectNssi", false)
 
 599         execution.setVariable("sliceTaskParams", sliceTaskParams)
 
 603      * prepare select nssi request
 
 606     public void preNSSIRequest(DelegateExecution execution) {
 
 608         List<Map> nssiNeedHandlerInfos =
 
 609                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
 
 611         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
 
 612         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
 
 614         TemplateInfo nsstInfo = nssiNeedHandlerInfo.get("nsstInfo") as TemplateInfo
 
 615         Map<String, Object> profileInfo = nssiNeedHandlerInfo.get("sliceProfile") as Map
 
 616         //profileInfo.remove("profileId")
 
 618         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
 
 619         logger.debug( "get NSI option OOF Url: " + urlString)
 
 621         String requestId = execution.getVariable("msoRequestId")
 
 622         String messageType = "NSSISelectionResponse"
 
 624         execution.setVariable("nssiSelectionUrl", "/api/oof/selection/nssi/v1")
 
 625         execution.setVariable("nssiSelection_messageType", messageType)
 
 626         execution.setVariable("nssiSelection_correlator", requestId)
 
 627         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
 
 628         execution.setVariable("nssiSelection_timeout", timeout)
 
 630         String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, nsstInfo, messageType,
 
 633         execution.setVariable("nssiSelection_oofRequest", oofRequest)
 
 634         logger.debug("Sending request to OOF: " + oofRequest)
 
 638      * process select nssi response
 
 641     public void processNSSIResp(DelegateExecution execution) {
 
 643         List<Map> nssiNeedHandlerInfos =
 
 644                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
 
 646         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
 
 647         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
 
 648         SubnetType subnetType = nssiNeedHandlerInfo.get("subnetType") as SubnetType
 
 650         SliceTaskParamsAdapter sliceTaskParams =
 
 651                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
 
 654         String OOFResponse = execution.getVariable("nssiSelection_oofResponse")
 
 655         logger.debug("NSI OOFResponse is: " + OOFResponse)
 
 656         execution.setVariable("OOFResponse", OOFResponse)
 
 657         //This needs to be changed to derive a value when we add policy to decide the solution options.
 
 659         Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
 
 660         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
 
 661         Map<String, Object> solution = nsiSolutions.get(0)
 
 663         String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
 
 664         Boolean isSharable = resourceSharingLevel == "shared"   //todo
 
 666         if (isSharable && solution != null) {
 
 667             processNssiResult(sliceTaskParams, subnetType, solution)
 
 670         execution.setVariable("sliceTaskParams", sliceTaskParams)
 
 671         //logger.debug("sliceTaskParams: "+ sliceTaskParams.convertToJson())
 
 672         logger.debug("*** Completed options Call to OOF ***")
 
 674         logger.debug("start parseServiceProfile")
 
 675         //parseServiceProfile(execution)
 
 676         logger.debug("end parseServiceProfile")
 
 678         if (currNssiIndex >= nssiNeedHandlerInfos.size() - 1) {
 
 679             execution.setVariable("needSelectNssi", false)
 
 681             execution.setVariable("currNssiIndex", currNssiIndex + 1)
 
 682             execution.setVariable("needSelectNssi", true)
 
 687     private void processNssiResult(SliceTaskParamsAdapter sliceTaskParams, SubnetType subnetType,
 
 688                                    Map<String, Object> solution) {
 
 689         switch (subnetType) {
 
 691                 sliceTaskParams.cnSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
 
 692                 sliceTaskParams.cnSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
 
 695                 sliceTaskParams.anSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
 
 696                 sliceTaskParams.anSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
 
 698             case SubnetType.TN_BH:
 
 699                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
 
 700                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
 
 702             case SubnetType.TN_FH:
 
 703                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
 
 704                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
 
 706             case SubnetType.TN_MH:
 
 707                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
 
 708                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")