488aca81c6a9d7baea45b2e50f14d516af2653d7
[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 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
28 import javax.annotation.PostConstruct;
29
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;
38
39 /**
40  * 
41  *  Service for config db interfaces
42  *
43  */
44 @Service
45 public class ConfigDbInterfaceService implements IConfigDbService {
46         
47         private ConfigDbRestClient restclient;
48         private String configDbBaseUrl = Configuration.getInstance().getConfigDbService();
49         
50         @PostConstruct
51         public void init() {
52                 this.restclient = BeanUtil.getBean(ConfigDbRestClient.class);
53         }
54         
55         /**
56          *  Fetches the current configuration of an S-NSSAI from config DB
57          */
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;
61
62                 ResponseEntity<Map<String,Integer>> response=restclient.sendGetRequest(reqUrl,new ParameterizedTypeReference<Map<String, Integer>>() {
63                 });
64                 responseMap=response.getBody();
65                 return responseMap;                     
66         }
67         
68         /**
69          *  Fetches the current configuration of RIC from config DB
70          */
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>>>() {
74                 });
75                 return response.getBody();
76         }
77         
78         /**
79          *  Fetches all the network functions of an S-NSSAI from config DB
80          */
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>>() {
85                 });
86                 for(NetworkFunctionModel networkFn:response.getBody()) {
87                         responseList.add(networkFn.getgNBDUId());       
88                 }
89                 return responseList;
90         }
91         
92         /**
93          *  Fetches the RICS of an S-NSSAI from config DB
94          */
95         public Map<String, List<String>> fetchRICsOfSnssai(String snssai){
96                 
97                 Map<String,List<String>> responseMap=new HashMap<>();
98                 
99                 String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-cell-list/"+snssai;
100                 
101                 ResponseEntity<Map<String,List<CellsModel>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,List<CellsModel>>>() {
102                 });
103
104                 
105                 for (Map.Entry<String, List<CellsModel>> entry : response.getBody().entrySet()) {
106                         List<String> cellslist=new ArrayList<>();
107                         for(CellsModel cellmodel:entry.getValue()) {
108                                 
109                                 cellslist.add(cellmodel.getCellLocalId());
110                         }
111                         responseMap.put(entry.getKey(), cellslist);
112                 }
113                 
114                 return responseMap;
115         }
116         
117         /**
118          *  Fetches the details of a service 
119          */
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>>() {
123                 });
124                 return response.getBody();
125         }       
126         
127 }