From 2074ab2e8b4416126542c09205d3ca6646ed6718 Mon Sep 17 00:00:00 2001 From: vempo Date: Sun, 28 Oct 2018 14:45:46 +0200 Subject: Removed support of dynamic configuration Configuration framework will not poll configuration for changes, and will not notify client code of them. Also minor cleanup, added unit tests. Change-Id: I428b23f7acb13c6610390f46aae6e011d6b0ee80 Issue-ID: SDC-1867 Signed-off-by: vempo --- .../onap/config/impl/ConfigurationRepository.java | 36 +++++++--------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java') diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java index 276dbe2805..132043d5b5 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java @@ -19,9 +19,7 @@ package org.onap.config.impl; import java.io.File; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; @@ -38,16 +36,7 @@ import org.onap.config.Constants; public final class ConfigurationRepository { - private static final ConfigurationRepository repo; - - private static final Set validCallers = Collections.unmodifiableSet(new HashSet<>( - Arrays.asList(ConfigurationChangeNotifier.NotificationData.class.getName(), - ConfigurationUtils.class.getName(), CliConfigurationImpl.class.getName(), - ConfigurationChangeNotifier.class.getName(), ConfigurationImpl.class.getName()))); - - static { - repo = new ConfigurationRepository(); - } + private static final ConfigurationRepository repo = new ConfigurationRepository(); private final Set tenants = new HashSet<>(); private final Set namespaces = new HashSet<>(); @@ -65,18 +54,12 @@ public final class ConfigurationRepository { }; private ConfigurationRepository() { - if (repo != null) { - throw new RuntimeException("Illegal access to configuration."); - } tenants.add(Constants.DEFAULT_TENANT); namespaces.add(Constants.DEFAULT_NAMESPACE); } public static ConfigurationRepository lookup() { - if (validCallers.contains(Thread.currentThread().getStackTrace()[2].getClassName())) { - return repo; - } - return null; + return repo; } public Set getTenants() { @@ -98,22 +81,22 @@ public final class ConfigurationRepository { public Configuration getConfigurationFor(String tenant, String namespace) throws Exception { ConfigurationHolder config; - String module = tenant + Constants.KEY_ELEMENTS_DELIMETER + namespace; + String module = tenant + Constants.KEY_ELEMENTS_DELIMITER + namespace; config = store.get(module); if (config == null) { config = new ConfigurationHolder(new BasicConfigurationBuilder<>(AgglomerateConfiguration.class)); store.put(module, config); } - return config.getConfiguration(tenant + Constants.KEY_ELEMENTS_DELIMETER + namespace); + return config.getConfiguration(tenant + Constants.KEY_ELEMENTS_DELIMITER + namespace); } public void populateConfiguration(String key, Configuration builder) { store.put(key, new ConfigurationHolder(builder)); - populateTenantsNamespace(key, false); + populateTenantsNamespace(key); } - private void populateTenantsNamespace(String key, boolean sourcedFromDb) { - String[] array = key.split(Constants.KEY_ELEMENTS_DELIMETER); + private void populateTenantsNamespace(String key) { + String[] array = key.split(Constants.KEY_ELEMENTS_DELIMITER); if (!array[1].equalsIgnoreCase(Constants.DB_NAMESPACE)) { tenants.add(array[0]); namespaces.add(array[1]); @@ -127,7 +110,7 @@ public final class ConfigurationRepository { store.put(key, holder); } holder.addOverrideConfiguration(file.getAbsolutePath(), ConfigurationUtils.getConfigurationBuilder(file, true)); - populateTenantsNamespace(key, true); + populateTenantsNamespace(key); } public void refreshOverrideConfigurationFor(String key, int index) { @@ -207,6 +190,7 @@ public final class ConfigurationRepository { } public Configuration getConfiguration(String namespace) throws Exception { + if (config == null) { config = builder.getConfiguration(); lastConfigurationBuildTime = new Timestamp(System.currentTimeMillis()); @@ -216,9 +200,11 @@ public final class ConfigurationRepository { .getInt("config.refresh.interval")) { lastConfigurationBuildTime = new Timestamp(System.currentTimeMillis()); } + if (composite == null && overrideConfiguration.size() != 0) { composite = getEffectiveConfiguration(config, overrideConfiguration.values()); } + return overrideConfiguration.size() == 0 ? config : composite; } } -- cgit 1.2.3-korg