aboutsummaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management/onap-configuration-management-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-api/src')
-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
5 files changed, 72 insertions, 188 deletions
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