aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/main/java')
-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
5 files changed, 7 insertions, 158 deletions
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);