aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-02-28 10:10:49 -0600
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2019-03-01 09:56:11 -0600
commitb001c1ac5a0b4d938a69adb47f4613f64dc71c1a (patch)
treea83c2887edc25fd4eb24f3f6d485e8f860069c19 /policy-management
parent8e9ddde1bb1e3fc3f7b85af653d6251daf7e77d6 (diff)
move all hard install config to environment vars
+ support multiple system properties files with variable interpolation loaded at initialization + support of configurable JVM options (-X, etc ..). + rearrange aaf configuration to avoid {{}} installation variables and use dynamic enviroment variables. + miscellaneous clean up in areas touched and checkstyle. Change-Id: I71ad839778e17eb57c098a2c5cc2bf96e468669a Issue-ID: POLICY-1524 Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java251
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java48
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java56
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java8
-rw-r--r--policy-management/src/main/server-gen/bin/policy-management-controller5
-rw-r--r--policy-management/src/main/server/config/aaf-credentials.properties9
-rw-r--r--policy-management/src/main/server/config/aaf-location.properties2
-rw-r--r--policy-management/src/main/server/config/aaf-system.properties43
-rw-r--r--policy-management/src/main/server/config/aaf.properties11
-rw-r--r--policy-management/src/main/server/config/engine-system.properties37
-rw-r--r--policy-management/src/main/server/config/engine.properties (renamed from policy-management/src/main/server/config/policy-engine.properties)48
-rw-r--r--policy-management/src/main/server/config/system.properties26
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java (renamed from policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java)101
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java10
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java2
15 files changed, 372 insertions, 285 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
index 2fcb07d5..b5c6fe94 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
@@ -1,8 +1,8 @@
/*
* ============LICENSE_START=======================================================
- * policy-management
+ * ONAP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. 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.
@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import java.util.function.BiPredicate;
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.utils.PropertyUtil;
import org.slf4j.Logger;
@@ -41,45 +42,60 @@ import org.slf4j.LoggerFactory;
* Properties based Persistence.
*/
public class FileSystemPersistence implements SystemPersistence {
-
+
+ /**
+ * Properties file extension.
+ */
+ public static final String PROPERTIES_FILE_EXTENSION = ".properties";
+
/**
- * policy controllers suffix.
+ * Policy controllers suffix.
*/
public static final String CONTROLLER_SUFFIX_IDENTIFIER = "-controller";
/**
- * policy controller properties file suffix.
+ * Policy controller properties file suffix.
*/
public static final String PROPERTIES_FILE_CONTROLLER_SUFFIX =
- CONTROLLER_SUFFIX_IDENTIFIER + ".properties";
+ CONTROLLER_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION;
/**
- * policy controller properties file suffix.
+ * Policy controller properties file suffix.
*/
public static final String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX =
- CONTROLLER_SUFFIX_IDENTIFIER + ".properties.bak";
+ CONTROLLER_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION + ".bak";
/**
- * policy engine properties file name.
+ * Policy engine properties file name.
*/
- public static final String PROPERTIES_FILE_ENGINE = "policy-engine.properties";
+ public static final String PROPERTIES_FILE_ENGINE = "engine" + PROPERTIES_FILE_EXTENSION;
/**
* Installation environment suffix for files.
*/
- public static final String ENV_SUFFIX = ".environment";
+ public static final String ENV_FILE_SUFFIX = ".environment";
/**
- * configuration directory.
+ * Environment properties extension.
+ */
+ public static final String ENV_FILE_EXTENSION = ENV_FILE_SUFFIX;
+
+ /**
+ * Installation environment suffix for files.
+ */
+ public static final String SYSTEM_PROPERTIES_SUFFIX = "-system";
+ public static final String SYSTEM_PROPERTIES_FILE_SUFFIX = SYSTEM_PROPERTIES_SUFFIX + PROPERTIES_FILE_EXTENSION;
+
+ /**
+ * Configuration directory.
*/
protected Path configurationDirectory = Paths.get(DEFAULT_CONFIGURATION_DIR);
/**
- * logger.
+ * Logger.
*/
private static final Logger logger = LoggerFactory.getLogger(FileSystemPersistence.class);
-
@Override
public void setConfigurationDir(String configDir) {
String tempConfigDir = configDir;
@@ -93,6 +109,11 @@ public class FileSystemPersistence implements SystemPersistence {
this.configurationDirectory = Paths.get(tempConfigDir);
}
+ setConfigurationDir();
+ }
+
+ @Override
+ public void setConfigurationDir() {
if (Files.notExists(this.configurationDirectory)) {
try {
Files.createDirectories(this.configurationDirectory);
@@ -103,7 +124,7 @@ public class FileSystemPersistence implements SystemPersistence {
if (!Files.isDirectory(this.configurationDirectory)) {
throw new IllegalStateException(
- "config directory: " + this.configurationDirectory + " is not a directory");
+ "config directory: " + this.configurationDirectory + " is not a directory");
}
}
@@ -112,22 +133,117 @@ public class FileSystemPersistence implements SystemPersistence {
return this.configurationDirectory;
}
+ protected Properties getProperties(Path propertiesPath) {
+ if (!Files.exists(propertiesPath)) {
+ throw new IllegalArgumentException("properties for " + propertiesPath.toString() + " are not persisted.");
+ }
+
+ try {
+ return PropertyUtil.getProperties(propertiesPath.toFile());
+ } catch (final Exception e) {
+ throw new IllegalArgumentException("can't read properties for " + propertiesPath.toString(), e);
+ }
+ }
+
@Override
- public Properties getEngineProperties() {
- final Path policyEnginePath =
- Paths.get(this.configurationDirectory.toString(), PROPERTIES_FILE_ENGINE);
+ public Properties getProperties(String name) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("properties name must be provided");
+ }
+
+ Path propertiesPath = Paths.get(this.configurationDirectory.toString());
+ if (name.endsWith(PROPERTIES_FILE_EXTENSION) || name.endsWith(ENV_FILE_EXTENSION)) {
+ propertiesPath = propertiesPath.resolve(name);
+ } else {
+ propertiesPath = propertiesPath.resolve(name + PROPERTIES_FILE_EXTENSION);
+ }
+
+ return getProperties(propertiesPath);
+ }
+
+ protected List<Properties> getPropertiesList(String suffix) {
+ return getPropertiesList(suffix, (name, props) -> true);
+ }
+
+ protected List<Properties> getPropertiesList(String suffix, BiPredicate<String, Properties> preCondition) {
+ List<Properties> properties = new ArrayList<>();
+ File[] files = this.sortedListFiles();
+ for (File file : files) {
+ if (file.getName().endsWith(suffix)) {
+ addToPropertiesList(file, properties, preCondition);
+ }
+ }
+ return properties;
+ }
+
+ private void addToPropertiesList(File file, List<Properties> properties,
+ BiPredicate<String, Properties> preCondition) {
try {
- if (Files.exists(policyEnginePath)) {
- return PropertyUtil.getProperties(policyEnginePath.toFile());
+ Properties proposedProps = getProperties(file.getName());
+ if (preCondition.test(file.getName(), proposedProps)) {
+ properties.add(proposedProps);
}
} catch (final Exception e) {
- logger.warn("{}: could not find {}", this, policyEnginePath, e);
+ logger.error("{}: cannot get properties {} because of {}", this, file.getName(),
+ e.getMessage(), e);
}
+ }
- return null;
+ @Override
+ public Properties getEnvironmentProperties(String name) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("environment name must be provided");
+ }
+
+ return this.getProperties(Paths.get(this.configurationDirectory.toString(), name + ENV_FILE_SUFFIX));
}
@Override
+ public List<Properties> getEnvironmentProperties() {
+ return getPropertiesList(ENV_FILE_SUFFIX);
+ }
+
+ @Override
+ public Properties getSystemProperties(String name) {
+ return this.getProperties(name + SYSTEM_PROPERTIES_SUFFIX);
+ }
+
+ @Override
+ public List<Properties> getSystemProperties() {
+ return getPropertiesList(SYSTEM_PROPERTIES_FILE_SUFFIX);
+ }
+
+ @Override
+ public Properties getEngineProperties() {
+ return this.getProperties(PROPERTIES_FILE_ENGINE);
+ }
+
+ @Override
+ public Properties getControllerProperties(String controllerName) {
+ return this.getProperties(controllerName + CONTROLLER_SUFFIX_IDENTIFIER);
+ }
+
+ @Override
+ public List<Properties> getControllerProperties() {
+ return getPropertiesList(PROPERTIES_FILE_CONTROLLER_SUFFIX, this::testControllerName);
+ }
+
+ private boolean testControllerName(String controllerFilename, Properties controllerProperties) {
+ String controllerName = controllerFilename
+ .substring(0, controllerFilename.length() - PROPERTIES_FILE_CONTROLLER_SUFFIX.length());
+ String controllerPropName = controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
+ if (controllerPropName == null) {
+ controllerProperties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, controllerName);
+ } else if (!controllerPropName.equals(controllerName)) {
+ logger.error("{}: mismatch controller named {} against {} in file {}",
+ this, controllerPropName, controllerName, controllerFilename);
+ return false;
+ }
+ return true;
+ }
+
+
+ @Override
public boolean backupController(String controllerName) {
final Path controllerPropertiesPath = Paths.get(this.configurationDirectory.toString(),
controllerName + PROPERTIES_FILE_CONTROLLER_SUFFIX);
@@ -209,97 +325,6 @@ public class FileSystemPersistence implements SystemPersistence {
return true;
}
- @Override
- public Properties getControllerProperties(String controllerName) {
- return this.getProperties(controllerName + CONTROLLER_SUFFIX_IDENTIFIER);
- }
-
- @Override
- public List<Properties> getControllerProperties() {
- final List<Properties> controllers = new ArrayList<>();
- final File[] controllerFiles = this.sortedListFiles();
- for (final File controllerFile : controllerFiles) {
- if (controllerFile.getName().endsWith(PROPERTIES_FILE_CONTROLLER_SUFFIX)) {
- final int idxSuffix = controllerFile.getName().indexOf(PROPERTIES_FILE_CONTROLLER_SUFFIX);
- final int lastIdxSuffix =
- controllerFile.getName().lastIndexOf(PROPERTIES_FILE_CONTROLLER_SUFFIX);
- if (idxSuffix != lastIdxSuffix) {
- throw new IllegalArgumentException(
- "Improper naming of controller properties file: " + "Expected <controller-name>"
- + FileSystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX);
- }
-
- final String name = controllerFile.getName().substring(0, lastIdxSuffix);
- try {
- final Properties controllerProperties = this.getControllerProperties(name);
- final String controllerName =
- controllerProperties.getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME);
- if (controllerName == null) {
- controllerProperties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, name);
- } else if (!controllerName.equals(name)) {
- logger.error("{}: mismatch controller named {} with file name {}", this, controllerName,
- controllerFile.getName());
- continue;
- }
- controllers.add(this.getControllerProperties(name));
- } catch (final Exception e) {
- logger.error("{}: cannot obtain properties for controller {} because of {}", name,
- e.getMessage(), e);
- }
- }
- }
- return controllers;
- }
-
- @Override
- public Properties getProperties(String name) {
- final Path propertiesPath =
- Paths.get(this.configurationDirectory.toString(), name + ".properties");
-
- if (!Files.exists(propertiesPath)) {
- throw new IllegalArgumentException("properties for " + name + " are not persisted.");
- }
-
- try {
- return PropertyUtil.getProperties(propertiesPath.toFile());
- } catch (final Exception e) {
- logger.warn("{}: can't read properties @ {}", name, propertiesPath);
- throw new IllegalArgumentException(
- "can't read properties for " + name + " @ " + propertiesPath, e);
- }
- }
-
- @Override
- public List<Properties> getEnvironmentProperties() {
- final List<Properties> envs = new ArrayList<>();
- final File[] envFiles = this.sortedListFiles();
- for (final File envFile : envFiles) {
- if (envFile.getName().endsWith(ENV_SUFFIX)) {
- final String name = envFile.getName().substring(0, envFile.getName().indexOf(ENV_SUFFIX));
- try {
- envs.add(this.getEnvironmentProperties(name));
- } catch (final Exception e) {
- logger.error("{}: cannot get environment {} because of {}", name, e.getMessage(), e);
- }
- }
- }
- return envs;
- }
-
- @Override
- public Properties getEnvironmentProperties(String name) {
- final Path envPath = Paths.get(this.configurationDirectory.toString(), name + ENV_SUFFIX);
- if (!Files.exists(envPath)) {
- throw new IllegalArgumentException("{} environment" + name + " cannot be retrieved");
- }
-
- try {
- return PropertyUtil.getProperties(envPath.toFile());
- } catch (final Exception e) {
- throw new IllegalArgumentException("cannot read environment " + name, e);
- }
- }
-
/**
* provides a list of files sorted by name in ascending order in the configuration directory.
*/
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
index 34b27c23..32852225 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. 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.
@@ -31,27 +31,32 @@ public interface SystemPersistence {
/**
* configuration directory.
*/
- public static final String DEFAULT_CONFIGURATION_DIR = "config";
+ String DEFAULT_CONFIGURATION_DIR = "config";
/**
* Persistence Manager. For now it is a file-based properties management, In the future, it will
* probably be DB based, so manager implementation will change.
*/
- public static final SystemPersistence manager = new FileSystemPersistence();
+ SystemPersistence manager = new FileSystemPersistence();
/**
* sets a configuration directory and ensures it exists.
*
* @param configDir configuration directory or null to use the default one
*/
- public void setConfigurationDir(String configDir);
+ void setConfigurationDir(String configDir);
+
+ /**
+ * sets the default configuration directory and ensures it exists.
+ */
+ void setConfigurationDir();
/**
* get configuration directory path.
*
* @return configuration directory path
*/
- public Path getConfigurationPath();
+ Path getConfigurationPath();
/**
* backs up a controller configuration.
@@ -59,7 +64,7 @@ public interface SystemPersistence {
* @param controllerName the controller name
* @return true if the configuration is backed up
*/
- public boolean backupController(String controllerName);
+ boolean backupController(String controllerName);
/**
* persists controller configuration.
@@ -71,7 +76,7 @@ public interface SystemPersistence {
* @throws IllegalArgumentException if the configuration cannot be handled by the persistence
* manager
*/
- public boolean storeController(String controllerName, Object configuration);
+ boolean storeController(String controllerName, Object configuration);
/**
* delete controller configuration.
@@ -79,7 +84,7 @@ public interface SystemPersistence {
* @param controllerName the controller name
* @return true if storage is succesful, false otherwise
*/
- public boolean deleteController(String controllerName);
+ boolean deleteController(String controllerName);
/**
* get controller properties.
@@ -90,34 +95,34 @@ public interface SystemPersistence {
* @throws IllegalArgumentException if the controller name does not lead to a properties
* configuration
*/
- public Properties getControllerProperties(String controllerName);
+ Properties getControllerProperties(String controllerName);
/**
* get controllers configuration.
*
* @return list of controllers properties
*/
- public List<Properties> getControllerProperties();
+ List<Properties> getControllerProperties();
/**
* get environments.
*
*/
- public List<Properties> getEnvironmentProperties();
+ List<Properties> getEnvironmentProperties();
/**
* get environment properties.
*
* @param environmentName name
*/
- public Properties getEnvironmentProperties(String environmentName);
+ Properties getEnvironmentProperties(String environmentName);
/**
* get the engine properties.
*
* @return the engine properties
*/
- public Properties getEngineProperties();
+ Properties getEngineProperties();
/**
* get properties by name.
@@ -127,5 +132,20 @@ public interface SystemPersistence {
*
* @throws IllegalArgumentException if the name does not lead to a properties configuration
*/
- public Properties getProperties(String name);
+ Properties getProperties(String name);
+
+ /**
+ * get system properties configuration.
+ *
+ * @param name name
+ * @return properties
+ */
+ Properties getSystemProperties(String name);
+
+ /**
+ * get system properties configuration list.
+ *
+ * @return list of system properties
+ */
+ List<Properties> getSystemProperties();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
index 79268b2c..5ebd0490 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
@@ -1,8 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * policy-management
+ * ONAP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. 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.
@@ -20,12 +20,10 @@
package org.onap.policy.drools.system;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.Properties;
-
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.utils.PropertyUtil;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.drools.utils.logging.MDCTransaction;
import org.slf4j.Logger;
@@ -36,13 +34,6 @@ import org.slf4j.LoggerFactory;
*/
public class Main {
- /** logback configuration file system property. */
- public static final String LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY =
- "logback.configurationFile";
-
- /** logback configuration file system property. */
- public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml";
-
/** constructor (hides public default one). */
private Main() {}
@@ -53,44 +44,27 @@ public class Main {
*/
public static void main(String[] args) {
- /* logging defaults */
-
- if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
- if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
- System.setProperty(
- LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT);
- } else {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
- }
- }
-
- /* make sure the default configuration directory is properly set up */
+ /* start logger */
- SystemPersistence.manager.setConfigurationDir(null);
+ Logger logger = LoggerFactory.getLogger(Main.class);
- /* logging defaults */
+ /* system properties */
- if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) {
- if (Files.exists(Paths.get(LOGBACK_CONFIGURATION_FILE_DEFAULT))) {
- System.setProperty(
- LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT);
- } else {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, ch.qos.logback.classic.Level.INFO.toString());
- }
+ for (Properties systemProperties : SystemPersistence.manager.getSystemProperties()) {
+ PropertyUtil.setSystemProperties(systemProperties);
}
/* 0. boot */
PolicyEngine.manager.boot(args);
- /* start logger */
+ /* 1.a. Configure Engine */
- final Logger logger = LoggerFactory.getLogger(Main.class);
-
- /* 1.a. Configure the Engine */
-
- Properties engineProperties = SystemPersistence.manager.getEngineProperties();
- if (engineProperties == null) {
+ Properties engineProperties;
+ try {
+ engineProperties = SystemPersistence.manager.getEngineProperties();
+ } catch (IllegalArgumentException iae) {
+ logger.warn("Main: engine properties not found. Using default configuration.", iae);
engineProperties = PolicyEngine.manager.defaultTelemetryConfig();
}
@@ -98,7 +72,7 @@ public class Main {
/* 1.b. Load Installation Environment(s) */
- for (final Properties env : SystemPersistence.manager.getEnvironmentProperties()) {
+ for (Properties env : SystemPersistence.manager.getEnvironmentProperties()) {
PolicyEngine.manager.setEnvironment(env);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
index 959114a2..bedd8d48 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
@@ -54,6 +54,7 @@ import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.server.restful.RestManager;
import org.onap.policy.drools.server.restful.aaf.AafTelemetryAuthFilter;
+import org.onap.policy.drools.utils.PropertyUtil;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.drools.utils.logging.MDCTransaction;
import org.slf4j.Logger;
@@ -429,7 +430,7 @@ class PolicyEngineManager implements PolicyEngine {
@Override
public synchronized void setEnvironment(Properties properties) {
- this.environment.putAll(properties);
+ this.environment.putAll(PropertyUtil.getInterpolatedProperties(properties));
}
@JsonIgnore
@@ -443,7 +444,10 @@ class PolicyEngineManager implements PolicyEngine {
public synchronized String getEnvironmentProperty(String envKey) {
String value = this.environment.getProperty(envKey);
if (value == null) {
- value = System.getenv(envKey);
+ value = System.getProperty(envKey);
+ if (value == null) {
+ value = System.getenv(envKey);
+ }
}
return value;
}
diff --git a/policy-management/src/main/server-gen/bin/policy-management-controller b/policy-management/src/main/server-gen/bin/policy-management-controller
index 589c4c32..79fab581 100644
--- a/policy-management/src/main/server-gen/bin/policy-management-controller
+++ b/policy-management/src/main/server-gen/bin/policy-management-controller
@@ -53,8 +53,9 @@ function um_start() {
source ${POLICY_HOME}/etc/profile.d/env.sh
${POLICY_HOME}/bin/configure-maven
+ JVM_OPTS=(${JVM_OPTIONS})
- # If 'system.properties' exists, convert it into JVM arguments.
+ # If 'system.properties' exists, convert it into "-D" JVM arguments.
# Note that the following also handles property values with spaces.
IFS=$'\n'
systemProperties=($(
@@ -71,7 +72,7 @@ function um_start() {
# to subprocesses
exec {cfg}>&-
fi
- nohup $JAVA_HOME/bin/java -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.out) 2> >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.err) &
+ nohup $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.out) 2> >( while read line; do echo "$(date): ${line}"; done > $_LOGS/$PNAME.err) &
_PID=$!
echo $_PID > $_PIDFILE
diff --git a/policy-management/src/main/server/config/aaf-credentials.properties b/policy-management/src/main/server/config/aaf-credentials.properties
deleted file mode 100644
index aaa5f161..00000000
--- a/policy-management/src/main/server/config/aaf-credentials.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-cm_url=https://AAF_LOCATE_URL/AAF_NS.cm:2.1
-cadi_x509_issuers=CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US
-cadi_keyfile=${{POLICY_HOME}}/config/aaf-cadi.keyfile
-cadi_keystore=${{POLICY_HOME}}/etc/ssl/policy-keystore
-cadi_keystore_password=${{KEYSTORE_PASSWD}}
-cadi_key_password=${{KEYSTORE_PASSWD}}
-cadi_alias=policy@policy.onap.org
-cadi_truststore=${{POLICY_HOME}}/etc/ssl/policy-truststore
-cadi_truststore_password=${{TRUSTSTORE_PASSWD}} \ No newline at end of file
diff --git a/policy-management/src/main/server/config/aaf-location.properties b/policy-management/src/main/server/config/aaf-location.properties
deleted file mode 100644
index dc828e71..00000000
--- a/policy-management/src/main/server/config/aaf-location.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-cadi_latitude=38.000
-cadi_longitude=-72.000
diff --git a/policy-management/src/main/server/config/aaf-system.properties b/policy-management/src/main/server/config/aaf-system.properties
new file mode 100644
index 00000000..05716cc2
--- /dev/null
+++ b/policy-management/src/main/server/config/aaf-system.properties
@@ -0,0 +1,43 @@
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2019 AT&T Intellectual Property. 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.
+# ============LICENSE_END=========================================================
+#
+
+# AAF related system properties
+
+aaf_locate_url=https://${env:AAF_HOST}:8095
+aaf_oauth2_introspect_url=https://AAF_LOCATE_URL/AAF_NS.introspect:2.1/introspect
+aaf_oauth2_token_url=https://AAF_LOCATE_URL/AAF_NS.token:2.1/token
+aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:2.1
+aaf_env=DEV
+
+cadi_protocols=TLSv1.1,TLSv1.2
+cadi_latitude=38.000
+cadi_longitude=-72.000
+cadi_loglevel=DEBUG
+
+cadi_x509_issuers=CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US
+cadi_keyfile=${env:POLICY_HOME}/config/aaf-cadi.keyfile
+cadi_keystore=${env:POLICY_HOME}/etc/ssl/policy-keystore
+cadi_keystore_password=${env:KEYSTORE_PASSWD}
+cadi_key_password=${env:KEYSTORE_PASSWD}
+cadi_alias=policy@policy.onap.org
+cadi_truststore=${env:POLICY_HOME}/etc/ssl/policy-truststore
+cadi_truststore_password=${env:TRUSTSTORE_PASSWD}
+
+cm_url=https://AAF_LOCATE_URL/AAF_NS.cm:2.1
diff --git a/policy-management/src/main/server/config/aaf.properties b/policy-management/src/main/server/config/aaf.properties
deleted file mode 100644
index 8084be99..00000000
--- a/policy-management/src/main/server/config/aaf.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-cadi_prop_files=${{POLICY_HOME}}/config/aaf-credentials.properties:${{POLICY_HOME}}/config/aaf-location.properties
-cadi_loglevel=DEBUG
-aaf_env=DEV
-aaf_locate_url=https://${{AAF_HOST}}:8095
-aaf_oauth2_introspect_url=https://AAF_LOCATE_URL/AAF_NS.introspect:2.1/introspect
-aaf_oauth2_token_url=https://AAF_LOCATE_URL/AAF_NS.token:2.1/token
-aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:2.1
-cadi_protocols=TLSv1.1,TLSv1.2
-cm_url=https://AAF_LOCATE_URL/AAF_NS.cm:2.1
-fs_url=https://AAF_LOCATE_URL/AAF_NS.fs.2.1
-gui_url=https://AAF_LOCATE_URL/AAF_NS.gui.2.1
diff --git a/policy-management/src/main/server/config/engine-system.properties b/policy-management/src/main/server/config/engine-system.properties
new file mode 100644
index 00000000..c1f21b86
--- /dev/null
+++ b/policy-management/src/main/server/config/engine-system.properties
@@ -0,0 +1,37 @@
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2019 AT&T Intellectual Property. 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.
+# ============LICENSE_END=========================================================
+#
+
+# system properties set within the application
+
+java.net.preferIPv4Stack=true
+
+# jmx
+
+com.sun.management.jmxremote.port=9991
+com.sun.management.jmxremote.authenticate=false
+com.sun.management.jmxremote.ssl=false
+
+# certs
+
+javax.net.ssl.trustStore=${env:POLICY_HOME}/etc/ssl/policy-truststore
+javax.net.ssl.trustStorePassword=${env:TRUSTSTORE_PASSWD}
+
+javax.net.ssl.keyStore=${env:POLICY_HOME}/etc/ssl/policy-keystore
+javax.net.ssl.keyStorePassword=${env:KEYSTORE_PASSWD}
diff --git a/policy-management/src/main/server/config/policy-engine.properties b/policy-management/src/main/server/config/engine.properties
index b43971f1..fec99b14 100644
--- a/policy-management/src/main/server/config/policy-engine.properties
+++ b/policy-management/src/main/server/config/engine.properties
@@ -1,15 +1,15 @@
###
# ============LICENSE_START=======================================================
-# policy-management
+# ONAP
# ================================================================================
-# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -18,38 +18,40 @@
# ============LICENSE_END=========================================================
###
-# Policy Engine Configuration
+# Policy Engine Configuration Channels
-# Configuration Channel Settings: PDPD-CONFIGURATION
+dmaap.source.topics=PDPD-CONFIGURATION,POLICY-PDP-PAP
-dmaap.source.topics=${env:PDPD_CONFIGURATION_TOPIC},POLICY-PDP-PAP
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.servers=${env:PDPD_CONFIGURATION_SERVERS}
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiKey=${env:PDPD_CONFIGURATION_API_KEY}
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiSecret=${env:PDPD_CONFIGURATION_API_SECRET}
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.consumerGroup=${env:PDPD_CONFIGURATION_CONSUMER_GROUP}
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.consumerInstance=${env:PDPD_CONFIGURATION_CONSUMER_INSTANCE}
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.managed=false
-dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.https=true
+dmaap.sink.topics=PDPD-CONFIGURATION,POLICY-PDP-PAP
-dmaap.sink.topics=${env:PDPD_CONFIGURATION_TOPIC},POLICY-PDP-PAP
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.servers=${env:PDPD_CONFIGURATION_SERVERS}
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiKey=${env:PDPD_CONFIGURATION_API_KEY}
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiSecret=${env:PDPD_CONFIGURATION_API_SECRET}
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.partitionKey=${env:PDPD_CONFIGURATION_PARTITION_KEY}
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.managed=false
-dmaap.sink.topics.${{PDPD_CONFIGURATION_TOPIC}}.https=true
+dmaap.source.topics.PDPD-CONFIGURATION.servers=${env:DMAAP_SERVERS}
+dmaap.source.topics.PDPD-CONFIGURATION.effectiveTopic=${env:PDPD_CONFIGURATION_TOPIC}
+dmaap.source.topics.PDPD-CONFIGURATION.apiKey=${env:PDPD_CONFIGURATION_API_KEY}
+dmaap.source.topics.PDPD-CONFIGURATION.apiSecret=${env:PDPD_CONFIGURATION_API_SECRET}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerGroup=${env:PDPD_CONFIGURATION_CONSUMER_GROUP}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerInstance=${env:PDPD_CONFIGURATION_CONSUMER_INSTANCE}
+dmaap.source.topics.PDPD-CONFIGURATION.managed=false
+dmaap.source.topics.PDPD-CONFIGURATION.https=true
+
+dmaap.sink.topics.PDPD-CONFIGURATION.servers=${env:DMAAP_SERVERS}
+dmaap.sink.topics.PDPD-CONFIGURATION.effectiveTopic=${env:PDPD_CONFIGURATION_TOPIC}
+dmaap.sink.topics.PDPD-CONFIGURATION.apiKey=${env:PDPD_CONFIGURATION_API_KEY}
+dmaap.sink.topics.PDPD-CONFIGURATION.apiSecret=${env:PDPD_CONFIGURATION_API_SECRET}
+dmaap.sink.topics.PDPD-CONFIGURATION.partitionKey=${env:PDPD_CONFIGURATION_PARTITION_KEY}
+dmaap.sink.topics.PDPD-CONFIGURATION.managed=false
+dmaap.sink.topics.PDPD-CONFIGURATION.https=true
# Configuration Channel Settings: POLICY-PDP-PAP
-dmaap.source.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
dmaap.source.topics.POLICY-PDP-PAP.servers=${env:DMAAP_SERVERS}
+dmaap.source.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
dmaap.source.topics.POLICY-PDP-PAP.apiKey=${env:POLICY_PDP_PAP_API_KEY}
dmaap.source.topics.POLICY-PDP-PAP.apiSecret=${env:POLICY_PDP_PAP_API_SECRET}
dmaap.source.topics.POLICY-PDP-PAP.managed=false
dmaap.source.topics.POLICY-PDP-PAP.https=true
-dmaap.sink.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
dmaap.sink.topics.POLICY-PDP-PAP.servers=${env:DMAAP_SERVERS}
+dmaap.sink.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
dmaap.sink.topics.POLICY-PDP-PAP.apiKey=${env:POLICY_PDP_PAP_API_KEY}
dmaap.sink.topics.POLICY-PDP-PAP.apiSecret=${env:POLICY_PDP_PAP_API_SECRET}
dmaap.sink.topics.POLICY-PDP-PAP.managed=false
diff --git a/policy-management/src/main/server/config/system.properties b/policy-management/src/main/server/config/system.properties
index 6bac0ea6..9b6be6b6 100644
--- a/policy-management/src/main/server/config/system.properties
+++ b/policy-management/src/main/server/config/system.properties
@@ -2,7 +2,7 @@
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2019 AT&T Intellectual Property. 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.
@@ -18,26 +18,8 @@
# ============LICENSE_END=========================================================
###
-# system properties passed to controller
+# system properties passed as "-D" arguments to the JVM process.
-# jmx
+# logging
-com.sun.management.jmxremote.port=9991
-com.sun.management.jmxremote.authenticate=false
-com.sun.management.jmxremote.ssl=false
-
-# certs
-
-javax.net.ssl.trustStore=${{POLICY_HOME}}/etc/ssl/policy-truststore
-javax.net.ssl.trustStorePassword=${{TRUSTSTORE_PASSWD}}
-
-javax.net.ssl.keyStore=${{POLICY_HOME}}/etc/ssl/policy-keystore
-javax.net.ssl.keyStorePassword=${{KEYSTORE_PASSWD}}
-
-# aaf
-
-cadi_prop_files=config/aaf.properties
-
-# standard logging
-
-logback.configurationFile=config/logback.xml
+logback.configurationFile=config/logback.xml \ No newline at end of file
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
index 1e51cfec..de0a7518 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. 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.
@@ -18,10 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.persistence.test;
+package org.onap.policy.drools.persistence;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.FileOutputStream;
@@ -30,56 +30,51 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.List;
import java.util.Properties;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import org.onap.policy.drools.persistence.FileSystemPersistence;
-import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* (File) System Persistence Tests.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SystemPersistenceTest {
-
- /**
- * logger.
- */
- private static final Logger logger = LoggerFactory.getLogger(SystemPersistenceTest.class);
-
/**
* sample configuration dir.
*/
- public static final String OTHER_CONFIG_DIR = "tmp";
+ private static final String OTHER_CONFIG_DIR = "tmp";
/**
* Test JUnit Controller Name.
*/
- public static final String TEST_CONTROLLER_NAME = "foo";
+ private static final String TEST_CONTROLLER_NAME = "foo";
/**
* Test JUnit Controller Name.
*/
- public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
+ private static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
/**
* Test JUnit Controller Name Backup.
*/
- public static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak";
+ private static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak";
/**
* Test JUnit Environment/Engine properties.
*/
- private static final String ENV_PROPS = "envProps";
+ private static final String ENV_PROPS = TEST_CONTROLLER_NAME;
private static final String ENV_PROPS_FILE = ENV_PROPS + ".environment";
- private static final String POLICY_ENGINE_PROPERTIES_FILE = "policy-engine.properties";
+
+ /**
+ * Test JUnit system properties.
+ */
+ private static final String SYSTEM_PROPS = TEST_CONTROLLER_NAME;
+ private static final String SYSTEM_PROPS_FILE = SYSTEM_PROPS + "-system.properties";
@BeforeClass
public static void setUp() throws IOException {
@@ -92,22 +87,21 @@ public class SystemPersistenceTest {
}
@Test
- public void test1NonDefaultConfigDir() throws IOException {
- logger.info("enter");
-
+ public void test1NonDefaultConfigDir() {
SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
- assertTrue(
- SystemPersistence.manager.getConfigurationPath().toString().equals(OTHER_CONFIG_DIR));
+ assertEquals(OTHER_CONFIG_DIR, SystemPersistence.manager.getConfigurationPath().toString());
SystemPersistence.manager.setConfigurationDir(null);
- assertTrue(SystemPersistence.manager.getConfigurationPath().toString()
- .equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR));
+ assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistence.manager.getConfigurationPath().toString());
+
+ SystemPersistence.manager.setConfigurationDir();
+ assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistence.manager.getConfigurationPath().toString());
}
@Test
- public void test2Engine() throws IOException {
- logger.info("enter");
-
+ public void test2Engine_Environment_System() throws IOException {
SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
final Path policyEnginePropsPath =
@@ -123,21 +117,33 @@ public class SystemPersistenceTest {
}
}
- assertEquals(SystemPersistence.manager.getEngineProperties(), engineProps);
+ assertEquals(engineProps, SystemPersistence.manager.getEngineProperties());
final Path environmentPropertiesPath =
Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE);
if (Files.notExists(environmentPropertiesPath)) {
Files.createFile(environmentPropertiesPath);
}
+ assertNotNull(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS));
assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty());
- assertTrue(SystemPersistence.manager.getEnvironmentProperties().size() == 1);
+ assertEquals(1, SystemPersistence.manager.getEnvironmentProperties().size());
+ assertEquals(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS),
+ SystemPersistence.manager.getEnvironmentProperties().get(0));
+
+ Path systemPropertiesPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), SYSTEM_PROPS_FILE);
+ if (Files.notExists(systemPropertiesPath)) {
+ Files.createFile(systemPropertiesPath);
+ }
+ assertNotNull(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS));
+ assertTrue(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS).isEmpty());
+ assertEquals(1, SystemPersistence.manager.getSystemProperties().size());
+ assertEquals(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS),
+ SystemPersistence.manager.getSystemProperties().get(0));
}
@Test
- public void test3PersistConfiguration() {
- logger.info("enter");
-
+ public void test3Controller() {
SystemPersistence.manager.setConfigurationDir(null);
final Path controllerPath = Paths
@@ -150,19 +156,21 @@ public class SystemPersistenceTest {
assertTrue(Files.notExists(controllerBakPath));
Properties properties = new Properties();
- properties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
SystemPersistence.manager.storeController(TEST_CONTROLLER_NAME, properties);
assertTrue(Files.exists(controllerPath));
properties = SystemPersistence.manager.getControllerProperties(TEST_CONTROLLER_NAME);
- assertTrue(properties != null);
+ assertNotNull(properties);
+
+ List<Properties> controllerPropsList = SystemPersistence.manager.getControllerProperties();
+ assertEquals(1, controllerPropsList.size());
+ assertEquals(TEST_CONTROLLER_NAME, controllerPropsList
+ .get(0).getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
SystemPersistence.manager.backupController(TEST_CONTROLLER_NAME);
assertTrue(Files.exists(controllerBakPath));
- assertFalse(SystemPersistence.manager.getControllerProperties().isEmpty());
-
SystemPersistence.manager.deleteController(TEST_CONTROLLER_NAME);
assertTrue(Files.notExists(controllerPath));
}
@@ -172,22 +180,25 @@ public class SystemPersistenceTest {
*
* @throws IOException throws IO exception
*/
- public static void cleanUpWorkingDirs() throws IOException {
-
+ private static void cleanUpWorkingDirs() throws IOException {
SystemPersistence.manager.setConfigurationDir(null);
- final Path testControllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ for (Properties properties : SystemPersistence.manager.getControllerProperties()) {
+ SystemPersistence.manager.deleteController(properties
+ .getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
+ }
+
final Path testControllerBakPath = Paths
.get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
- final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, POLICY_ENGINE_PROPERTIES_FILE);
+ final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
+ final Path systemPath = Paths.get(OTHER_CONFIG_DIR, SYSTEM_PROPS_FILE);
- Files.deleteIfExists(testControllerPath);
Files.deleteIfExists(testControllerBakPath);
Files.deleteIfExists(policyEnginePath);
Files.deleteIfExists(environmentPath);
+ Files.deleteIfExists(systemPath);
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 4b8357a2..8050b26a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -368,6 +368,16 @@ public class PolicyEngineManagerTest {
assertNotNull(mgr.getEnvironmentProperty("PATH"));
assertNull(mgr.getEnvironmentProperty("unknown-env-property"));
+
+ System.setProperty("propS-a", "valueS-a");
+ assertEquals("valueS-a", mgr.getEnvironmentProperty("propS-a"));
+
+ Properties props3 = new Properties();
+ props3.put("prop3-a", "${env:HOME}");
+ mgr.setEnvironment(props3);
+ assertEquals(System.getenv("HOME"), mgr.getEnvironmentProperty("prop3-a"));
+ assertEquals("valueS-a", mgr.getEnvironmentProperty("propS-a"));
+ assertEquals(newValue, mgr.getEnvironmentProperty(propKey));
}
@Test
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index a00d6db2..64af6d4f 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
@@ -163,7 +163,7 @@ public class PolicyEngineTest {
PolicyEngine.manager.configure(engineProps);
assertFalse(PolicyEngine.manager.isAlive());
- logger.info("policy-engine {} has configuration {}", PolicyEngine.manager, engineProps);
+ logger.info("engine {} has configuration {}", PolicyEngine.manager, engineProps);
gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Config.json"));
}