1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   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
 
  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;
 
  28 import javax.annotation.PostConstruct;
 
  30 import org.onap.slice.analysis.ms.models.Configuration;
 
  31 import org.onap.slice.analysis.ms.models.configdb.CellsModel;
 
  32 import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel;
 
  33 import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient;
 
  34 import org.onap.slice.analysis.ms.utils.BeanUtil;
 
  35 import org.springframework.core.ParameterizedTypeReference;
 
  36 import org.springframework.http.ResponseEntity;
 
  37 import org.springframework.stereotype.Service;
 
  41  *  Service for config db interfaces
 
  45 public class ConfigDbInterfaceService implements IConfigDbService {
 
  47         private ConfigDbRestClient restclient;
 
  48         private String configDbBaseUrl = Configuration.getInstance().getConfigDbService();
 
  52                 this.restclient = BeanUtil.getBean(ConfigDbRestClient.class);
 
  56          *  Fetches the current configuration of an S-NSSAI from config DB
 
  58         public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai){
 
  59                 Map<String,Integer> responseMap = null;
 
  60                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/profile-config/"+snssai;
 
  62                 ResponseEntity<Map<String,Integer>> response=restclient.sendGetRequest(reqUrl,new ParameterizedTypeReference<Map<String, Integer>>() {
 
  64                 responseMap=response.getBody();
 
  69          *  Fetches the current configuration of RIC from config DB
 
  71         public Map<String,Map<String,Integer>> fetchCurrentConfigurationOfRIC(String snssai){
 
  72                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/slice-config/"+snssai;
 
  73                 ResponseEntity<Map<String,Map<String,Integer>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,Map<String,Integer>>>() {
 
  75                 return response.getBody();
 
  79          *  Fetches all the network functions of an S-NSSAI from config DB
 
  81         public List<String> fetchNetworkFunctionsOfSnssai(String snssai){
 
  82                 List<String> responseList=new ArrayList<>();
 
  83                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-list/"+snssai;
 
  84                 ResponseEntity<List<NetworkFunctionModel>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<List<NetworkFunctionModel>>() {
 
  86                 for(NetworkFunctionModel networkFn:response.getBody()) {
 
  87                         responseList.add(networkFn.getgNBDUId());       
 
  93          *  Fetches the RICS of an S-NSSAI from config DB
 
  95         public Map<String, List<String>> fetchRICsOfSnssai(String snssai){
 
  97                 Map<String,List<String>> responseMap=new HashMap<>();
 
  99                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-cell-list/"+snssai;
 
 101                 ResponseEntity<Map<String,List<CellsModel>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,List<CellsModel>>>() {
 
 105                 for (Map.Entry<String, List<CellsModel>> entry : response.getBody().entrySet()) {
 
 106                         List<String> cellslist=new ArrayList<>();
 
 107                         for(CellsModel cellmodel:entry.getValue()) {
 
 109                                 cellslist.add(cellmodel.getCellLocalId());
 
 111                         responseMap.put(entry.getKey(), cellslist);
 
 118          *  Fetches the details of a service 
 
 120         public Map<String,String> fetchServiceDetails(String snssai){
 
 121                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/subscriber-details/"+snssai;
 
 122                 ResponseEntity<Map<String,String>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,String>>() {
 
 124                 return response.getBody();