aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dcae/ApplicationConfigurationListener.java22
-rw-r--r--src/main/java/org/onap/dcae/VesApplication.java6
-rw-r--r--src/main/java/org/onap/dcae/configuration/ConfigurationHandler.java20
-rw-r--r--src/test/java/org/onap/dcae/ApplicationConfigurationListenerTest.java4
-rw-r--r--src/test/java/org/onap/dcae/configuration/CbsConfigurationHandlerTest.java23
5 files changed, 37 insertions, 38 deletions
diff --git a/src/main/java/org/onap/dcae/ApplicationConfigurationListener.java b/src/main/java/org/onap/dcae/ApplicationConfigurationListener.java
index b86bc1ec..c847cddc 100644
--- a/src/main/java/org/onap/dcae/ApplicationConfigurationListener.java
+++ b/src/main/java/org/onap/dcae/ApplicationConfigurationListener.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VES Collector
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. 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.
@@ -29,7 +29,7 @@ import reactor.core.Disposable;
import java.time.Duration;
/**
- * ApplicationConfigurationListener is used to listen at notifications with configuration updates send from Consul.
+ * ApplicationConfigurationListener is used to listen at notifications with configuration updates.
*/
public class ApplicationConfigurationListener implements Runnable {
@@ -42,7 +42,7 @@ public class ApplicationConfigurationListener implements Runnable {
/**
* Constructor
* @param interval defines period of time when notification can come
- * @param configurationHandler handles notifications send by Consul
+ * @param configurationHandler handles notifications
*/
public ApplicationConfigurationListener(Duration interval, ConfigurationHandler configurationHandler) {
this.interval = interval;
@@ -50,7 +50,7 @@ public class ApplicationConfigurationListener implements Runnable {
}
/**
- * Reload listener to start listening for Consul notifications with defined interval.
+ * Reload listener to start listening for configurations notifications with defined interval.
* @param interval defines period of time when notification can come
*/
public synchronized void reload(Duration interval) {
@@ -64,23 +64,23 @@ public class ApplicationConfigurationListener implements Runnable {
}
/**
- * Start listening for Consul notification.
+ * Start listening for configurations notification.
*/
@Override
public void run() {
- Disposable consulListener = null;
+ Disposable configListener = null;
do {
try {
- consulListener = listenForConfigurationUpdates();
+ configListener = listenForConfigurationUpdates();
synchronized (this) {
- log.info("Switch to configuration handler thread. Active waiting for configuration from Consul.");
+ log.info("Switch to configuration handler thread. Active waiting for configuration.");
this.wait();
}
} catch (Exception e) {
- log.error("Unexpected error occurred during handling data from Consul.", e);
+ log.error("Unexpected error occurred during handling data.", e);
terminate();
} finally {
- stopListeningForConfigurationUpdates(consulListener);
+ stopListeningForConfigurationUpdates(configListener);
}
} while (!this.terminate);
}
@@ -95,7 +95,7 @@ public class ApplicationConfigurationListener implements Runnable {
/**
* Release resources when there is a need to stop listener
- * @param consulListener Handler to Consul listener
+ * @param consulListener Handler to configurations listener
*/
void stopListeningForConfigurationUpdates(Disposable consulListener) {
if (consulListener != null) {
diff --git a/src/main/java/org/onap/dcae/VesApplication.java b/src/main/java/org/onap/dcae/VesApplication.java
index f8cd74ad..75fd4594 100644
--- a/src/main/java/org/onap/dcae/VesApplication.java
+++ b/src/main/java/org/onap/dcae/VesApplication.java
@@ -3,7 +3,7 @@
* PROJECT
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. 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.
@@ -66,7 +66,7 @@ public class VesApplication {
applicationLock.lock();
try {
startApplication(args);
- startListeningForApplicationConfigurationStoredInConsul();
+ startListeningForApplicationConfiguration();
} finally {
applicationLock.unlock();
}
@@ -110,7 +110,7 @@ public class VesApplication {
context = SpringApplication.run(VesApplication.class);
}
- private static void startListeningForApplicationConfigurationStoredInConsul() {
+ private static void startListeningForApplicationConfiguration() {
ConfigurationHandler cbsHandler = new ConfigurationHandler(new CbsClientConfigurationProvider(), configUpdater);
ApplicationConfigurationListener applicationConfigProvider = new ApplicationConfigurationListener(Duration.ofMinutes(DEFAULT_CONFIGURATION_FETCH_PERIOD), cbsHandler);
diff --git a/src/main/java/org/onap/dcae/configuration/ConfigurationHandler.java b/src/main/java/org/onap/dcae/configuration/ConfigurationHandler.java
index ebdf0474..aa3561b6 100644
--- a/src/main/java/org/onap/dcae/configuration/ConfigurationHandler.java
+++ b/src/main/java/org/onap/dcae/configuration/ConfigurationHandler.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VES Collector
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.s
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.s
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,8 +37,8 @@ import reactor.core.publisher.Mono;
import java.time.Duration;
/**
- * ConfigurationHandler is responsible for receiving configuration updates from Consul.
- * Any change made in the Consul will be reported as a notification.
+ * ConfigurationHandler is responsible for receiving configuration updates from config file or Consul (if config file doesn't exist).
+ * Any change made in the configuration will be reported as a notification.
*/
public class ConfigurationHandler {
@@ -61,12 +61,12 @@ public class ConfigurationHandler {
/**
* Start listen for application configuration notifications with configuration changes
* @param interval defines period of time when notification can come
- * @return {@link Disposable} handler to close Consul listener at the end
+ * @return {@link Disposable} handler to close configuration listener at the end
*/
public Disposable startListen(Duration interval) {
- log.info("Start listening for configuration from Consul ...");
- log.info(String.format("Consul configuration will be fetched in %s period.", interval));
+ log.info("Start listening for configuration ...");
+ log.info(String.format("Configuration will be fetched in %s period.", interval));
// Polling properties
final Duration initialDelay = Duration.ofSeconds(5);
@@ -78,7 +78,7 @@ public class ConfigurationHandler {
return createCbsClient(cbsClientConfiguration)
.flatMapMany(cbsClient -> cbsClient.updates(request, initialDelay, period))
.subscribe(
- this::handleConfigurationFromConsul,
+ this::handleConfiguration,
this::handleError
);
}
@@ -87,8 +87,8 @@ public class ConfigurationHandler {
return CbsClientFactory.createCbsClient(cbsClientConfiguration);
}
- void handleConfigurationFromConsul(JsonObject jsonObject) {
- log.info("Configuration update from Consul {}", jsonObject);
+ void handleConfiguration(JsonObject jsonObject) {
+ log.info("Configuration update {}", jsonObject);
if(jsonObject.has(CONFIG_DICT)) {
JsonObject config = jsonObject.getAsJsonObject(CONFIG_DICT);
JSONObject jObject = new JSONObject(config.toString());
@@ -99,7 +99,7 @@ public class ConfigurationHandler {
}
private void handleError(Throwable throwable) {
- log.error("Unexpected error occurred during fetching configuration from Consul", throwable);
+ log.error("Unexpected error occurred during fetching configuration", throwable);
}
private CbsRequest createCbsRequest() {
diff --git a/src/test/java/org/onap/dcae/ApplicationConfigurationListenerTest.java b/src/test/java/org/onap/dcae/ApplicationConfigurationListenerTest.java
index 49132f1e..1aa54257 100644
--- a/src/test/java/org/onap/dcae/ApplicationConfigurationListenerTest.java
+++ b/src/test/java/org/onap/dcae/ApplicationConfigurationListenerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VES Collector
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-2021 Nokia. 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.
@@ -43,7 +43,7 @@ public class ApplicationConfigurationListenerTest {
private ApplicationConfigurationListener applicationConfigurationListener;
@Test
- public void shouldStopJobAndCloseConnectionWhenErrorOccurredDuringListenAtConsulChange() {
+ public void shouldStopJobAndCloseConnectionWhenErrorOccurredDuringListenAtConfigChange() {
// given
Mockito.doThrow(new RuntimeException("Simulate exception")).when(configurationHandler).startListen(any());
diff --git a/src/test/java/org/onap/dcae/configuration/CbsConfigurationHandlerTest.java b/src/test/java/org/onap/dcae/configuration/CbsConfigurationHandlerTest.java
index 7b1af1de..8ad1dd0a 100644
--- a/src/test/java/org/onap/dcae/configuration/CbsConfigurationHandlerTest.java
+++ b/src/test/java/org/onap/dcae/configuration/CbsConfigurationHandlerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VES Collector
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.s
+ * Copyright (C) 2020-2021 Nokia. All rights reserved.s
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,9 +41,9 @@ import java.time.Duration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class CbsConfigurationHandlerTest {
@@ -67,9 +67,8 @@ public class CbsConfigurationHandlerTest {
@Test
public void shouldCreateCbsConfigurationHandler() {
// given
-
- when(cbsConfigurationHandler.createCbsClient(cbsClientConfiguration)).thenReturn(cbsClient);
- when(cbsClientConfigurationProvider.get()).thenReturn(cbsClientConfiguration);
+ doReturn(cbsClient).when(cbsConfigurationHandler).createCbsClient(cbsClientConfiguration);
+ doReturn(cbsClientConfiguration).when(cbsClientConfigurationProvider).get();
// when
final Disposable handler = cbsConfigurationHandler.startListen(Duration.ofMinutes(5));
@@ -81,10 +80,10 @@ public class CbsConfigurationHandlerTest {
@Test
public void shouldUpdateAppConfigurationWhenConfigurationIsValid() {
// given
- final JsonObject configuration = createConsulConfiguration(VES_CONSUL_CONFIG);
+ final JsonObject configuration = createConfiguration(VES_CONSUL_CONFIG);
// when
- this.cbsConfigurationHandler.handleConfigurationFromConsul(configuration);
+ this.cbsConfigurationHandler.handleConfiguration(configuration);
// then
final ArgumentCaptor<Option<JSONObject>> acConfiguration = ArgumentCaptor.forClass(Option.class);
@@ -93,12 +92,12 @@ public class CbsConfigurationHandlerTest {
}
@Test
- public void shouldReportAnErrorWhenConsulReturnsEmptyConfiguration() {
+ public void shouldReportAnErrorWhenConfigHandlerReturnsEmptyConfiguration() {
// given
- final JsonObject configuration = createConsulConfiguration("{}");
+ final JsonObject configuration = createConfiguration("{}");
// when
- assertThatThrownBy(() -> this.cbsConfigurationHandler.handleConfigurationFromConsul(configuration))
+ assertThatThrownBy(() -> this.cbsConfigurationHandler.handleConfiguration(configuration))
.isInstanceOf(IllegalArgumentException.class).hasMessageContaining(String.format("Invalid application configuration: %s ", "{}"));
// then
@@ -109,8 +108,8 @@ public class CbsConfigurationHandlerTest {
return new JSONObject(vesConfig).toString();
}
- private JsonObject createConsulConfiguration(String vesConsulConfig) {
- return new JsonParser().parse(vesConsulConfig).getAsJsonObject();
+ private JsonObject createConfiguration(String vesConfig) {
+ return new JsonParser().parse(vesConfig).getAsJsonObject();
}