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