summaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management
diff options
context:
space:
mode:
Diffstat (limited to 'common/onap-common-configuration-management')
-rwxr-xr-xcommon/onap-common-configuration-management/onap-configuration-management-core/pom.xml4
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
<!--
  ============LICENSE_START=======================================================
   Copyright (C) 2018 Ericsson. All rights reserved.
  ================================================================================
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

  SPDX-License-Identifier: Apache-2.0
  ============LICENSE_END=========================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.onap.policy.apex-pdp.plugins</groupId>
        <artifactId>plugins</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </parent>

    <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
    <artifactId>plugins-executor</artifactId>
    <packaging>pom</packaging>

    <name>${project.artifactId}</name>
    <description>Plugins for logic execution in Apex</description>

    <dependencies>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.core</groupId>
            <artifactId>core-engine</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <modules>
        <module>plugins-executor-java</module>
        <module>plugins-executor-javascript</module>
        <module>plugins-executor-jruby</module>
        <module>plugins-executor-jython</module>
        <module>plugins-executor-mvel</module>
    </modules>

    <profiles>
        <profile>
            <id>apexSite</id>
            <activation>
                <property>
                    <name>apexSite</name>
                </property>
            </activation>
            <properties>
                <adsite-plugins-executor-dir>${project.basedir}/src</adsite-plugins-executor-dir>
            </properties>
            <distributionManagement>
                <site>
                    <id>${project.artifactId}-site</id>
                    <url>${apex.adsite.prefix}/modules/${project.parent.artifactId}/${project.artifactId}/</url>
                </site>
            </distributionManagement>
        </profile>
    </profiles>
