1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   4  *  ================================================================================
 
   5  *   Copyright (C) 2020 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;
 
  27 import javax.annotation.PostConstruct;
 
  29 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
 
  30 import org.onap.slice.analysis.ms.models.CUModel;
 
  31 import org.onap.slice.analysis.ms.models.MLOutputModel;
 
  32 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
 
  33 import org.onap.slice.analysis.ms.utils.BeanUtil;
 
  34 import org.slf4j.Logger;
 
  35 import org.slf4j.LoggerFactory;
 
  36 import org.springframework.context.annotation.Scope;
 
  37 import org.springframework.stereotype.Component;
 
  40  * Process the message sent by ML service and sends notification to policy
 
  44 public class MLMessageProcessor {
 
  45         private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
 
  47         private IConfigDbService configDbService;
 
  48         private PolicyService policyService;
 
  53                 configDbService = BeanUtil.getBean(IConfigDbService.class);
 
  56         public void processMLMsg(MLOutputModel mlOutputMsg) {
 
  57                 String snssai = mlOutputMsg.getSnssai();
 
  58                 List<CUModel> cuData = mlOutputMsg.getData();
 
  59                 Map<String, List<String>>  ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai);
 
  60                 log.debug("RIC to cell mapping of S-NSSAI {} is {}",snssai,ricToCellMapping);
 
  61                 for(CUModel cuModel: cuData) {
 
  62                         String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId());
 
  63                         ricToCellMapping.forEach((ricId, cells) -> {
 
  64                                 if(cells.contains(cellId)) {
 
  65                                         cuModel.setNearRTRICId(ricId);
 
  69                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
 
  70                 addProps.setResourceConfig(mlOutputMsg);
 
  71                 policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai));