From 5e7e5f2c0cdd4e5554f4d8629403b7c554b3a0aa Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Fri, 31 Mar 2023 13:20:42 +0200 Subject: Changes needed to make custom adapters that accesses CCSDK To access the CCSDK a custom adapter needs the controller configuration. Issue-ID: CCSDK-3883 Signed-off-by: PatrikBuhr Change-Id: I6fb3eb3bb953f3fc209229282b66c9e1aa10cdee --- .../clients/A1ClientFactory.java | 15 +++++---------- .../clients/CcsdkA1AdapterClient.java | 20 +++++++++----------- .../configuration/ApplicationConfig.java | 11 ----------- .../configuration/ApplicationConfigParser.java | 19 ++++++++++++------- .../configuration/RicConfig.java | 2 +- .../controllers/v2/PolicyController.java | 1 - 6 files changed, 27 insertions(+), 41 deletions(-) (limited to 'a1-policy-management/src/main/java') 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 14738a91..54dfab88 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 @@ -84,7 +84,7 @@ public class A1ClientFactory { } else if (version == A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1 || 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); + return new CcsdkA1AdapterClient(version, ric.getConfig(), this.restClientFactory); } else if (version == A1ProtocolType.CUSTOM_PROTOCOL) { return createCustomAdapter(ric); } else { @@ -94,17 +94,12 @@ public class A1ClientFactory { } private ControllerConfig getControllerConfig(Ric ric) throws ServiceException { - String controllerName = ric.getConfig().getControllerName(); - if (controllerName.isEmpty()) { + ControllerConfig controllerConfig = ric.getConfig().getControllerConfig(); + if (controllerConfig == null) { ric.setProtocolVersion(A1ProtocolType.UNKNOWN); throw new ServiceException("No controller configured for Near-RT RIC: " + ric.id()); } - try { - return this.appConfig.getControllerConfig(controllerName); - } catch (ServiceException e) { - ric.setProtocolVersion(A1ProtocolType.UNKNOWN); - throw e; - } + return controllerConfig; } private A1Client createCustomAdapter(Ric ric) throws ServiceException { @@ -127,7 +122,7 @@ public class A1ClientFactory { } private void assertNoControllerConfig(Ric ric, A1ProtocolType version) throws ServiceException { - if (!ric.getConfig().getControllerName().isEmpty()) { + if (ric.getConfig().getControllerConfig() != null) { ric.setProtocolVersion(A1ProtocolType.UNKNOWN); throw new ServiceException( "Controller config should be empty, ric: " + ric.id() + " when using protocol version: " + version); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java index 225d2f71..3b0d12a4 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java @@ -85,7 +85,6 @@ public class CcsdkA1AdapterClient implements A1Client { private static final String GET_POLICY_RPC = "getA1Policy"; private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ControllerConfig controllerConfig; private final AsyncRestClient restClient; private final RicConfig ricConfig; private final A1ProtocolType protocolType; @@ -103,10 +102,10 @@ public class CcsdkA1AdapterClient implements A1Client { * * @throws IllegalArgumentException when the protocolType is wrong. */ - public CcsdkA1AdapterClient(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig, + public CcsdkA1AdapterClient(A1ProtocolType protocolType, RicConfig ricConfig, AsyncRestClientFactory restClientFactory) { - this(protocolType, ricConfig, controllerConfig, - restClientFactory.createRestClientNoHttpProxy(controllerConfig.getBaseUrl() + "/rests/operations")); + this(protocolType, ricConfig, restClientFactory + .createRestClientNoHttpProxy(ricConfig.getControllerConfig().getBaseUrl() + "/rests/operations")); } /** @@ -123,16 +122,15 @@ public class CcsdkA1AdapterClient implements A1Client { * * @throws IllegalArgumentException when the protocolType is illegal. */ - CcsdkA1AdapterClient(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig, - AsyncRestClient restClient) { + CcsdkA1AdapterClient(A1ProtocolType protocolType, RicConfig ricConfig, AsyncRestClient restClient) { if (A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1.equals(protocolType) // || A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1.equals(protocolType) // || A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0.equals(protocolType)) { this.restClient = restClient; this.ricConfig = ricConfig; this.protocolType = protocolType; - this.controllerConfig = controllerConfig; - logger.debug("CcsdkA1AdapterClient for ric: {}, a1Controller: {}", ricConfig.getRicId(), controllerConfig); + logger.debug("CcsdkA1AdapterClient for ric: {}, a1Controller: {}", ricConfig.getRicId(), + ricConfig.getControllerConfig()); } else { logger.error("Not supported protocoltype: {}", protocolType); throw new IllegalArgumentException("Not handeled protocolversion: " + protocolType); @@ -284,10 +282,10 @@ public class CcsdkA1AdapterClient implements A1Client { final String inputJsonString = A1AdapterJsonHelper.createInputJsonString(inputParams); logger.debug("POST inputJsonString = {}", inputJsonString); - + ControllerConfig controllerConfig = this.ricConfig.getControllerConfig(); return restClient - .postWithAuthHeader(controllerUrl(rpcName), inputJsonString, this.controllerConfig.getUserName(), - this.controllerConfig.getPassword()) // + .postWithAuthHeader(controllerUrl(rpcName), inputJsonString, controllerConfig.getUserName(), + controllerConfig.getPassword()) // .flatMap(resp -> extractResponseBody(resp, ricUrl)); } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java index 358680a0..eea96927 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java @@ -100,8 +100,6 @@ public class ApplicationConfig { private Map ricConfigs = new HashMap<>(); - private Map controllerConfigs = new HashMap<>(); - private WebClientConfig webClientConfig = null; public synchronized Collection getRicConfigs() { @@ -130,14 +128,6 @@ public class ApplicationConfig { return this.webClientConfig; } - public synchronized ControllerConfig getControllerConfig(String name) throws ServiceException { - ControllerConfig controllerConfig = this.controllerConfigs.get(name); - if (controllerConfig == null) { - throw new ServiceException("Could not find controller config: " + name); - } - return controllerConfig; - } - public synchronized RicConfig getRic(String ricId) throws ServiceException { RicConfig ricConfig = this.ricConfigs.get(ricId); if (ricConfig == null) { @@ -166,7 +156,6 @@ public class ApplicationConfig { ApplicationConfigParser.ConfigParserResult parserResult) { Collection modifications = new ArrayList<>(); - this.controllerConfigs = parserResult.getControllerConfigs(); Map newRicConfigs = new HashMap<>(); for (RicConfig newConfig : parserResult.getRicConfigs()) { 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 9df901fa..45305f84 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 @@ -81,8 +81,9 @@ public class ApplicationConfigParser { throw new ServiceException("Missing root configuration \"" + CONFIG + "\" in JSON: " + root); } - List ricConfigs = parseRics(pmsConfigJson); Map controllerConfigs = parseControllerConfigs(pmsConfigJson); + List ricConfigs = parseRics(pmsConfigJson, controllerConfigs); + checkConfigurationConsistency(ricConfigs, controllerConfigs); return ConfigParserResult.builder() // @@ -133,22 +134,26 @@ public class ApplicationConfigParser { if (!ricNames.add(ric.getRicId())) { throw new ServiceException("Configuration error, more than one RIC with name: " + ric.getRicId()); } - if (!ric.getControllerName().isEmpty() && controllerConfigs.get(ric.getControllerName()) == null) { - throw new ServiceException( - "Configuration error, controller configuration not found: " + ric.getControllerName()); - } } } - private List parseRics(JsonObject config) throws ServiceException { + private List parseRics(JsonObject config, Map controllerConfigs) + throws ServiceException { List result = new ArrayList<>(); for (JsonElement ricElem : getAsJsonArray(config, "ric")) { JsonObject ricJsonObj = ricElem.getAsJsonObject(); + String controllerName = getString(ricJsonObj, CONTROLLER, ""); + ControllerConfig controllerConfig = controllerConfigs.get(controllerName); + if (!controllerName.isEmpty() && controllerConfig == null) { + throw new ServiceException( + "Configuration error, controller configuration not found: " + controllerName); + } + RicConfig ricConfig = RicConfig.builder() // .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString()) // .baseUrl(get(ricJsonObj, "baseUrl").getAsString()) // .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray())) // - .controllerName(getString(ricJsonObj, CONTROLLER, "")) + .controllerConfig(controllerConfig) .customAdapterClass(getString(ricJsonObj, "customAdapterClass", "")) // .build(); if (!ricConfig.getBaseUrl().isEmpty()) { 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 ffe853f5..05ba6672 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 @@ -36,7 +36,7 @@ public class RicConfig { private String ricId; @Builder.Default - private String controllerName = ""; + private ControllerConfig controllerConfig = null; private String baseUrl; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java index f5950c9b..500ddd2a 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java @@ -57,7 +57,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; -- cgit 1.2.3-korg