</project>
/main/java/org/onap/config/NonConfigResource.java
@@ -21,14 +21,15 @@ import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
public class NonConfigResource {
- private static final Set<URL> urls = new HashSet<>();
- private static final Set<File> files = new HashSet<>();
+ private static final Set<URL> urls = Collections.synchronizedSet(new HashSet<>());
+ private static final Set<File> files = Collections.synchronizedSet(new HashSet<>());
public static void add(URL url) {
urls.add(url);
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AgglomerateConfiguration.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AgglomerateConfiguration.java
deleted file mode 100644
index ed2511d722..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/AgglomerateConfiguration.java
+++ /dev/null
@@ -1,39 +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.util.Collections;
-import java.util.Map;
-import java.util.WeakHashMap;
-import org.apache.commons.configuration2.DatabaseConfiguration;
-
-public class AgglomerateConfiguration extends DatabaseConfiguration {
-
- private final Map<String, Object> store = Collections.synchronizedMap(new WeakHashMap<>());
-
- public Object getPropertyValue(String key) {
-
- Object objToReturn = store.get(key);
- if (objToReturn == null && !store.containsKey(key)) {
- objToReturn = super.getProperty(key);
- store.put(key, objToReturn);
- }
-
- return objToReturn;
- }
-
-}
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 32a1902151..e81d82bf7d 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
@@ -35,10 +35,10 @@ import org.onap.config.type.ConfigurationMode;
public final class AggregateConfiguration {
- private final Map<String, Configuration> rootConfig = new HashMap<>();
- private final Map<String, Configuration> unionConfig = new HashMap<>();
- private final Map<String, Configuration> mergeConfig = new HashMap<>();
- private final Map<String, Configuration> overrideConfig = new LinkedHashMap<>();
+ private final Map<String, Configuration> rootConfig = Collections.synchronizedMap(new HashMap<>());
+ private final Map<String, Configuration> unionConfig = Collections.synchronizedMap(new HashMap<>());
+ private final Map<String, Configuration> mergeConfig = Collections.synchronizedMap(new HashMap<>());
+ private final Map<String, Configuration> overrideConfig = Collections.synchronizedMap(new LinkedHashMap<>());
public void addConfig(File file) throws Exception {
addConfig(file.getAbsolutePath().toUpperCase(), ConfigurationUtils.getMergeStrategy(file),
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 af5ae04104..9a93801144 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
@@ -39,14 +39,26 @@ import org.onap.config.api.Hint;
public class ConfigurationImpl implements org.onap.config.api.Configuration {
private static final String KEY_CANNOT_BE_NULL = "Key can't be null.";
- private static final ThreadLocal<String> tenant = ThreadLocal.withInitial(() -> Constants.DEFAULT_TENANT);
+
+ private static final ThreadLocal<String> TENANT = ThreadLocal.withInitial(() -> Constants.DEFAULT_TENANT);
+
+ private static final Object LOCK = new Object();
private static boolean instantiated = false;
public ConfigurationImpl() throws Exception {
+
+ synchronized (LOCK) {
+ init();
+ }
+ }
+
+ private void init() throws Exception {
+
if (instantiated || !CliConfigurationImpl.class.isAssignableFrom(this.getClass())) {
throw new RuntimeException("Illegal access to configuration.");
}
+
Map<String, AggregateConfiguration> moduleConfigStore = new HashMap<>();
List<URL> classpathResources = ConfigurationUtils.getAllClassPathResources();
Predicate<URL> predicate = ConfigurationUtils::isConfig;
@@ -107,6 +119,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
}
}
+
populateFinalConfigurationIncrementally(moduleConfigStore);
String nodeConfigLocation = System.getProperty("node.config.location");
if (nodeConfigLocation != null && nodeConfigLocation.trim().length() > 0) {
@@ -122,6 +135,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
}
}
+
instantiated = true;
}
@@ -186,8 +200,9 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
@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();
+ tenantId = TENANT.get();
} else {
tenantId = tenantId.toUpperCase();
}
@@ -218,8 +233,9 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
@Override
public Map generateMap(String tenantId, String namespace, String key) {
+
if (tenantId == null || tenantId.trim().length() == 0) {
- tenantId = tenant.get();
+ tenantId = TENANT.get();
} else {
tenantId = tenantId.toUpperCase();
}
@@ -277,7 +293,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
if (tenant == null || tenant.trim().length() == 0) {
- tenant = ConfigurationImpl.tenant.get();
+ tenant = TENANT.get();
} else {
tenant = tenant.toUpperCase();
}
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 132043d5b5..5b950d1af6 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
@@ -20,6 +20,7 @@ import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -38,10 +39,14 @@ public final class ConfigurationRepository {
private static final ConfigurationRepository repo = new ConfigurationRepository();
- private final Set<String> tenants = new HashSet<>();
- private final Set<String> namespaces = new HashSet<>();
- private final LinkedHashMap<String, ConfigurationHolder> store =
+ private final Set<String> tenants = Collections.synchronizedSet(new HashSet<>());
+
+ private final Set<String> namespaces = Collections.synchronizedSet(new HashSet<>());
+
+ private final Map<String, ConfigurationHolder> store = Collections.synchronizedMap(
+
new LinkedHashMap<String, ConfigurationHolder>(16, 0.75f, true) {
+
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
try {
@@ -51,7 +56,8 @@ public final class ConfigurationRepository {
return false;
}
}
- };
+ });
+
private ConfigurationRepository() {
tenants.add(Constants.DEFAULT_TENANT);
@@ -80,13 +86,8 @@ public final class ConfigurationRepository {
}
public Configuration getConfigurationFor(String tenant, String namespace) throws Exception {
- ConfigurationHolder config;
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);
- }
+ ConfigurationHolder config = store.get(module);
return config.getConfiguration(tenant + Constants.KEY_ELEMENTS_DELIMITER + namespace);
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/TestCMSuite.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/TestCMSuite.java
deleted file mode 100755
index 6c460160d0..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/TestCMSuite.java
+++ /dev/null
@@ -1,52 +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;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.onap.config.test.CliFallbackAndLookupTest;
-import org.onap.config.test.CliTest;
-import org.onap.config.test.ConfigSourceLocationTest;
-import org.onap.config.test.FallbackConfigTest;
-import org.onap.config.test.FallbackToGlobalNamespaceTest;
-import org.onap.config.test.GlobalAndNamespaceConfigTest;
-import org.onap.config.test.JavaPropertiesConfigTest;
-import org.onap.config.test.JsonConfigTest;
-import org.onap.config.test.LoadOrderMergeAndOverrideTest;
-import org.onap.config.test.ModeAsConfigPropTest;
-import org.onap.config.test.MultiTenancyConfigTest;
-import org.onap.config.test.NodeSpecificCliTest;
-import org.onap.config.test.ValidateDefaultModeTest;
-import org.onap.config.test.XmlConfigTest;
-import org.onap.config.test.YamlConfigTest;
-
-/**
- * Created by sheetalm on 10/25/2016.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses(
- {ConfigurationUtilsTest.class, JavaPropertiesConfigTest.class, JsonConfigTest.class, XmlConfigTest.class,
- YamlConfigTest.class, CliFallbackAndLookupTest.class, CliTest.class, ConfigSourceLocationTest.class,
- FallbackConfigTest.class, FallbackToGlobalNamespaceTest.class, GlobalAndNamespaceConfigTest.class,
- ModeAsConfigPropTest.class, MultiTenancyConfigTest.class, NodeSpecificCliTest.class,
- ValidateDefaultModeTest.class, LoadOrderMergeAndOverrideTest.class})
-public class TestCMSuite extends junit.framework.TestSuite {
-
- private TestCMSuite() {
- // prevent instantiation
- }
-}