50a60ac3f57cac4d824d99df6ad75feda016df03
[dcaegen2/services.git] /
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 package org.onap.slice.analysis.ms.configdb;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Objects;
28
29 import org.onap.slice.analysis.ms.models.Configuration;
30 import org.onap.slice.analysis.ms.models.configdb.CellsModel;
31 import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel;
32 import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.core.ParameterizedTypeReference;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.stereotype.Service;
37
38 /**
39  *
40  *  Service for config db interfaces
41  *
42  */
43 @Service
44 public class ConfigDbInterfaceService implements IConfigDbService {
45
46         @Autowired
47         private ConfigDbRestClient restclient;
48         private String configDbBaseUrl = Configuration.getInstance().getConfigDbService();
49
50         /**
51          *  Fetches the current configuration of an S-NSSAI from config DB
52          */
53         public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai){
54                 Map<String,Integer> responseMap = null;
55                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/profile-config/"+snssai;
56
57                 ResponseEntity<Map<String,Integer>> response=restclient.sendGetRequest(reqUrl,new ParameterizedTypeReference<Map<String, Integer>>() {
58                 });
59                 responseMap=response.getBody();
60                 return responseMap;
61         }
62
63         /**
64          *  Fetches the current configuration of RIC from config DB
65          */
66         public Map<String, Map<String, Object>> fetchCurrentConfigurationOfRIC(String snssai) {
67                 String reqUrl = configDbBaseUrl + "/api/sdnc-config-db/v4/slice-config/" + snssai;
68                 Map<String, Map<String, Object>> responseMap = new HashMap<String, Map<String, Object>>();
69                 ResponseEntity<Map<String, List<Map<String, Object>>>> response = restclient.sendGetRequest(reqUrl,
70                                 new ParameterizedTypeReference<Map<String, List<Map<String, Object>>>>() {
71                                 });
72                 if (Objects.nonNull(response)) {
73                         for (Map.Entry<String, List<Map<String, Object>>> entry : response.getBody().entrySet()) {
74                                 List<Map<String, Object>> list = entry.getValue();
75                                 if (!list.isEmpty()) {
76                                         list.forEach(l -> {
77                                                 if (l.containsKey("nearRTRICId")) {
78                                                         responseMap.put(String.valueOf(l.get("nearRTRICId")), l);
79                                                 }
80                                         });
81                                 }
82
83                         }
84                 }
85                 return responseMap;
86         }
87
88         /**
89          *  Fetches all the network functions of an S-NSSAI from config DB
90          */
91         public List<String> fetchNetworkFunctionsOfSnssai(String snssai){
92                 List<String> responseList=new ArrayList<>();
93                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-list/"+snssai;
94                 ResponseEntity<List<NetworkFunctionModel>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<List<NetworkFunctionModel>>() {
95                 });
96                 for(NetworkFunctionModel networkFn:response.getBody()) {
97                         responseList.add(networkFn.getgNBDUId());
98                 }
99                 return responseList;
100         }
101
102         /**
103          *  Fetches the RICS of an S-NSSAI from config DB
104          */
105         public Map<String, List<String>> fetchRICsOfSnssai(String snssai){
106                 Map<String,List<String>> responseMap=new HashMap<>();
107                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-cell-list/"+snssai;
108                 ResponseEntity<Map<String,List<CellsModel>>> response = restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,List<CellsModel>>>() {
109                 });
110
111                 for (Map.Entry<String, List<CellsModel>> entry : response.getBody().entrySet()) {
112                         List<String> cellslist=new ArrayList<>();
113                         for(CellsModel cellmodel:entry.getValue()) {
114                                 cellslist.add(cellmodel.getCellLocalId());
115                         }
116                         responseMap.put(entry.getKey(), cellslist);
117                 }
118                 return responseMap;
119         }
120
121         /**
122          *  Fetches the details of a service
123          */
124         public Map<String,String> fetchServiceDetails(String snssai){
125                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/subscriber-details/"+snssai;
126                 ResponseEntity<Map<String,String>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,String>>() {
127                 });
128                 return response.getBody();
129         }
130
131 }
132