2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.sdnc.northbound.restadpter;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.ArrayList;
26 import java.util.Enumeration;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Properties;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.web.util.UriComponentsBuilder;
35 * This class provides Near-RIC api to invoke the A1 interface
37 * @author lathishbabu.ganesan@est.tech
41 public class NearRicUrlProvider {
43 // nearRicMap provides mapping from nearRtRicId to domainname:port of nearRTRics
44 private HashMap<String, String> nearRicMap = new HashMap<>();
45 private static final String NEAR_RIC_LIST_FILE = "NearRtRicList.properties";
46 private final Logger log = LoggerFactory.getLogger(NearRicUrlProvider.class);
48 public NearRicUrlProvider() {
50 readNearRtRicConfigFile();
51 } catch (IOException ex) {
52 log.error("Exception while reading nearRtRicConfigFile: {}", ex);
56 private void readNearRtRicConfigFile() throws IOException {
57 InputStream inputStream = NearRicUrlProvider.class.getClassLoader().getResourceAsStream(NEAR_RIC_LIST_FILE);
58 if (inputStream == null) {
59 log.error("The file {} not found in classpath", NEAR_RIC_LIST_FILE);
61 Properties properties = new Properties();
62 properties.load(inputStream);
63 Enumeration<?> keys = properties.propertyNames();
64 while (keys.hasMoreElements()) {
65 String key = (String) keys.nextElement();
66 nearRicMap.put(key, properties.getProperty(key));
73 * Retrieve the list of Near-RICs
75 * @return the list of Near-RICs
77 public List<String> getNearRTRicIdsList () {
78 return new ArrayList<>(nearRicMap.keySet());
82 * Retrieve the base url of the Near-RIC
84 * @return the base url
86 public String getBaseUrl(final String nearRtRicId) {
87 String baseUrl = "http://" + nearRicMap.get(nearRtRicId) + "/a1-p/";
88 return UriComponentsBuilder.fromUriString(baseUrl).build().toString();
92 * Retrieve the url of A1 healthcheck
94 * @return the health check url
96 public String getHealthCheck(final String nearRtRicId) {
97 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("healthcheck").build()
102 * Retrieve the policy type url
104 * @return the base url with the policytypes
106 public String getPolicyTypes(final String nearRtRicId) {
107 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes/").build()
112 * Retrieve the url of policy type id
114 * @param policyTypeId Policy Type Id
115 * @return the policy type id url
117 public String getPolicyTypeId(final String nearRtRicId, final String policyTypeId) {
118 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes")
119 .pathSegment(policyTypeId).build().toString();
123 * Retrieve the url of the policy instances
125 * @param policyTypeId Policy Type Id
126 * @return the policy instances for the given policy type
128 public String getPolicyInstances(final String nearRtRicId, final String policyTypeId) {
129 return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
134 * Retrieve the url of the policy instance id
136 * @param policyTypeId Policy Type Id
137 * @param policyInstanceId Policy Instance Id
138 * @return the policy instance id for the given policy type
140 public String getPolicyInstanceId(final String nearRtRicId, final String policyTypeId, final String policyInstanceId) {
141 return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
142 .pathSegment(policyInstanceId).build().toString();
146 * Retrieve the url of the policy instance id status
148 * @param policyTypeId Policy Type Id
149 * @param policyInstanceId Policy Instance Id
150 * @return the policy instance id status for the given policy type
152 public String getPolicyInstanceIdStatus(final String nearRtRicId, final String policyTypeId,
153 final String policyInstanceId) {
154 return UriComponentsBuilder.fromUriString(getPolicyInstanceId(nearRtRicId, policyTypeId, policyInstanceId))
155 .pathSegment("status").build().toString();