To access the CCSDK a custom adapter needs the controller configuration.
Issue-ID: CCSDK-3883
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I6fb3eb3bb953f3fc209229282b66c9e1aa10cdee
} 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 {
}
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 {
}
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);
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;
*
* @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"));
}
/**
*
* @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);
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));
}
private Map<String, RicConfig> ricConfigs = new HashMap<>();
- private Map<String, ControllerConfig> controllerConfigs = new HashMap<>();
-
private WebClientConfig webClientConfig = null;
public synchronized Collection<RicConfig> getRicConfigs() {
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) {
ApplicationConfigParser.ConfigParserResult parserResult) {
Collection<RicConfigUpdate> modifications = new ArrayList<>();
- this.controllerConfigs = parserResult.getControllerConfigs();
Map<String, RicConfig> newRicConfigs = new HashMap<>();
for (RicConfig newConfig : parserResult.getRicConfigs()) {
throw new ServiceException("Missing root configuration \"" + CONFIG + "\" in JSON: " + root);
}
- List<RicConfig> ricConfigs = parseRics(pmsConfigJson);
Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(pmsConfigJson);
+ List<RicConfig> ricConfigs = parseRics(pmsConfigJson, controllerConfigs);
+
checkConfigurationConsistency(ricConfigs, controllerConfigs);
return ConfigParserResult.builder() //
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<RicConfig> parseRics(JsonObject config) throws ServiceException {
+ private List<RicConfig> parseRics(JsonObject config, Map<String, ControllerConfig> controllerConfigs)
+ throws ServiceException {
List<RicConfig> 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()) {
private String ricId;
@Builder.Default
- private String controllerName = "";
+ private ControllerConfig controllerConfig = null;
private String baseUrl;
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;
private A1ClientFactory factoryUnderTest;
private static RicConfig ricConfig(String controllerName, String customAdapter) {
+ ControllerConfig controllerConfig = null;
+ if (!controllerName.isEmpty()) {
+ controllerConfig = ControllerConfig.builder().baseUrl("baseUrl").name(controllerName).build();
+ }
return RicConfig.builder() //
.ricId(RIC_NAME) //
.baseUrl("baseUrl") //
- .controllerName(controllerName) //
+ .controllerConfig(controllerConfig) //
.customAdapterClass(customAdapter) //
.build();
}
@DisplayName("test create check types controllers")
void create_check_types_controllers() throws ServiceException {
this.ric = new Ric(ricConfig("anythingButEmpty"));
- whenGetGetControllerConfigReturn();
- whenGetGetControllerConfigReturn();
assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1) instanceof CcsdkA1AdapterClient);
- whenGetGetControllerConfigReturn();
assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1) instanceof CcsdkA1AdapterClient);
}
when(clientMock.getProtocolVersion()).thenReturn(Mono.just(protocol));
}
- private void whenGetGetControllerConfigReturn() throws ServiceException {
- ControllerConfig controllerCfg = ControllerConfig.builder() //
- .name("name") //
- .baseUrl("baseUrl") //
- .password("pass") //
- .userName("user") //
- .build();
- when(applicationConfigMock.getControllerConfig(any())).thenReturn(controllerCfg);
- }
-
}
import java.util.Arrays;
import java.util.Vector;
-import org.json.JSONObject;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
-import reactor.core.publisher.Mono;
public class A1ClientHelper {
private A1ClientHelper() {}
- protected static Mono<String> createOutputJsonResponse(String key, String value) {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put(key, value);
- JSONObject responseJson = new JSONObject();
- responseJson.put("output", paramsJson);
- return Mono.just(responseJson.toString());
- }
-
- protected static Ric createRic(String url) {
+ private static Ric createRic(String url) {
RicConfig cfg = RicConfig.builder().ricId("ric") //
.baseUrl(url) //
.managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
return new Ric(cfg);
}
- protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
+ public static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
String callbackUrl = "https://test.com";
return Policy.builder() //
.id(policyId) //
.build();
}
- protected static PolicyType createPolicyType(String name) {
+ public static PolicyType createPolicyType(String name) {
return PolicyType.builder().id(name).schema("schema").build();
}
-
- protected static String getCreateSchema(String policyType, String policyTypeId) {
- JSONObject obj = new JSONObject(policyType);
- JSONObject schemaObj = obj.getJSONObject("create_schema");
- schemaObj.put("title", policyTypeId);
- return schemaObj.toString();
- }
}
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
+import java.util.Vector;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterOutput;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterRequest;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientResponseException;
void createClientWithWrongProtocol_thenErrorIsThrown() {
AsyncRestClient asyncRestClient = new AsyncRestClient("", null, null, new SecurityContext(""));
assertThrows(IllegalArgumentException.class, () -> {
- new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, null, asyncRestClient);
+ new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, asyncRestClient);
});
}
@DisplayName("test get Policy Type Identities STD V1")
void getPolicyTypeIdentities_STD_V1() {
clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
List<String> policyTypeIds = clientUnderTest.getPolicyTypeIdentities().block();
assertEquals(1, policyTypeIds.size(), "should hardcoded to one");
assertEquals("", policyTypeIds.get(0), "should hardcoded to empty");
}
+ private Ric createRic(String url) {
+ RicConfig cfg = RicConfig.builder().ricId("ric") //
+ .baseUrl(url) //
+ .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
+ .controllerConfig(controllerConfig()) //
+ .build();
+ return new Ric(cfg);
+ }
+
private void testGetPolicyTypeIdentities(A1ProtocolType protocolType, String expUrl) {
clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
String response = createOkResponseWithBody(Arrays.asList(POLICY_TYPE_1_ID));
whenAsyncPostThenReturn(Mono.just(response));
void getTypeSchema_STD_V1() {
clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
String policyType = clientUnderTest.getPolicyTypeSchema("").block();
private void testGetTypeSchema(A1ProtocolType protocolType, String expUrl, String policyTypeId,
String getSchemaResponseFile) throws IOException {
clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
String ricResponse = loadFile(getSchemaResponseFile);
JsonElement elem = gson().fromJson(ricResponse, JsonElement.class);
private void getPolicyIdentities(A1ProtocolType protocolType, String... expUrls) {
clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
String resp = createOkResponseWithBody(Arrays.asList("xxx"));
whenAsyncPostThenReturn(Mono.just(resp));
private void putPolicy(A1ProtocolType protocolType, String expUrl) {
clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
whenPostReturnOkResponse();
@DisplayName("test post Rejected")
void postRejected() {
clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
final String policyJson = "{}";
AdapterOutput adapterOutput = new AdapterOutput(HttpStatus.BAD_REQUEST.value(), "NOK");
private void deleteAllPolicies(A1ProtocolType protocolType, String expUrl) {
clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
String resp = createOkResponseWithBody(Arrays.asList("xxx"));
whenAsyncPostThenReturn(Mono.just(resp));
@DisplayName("test get Version OSC")
void getVersion_OSC() {
clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, // Version irrelevant here
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
whenAsyncPostThenReturn(Mono.error(new Exception("Error"))).thenReturn(Mono.just(createOkResponseString(true)));
@DisplayName("test Get Status")
void testGetStatus() {
clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, //
- A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
- controllerConfig(), asyncRestClientMock);
+ createRic(RIC_1_URL).getConfig(), //
+ asyncRestClientMock);
whenPostReturnOkResponse();
Policy policy = A1ClientHelper.createPolicy(RIC_1_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE_1_ID);
import java.util.List;
import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Mono<String> returnedMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_ID);
verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_1_ID);
- StepVerifier.create(returnedMono).expectNext(A1ClientHelper.getCreateSchema(policyType, POLICY_TYPE_1_ID))
- .expectComplete().verify();
+ StepVerifier.create(returnedMono).expectNext(getCreateSchema(policyType, POLICY_TYPE_1_ID)).expectComplete()
+ .verify();
}
@Test
verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_2_ID + POLICIES);
verify(asyncRestClientMock).delete(POLICYTYPES_URL + POLICY_TYPE_2_ID + POLICIES + "/" + POLICY_2_ID);
}
+
+ private String getCreateSchema(String policyType, String policyTypeId) {
+ JSONObject obj = new JSONObject(policyType);
+ JSONObject schemaObj = obj.getJSONObject("create_schema");
+ schemaObj.put("title", policyTypeId);
+ return schemaObj.toString();
+ }
}
private static final PolicyType POLICY_TYPE_1 = PolicyType.builder().id(POLICY_TYPE_1_NAME).schema("").build();
private static final Ric RIC_1 = new Ric(RicConfig.builder().ricId("ric_1").baseUrl("baseUrl1")
- .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))).controllerName("controllerName")
- .build());
+ .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))).build());
private static final String POLICY_1_ID = "policyId1";
private static final Policy POLICY_1 = Policy.builder().id(POLICY_1_ID).json("").ownerServiceId("service")
.ricId("ric_1") //
.baseUrl("baseUrl1") //
.managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
- .controllerName("controllerName") //
.build());
private static final String POLICY_1_ID = "policyId1";
ric1 = new Ric(RicConfig.builder() //
.ricId(RIC_1_NAME) //
.baseUrl("baseUrl1") //
- .controllerName("controllerName") //
.build());
policy1 = createPolicy("policyId1", false);
policyTypes = new PolicyTypes(appConfig);