1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   4  *  ================================================================================
 
   5  *   Copyright (C) 2020-2021 Wipro Limited.
 
   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=========================================================
 
  20  *******************************************************************************/
 
  22 package org.onap.slice.analysis.ms.service;
 
  24 import java.util.List;
 
  26 import java.util.Objects;
 
  28 import org.onap.slice.analysis.ms.configdb.AaiInterface;
 
  29 import org.onap.slice.analysis.ms.configdb.CpsInterface;
 
  30 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
 
  31 import org.onap.slice.analysis.ms.models.CUModel;
 
  32 import org.onap.slice.analysis.ms.models.Configuration;
 
  33 import org.onap.slice.analysis.ms.models.MLOutputModel;
 
  34 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
 
  35 import org.slf4j.Logger;
 
  36 import org.slf4j.LoggerFactory;
 
  37 import org.springframework.beans.factory.annotation.Autowired;
 
  38 import org.springframework.context.annotation.Scope;
 
  39 import org.springframework.stereotype.Component;
 
  42  * Process the message sent by ML service and sends notification to policy
 
  46 public class MLMessageProcessor {
 
  47         private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
 
  50         private IConfigDbService configDbService;
 
  53         private PolicyService policyService;
 
  56         private AaiInterface aaiInterface;
 
  59         private CpsInterface cpsInterface;
 
  61         public void processMLMsg(MLOutputModel mlOutputMsg) {
 
  62                 Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true
 
  63                                 : Configuration.getInstance().getConfigDbEnabled();
 
  64                 Map<String, List<String>> ricToCellMapping = null;
 
  65                 Map<String, String> serviceDetails = null;
 
  66                 String snssai = mlOutputMsg.getSnssai();
 
  67                 List<CUModel> cuData = mlOutputMsg.getData();
 
  68                 if (isConfigDbEnabled) {
 
  69                         ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai);
 
  71                         ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai);
 
  73                 log.debug("RIC to cell mapping of S-NSSAI {} is {}", snssai, ricToCellMapping);
 
  74                 for (CUModel cuModel : cuData) {
 
  75                         String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId());
 
  76                         ricToCellMapping.forEach((ricId, cells) -> {
 
  77                                 if (cells.contains(cellId)) {
 
  78                                         cuModel.setNearRTRICId(ricId);
 
  82                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
 
  83                 addProps.setResourceConfig(mlOutputMsg);
 
  85                 if (isConfigDbEnabled) {
 
  86                         serviceDetails = configDbService.fetchServiceDetails(snssai);
 
  88                         serviceDetails = aaiInterface.fetchServiceDetails(snssai);
 
  91                 policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails);