bee7b30ef98b2081d688a42b902634343a1d0a4d
[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 javax.annotation.PostConstruct;
28
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;
38
39 /**
40  * Process the message sent by ML service and sends notification to policy
41  */
42 @Component
43 @Scope("Prototype")
44 public class MLMessageProcessor {
45         private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
46
47         private IConfigDbService configDbService;
48         private PolicyService policyService;
49
50
51         @PostConstruct
52         public void init() {
53                 configDbService = BeanUtil.getBean(IConfigDbService.class);
54         }
55         
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);
66                                 }
67                         });
68                 }
69                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
70                 addProps.setResourceConfig(mlOutputMsg);
71                 policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai));  
72         }
73 }