aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-12-20 13:40:14 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2022-01-12 09:55:58 +0100
commit0f8b20544745afaf9c7b38140b9516667d9c4752 (patch)
tree5794cf7640a0f53a79cd9ae19b52f78c810191f1 /a1-policy-management
parent2a56cf71506081a7c2c08f46791fbf8132dfac31 (diff)
PMS, Removed use of CBS
Removing usage of the deprecated component CBS, which was used for application configuration data. Change-Id: I11fbc1ff6e6caa1af448bc2918f4364777094e25 Issue-ID: CCSDK-3560 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management')
-rw-r--r--a1-policy-management/api/pms-api.json6
-rw-r--r--a1-policy-management/api/pms-api.yaml6
-rw-r--r--a1-policy-management/pom.xml12
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java22
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessor.java89
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java50
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java145
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java169
10 files changed, 18 insertions, 485 deletions
diff --git a/a1-policy-management/api/pms-api.json b/a1-policy-management/api/pms-api.json
index b5936e5c..be0152f5 100644
--- a/a1-policy-management/api/pms-api.json
+++ b/a1-policy-management/api/pms-api.json
@@ -472,8 +472,7 @@
}},
"/a1-policy/v2/configuration": {
"get": {
- "summary": "Returns the contents of the configuration file",
- "description": "Note that the file contents is not relevant if the Consul is used.",
+ "summary": "Returns the contents of the application configuration file",
"operationId": "getConfiguration",
"responses": {
"200": {
@@ -493,7 +492,6 @@
"content": {"application/json": {"schema": {"type": "object"}}},
"required": true
},
- "description": "Note that the file is ignored if the Consul is used.",
"operationId": "putConfiguration",
"responses": {
"200": {
@@ -608,7 +606,7 @@
"schema": {"type": "string"},
"in": "query",
"name": "policytype_id",
- "description": "The identity of a policy type. If given, all Near-RT RICs supporteing the policy type are returned",
+ "description": "The identity of a policy type. If given, all Near-RT RICs supporting the policy type are returned",
"required": false
}],
"tags": ["NearRT-RIC Repository"]
diff --git a/a1-policy-management/api/pms-api.yaml b/a1-policy-management/api/pms-api.yaml
index 8aab618d..c23f0fcf 100644
--- a/a1-policy-management/api/pms-api.yaml
+++ b/a1-policy-management/api/pms-api.yaml
@@ -325,8 +325,7 @@ paths:
get:
tags:
- Management of configuration
- summary: Returns the contents of the configuration file
- description: Note that the file contents is not relevant if the Consul is used.
+ summary: Returns the contents of the application configuration file
operationId: getConfiguration
responses:
200:
@@ -345,7 +344,6 @@ paths:
tags:
- Management of configuration
summary: Replace the current configuration file with the given configuration
- description: Note that the file is ignored if the Consul is used.
operationId: putConfiguration
requestBody:
content:
@@ -485,7 +483,7 @@ paths:
parameters:
- name: policytype_id
in: query
- description: The identity of a policy type. If given, all Near-RT RICs supporteing
+ description: The identity of a policy type. If given, all Near-RT RICs supporting
the policy type are returned
required: false
style: form
diff --git a/a1-policy-management/pom.xml b/a1-policy-management/pom.xml
index c7506b01..dc1d7f23 100644
--- a/a1-policy-management/pom.xml
+++ b/a1-policy-management/pom.xml
@@ -37,7 +37,6 @@
<springfox.version>3.0.0</springfox.version>
<!-- Do not change to version 3.0.0! Will break the generated json. -->
<immutable.version>2.8.8</immutable.version>
- <sdk.version>1.1.6</sdk.version>
<json.version>20200518</json.version>
<formatter-maven-plugin.version>2.13.0</formatter-maven-plugin.version>
<spotless-maven-plugin.version>2.5.0</spotless-maven-plugin.version>
@@ -81,6 +80,10 @@
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webflux</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
@@ -112,11 +115,6 @@
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
- <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
- <artifactId>cbs-client</artifactId>
- <version>${sdk.version}</version>
- </dependency>
- <dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
@@ -433,4 +431,4 @@
</plugin>
</plugins>
</build>
-</project>
+</project> \ No newline at end of file
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
index e07ea284..7a65bacb 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
@@ -37,8 +37,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationCo
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
-import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
-import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,23 +57,19 @@ public class ConfigurationController {
public static final String API_DESCRIPTION = "";
private final ConfigurationFile configurationFile;
- private final RefreshConfigTask refreshConfigTask;
private final ApplicationConfig applicationConfig;
ConfigurationController(@Autowired ConfigurationFile configurationFile,
- @Autowired RefreshConfigTask refreshConfigTask, @Autowired ApplicationConfig applicationConfig) {
+ @Autowired ApplicationConfig applicationConfig) {
this.configurationFile = configurationFile;
- this.refreshConfigTask = refreshConfigTask;
this.applicationConfig = applicationConfig;
-
}
private static Gson gson = new GsonBuilder() //
.create(); //
@PutMapping(path = Consts.V2_API_ROOT + "/configuration", consumes = MediaType.APPLICATION_JSON_VALUE)
- @Operation(summary = "Replace the current configuration file with the given configuration", //
- description = "Note that the file is ignored if the Consul is used.")
+ @Operation(summary = "Replace the current configuration file with the given configuration")
@ApiResponses(value = { //
@ApiResponse(responseCode = "200", //
description = "Configuration updated", //
@@ -89,7 +83,6 @@ public class ConfigurationController {
})
public ResponseEntity<Object> putConfiguration(@RequestBody Object configuration) {
try {
- validateConfigFileIsUsed();
String configAsString = gson.toJson(configuration);
JsonObject configJson = JsonParser.parseString(configAsString).getAsJsonObject();
ApplicationConfigParser configParser = new ApplicationConfigParser(applicationConfig);
@@ -107,8 +100,7 @@ public class ConfigurationController {
}
@GetMapping(path = Consts.V2_API_ROOT + "/configuration", produces = MediaType.APPLICATION_JSON_VALUE)
- @Operation(summary = "Returns the contents of the configuration file", //
- description = "Note that the file contents is not relevant if the Consul is used.") //
+ @Operation(summary = "Returns the contents of the application configuration file") //
@ApiResponses(value = { //
@ApiResponse(responseCode = "200", //
description = "Configuration", //
@@ -120,7 +112,6 @@ public class ConfigurationController {
})
public ResponseEntity<Object> getConfiguration() {
try {
- validateConfigFileIsUsed();
Optional<JsonObject> rootObject = configurationFile.readFile();
if (rootObject.isPresent()) {
return new ResponseEntity<>(rootObject.get().toString(), HttpStatus.OK);
@@ -132,11 +123,4 @@ public class ConfigurationController {
}
}
- private void validateConfigFileIsUsed() throws ServiceException {
- if (this.refreshConfigTask.isConsulUsed()) {
- throw new ServiceException("Config file not used (Consul is used)", HttpStatus.FORBIDDEN);
- }
-
- }
-
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java
index 214f62d1..a531a73f 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java
@@ -123,7 +123,7 @@ public class RicRepositoryController {
})
public ResponseEntity<Object> getRics( //
@Parameter(name = Consts.POLICY_TYPE_ID_PARAM, required = false,
- description = "The identity of a policy type. If given, all Near-RT RICs supporteing the policy type are returned") //
+ description = "The identity of a policy type. If given, all Near-RT RICs supporting the policy type are returned") //
@RequestParam(name = Consts.POLICY_TYPE_ID_PARAM, required = false) String supportingPolicyType)
throws EntityNotFoundException {
if ((supportingPolicyType != null) && (this.types.get(supportingPolicyType) == null)) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
index 14acca95..327dee60 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
@@ -37,7 +37,6 @@ import java.util.List;
import java.util.Map;
import java.util.Vector;
-import org.jetbrains.annotations.Nullable;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
@@ -45,6 +44,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
import org.springframework.util.FileSystemUtils;
@Configuration
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessor.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessor.java
deleted file mode 100644
index 3a4abcf2..00000000
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================LICENSE_END===================================
- */
-
-package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
-
-import java.util.Optional;
-import java.util.Properties;
-
-import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import reactor.core.publisher.Mono;
-
-/**
- * This class reads a few environment variables used for locating the Consul
- * (Config Binding Service).
- */
-class EnvironmentProcessor {
-
- private static final int DEFAULT_CONSUL_PORT = 8500;
- private static final Logger logger = LoggerFactory.getLogger(EnvironmentProcessor.class);
-
- private EnvironmentProcessor() {}
-
- static Mono<EnvProperties> readEnvironmentVariables(Properties systemEnvironment) {
-
- EnvProperties envProperties;
- try {
- envProperties = ImmutableEnvProperties.builder() //
- .consulHost(getConsulHost(systemEnvironment)) //
- .consulPort(getConsultPort(systemEnvironment)) //
- .cbsName(getConfigBindingService(systemEnvironment)) //
- .appName(getService(systemEnvironment)) //
- .build();
- } catch (ServiceException e) {
- return Mono.error(e);
- }
- logger.trace("Evaluated environment system variables {}", envProperties);
- return Mono.just(envProperties);
- }
-
- private static String getConsulHost(Properties systemEnvironments) throws ServiceException {
- return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_HOST"))
- .orElseThrow(() -> new ServiceException("$CONSUL_HOST environment has not been defined"));
- }
-
- private static Integer getConsultPort(Properties systemEnvironments) {
- return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")) //
- .map(Integer::valueOf) //
- .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul);
- }
-
- private static String getConfigBindingService(Properties systemEnvironments) throws ServiceException {
- return Optional.ofNullable(systemEnvironments.getProperty("CONFIG_BINDING_SERVICE")) //
- .orElseThrow(() -> new ServiceException("$CONFIG_BINDING_SERVICE environment has not been defined"));
- }
-
- private static String getService(Properties systemEnvironments) throws ServiceException {
- return Optional
- .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME"))
- .orElse(systemEnvironments.getProperty("SERVICE_NAME")))
- .orElseThrow(() -> new ServiceException(
- "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"));
- }
-
- private static Integer getDefaultPortOfConsul() {
- logger.warn("$CONSUL_PORT variable will be set to default port {}", DEFAULT_CONSUL_PORT);
- return DEFAULT_CONSUL_PORT;
- }
-}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index 7fd54a7c..651ba5ed 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -42,12 +42,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric.RicState;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -60,8 +54,7 @@ import reactor.core.publisher.Mono;
import reactor.util.annotation.Nullable;
/**
- * Regularly refreshes the configuration from Consul or from a local
- * configuration file.
+ * Regularly refreshes the component configuration from a configuration file.
*/
@Component
@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
@@ -84,9 +77,6 @@ public class RefreshConfigTask {
@Getter(AccessLevel.PROTECTED)
private Disposable refreshTask = null;
- @Getter
- private boolean isConsulUsed = false;
-
private final Rics rics;
private final A1ClientFactory a1ClientFactory;
private final Policies policies;
@@ -127,24 +117,14 @@ public class RefreshConfigTask {
Flux<RicConfigUpdate.Type> createRefreshTask() {
Flux<JsonObject> loadFromFile = regularInterval() //
- .filter(notUsed -> !this.isConsulUsed) //
.flatMap(notUsed -> loadConfigurationFromFile()) //
.onErrorResume(this::ignoreErrorFlux) //
.doOnNext(json -> logger.debug("loadFromFile succeeded")) //
.doOnTerminate(() -> logger.error("loadFromFile Terminate"));
- Flux<JsonObject> loadFromConsul = regularInterval() //
- .flatMap(i -> getEnvironment(systemEnvironment)) //
- .flatMap(this::createCbsClient) //
- .flatMap(this::getFromCbs) //
- .onErrorResume(this::ignoreErrorMono) //
- .doOnNext(json -> logger.debug("loadFromConsul succeeded")) //
- .doOnNext(json -> this.isConsulUsed = true) //
- .doOnTerminate(() -> logger.error("loadFromConsul Terminated"));
-
final int CONCURRENCY = 50; // Number of RIC synched in paralell
- return Flux.merge(loadFromFile, loadFromConsul) //
+ return loadFromFile //
.flatMap(this::parseConfiguration) //
.flatMap(this::updateConfig, CONCURRENCY) //
.flatMap(this::handleUpdatedRicConfig) //
@@ -157,38 +137,12 @@ public class RefreshConfigTask {
.limitRate(1); // Limit so that only one event is emitted at a time
}
- Mono<EnvProperties> getEnvironment(Properties systemEnvironment) {
- return EnvironmentProcessor.readEnvironmentVariables(systemEnvironment) //
- .onErrorResume(t -> Mono.empty());
- }
-
- Mono<CbsClient> createCbsClient(EnvProperties env) {
- return CbsClientFactory.createCbsClient(env) //
- .onErrorResume(this::ignoreErrorMono);
- }
-
- private Mono<JsonObject> getFromCbs(CbsClient cbsClient) {
- try {
- final CbsRequest getConfigRequest = CbsRequests.getAll(RequestDiagnosticContext.create());
- return cbsClient.get(getConfigRequest) //
- .onErrorResume(this::ignoreErrorMono);
- } catch (Exception e) {
- return ignoreErrorMono(e);
- }
- }
-
private <R> Flux<R> ignoreErrorFlux(Throwable throwable) {
String errMsg = throwable.toString();
logger.warn("Could not refresh application configuration. {}", errMsg);
return Flux.empty();
}
- private <R> Mono<R> ignoreErrorMono(Throwable throwable) {
- String errMsg = throwable.toString();
- logger.warn("Could not refresh application configuration. {}", errMsg);
- return Mono.empty();
- }
-
private Mono<ApplicationConfigParser.ConfigParserResult> parseConfiguration(JsonObject jsonObject) {
try {
ApplicationConfigParser parser = new ApplicationConfigParser(this.appConfig);
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java
deleted file mode 100644
index 64a7a19e..00000000
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================LICENSE_END===================================
- */
-
-package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
-
-import static ch.qos.logback.classic.Level.WARN;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.read.ListAppender;
-
-import java.util.Properties;
-
-import org.junit.jupiter.api.Test;
-import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
-import reactor.test.StepVerifier;
-
-class EnvironmentProcessorTest {
- private static final String CONSUL_HOST = "CONSUL_HOST";
- private static final String CONSUL_HOST_VALUE = "consulHost";
-
- private static final String CONFIG_BINDING_SERVICE = "CONFIG_BINDING_SERVICE";
- private static final String CONFIG_BINDING_SERVICE_VALUE = "configBindingService";
-
- private static final String HOSTNAME = "HOSTNAME";
- private static final String HOSTNAME_VALUE = "hostname";
-
- @Test
- void allPropertiesAvailableWithHostname_thenAllPropertiesAreReturnedWithGivenConsulPort() {
- Properties systemEnvironment = new Properties();
- String consulPort = "8080";
- systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
- systemEnvironment.put("CONSUL_PORT", consulPort);
- systemEnvironment.put(CONFIG_BINDING_SERVICE, CONFIG_BINDING_SERVICE_VALUE);
- systemEnvironment.put(HOSTNAME, HOSTNAME_VALUE);
-
- EnvProperties expectedEnvProperties = ImmutableEnvProperties.builder() //
- .consulHost(CONSUL_HOST_VALUE) //
- .consulPort(Integer.valueOf(consulPort)) //
- .cbsName(CONFIG_BINDING_SERVICE_VALUE) //
- .appName(HOSTNAME_VALUE) //
- .build();
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectNext(expectedEnvProperties).expectComplete();
- }
-
- @Test
- void consulHostMissing_thenExceptionReturned() {
- Properties systemEnvironment = new Properties();
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(throwable -> throwable instanceof ServiceException
- && throwable.getMessage().equals("$CONSUL_HOST environment has not been defined"))
- .verify();
- }
-
- @Test
- void withAllPropertiesExceptConsulPort_thenAllPropertiesAreReturnedWithDefaultConsulPortAndWarning() {
- Properties systemEnvironment = new Properties();
- systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
- systemEnvironment.put(CONFIG_BINDING_SERVICE, CONFIG_BINDING_SERVICE_VALUE);
- systemEnvironment.put(HOSTNAME, HOSTNAME_VALUE);
-
- String defaultConsulPort = "8500";
- EnvProperties expectedEnvProperties = ImmutableEnvProperties.builder() //
- .consulHost(CONSUL_HOST_VALUE) //
- .consulPort(Integer.valueOf(defaultConsulPort)) //
- .cbsName(CONFIG_BINDING_SERVICE_VALUE) //
- .appName(HOSTNAME_VALUE) //
- .build();
-
- final ListAppender<ILoggingEvent> logAppender =
- LoggingUtils.getLogListAppender(EnvironmentProcessor.class, WARN);
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectNext(expectedEnvProperties).expectComplete();
-
- assertThat(logAppender.list.get(0).getFormattedMessage())
- .isEqualTo("$CONSUL_PORT variable will be set to default port " + defaultConsulPort);
- }
-
- @Test
- void configBindingServiceMissing_thenExceptionReturned() {
- Properties systemEnvironment = new Properties();
- systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(throwable -> throwable instanceof ServiceException
- && throwable.getMessage().equals("$CONFIG_BINDING_SERVICE environment has not been defined"))
- .verify();
- }
-
- @Test
- void allPropertiesAvailableWithServiceName_thenAllPropertiesAreReturned() {
- Properties systemEnvironment = new Properties();
- String consulPort = "8080";
- systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
- systemEnvironment.put("CONSUL_PORT", consulPort);
- systemEnvironment.put(CONFIG_BINDING_SERVICE, CONFIG_BINDING_SERVICE_VALUE);
- systemEnvironment.put("SERVICE_NAME", HOSTNAME_VALUE);
-
- EnvProperties expectedEnvProperties = ImmutableEnvProperties.builder() //
- .consulHost(CONSUL_HOST_VALUE) //
- .consulPort(Integer.valueOf(consulPort)) //
- .cbsName(CONFIG_BINDING_SERVICE_VALUE) //
- .appName(HOSTNAME_VALUE) //
- .build();
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectNext(expectedEnvProperties).expectComplete();
- }
-
- @Test
- void serviceNameAndHostnameMissing_thenExceptionIsReturned() {
- Properties systemEnvironment = new Properties();
- systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
- systemEnvironment.put(CONFIG_BINDING_SERVICE, CONFIG_BINDING_SERVICE_VALUE);
-
- StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(throwable -> throwable instanceof ServiceException && throwable.getMessage()
- .equals("Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"))
- .verify();
- }
-}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
index bef619cc..6c7607e9 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
@@ -20,10 +20,7 @@
package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
-import static ch.qos.logback.classic.Level.ERROR;
-import static ch.qos.logback.classic.Level.WARN;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -31,9 +28,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.read.ListAppender;
-
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.JsonObject;
@@ -42,9 +36,7 @@ import com.google.gson.JsonParser;
import java.io.IOException;
import java.net.URL;
import java.time.Duration;
-import java.time.Instant;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Optional;
import java.util.Properties;
@@ -65,35 +57,21 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableConf
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
-import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
-import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
-
-import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
class RefreshConfigTaskTest {
- private static final boolean CONFIG_FILE_EXISTS = true;
- private static final boolean CONFIG_FILE_DOES_NOT_EXIST = false;
-
private RefreshConfigTask refreshTaskUnderTest;
@Spy
ApplicationConfig appConfig;
@Mock
- CbsClient cbsClient;
-
- @Mock
ConfigurationFile configurationFileMock;
private static final String RIC_1_NAME = "ric1";
@@ -104,15 +82,6 @@ class RefreshConfigTaskTest {
.controllerName("") //
.build();
- private static EnvProperties properties() {
- return ImmutableEnvProperties.builder() //
- .consulHost("host") //
- .consulPort(123) //
- .cbsName("cbsName") //
- .appName("appName") //
- .build();
- }
-
private RefreshConfigTask createTestObject(boolean configFileExists) {
return createTestObject(configFileExists, new Rics(), new Policies(appConfig), true);
}
@@ -131,7 +100,7 @@ class RefreshConfigTaskTest {
@Test
void whenTheConfigurationFits_thenConfiguredRicsArePutInRepository() throws Exception {
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
+ refreshTaskUnderTest = this.createTestObject(true);
refreshTaskUnderTest.systemEnvironment = new Properties();
// When
when(configurationFileMock.readFile()).thenReturn(getCorrectJson());
@@ -157,7 +126,7 @@ class RefreshConfigTaskTest {
@Test
void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception {
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_EXISTS);
+ refreshTaskUnderTest = this.createTestObject(true);
// When
when(configurationFileMock.readFile()).thenReturn(Optional.empty());
@@ -174,134 +143,6 @@ class RefreshConfigTaskTest {
assertThat(appConfig.getRicConfigs()).isEmpty();
}
- @Test
- void whenPeriodicConfigRefreshNoConsul_thenErrorIsLogged() {
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST);
- refreshTaskUnderTest.systemEnvironment = new Properties();
-
- EnvProperties props = properties();
- doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any());
-
- doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props);
- when(cbsClient.get(any())).thenReturn(Mono.error(new IOException()));
-
- final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, WARN);
-
- StepVerifier //
- .create(refreshTaskUnderTest.createRefreshTask()) //
- .expectSubscription() //
- .expectNoEvent(Duration.ofMillis(1000)) //
- .thenCancel() //
- .verify();
-
- await().until(() -> logAppender.list.size() > 0);
- assertThat(logAppender.list.get(0).getFormattedMessage())
- .isEqualTo("Could not refresh application configuration. java.io.IOException");
- }
-
- @Test
- void whenPeriodicConfigRefreshSuccess_thenNewConfigIsCreatedAndRepositoryUpdated() throws Exception {
- Rics rics = new Rics();
- Policies policies = new Policies(appConfig);
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, rics, policies, false);
- refreshTaskUnderTest.systemEnvironment = new Properties();
-
- RicConfig changedRicConfig = getRicConfig(RIC_1_NAME);
- rics.put(new Ric(changedRicConfig));
- RicConfig removedRicConfig = getRicConfig("removed");
- Ric removedRic = new Ric(removedRicConfig);
- rics.put(removedRic);
- appConfig.setConfiguration(configParserResult(changedRicConfig, removedRicConfig));
-
- Policy policy = getPolicy(removedRic);
- policies.put(policy);
-
- EnvProperties props = properties();
- doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any());
- doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props);
-
- JsonObject configAsJson = getCorrectJson().get();
- String newBaseUrl = "newBaseUrl";
- modifyTheRicConfiguration(configAsJson, newBaseUrl);
- when(cbsClient.get(any())).thenReturn(Mono.just(configAsJson));
-
- StepVerifier //
- .create(refreshTaskUnderTest.createRefreshTask()) //
- .expectSubscription() //
- .expectNextCount(3) // CHANGED REMOVED ADDED
- .thenCancel() //
- .verify();
-
- assertThat(appConfig.getRicConfigs()).hasSize(2);
- assertThat(appConfig.getRic(RIC_1_NAME).baseUrl()).isEqualTo(newBaseUrl);
- String ric2Name = "ric2";
- assertThat(appConfig.getRic(ric2Name)).isNotNull();
-
- // assertThat(rics.size()).isEqualTo(2);
- assertThat(rics.get(RIC_1_NAME).getConfig().baseUrl()).isEqualTo(newBaseUrl);
- assertThat(rics.get(ric2Name)).isNotNull();
-
- assertThat(policies.size()).isZero();
- }
-
- @Test
- void whenPeriodicConfigRefreshInvalidJson_thenErrorIsLogged() throws Exception {
- Rics rics = new Rics();
- Policies policies = new Policies(appConfig);
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, rics, policies, false);
- refreshTaskUnderTest.systemEnvironment = new Properties();
-
- appConfig.setConfiguration(configParserResult());
-
- EnvProperties props = properties();
- doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any());
- doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props);
-
- JsonObject emptyJsonObject = new JsonObject();
- when(cbsClient.get(any())).thenReturn(Mono.just(emptyJsonObject));
-
- final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR);
-
- StepVerifier //
- .create(refreshTaskUnderTest.createRefreshTask()) //
- .expectSubscription() //
- .expectNoEvent(Duration.ofMillis(1000)) //
- .thenCancel() //
- .verify();
-
- await().until(() -> logAppender.list.size() > 0);
- assertThat(logAppender.list.get(0).getFormattedMessage()).startsWith(
- "Could not parse configuration org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException: ");
- }
-
- private RicConfig getRicConfig(String name) {
- RicConfig ricConfig = ImmutableRicConfig.builder() //
- .ricId(name) //
- .baseUrl("url") //
- .managedElementIds(Collections.emptyList()) //
- .controllerName("controllerName") //
- .build();
- return ricConfig;
- }
-
- private Policy getPolicy(Ric ric) {
- PolicyType type = PolicyType.builder() //
- .id("type") //
- .schema("{}") //
- .build();
- Policy policy = Policy.builder() //
- .id("id") //
- .type(type) //
- .lastModified(Instant.now()) //
- .ric(ric) //
- .json("{}") //
- .ownerServiceId("ownerServiceId") //
- .isTransient(false) //
- .statusNotificationUri("/policy_status?id=XXX") //
- .build();
- return policy;
- }
-
ConfigParserResult configParserResult(RicConfig... rics) {
return ImmutableConfigParserResult.builder() //
.ricConfigs(Arrays.asList(rics)) //
@@ -311,12 +152,6 @@ class RefreshConfigTaskTest {
.build();
}
- private void modifyTheRicConfiguration(JsonObject configAsJson, String newBaseUrl) {
- ((JsonObject) configAsJson.getAsJsonObject("config") //
- .getAsJsonArray("ric").get(0)) //
- .addProperty("baseUrl", newBaseUrl);
- }
-
private static Optional<JsonObject> getCorrectJson() throws IOException {
URL url = ApplicationConfigParser.class.getClassLoader().getResource("test_application_configuration.json");
String string = Resources.toString(url, Charsets.UTF_8);