1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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 *******************************************************************************/
21 package org.onap.slice.analysis.ms.configdb;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Objects;
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;
40 * Service for config db interfaces
44 public class ConfigDbInterfaceService implements IConfigDbService {
47 private ConfigDbRestClient restclient;
48 private String configDbBaseUrl = Configuration.getInstance().getConfigDbService();
51 * Fetches the current configuration of an S-NSSAI from config DB
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;
57 ResponseEntity<Map<String,Integer>> response=restclient.sendGetRequest(reqUrl,new ParameterizedTypeReference<Map<String, Integer>>() {
59 responseMap=response.getBody();
64 * Fetches the current configuration of RIC from config DB
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>>>>() {
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()) {
77 if (l.containsKey("nearRTRICId")) {
78 responseMap.put(String.valueOf(l.get("nearRTRICId")), l);
89 * Fetches all the network functions of an S-NSSAI from config DB
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>>() {
96 for(NetworkFunctionModel networkFn:response.getBody()) {
97 responseList.add(networkFn.getgNBDUId());
103 * Fetches the RICS of an S-NSSAI from config DB
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>>>() {
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());
116 responseMap.put(entry.getKey(), cellslist);
122 * Fetches the details of a service
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>>() {
128 return response.getBody();