summaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src/main/java/org')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java7
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java45
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java62
3 files changed, 89 insertions, 25 deletions
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 bdda8e84..2390fc89 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
@@ -182,10 +182,9 @@ class SystemPropertiesPersistence implements SystemPersistence {
}
}
- try {
- File controllerPropertiesFile = controllerPropertiesPath.toFile();
- FileWriter writer = new FileWriter(controllerPropertiesFile);
- properties.store(writer, "Machine created Policy Controller Configuration");
+ File controllerPropertiesFile = controllerPropertiesPath.toFile();
+ try (FileWriter writer = new FileWriter(controllerPropertiesFile)) {
+ properties.store(writer, "Machine created Policy Controller Configuration");
} catch (Exception e) {
logger.warn("{}: cannot be STORED", controllerName, e);
return false;
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 fe0cc01f..49dfafca 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
@@ -21,6 +21,8 @@
package org.onap.policy.drools.system;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
@@ -54,9 +56,25 @@ public class Main {
* main
*
* @param args program arguments
+ * @throws IOException
*/
public static void main(String args[]) {
+ /* make sure the configuration directory exists */
+
+ Path configDir = Paths.get(SystemPersistence.CONFIG_DIR_NAME);
+ if (Files.notExists(configDir)) {
+ try {
+ Files.createDirectories(configDir);
+ } catch (IOException e) {
+ throw new IllegalStateException("cannot create " + SystemPersistence.CONFIG_DIR_NAME, e);
+ }
+ }
+
+ if (!Files.isDirectory(configDir))
+ throw new IllegalStateException
+ ("config directory: " + configDir + " is not a directory");
+
/* logging defaults */
if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null)
@@ -66,24 +84,23 @@ public class Main {
PolicyEngine.manager.boot(args);
- Logger logger = LoggerFactory.getLogger(Main.class);
+ /* start logger */
- File configDir = new File(SystemPersistence.CONFIG_DIR_NAME);
-
- if (!configDir.isDirectory()) {
- throw new IllegalArgumentException
- ("config directory: " + configDir.getAbsolutePath() +
- " not found");
- }
+ Logger logger = LoggerFactory.getLogger(Main.class);
/* 1. Configure the Engine */
-
+
+ Path policyEnginePath = Paths.get(configDir.toString(), SystemPersistence.PROPERTIES_FILE_ENGINE);
try {
- Path policyEnginePath = Paths.get(configDir.toPath().toString(), SystemPersistence.PROPERTIES_FILE_ENGINE);
- Properties properties = PropertyUtil.getProperties(policyEnginePath.toFile());
- PolicyEngine.manager.configure(properties);
+ if (Files.exists(policyEnginePath))
+ PolicyEngine.manager.configure(PropertyUtil.getProperties(policyEnginePath.toFile()));
+ else
+ PolicyEngine.manager.configure(PolicyEngine.manager.defaultTelemetryConfig());
} catch (Exception e) {
- logger.warn("Main: cannot initialize {} because of {}", PolicyEngine.manager, e.getMessage(), e);
+ logger.warn("Main: {} could not find custom configuration in {}.",
+ PolicyEngine.manager, SystemPersistence.PROPERTIES_FILE_ENGINE, e);
+
+ /* continue without telemetry or other custom components - this is OK */
}
/* 2. Start the Engine with the basic services only (no Policy Controllers) */
@@ -102,7 +119,7 @@ public class Main {
/* 3. Create and start the controllers */
- File[] controllerFiles = configDir.listFiles();
+ File[] controllerFiles = configDir.toFile().listFiles();
for (File config : controllerFiles) {
if (config.getName().endsWith(SystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX)) {
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 36821659..d7e0ecdd 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
@@ -45,6 +45,7 @@ import org.onap.policy.drools.properties.Startable;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
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 com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -71,17 +72,21 @@ import com.google.gson.GsonBuilder;
* <br>
* PolicyEngine 1 --- 1 ManagementServer
*/
-public interface PolicyEngine extends Startable, Lockable, TopicListener {
+public interface PolicyEngine extends Startable, Lockable, TopicListener {
+ /**
+ * Default Telemetry Server Port
+ */
+ public static final int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
/**
- * Default Config Server Port
+ * Default Telemetry Server Hostname
*/
- public static final int CONFIG_SERVER_DEFAULT_PORT = 9696;
+ public static final String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
/**
- * Default Config Server Hostname
+ * Default Telemetry Server Name
*/
- public static final String CONFIG_SERVER_DEFAULT_HOST = "localhost";
+ public static final String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
/**
* Boot the engine
@@ -89,7 +94,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param cliArgs command line arguments
*/
public void boot(String cliArgs[]);
-
+
/**
* configure the policy engine according to the given properties
*
@@ -308,6 +313,13 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* Invoked when the host goes into the standby state.
*/
public void deactivate();
+
+ /**
+ * produces a default telemetry configuration
+ *
+ * @return policy engine configuration
+ */
+ public Properties defaultTelemetryConfig();
/**
* Policy Engine Manager
@@ -319,6 +331,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* Policy Engine Manager Implementation
*/
class PolicyEngineManager implements PolicyEngine {
+
/**
* logger
*/
@@ -390,6 +403,41 @@ class PolicyEngineManager implements PolicyEngine {
}
}
+
+ /**
+ * produces a minimum configuration with the telemetry service enabled
+ *
+ * @return policy engine configuration
+ */
+ @Override
+ public final Properties defaultTelemetryConfig() {
+ Properties defaultConfig = new Properties();
+
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES, "TELEMETRY");
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
+ TELEMETRY_SERVER_DEFAULT_NAME +
+ PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX,
+ TELEMETRY_SERVER_DEFAULT_HOST);
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
+ TELEMETRY_SERVER_DEFAULT_NAME +
+ PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ "" + TELEMETRY_SERVER_DEFAULT_PORT);
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
+ TELEMETRY_SERVER_DEFAULT_NAME +
+ PolicyProperties.PROPERTY_HTTP_REST_PACKAGES_SUFFIX,
+ RestManager.class.getPackage().getName());
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
+ TELEMETRY_SERVER_DEFAULT_NAME +
+ PolicyProperties.PROPERTY_HTTP_SWAGGER_SUFFIX,
+ true);
+ defaultConfig.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
+ TELEMETRY_SERVER_DEFAULT_NAME +
+ PolicyProperties.PROPERTY_MANAGED_SUFFIX,
+ false);
+
+ return defaultConfig;
+ }
+
@Override
public synchronized void configure(Properties properties) {
@@ -813,7 +861,7 @@ class PolicyEngineManager implements PolicyEngine {
logger.error("{}: cannot start http-server {} because of {}", this,
httpServer, e.getMessage(), e);
}
- }
+ }
/* policy-engine dispatch pre stop hook */
for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {