84ff37154e910b0154897ab70b2fa272f49ff190
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  *******************************************************************************/
21
22 package org.onap.slice.analysis.ms.service;
23
24 import java.util.List;
25 import java.util.Map;
26
27 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
28 import org.onap.slice.analysis.ms.models.CUModel;
29 import org.onap.slice.analysis.ms.models.MLOutputModel;
30 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Component;
36
37 /**
38  * Process the message sent by ML service and sends notification to policy
39  */
40 @Component
41 @Scope("prototype")
42 public class MLMessageProcessor {
43         private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
44         
45         @Autowired
46         private IConfigDbService configDbService;
47         
48         @Autowired
49         private PolicyService policyService;
50         
51         public void processMLMsg(MLOutputModel mlOutputMsg) {
52                 String snssai = mlOutputMsg.getSnssai();
53                 List<CUModel> cuData = mlOutputMsg.getData();
54                 Map<String, List<String>>  ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai);
55                 log.debug("RIC to cell mapping of S-NSSAI {} is {}",snssai,ricToCellMapping);
56                 for(CUModel cuModel: cuData) {
57                         String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId());
58                         ricToCellMapping.forEach((ricId, cells) -> {
59                                 if(cells.contains(cellId)) {
60                                         cuModel.setNearRTRICId(ricId);
61                                 }
62                         });
63                 }
64                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
65                 addProps.setResourceConfig(mlOutputMsg);
66                 policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai));  
67         }
68 }