summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2022-05-11 13:10:40 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2022-05-12 09:18:45 +0200
commit4faa502e6fb2a1d242618ba1513a47eb55d0a530 (patch)
treea0c3fe4c2cc9ee96163486229be76ba13ae9b410 /a1-policy-management/src/main
parentf5f34a552b1559d79a74ae9e3e79686d6b93af70 (diff)
NONRTRIC PMS added support for custom A1 adapters
Added support for added external A1-P adapter. This makes it possible to design and include adapter to APIs for accessing of A1 policies (in a NearRT-RIC) without any changes in this SW. Issue-ID: CCSDK-3655 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: Idc7bf97963a2455bde983b06a5f861df77d901ae
Diffstat (limited to 'a1-policy-management/src/main')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java8
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java24
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java7
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java20
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/RicConfig.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java10
6 files changed, 63 insertions, 8 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
index 5e498e4b..a691ee1e 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
@@ -22,6 +22,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.clients;
import java.util.List;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import reactor.core.publisher.Flux;
@@ -33,6 +34,10 @@ import reactor.core.publisher.Mono;
*/
public interface A1Client {
+ public interface Factory {
+ A1Client create(RicConfig ricConfig, AsyncRestClientFactory restClientFactory);
+ }
+
public enum A1ProtocolType {
UNKNOWN, //
STD_V1_1, // STD A1 version 1.1
@@ -40,7 +45,8 @@ public interface A1Client {
OSC_V1, // OSC 'A1'
CCSDK_A1_ADAPTER_STD_V1_1, // CCSDK_A1_ADAPTER with STD A1 version 1.1 southbound
CCSDK_A1_ADAPTER_STD_V2_0_0, // CCSDK_A1_ADAPTER with STD A1 version 2.0.0 southbound
- CCSDK_A1_ADAPTER_OSC_V1 // CCSDK_A1_ADAPTER with OSC 'A1' southbound
+ CCSDK_A1_ADAPTER_OSC_V1, // CCSDK_A1_ADAPTER with OSC 'A1' southbound
+ CUSTOM_PROTOCOL // Some other protocol handled by some custom A1 adapter class.
}
public Mono<A1ProtocolType> getProtocolVersion();
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
index 1d465c3a..04dd08ee 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
@@ -20,9 +20,12 @@
package org.onap.ccsdk.oran.a1policymanagementservice.clients;
+import java.lang.reflect.Constructor;
+
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.slf4j.Logger;
@@ -83,6 +86,8 @@ public class A1ClientFactory {
|| version == A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1
|| version == A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0) {
return new CcsdkA1AdapterClient(version, ric.getConfig(), getControllerConfig(ric), this.restClientFactory);
+ } else if (version == A1ProtocolType.CUSTOM_PROTOCOL) {
+ return createCustomAdapter(ric);
} else {
logger.error("Unhandled protocol: {}", version);
throw new ServiceException("Unhandled protocol");
@@ -103,6 +108,25 @@ public class A1ClientFactory {
}
}
+ private A1Client createCustomAdapter(Ric ric) throws ServiceException {
+ try {
+ Class<?> clazz = Class.forName(ric.getConfig().customAdapterClass());
+ if (A1Client.class.isAssignableFrom(clazz)) {
+ Constructor<?> constructor = clazz.getConstructor(RicConfig.class, AsyncRestClientFactory.class);
+ return (A1Client) constructor.newInstance(ric.getConfig(), this.restClientFactory);
+ } else if (A1Client.Factory.class.isAssignableFrom(clazz)) {
+ A1Client.Factory factory = (A1Client.Factory) clazz.getDeclaredConstructor().newInstance();
+ return factory.create(ric.getConfig(), this.restClientFactory);
+ } else {
+ throw new ServiceException("The custom class must either implement A1Client.Factory or A1Client");
+ }
+ } catch (ClassNotFoundException e) {
+ throw new ServiceException("Could not find class: " + ric.getConfig().customAdapterClass(), e);
+ } catch (Exception e) {
+ throw new ServiceException("Cannot create custom adapter: " + ric.getConfig().customAdapterClass(), e);
+ }
+ }
+
private void assertNoControllerConfig(Ric ric, A1ProtocolType version) throws ServiceException {
if (!ric.getConfig().controllerName().isEmpty()) {
ric.setProtocolVersion(A1ProtocolType.UNKNOWN);
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
index d0f4da28..b91edee3 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
@@ -41,6 +41,13 @@ import reactor.core.publisher.Mono;
public class StdA1ClientVersion2 implements A1Client {
static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC
+ public static class Factory implements A1Client.Factory {
+ @Override
+ public A1Client create(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
+ return new StdA1ClientVersion2(ricConfig, restClientFactory);
+ }
+ }
+
public static class OranV2UriBuilder implements A1UriBuilder {
private final RicConfig ricConfig;
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
index 726d67fc..fc1985ac 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
@@ -163,13 +163,13 @@ public class ApplicationConfigParser {
private List<RicConfig> parseRics(JsonObject config) throws ServiceException {
List<RicConfig> result = new ArrayList<>();
for (JsonElement ricElem : getAsJsonArray(config, "ric")) {
- JsonObject ricAsJson = ricElem.getAsJsonObject();
- JsonElement controllerNameElement = ricAsJson.get(CONTROLLER);
+ JsonObject ricJsonObj = ricElem.getAsJsonObject();
RicConfig ricConfig = ImmutableRicConfig.builder() //
- .ricId(get(ricAsJson, "name", "id", "ricId").getAsString()) //
- .baseUrl(get(ricAsJson, "baseUrl").getAsString()) //
- .managedElementIds(parseManagedElementIds(get(ricAsJson, "managedElementIds").getAsJsonArray())) //
- .controllerName(controllerNameElement != null ? controllerNameElement.getAsString() : "") //
+ .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString()) //
+ .baseUrl(get(ricJsonObj, "baseUrl").getAsString()) //
+ .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray())) //
+ .controllerName(getString(ricJsonObj, CONTROLLER, ""))
+ .customAdapterClass(getString(ricJsonObj, "customAdapterClass", "")) //
.build();
if (!ricConfig.baseUrl().isEmpty()) {
result.add(ricConfig);
@@ -180,6 +180,14 @@ public class ApplicationConfigParser {
return result;
}
+ String getString(JsonObject obj, String name, String defaultValue) {
+ JsonElement elem = obj.get(name);
+ if (elem != null) {
+ return elem.getAsString();
+ }
+ return defaultValue;
+ }
+
Map<String, ControllerConfig> parseControllerConfigs(JsonObject config) throws ServiceException {
if (config.get(CONTROLLER) == null) {
return new HashMap<>();
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/RicConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/RicConfig.java
index 7f7f9f5e..251be5e7 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/RicConfig.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/RicConfig.java
@@ -34,4 +34,6 @@ public interface RicConfig {
public ImmutableList<String> managedElementIds();
+ public String customAdapterClass();
+
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
index f43737f5..012f1f62 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java
@@ -40,7 +40,7 @@ public class Ric {
private RicConfig ricConfig;
private RicState state = RicState.UNAVAILABLE;
private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
- @Getter
+
@Setter
private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
@@ -73,6 +73,14 @@ public class Ric {
this.state = state;
}
+ public synchronized A1ProtocolType getProtocolVersion() {
+ if (this.ricConfig.customAdapterClass().isEmpty()) {
+ return this.protocolVersion;
+ } else {
+ return A1ProtocolType.CUSTOM_PROTOCOL;
+ }
+ }
+
/**
* Gets the nodes managed by this Ric.
*