8bc7b0d575c1a5d6b796bf25e2e490af4bb6836b
[dcaegen2/services.git] / components / slice-analysis-ms / src / main / java / org / onap / slice / analysis / ms / service / MLMessageProcessor.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
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 import java.util.Objects;
27
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;
40
41 /**
42  * Process the message sent by ML service and sends notification to policy
43  */
44 @Component
45 @Scope("prototype")
46 public class MLMessageProcessor {
47         private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
48
49         @Autowired
50         private IConfigDbService configDbService;
51
52         @Autowired
53         private PolicyService policyService;
54
55         @Autowired
56         private AaiInterface aaiInterface;
57
58         @Autowired
59         private CpsInterface cpsInterface;
60
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);
70                 } else {
71                         ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai);
72                 }
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);
79                                 }
80                         });
81                 }
82                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
83                 addProps.setResourceConfig(mlOutputMsg);
84
85                 if (isConfigDbEnabled) {
86                         serviceDetails = configDbService.fetchServiceDetails(snssai);
87                 } else {
88                         serviceDetails = aaiInterface.fetchServiceDetails(snssai);
89
90                 }
91                 policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails);
92         }
93
94 }