X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=sdnc-a1-controller%2Fnorthbound%2Fnonrt-ric-api%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fsdnc%2Fnorthbound%2Frestadpter%2FNearRicUrlProvider.java;h=8c2d69237f1df790d0680dd027cb9f0acd8de023;hb=238fd97d5c8320cc8a53e04e04cfd39dcf900c4e;hp=469e4075a38314ebf3d9db9ab23c44ee2dc0e878;hpb=b6fe5a1bbad372357f6b441e1657dd8bbe48dc1a;p=nonrtric.git diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java index 469e4075..8c2d6923 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java @@ -20,97 +20,145 @@ package org.onap.sdnc.northbound.restadpter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; +import org.onap.sdnc.northbound.exceptions.NearRtRicNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.util.UriComponentsBuilder; /** * This class provides Near-RIC api to invoke the A1 interface - * + * * @author lathishbabu.ganesan@est.tech * */ public class NearRicUrlProvider { - private String baseUrl; + // nearRicMap provides mapping from nearRtRicId to domainname:port of nearRTRics + private HashMap nearRicMap = new HashMap<>(); + private static final String NEAR_RIC_LIST_FILE = "NearRtRicList.properties"; + private final Logger log = LoggerFactory.getLogger(NearRicUrlProvider.class); public NearRicUrlProvider() { - // Near ric ip is passed in payload - baseUrl = "http://localhost:8080/a1-p/"; + try { + readNearRtRicConfigFile(); + } catch (IOException ex) { + log.error("Exception while reading nearRtRicConfigFile: {}", ex); + } + } + + private void readNearRtRicConfigFile() throws IOException { + InputStream inputStream = NearRicUrlProvider.class.getClassLoader().getResourceAsStream(NEAR_RIC_LIST_FILE); + if (inputStream == null) { + log.error("The file {} not found in classpath", NEAR_RIC_LIST_FILE); + } else { + Properties properties = new Properties(); + properties.load(inputStream); + Enumeration keys = properties.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + nearRicMap.put(key, properties.getProperty(key)); + } + inputStream.close(); + } + } + + /** + * Retrieve the list of Near-RICs + * + * @return the list of Near-RICs + */ + public List getNearRTRicIdsList () { + return new ArrayList<>(nearRicMap.keySet()); } /** * Retrieve the base url of the Near-RIC - * + * * @return the base url */ - public String getBaseUrl() { + public String getBaseUrl(final String nearRtRicId) { + if (!nearRicMap.containsKey(nearRtRicId)) { + throw new NearRtRicNotFoundException("NearRtRic with this ID is not known by the A1 controller"); + } + String baseUrl = "http://" + nearRicMap.get(nearRtRicId) + "/a1-p/"; return UriComponentsBuilder.fromUriString(baseUrl).build().toString(); } /** * Retrieve the url of A1 healthcheck - * + * * @return the health check url */ - public String getHealthCheck() { - return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("healthcheck").build() + public String getHealthCheck(final String nearRtRicId) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("healthcheck").build() .toString(); } /** * Retrieve the policy type url - * + * * @return the base url with the policytypes */ - public String getPolicyTypes() { - return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes").build() + public String getPolicyTypes(final String nearRtRicId) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes/").build() .toString(); } /** * Retrieve the url of policy type id - * + * * @param policyTypeId Policy Type Id * @return the policy type id url */ - public String getPolicyTypeId(final String policyTypeId) { - return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes") + public String getPolicyTypeId(final String nearRtRicId, + final String policyTypeId) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes") .pathSegment(policyTypeId).build().toString(); } /** * Retrieve the url of the policy instances - * + * * @param policyTypeId Policy Type Id * @return the policy instances for the given policy type */ - public String getPolicyInstances(final String policyTypeId) { - return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies") + public String getPolicyInstances(final String nearRtRicId, + final String policyTypeId) { + return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies") .build().toString(); } /** * Retrieve the url of the policy instance id - * + * * @param policyTypeId Policy Type Id * @param policyInstanceId Policy Instance Id * @return the policy instance id for the given policy type */ - public String getPolicyInstanceId(final String policyTypeId, final String policyInstanceId) { - return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies") + public String getPolicyInstanceId(final String nearRtRicId, final String policyTypeId, + final String policyInstanceId) { + return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies") .pathSegment(policyInstanceId).build().toString(); } /** * Retrieve the url of the policy instance id status - * + * * @param policyTypeId Policy Type Id * @param policyInstanceId Policy Instance Id * @return the policy instance id status for the given policy type */ - public String getPolicyInstanceIdStatus(final String policyTypeId, + public String getPolicyInstanceIdStatus(final String nearRtRicId, final String policyTypeId, final String policyInstanceId) { - return UriComponentsBuilder.fromUriString(getPolicyInstanceId(policyTypeId, policyInstanceId)) + return UriComponentsBuilder.fromUriString(getPolicyInstanceId(nearRtRicId, policyTypeId, policyInstanceId)) .pathSegment("status").build().toString(); } }