summaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-10-28 14:45:46 +0200
committervempo <vitaliy.emporopulo@amdocs.com>2018-10-28 14:45:46 +0200
commit2074ab2e8b4416126542c09205d3ca6646ed6718 (patch)
treeab4e013ce2d30d8e87221b58d673b6525d952dd9 /common/onap-common-configuration-management
parent313e73a58a9a01bbceb007b6de617fda521bdd6e (diff)
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 <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'common/onap-common-configuration-management')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/pom.xml8
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java51
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java29
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java4
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java104
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-api/src/test/java/org/onap/config/api/ConfigurationTest.java72
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java22
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/Constants.java2
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AggregateConfiguration.java12
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/CliConfigurationImpl.java161
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationChangeNotifier.java393
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java59
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java36
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/type/ConfigurationUpdate.java45
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/resources/config-system.properties3
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/LoadOrderConfiguration/config.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config-NS.properties13
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.json12
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.properties3
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.xml18
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.yaml9
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/XMLConfiguration/config.xml1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/YAMLConfiguration/config.yaml1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/config-system.properties3
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/fallback/config-fallback.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/java-properties/config.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-at.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-tf.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-vf.properties1
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config.properties1
30 files changed, 107 insertions, 961 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/pom.xml b/common/onap-common-configuration-management/onap-configuration-management-api/pom.xml
index 08be65ab3e..e402be2700 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-api/pom.xml
+++ b/common/onap-common-configuration-management/onap-configuration-management-api/pom.xml
@@ -13,4 +13,12 @@
<version>1.3.1-SNAPSHOT</version>
</parent>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
</project>
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java
index 3232d49277..d5b5a10bcf 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/Configuration.java
@@ -161,35 +161,6 @@ public interface Configuration {
return get(tenantId, namespace, null, clazz, Hint.EXTERNAL_LOOKUP);
}
- default <T> DynamicConfiguration<T> getDynamicConfiguration(String key, Class<T> clazz, T defaultValue) {
- return getDynamicConfiguration(null, key, clazz, defaultValue);
- }
-
- default <T> DynamicConfiguration<T> getDynamicConfiguration(String namespace, String key, Class<T> clazz,
- T defaultValue) {
- return getDynamicConfiguration(TENANT.get(), namespace, key, clazz, defaultValue);
- }
-
- default <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, String namespace, String key,
- Class<T> clazz, T defaultValue) {
- return DynamicConfiguration.getDynamicConfiguration(tenant, namespace, key, clazz, defaultValue, this);
- }
-
- default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String key, Class<T> clazz,
- T defaultValue) {
- return getDynamicConfigurationValues(null, key, clazz, defaultValue);
- }
-
- default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String namespace, String key,
- Class<T> clazz, T defaultValue) {
- return getDynamicConfigurationValues(TENANT.get(), namespace, key, clazz, defaultValue);
- }
-
- default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String tenant, String namespace, String key,
- Class<T> clazz, T defaultValue) {
- return DynamicConfiguration.getDynConfiguration(tenant, namespace, key, clazz, defaultValue, this);
- }
-
default List<String> getAsStringValues(String key) {
return getAsStringValues(null, key);
}
@@ -294,28 +265,6 @@ public interface Configuration {
return tempArray == null ? Collections.emptyList() : Arrays.asList(tempArray);
}
- default void addConfigurationChangeListener(String key, ConfigurationChangeListener myself) {
- addConfigurationChangeListener(null, key, myself);
- }
-
- default void addConfigurationChangeListener(String namespace, String key, ConfigurationChangeListener myself) {
- addConfigurationChangeListener(TENANT.get(), namespace, key, myself);
- }
-
- void addConfigurationChangeListener(String tenant, String namespace, String key,
- ConfigurationChangeListener myself);
-
- default void removeConfigurationChangeListener(String key, ConfigurationChangeListener myself) {
- removeConfigurationChangeListener(null, key, myself);
- }
-
- default void removeConfigurationChangeListener(String namespace, String key, ConfigurationChangeListener myself) {
- removeConfigurationChangeListener(TENANT.get(), namespace, key, myself);
- }
-
- void removeConfigurationChangeListener(String tenant, String namespace, String key,
- ConfigurationChangeListener myself);
-
default <T> Map<String, T> populateMap(String key, Class<T> clazz) {
return populateMap(null, key, clazz);
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java
deleted file mode 100644
index dddd751383..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationChangeListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.config.api;
-
-public interface ConfigurationChangeListener {
-
- default void notify(String tenantId, String component, String key, Object oldValue, Object newValue) {
- }
-
- default void notify(String component, String key, Object oldValue, Object newValue) {
- }
-
- default void notify(String key, Object oldValue, Object newValue) {
- }
-}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java
index d91fdb15f4..0bb33595e5 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/ConfigurationManager.java
@@ -38,12 +38,8 @@ public interface ConfigurationManager extends Configuration {
String getConfigurationValue(Map<String, Object> queryData);
- void updateConfigurationValue(Map<String, Object> updateData);
-
Map<String, String> listConfiguration(Map<String, Object> query);
- boolean updateConfigurationValues(String tenant, String namespace, Map configKeyValueStore);
-
Collection<String> getTenants();
Collection<String> getNamespaces();
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java
deleted file mode 100644
index c2973a493f..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-api/src/main/java/org/onap/config/api/DynamicConfiguration.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.config.api;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-
-public class DynamicConfiguration<T> {
-
- private String tenant;
-
- private String namespace;
-
- private String key;
-
- private Configuration configuration;
-
- private Class clazz;
-
- private T defaultValue;
-
- public static <K> DynamicConfiguration<List<K>> getDynConfiguration(String tenant, String namespace, String key,
- Class<K> clazz, K defaultValue, Configuration configuration) {
- if (clazz.isPrimitive()) {
- throw new RuntimeException("Only Wrapper classes like Integer, Long, Double, "
- + "Boolean etc including String are supported.");
- }
- return getDynamicConfiguration(tenant, namespace, key, getArrayClass(clazz),
- Collections.singletonList(defaultValue), configuration);
- }
-
- public static <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant, String namespace, String key,
- Class<T> clazz, T defaultValue, Configuration configuration) {
- DynamicConfiguration<T> dynamicConfiguration = new DynamicConfiguration<>();
- dynamicConfiguration.tenant = tenant;
- dynamicConfiguration.namespace = namespace;
- dynamicConfiguration.key = key;
- dynamicConfiguration.clazz = clazz;
- dynamicConfiguration.defaultValue = defaultValue;
- dynamicConfiguration.configuration = configuration;
- return dynamicConfiguration;
- }
-
- public static Class getArrayClass(Class clazz) {
- Class arrayClass = null;
- switch (clazz.getName()) {
- case "java.lang.Byte":
- arrayClass = Byte[].class;
- break;
- case "java.lang.Short":
- arrayClass = Short[].class;
- break;
- case "java.lang.Integer":
- arrayClass = Integer[].class;
- break;
- case "java.lang.Long":
- arrayClass = Long[].class;
- break;
- case "java.lang.Float":
- arrayClass = Float[].class;
- break;
- case "java.lang.Double":
- arrayClass = Double[].class;
- break;
- case "java.lang.Boolean":
- arrayClass = Boolean[].class;
- break;
- case "java.lang.Character":
- arrayClass = Character[].class;
- break;
- case "java.lang.String":
- arrayClass = String[].class;
- break;
- default:
- }
- return arrayClass;
- }
-
- public T get() {
- Object toReturn = configuration.get(tenant, namespace, key, clazz, Hint.LATEST_LOOKUP, Hint.EXTERNAL_LOOKUP,
- Hint.NODE_SPECIFIC);
- if (toReturn != null && toReturn.getClass().isArray()) {
- toReturn = Arrays.asList((Object[]) toReturn);
- }
- return toReturn == null ? defaultValue : (T) toReturn;
- }
-
-}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-api/src/test/java/org/onap/config/api/ConfigurationTest.java b/common/onap-common-configuration-management/onap-configuration-management-api/src/test/java/org/onap/config/api/ConfigurationTest.java
new file mode 100644
index 0000000000..9945a938d3
--- /dev/null
+++ b/common/onap-common-configuration-management/onap-configuration-management-api/src/test/java/org/onap/config/api/ConfigurationTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.config.api;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author evitaliy
+ * @since 28 Oct 2018
+ */
+public class ConfigurationTest {
+
+ @After
+ public void cleanUp() {
+ Configuration.TENANT.remove();
+ }
+
+ @Test
+ public void tenantRetrievedWhenPreviouslySet() {
+ final String tenantId = "abc";
+ Configuration.setTenantId(tenantId);
+ Assert.assertEquals(tenantId, Configuration.TENANT.get());
+ }
+
+ @Test
+ public void tenantEmptyWhenNeverSet() {
+ Assert.assertNull(Configuration.TENANT.get());
+ }
+
+ @Test
+ public void tenantNullWhenNullSet() {
+ Configuration.setTenantId("xyz");
+ Configuration.setTenantId(null);
+ Assert.assertNull(Configuration.TENANT.get());
+ }
+
+ @Test
+ public void tenantNullWhenEmptySet() {
+ Configuration.setTenantId("xyz");
+ Configuration.setTenantId("");
+ Assert.assertNull(Configuration.TENANT.get());
+ }
+
+ @Test
+ public void tenantDoesNotPropagateToAnotherThread() throws ExecutionException, InterruptedException {
+ final String currentTenant = "xyz";
+ Configuration.setTenantId(currentTenant);
+ CompletableFuture<String> result = new CompletableFuture<>();
+ Thread otherThread = new Thread(() -> result.complete(Configuration.TENANT.get()));
+ otherThread.start();
+ Assert.assertNull("Tenant in the other thread expected to be null", result.get());
+ Assert.assertEquals(currentTenant, Configuration.TENANT.get());
+ }
+} \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
index 528941b923..dcdf17a992 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
@@ -48,10 +48,8 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.LinkedTransferQueue;
-import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TransferQueue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -102,14 +100,7 @@ public class ConfigurationUtils {
}
private ConfigurationUtils() {
- }
-
- public static ThreadFactory getThreadFactory() {
- return r1 -> {
- Thread thread = Executors.privilegedThreadFactory().newThread(r1);
- thread.setDaemon(true);
- return thread;
- };
+ // prevent instantiation
}
public static Collection<File> getAllFiles(File file, boolean recursive, boolean onlyDirectory) {
@@ -303,8 +294,9 @@ public class ConfigurationUtils {
}
public static boolean isWrapperClass(Class clazz) {
- return clazz == String.class || clazz == Boolean.class || clazz == Character.class
- || Number.class.isAssignableFrom(clazz);
+ return clazz == String.class || clazz == Boolean.class || clazz == Character.class || Number.class
+ .isAssignableFrom(
+ clazz);
}
public static Class getArrayClass(Class clazz) {
@@ -324,8 +316,8 @@ public class ConfigurationUtils {
return builder;
}
- private static ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>
- getFileBasedConfigurationReloadingFileBasedConfigurationBuilder(ConfigurationType configType) {
+ private static ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> getFileBasedConfigurationReloadingFileBasedConfigurationBuilder(
+ ConfigurationType configType) {
ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder;
switch (configType) {
@@ -569,7 +561,7 @@ public class ConfigurationUtils {
stack.push(element);
}
String toReturn = stack.pop();
- return stack.pop() + Constants.KEY_ELEMENTS_DELIMETER + toReturn;
+ return stack.pop() + Constants.KEY_ELEMENTS_DELIMITER + toReturn;
}
public static String getNamespace(File file) {
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/Constants.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/Constants.java
index 290a7a5a4b..97963c4c4e 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/Constants.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/Constants.java
@@ -21,7 +21,7 @@ public class Constants {
public static final String DEFAULT_TENANT = "GLOBAL";
public static final String DEFAULT_NAMESPACE = "COMMON";
public static final String DB_NAMESPACE = "SYSTEM";
- public static final String KEY_ELEMENTS_DELIMETER = "-";
+ public static final String KEY_ELEMENTS_DELIMITER = "-";
public static final String TENANT_NAMESPACE_SEPARATOR = ":";
public static final String NAMESPACE_KEY = "_config.namespace";
public static final String MODE_KEY = "_config.mergeStrategy";
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AggregateConfiguration.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AggregateConfiguration.java
index 80fbaf8fd0..32a1902151 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AggregateConfiguration.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AggregateConfiguration.java
@@ -40,18 +40,6 @@ public final class AggregateConfiguration {
private final Map<String, Configuration> mergeConfig = new HashMap<>();
private final Map<String, Configuration> overrideConfig = new LinkedHashMap<>();
- public AggregateConfiguration() {
-
- try {
- Class clazz = Class.forName(Thread.currentThread().getStackTrace()[2].getClassName());
- if (!clazz.getCanonicalName().equals(ConfigurationImpl.class.getCanonicalName())) {
- throw new RuntimeException("Illegal access.");
- }
- } catch (ClassNotFoundException cfe) {
- throw new RuntimeException("Class not found while loading change notifier");
- }
- }
-
public void addConfig(File file) throws Exception {
addConfig(file.getAbsolutePath().toUpperCase(), ConfigurationUtils.getMergeStrategy(file),
ConfigurationUtils.getConfigurationBuilder(file, false).getConfiguration());
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/CliConfigurationImpl.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/CliConfigurationImpl.java
index 7f753fd1fd..77d0c11c9f 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/CliConfigurationImpl.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/CliConfigurationImpl.java
@@ -16,17 +16,13 @@
package org.onap.config.impl;
-import static org.onap.config.Constants.DB_NAMESPACE;
import static org.onap.config.Constants.DEFAULT_NAMESPACE;
import static org.onap.config.Constants.DEFAULT_TENANT;
-import static org.onap.config.Constants.KEY_ELEMENTS_DELIMETER;
import static org.onap.config.Constants.LOAD_ORDER_KEY;
import static org.onap.config.Constants.MBEAN_NAME;
import static org.onap.config.Constants.MODE_KEY;
import static org.onap.config.Constants.NAMESPACE_KEY;
-import java.io.File;
-import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -39,22 +35,12 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.management.MBeanServer;
-import javax.management.MBeanServerDelegate;
-import javax.management.MBeanServerNotification;
-import javax.management.Notification;
import javax.management.ObjectName;
import javax.management.StandardMBean;
-import org.apache.commons.configuration2.CombinedConfiguration;
-import org.apache.commons.configuration2.CompositeConfiguration;
-import org.apache.commons.configuration2.Configuration;
-import org.apache.commons.configuration2.FileBasedConfiguration;
-import org.apache.commons.configuration2.PropertiesConfiguration;
import org.onap.config.ConfigurationUtils;
-import org.onap.config.Constants;
import org.onap.config.api.ConfigurationManager;
import org.onap.config.api.Hint;
import org.onap.config.type.ConfigurationQuery;
-import org.onap.config.type.ConfigurationUpdate;
public final class CliConfigurationImpl extends ConfigurationImpl implements ConfigurationManager {
@@ -65,27 +51,6 @@ public final class CliConfigurationImpl extends ConfigurationImpl implements Con
mbs.unregisterMBean(name);
}
mbs.registerMBean(new StandardMBean(this, ConfigurationManager.class), name);
- mbs.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
- (notification, handback) -> handleNotification(notification), null, null);
- }
-
- public void handleNotification(Notification notification) {
- if (notification instanceof MBeanServerNotification) {
- MBeanServerNotification mbs = (MBeanServerNotification) notification;
- if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(mbs.getType())) {
- try {
- String mbean = ConfigurationRepository.lookup().getConfigurationFor(DEFAULT_TENANT, DB_NAMESPACE)
- .getString("shutdown.mbean");
- if (mbs.getMBeanName().equals(mbean == null ? new ObjectName(MBEAN_NAME) : new ObjectName(mbean))) {
- changeNotifier.shutdown();
- }
- } catch (Exception exception) {
- //do nothing.
- }
- } else if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(mbs.getType())) {
- mbs.getMBeanName();
- }
- }
}
public String getConfigurationValue(Map<String, Object> input) {
@@ -116,7 +81,9 @@ public final class CliConfigurationImpl extends ConfigurationImpl implements Con
}
private Object getInput(Map<String, Object> input) {
+
Object toReturn = null;
+
try {
toReturn = Class.forName(input.get("ImplClass").toString()).newInstance();
Method[] methods = toReturn.getClass().getMethods();
@@ -132,111 +99,6 @@ public final class CliConfigurationImpl extends ConfigurationImpl implements Con
return toReturn;
}
- public void updateConfigurationValue(Map<String, Object> input) {
- updateConfigurationValue((ConfigurationUpdate) getInput(input));
- }
-
- private void updateConfigurationValue(ConfigurationUpdate updateData) {
-
- try {
- if (!ConfigurationRepository.lookup().isValidTenant(updateData.getTenant())) {
- throw new RuntimeException("Invalid tenantId.");
- }
- if (!ConfigurationRepository.lookup().isValidNamespace(updateData.getNamespace())) {
- throw new RuntimeException("Invalid Namespace.");
- }
- } catch (NullPointerException e1) {
- e1.printStackTrace();
- }
-
- try {
- boolean keyPresent = isKeyExists(updateData.getTenant(), updateData.getNamespace(), updateData.getKey());
- if (keyPresent) {
- boolean isUpdated = false;
- Object[] paramArray =
- new Object[] {updateData.getTenant() + KEY_ELEMENTS_DELIMETER + updateData.getNamespace(),
- System.currentTimeMillis(), updateData.getKey(), getConfigurationValue(updateData),
- updateData.getValue()};
- Configuration config = ConfigurationRepository.lookup()
- .getConfigurationFor(updateData.getTenant(), updateData.getNamespace());
- if (config instanceof AgglomerateConfiguration || config instanceof CombinedConfiguration) {
- CompositeConfiguration cc = new CompositeConfiguration();
- cc.addConfiguration(config);
- config = cc;
- }
- CompositeConfiguration configuration = (CompositeConfiguration) config;
- int overrideIndex = -1;
- for (int i = 0; i < configuration.getNumberOfConfigurations(); i++) {
- if (!updateData.isNodeOverride() && (
- configuration.getConfiguration(i) instanceof AgglomerateConfiguration
- || configuration.getConfiguration(i) instanceof CombinedConfiguration)) {
- configuration.getConfiguration(i).setProperty(updateData.getKey(), updateData.getValue());
- isUpdated = true;
- break;
- } else if (updateData.isNodeOverride() && configuration.getConfiguration(
- i) instanceof FileBasedConfiguration) {
- configuration.getConfiguration(i).setProperty(updateData.getKey(), updateData.getValue());
- isUpdated = true;
- overrideIndex = i;
- break;
- }
- }
- if (!isUpdated) {
- if (updateData.isNodeOverride()) {
- PropertiesConfiguration pc = new PropertiesConfiguration();
- pc.setProperty(NAMESPACE_KEY,
- updateData.getTenant() + Constants.TENANT_NAMESPACE_SEPARATOR
- + updateData.getNamespace());
- pc.setProperty(MODE_KEY, "OVERRIDE");
- pc.setProperty(updateData.getKey(), updateData.getValue());
- String nodeConfigLocation = System.getProperty("node.config.location");
- if (nodeConfigLocation != null && nodeConfigLocation.trim().length() > 0) {
- File file = new File(nodeConfigLocation,
- updateData.getTenant() + File.separator + updateData.getNamespace() + File.separator
- + "config.properties");
- file.getParentFile().mkdirs();
- PrintWriter out = new PrintWriter(file);
- pc.write(out);
- out.close();
- ConfigurationRepository.lookup().populateOverrideConfiguration(
- updateData.getTenant() + KEY_ELEMENTS_DELIMETER + updateData.getNamespace(), file);
- }
- } else {
- configuration.getConfiguration(0).setProperty(updateData.getKey(), updateData.getValue());
- }
- }
- if (updateData.isNodeOverride()) {
- ConfigurationRepository.lookup().refreshOverrideConfigurationFor(
- updateData.getTenant() + KEY_ELEMENTS_DELIMETER + updateData.getNamespace(), overrideIndex);
- }
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- private boolean isKeyExists(String tenant, String namespace, String key) {
- boolean keyExist = false;
- try {
- keyExist = ConfigurationRepository.lookup().getConfigurationFor(tenant, namespace).containsKey(key);
- if (!keyExist && !DEFAULT_TENANT.equals(tenant)) {
- keyExist = ConfigurationRepository.lookup().getConfigurationFor(DEFAULT_TENANT, namespace)
- .containsKey(key);
- }
- if (!keyExist && !DEFAULT_NAMESPACE.equals(namespace)) {
- keyExist = ConfigurationRepository.lookup().getConfigurationFor(tenant, DEFAULT_NAMESPACE)
- .containsKey(key);
- }
- if (!keyExist && !DEFAULT_TENANT.equals(tenant) && !DEFAULT_NAMESPACE.equals(namespace)) {
- keyExist = ConfigurationRepository.lookup().getConfigurationFor(DEFAULT_TENANT, DEFAULT_NAMESPACE)
- .containsKey(key);
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- return keyExist;
- }
-
public Map<String, String> listConfiguration(Map<String, Object> input) {
return listConfiguration((ConfigurationQuery) getInput(input));
}
@@ -256,6 +118,7 @@ public final class CliConfigurationImpl extends ConfigurationImpl implements Con
}
private ArrayList<String> getInMemoryKeys(String tenant, String namespace) {
+
ArrayList<String> keys = new ArrayList<>();
try {
@@ -274,24 +137,6 @@ public final class CliConfigurationImpl extends ConfigurationImpl implements Con
}
@Override
- public boolean updateConfigurationValues(String tenant, String namespace, Map configKeyValueStore) {
- boolean valueToReturn = true;
- for (String s : (Iterable<String>) configKeyValueStore.keySet()) {
- try {
- String key = s;
- ConfigurationUpdate updateData = new ConfigurationUpdate();
- updateData.tenant(tenant).namespace(namespace).key(key);
- updateData.value(configKeyValueStore.get(key).toString());
- updateConfigurationValue(updateData);
- } catch (Exception exception) {
- exception.printStackTrace();
- valueToReturn = false;
- }
- }
- return valueToReturn;
- }
-
- @Override
public Collection<String> getTenants() {
return ConfigurationRepository.lookup().getTenants();
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationChangeNotifier.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationChangeNotifier.java
deleted file mode 100644
index cd6481f97b..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationChangeNotifier.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.config.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.reflect.Method;
-import java.nio.file.ClosedWatchServiceException;
-import java.nio.file.FileSystems;
-import java.nio.file.Path;
-import java.nio.file.StandardWatchEventKinds;
-import java.nio.file.WatchEvent;
-import java.nio.file.WatchKey;
-import java.nio.file.WatchService;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.Vector;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import org.onap.config.ConfigurationUtils;
-import org.onap.config.Constants;
-import org.onap.config.api.ConfigurationChangeListener;
-import org.onap.config.api.ConfigurationManager;
-import org.onap.config.api.Hint;
-
-
-public final class ConfigurationChangeNotifier {
-
- static {
- if (!Thread.currentThread().getStackTrace()[2].getClassName().equals(ConfigurationImpl.class.getName())) {
- throw new RuntimeException("Illegal access.");
- }
- }
-
- private final HashMap<String, List<NotificationData>> store = new HashMap<>();
- private final ScheduledExecutorService executor =
- Executors.newScheduledThreadPool(5, ConfigurationUtils.getThreadFactory());
- private final ExecutorService notificationExecutor =
- Executors.newCachedThreadPool(ConfigurationUtils.getThreadFactory());
- private final Map<String, WatchService> watchServiceCollection = Collections.synchronizedMap(new HashMap<>());
-
- public ConfigurationChangeNotifier(Map<String, AggregateConfiguration> inMemoryConfig) {
- executor.scheduleWithFixedDelay(() -> this.pollFilesystemAndUpdateConfigurationIfRequired(inMemoryConfig,
- System.getProperty("config.location"), false), 1, 1, TimeUnit.MILLISECONDS);
- executor.scheduleWithFixedDelay(() -> this.pollFilesystemAndUpdateConfigurationIfRequired(inMemoryConfig,
- System.getProperty("tenant.config.location"), true), 1, 1, TimeUnit.MILLISECONDS);
- executor.scheduleWithFixedDelay(() -> this.pollFilesystemAndUpdateNodeSpecificConfigurationIfRequired(
- System.getProperty("node.config.location")), 1, 1, TimeUnit.MILLISECONDS);
- }
-
- public void pollFilesystemAndUpdateConfigurationIfRequired(Map<String, AggregateConfiguration> inMemoryConfig,
- String location, boolean isTenantLocation) {
- try {
- Set<Path> paths = watchForChange(location);
- if (paths != null) {
- for (Path path : paths) {
- File file = path.toAbsolutePath().toFile();
- String repositoryKey = null;
- if (ConfigurationUtils.isConfig(file) && file.isFile()) {
- if (isTenantLocation) {
- Collection<File> tenantsRoot =
- ConfigurationUtils.getAllFiles(new File(location), false, true);
- for (File tenantRoot : tenantsRoot) {
- if (file.getAbsolutePath().startsWith(tenantRoot.getAbsolutePath())) {
- repositoryKey = ConfigurationUtils.getConfigurationRepositoryKey(
- (tenantRoot.getName() + Constants.TENANT_NAMESPACE_SEPARATOR
- + ConfigurationUtils.getNamespace(file))
- .split(Constants.TENANT_NAMESPACE_SEPARATOR));
- }
- }
- } else {
- repositoryKey = ConfigurationUtils.getConfigurationRepositoryKey(file);
- }
- AggregateConfiguration config = inMemoryConfig.get(repositoryKey);
- if (config != null) {
- LinkedHashMap origConfig = ConfigurationUtils.toMap(config.getFinalConfiguration());
- config.addConfig(file);
- LinkedHashMap latestConfig = ConfigurationUtils.toMap(config.getFinalConfiguration());
- Map map = ConfigurationUtils.diff(origConfig, latestConfig);
- String[] tenantNamespaceArray = repositoryKey.split(Constants.KEY_ELEMENTS_DELIMETER);
- updateConfigurationValues(tenantNamespaceArray[0], tenantNamespaceArray[1], map);
- }
- } else {
- for (String configKey : inMemoryConfig.keySet()) {
- repositoryKey = configKey;
- AggregateConfiguration config = inMemoryConfig.get(repositoryKey);
- if (config.containsConfig(file)) {
- LinkedHashMap origConfig = ConfigurationUtils.toMap(config.getFinalConfiguration());
- config.removeConfig(file);
- LinkedHashMap latestConfig = ConfigurationUtils.toMap(config.getFinalConfiguration());
- Map map = ConfigurationUtils.diff(origConfig, latestConfig);
- String[] tenantNamespaceArray = repositoryKey.split(Constants.KEY_ELEMENTS_DELIMETER);
- updateConfigurationValues(tenantNamespaceArray[0], tenantNamespaceArray[1], map);
- }
- }
- }
- }
- }
- } catch (ClosedWatchServiceException exception) {
- // do nothing.
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- public void pollFilesystemAndUpdateNodeSpecificConfigurationIfRequired(String location) {
- try {
- Set<Path> paths = watchForChange(location);
- if (paths != null) {
- for (Path path : paths) {
- File file = path.toAbsolutePath().toFile();
-
- if (ConfigurationUtils.isConfig(file)) {
- String repositoryKey = ConfigurationUtils.getConfigurationRepositoryKey(file);
- ConfigurationRepository.lookup().populateOverrideConfiguration(repositoryKey, file);
- } else {
- ConfigurationRepository.lookup().removeOverrideConfiguration(file);
- }
- }
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- private Set<Path> watchForChange(String location) throws Exception {
- if (location == null || location.trim().length() == 0) {
- return Collections.emptySet();
- }
- File file = new File(location);
- if (!file.exists()) {
- return Collections.emptySet();
- }
- Path path = file.toPath();
- Set<Path> toReturn = new HashSet<>();
- try (final WatchService watchService = FileSystems.getDefault().newWatchService()) {
- watchServiceCollection.put(location, watchService);
- path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE,
- StandardWatchEventKinds.ENTRY_DELETE);
- for (File dir : ConfigurationUtils.getAllFiles(file, true, true)) {
- dir.toPath().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY,
- StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
- }
- while (true) {
- final WatchKey wk = watchService.take();
- Thread.sleep(ConfigurationRepository.lookup()
- .getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE)
- .getLong("event.fetch.delay"));
- for (WatchEvent<?> event : wk.pollEvents()) {
- Object context = event.context();
- if (context instanceof Path) {
- File newFile = new File(((Path) wk.watchable()).toFile(), context.toString());
- if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
- if (newFile.isDirectory()) {
- newFile.toPath().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY,
- StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
- continue;
- }
- } else if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
- if (newFile.isDirectory()) {
- continue;
- }
- }
- toReturn.add(newFile.toPath());
- }
- }
- if (toReturn.isEmpty()) {
- continue;
- }
- break;
- }
- }
- return toReturn;
- }
-
- private void updateConfigurationValues(String tenant, String namespace, Map map) throws Exception {
- MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
- ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME);
- ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true);
- conf.updateConfigurationValues(tenant, namespace, map);
- }
-
- public void shutdown() {
- for (WatchService watch : watchServiceCollection.values()) {
- try {
- watch.close();
- } catch (IOException exception) {
- //do nothing
- }
- }
- executor.shutdownNow();
- }
-
- public void notifyChangesTowards(String tenant, String component, String key, ConfigurationChangeListener myself)
- throws Exception {
- List<NotificationData> notificationList = store.get(tenant + Constants.KEY_ELEMENTS_DELIMETER + component);
- if (notificationList == null) {
- notificationList = Collections.synchronizedList(new ArrayList<>());
- store.put(tenant + Constants.KEY_ELEMENTS_DELIMETER + component, notificationList);
- executor.scheduleWithFixedDelay(
- () -> triggerScanning(tenant + Constants.KEY_ELEMENTS_DELIMETER + component), 1, 30000,
- TimeUnit.MILLISECONDS);
- }
- notificationList.add(new NotificationData(tenant, component, key, myself));
- }
-
- private void triggerScanning(String key) {
- if (store.get(key) != null) {
- notificationExecutor.submit(() -> scanForChanges(key));
- } else {
- throw new IllegalArgumentException("Notification service for " + key + " is suspended.");
- }
- }
-
- private void scanForChanges(String key) {
- List<NotificationData> list = store.get(key);
- if (list != null) {
- list.stream().filter(NotificationData::isChanged)
- .forEach(notificationData -> notificationExecutor.submit(() -> sendNotification(notificationData)));
- }
- }
-
- private void sendNotification(NotificationData notificationData) {
- try {
- notificationData.dispatchNotification();
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- public void stopNotificationTowards(String tenant, String component, String key, ConfigurationChangeListener myself)
- throws Exception {
- List<NotificationData> notificationList = store.get(tenant + Constants.KEY_ELEMENTS_DELIMETER + component);
- if (notificationList != null) {
- boolean removed = notificationList.remove(new NotificationData(tenant, component, key, myself));
- if (removed && notificationList.isEmpty()) {
- store.remove(tenant + Constants.KEY_ELEMENTS_DELIMETER + component);
- }
- }
-
- }
-
- static class NotificationData {
-
- final String tenant;
-
- final String namespace;
-
- final String key;
-
- final ConfigurationChangeListener myself;
-
- Object currentValue;
-
- boolean isArray;
-
- public NotificationData(String tenant, String component, String key, ConfigurationChangeListener myself)
- throws Exception {
- this.tenant = tenant;
- this.namespace = component;
- this.key = key;
- this.myself = myself;
- if (!ConfigurationRepository.lookup().getConfigurationFor(tenant, component).containsKey(key)) {
- throw new RuntimeException("Key[" + key + "] not found.");
- }
- isArray = ConfigurationUtils.isArray(tenant, component, key, Hint.DEFAULT.value());
- if (isArray) {
- currentValue = ConfigurationManager.lookup().getAsStringValues(tenant, component, key);
- } else {
- currentValue = ConfigurationManager.lookup().getAsString(tenant, component, key);
- }
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(tenant, namespace, key, myself, currentValue, isArray);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof NotificationData)) {
- return false;
- }
- NotificationData nd = (NotificationData) obj;
- return Objects.equals(tenant, nd.tenant) && Objects.equals(namespace, nd.namespace) && Objects.equals(key,
- nd.key) && Objects.equals(myself, nd.myself) && Objects.equals(currentValue, nd.currentValue)
- // it's either String or List<String>
- && isArray == nd.isArray;
- }
-
- public boolean isChanged() {
- Object latestValue;
- try {
- if (isArray) {
- latestValue = ConfigurationManager.lookup().getAsStringValues(tenant, namespace, key);
- } else {
- latestValue = ConfigurationManager.lookup().getAsString(tenant, namespace, key);
- }
- if (!isArray) {
- return !currentValue.equals(latestValue);
- } else {
- Collection<String> oldCollection = (Collection<String>) currentValue;
- Collection<String> newCollection = (Collection<String>) latestValue;
- for (String val : oldCollection) {
- if (!newCollection.remove(val)) {
- return true;
- }
- }
- return !newCollection.isEmpty();
- }
- } catch (Exception exception) {
- return false;
- }
- }
-
- public void dispatchNotification() throws Exception {
- Method method = null;
- Vector<Object> parameters = null;
- try {
- Object latestValue;
- if (isArray) {
- latestValue = ConfigurationManager.lookup().getAsStringValues(tenant, namespace, key);
- } else {
- latestValue = ConfigurationManager.lookup().getAsString(tenant, namespace, key);
- }
- Method[] methods = myself.getClass().getDeclaredMethods();
- if (methods != null && methods.length > 0) {
- method = methods[0];
- int paramCount = method.getParameterCount();
- parameters = new Vector<>();
- if (paramCount > 4) {
- if (tenant.equals(Constants.DEFAULT_TENANT)) {
- parameters.add(null);
- } else {
- parameters.add(tenant);
- }
- }
- if (paramCount > 3) {
- if (namespace.equals(Constants.DEFAULT_NAMESPACE)) {
- parameters.add(null);
- } else {
- parameters.add(namespace);
- }
- }
- parameters.add(key);
- parameters.add(currentValue);
- parameters.add(latestValue);
- method.setAccessible(true);
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- } finally {
- isArray = ConfigurationUtils.isArray(tenant, namespace, key, Hint.DEFAULT.value());
- if (isArray) {
- currentValue = ConfigurationManager.lookup().getAsStringValues(tenant, namespace, key);
- } else {
- currentValue = ConfigurationManager.lookup().getAsString(tenant, namespace, key);
- }
- if (method != null && parameters != null) {
- method.invoke(myself, parameters.toArray());
- }
- }
- }
- }
-}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
index 58720fc76d..af5ae04104 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
@@ -34,7 +34,6 @@ import org.onap.config.ConfigurationUtils;
import org.onap.config.Constants;
import org.onap.config.NonConfigResource;
import org.onap.config.api.Config;
-import org.onap.config.api.ConfigurationChangeListener;
import org.onap.config.api.Hint;
public class ConfigurationImpl implements org.onap.config.api.Configuration {
@@ -44,8 +43,6 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
private static boolean instantiated = false;
- ConfigurationChangeNotifier changeNotifier;
-
public ConfigurationImpl() throws Exception {
if (instantiated || !CliConfigurationImpl.class.isAssignableFrom(this.getClass())) {
throw new RuntimeException("Illegal access to configuration.");
@@ -126,15 +123,14 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
}
instantiated = true;
- changeNotifier = new ConfigurationChangeNotifier(moduleConfigStore);
}
private void populateFinalConfigurationIncrementally(Map<String, AggregateConfiguration> configs) {
- if (configs.get(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMETER + Constants.DB_NAMESPACE) != null) {
+ if (configs.get(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + Constants.DB_NAMESPACE) != null) {
ConfigurationRepository.lookup().populateConfiguration(
- Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMETER + Constants.DB_NAMESPACE,
- configs.remove(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMETER + Constants.DB_NAMESPACE)
+ Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + Constants.DB_NAMESPACE,
+ configs.remove(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER + Constants.DB_NAMESPACE)
.getFinalConfiguration());
}
@@ -189,43 +185,6 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
@Override
- public void addConfigurationChangeListener(String tenant, String namespace, String key,
- ConfigurationChangeListener myself) {
- tenant = ConfigurationRepository.lookup().isValidTenant(tenant) ? tenant.toUpperCase()
- : Constants.DEFAULT_TENANT;
- namespace = ConfigurationRepository.lookup().isValidNamespace(namespace) ? namespace.toUpperCase()
- : Constants.DEFAULT_NAMESPACE;
- if (key == null || key.trim().length() == 0) {
- throw new IllegalArgumentException(KEY_CANNOT_BE_NULL);
- }
- if (myself == null) {
- throw new IllegalArgumentException("ConfigurationChangeListener instance is null.");
- }
- try {
- changeNotifier.notifyChangesTowards(tenant, namespace, key, myself);
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- @Override
- public void removeConfigurationChangeListener(String tenant, String namespace, String key,
- ConfigurationChangeListener myself) {
- tenant = ConfigurationRepository.lookup().isValidTenant(tenant) ? tenant.toUpperCase()
- : Constants.DEFAULT_TENANT;
- namespace = ConfigurationRepository.lookup().isValidNamespace(namespace) ? namespace.toUpperCase()
- : Constants.DEFAULT_NAMESPACE;
- if (key == null || key.trim().length() == 0) {
- throw new IllegalArgumentException(KEY_CANNOT_BE_NULL);
- }
- try {
- changeNotifier.stopNotificationTowards(tenant, namespace, key, myself);
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
-
- @Override
public <T> Map<String, T> populateMap(String tenantId, String namespace, String key, Class<T> clazz) {
if (tenantId == null || tenantId.trim().length() == 0) {
tenantId = tenant.get();
@@ -574,16 +533,4 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
return collection;
}
-
- public void shutdown() {
- if (changeNotifier != null) {
- try {
- changeNotifier.shutdown();
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- }
-
-
}
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<String> 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<String> tenants = new HashSet<>();
private final Set<String> 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<String> 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;
}
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/type/ConfigurationUpdate.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/type/ConfigurationUpdate.java
deleted file mode 100644
index f14b4ec3a6..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/type/ConfigurationUpdate.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.config.type;
-
-public class ConfigurationUpdate extends ConfigurationQuery {
-
- private String value;
- private boolean nodeOverride;
-
- public ConfigurationUpdate value(String val) {
- value = val;
- return this;
- }
-
- public ConfigurationUpdate nodeOverride(boolean val) {
- nodeOverride = val;
- return this;
- }
-
- public String getValue() {
- if (value != null && value.split(",").length > 1 && !value.matches("^\\[.*\\]$")) {
- return "[" + value + "]";
- }
- return value;
- }
-
- public boolean isNodeOverride() {
- return nodeOverride;
- }
-
-}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/resources/config-system.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/resources/config-system.properties
index f8222a3e0c..785b0f94cc 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/resources/config-system.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/resources/config-system.properties
@@ -1,3 +1,2 @@
config.size.max=100
-config.refresh.interval=30000
-event.fetch.delay=5000 \ No newline at end of file
+config.refresh.interval=30000 \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/LoadOrderConfiguration/config.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/LoadOrderConfiguration/config.properties
index abab7891ca..bcc44a7ddd 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/LoadOrderConfiguration/config.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/LoadOrderConfiguration/config.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=14
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.supportedEncryption=MD5
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config-NS.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config-NS.properties
deleted file mode 100644
index 87e98be115..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config-NS.properties
+++ /dev/null
@@ -1,13 +0,0 @@
-artifact.name.maxlength=14
-artifact.extension=pdf, zip, xml
-artifact.supportedEncryption=Base64
-artifact.supportedEncryption=MD5
-artifact.name.allowedChar=a-zA-Z
-artifact.name.allowedchar=a-zA-Z
-artifact.status=deleted
-artifact.status=Deleted
-artifact.persistLocation=/opt/spool, ${sys:user.home}/asdc
-artifact.jsonSchema=@GeneratorsList.json
-artifact.xmlSchema=@${env:PATH}/myschema.json
-artifact.consumerAPPC=${artifact.consumer}
-_config.namespace=UnregisterNotification \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.json b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.json
deleted file mode 100644
index 998bba0e34..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "artifact": {
- "name": {
- "minlength": "6"
- },
- "extension": "pdf,tgz,xls"
- },
- "_config": {
- "mergeStrategy": "union",
- "namespace": "UnregisterNotification"
- }
-} \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.properties
deleted file mode 100644
index 4daad19dcc..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-maxCachedBufferSize=1024
-artifact.maxsize=1024
-artifact.name.maxlength=28 \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.xml b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.xml
deleted file mode 100644
index 7f929af1bd..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
- <artifact>
- <name>
- <maxlength>28</maxlength>
- </name>
- <extension>gz,tgz</extension>
- <supportedencryption>Base64</supportedencryption>
- <status>deleted</status>
- <mandatory>
- <name>true</name>
- </mandatory>
- </artifact>
- <_config>
- <namespace>UnregisterNotification</namespace>
- <mergeStrategy>merge</mergeStrategy>
- </_config>
-</configuration> \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.yaml b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.yaml
deleted file mode 100644
index 1deb37ac7a..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/UnregisterNotification/config.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-
- artifact:
- name:
- allowedChar: "a-zA-Z_0-9"
- encoded: true
- consumer: "appc,catalog"
- _config:
- mergeStrategy: "override"
- namespace: "UnregisterNotification" \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/XMLConfiguration/config.xml b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/XMLConfiguration/config.xml
index 10c7c20620..d1441ef0a9 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/XMLConfiguration/config.xml
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/XMLConfiguration/config.xml
@@ -6,7 +6,6 @@
<allowedChar>a-zA-Z</allowedChar>
<allowedchar>a-zA-Z</allowedchar>
</name>
- <!-- <maxsize></maxsize> -->
<extension>pdf</extension>
<extension>zip,xml</extension>
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/YAMLConfiguration/config.yaml b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/YAMLConfiguration/config.yaml
index f483f36734..b28066c78a 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/YAMLConfiguration/config.yaml
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/YAMLConfiguration/config.yaml
@@ -3,7 +3,6 @@ artifact:
maxlength: 14
allowedChar: "a-zA-Z"
allowedchar: "a-zA-Z"
- #maxsize: ""
extension:
-
pdf
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/config-system.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/config-system.properties
index f8222a3e0c..785b0f94cc 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/config-system.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/config-system.properties
@@ -1,3 +1,2 @@
config.size.max=100
-config.refresh.interval=30000
-event.fetch.delay=5000 \ No newline at end of file
+config.refresh.interval=30000 \ No newline at end of file
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/fallback/config-fallback.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/fallback/config-fallback.properties
index 0cd81fd212..803403ee82 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/fallback/config-fallback.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/fallback/config-fallback.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=14
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.supportedEncryption=MD5
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/java-properties/config.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/java-properties/config.properties
index 7d6c84b2e9..2f0b132de9 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/java-properties/config.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/java-properties/config.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=14
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.supportedEncryption=MD5
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-at.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-at.properties
index 0c484a640b..6cc0cfbc19 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-at.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-at.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=20
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.name.allowedChar=a-zA-Z
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-tf.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-tf.properties
index d39e688f4c..9abab7446d 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-tf.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-tf.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=30
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.name.allowedChar=a-zA-Z
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-vf.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-vf.properties
index 3fc228ed16..3ac9aeda84 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-vf.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config-vf.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=24
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.name.allowedChar=a-zA-Z
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config.properties b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config.properties
index cafafccb0a..db64ba7b66 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config.properties
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/multitenancy/config.properties
@@ -1,5 +1,4 @@
artifact.name.maxlength=14
-#artifact.maxsize=
artifact.extension=pdf, zip, xml
artifact.supportedEncryption=Base64
artifact.name.allowedChar=a-zA-Z