summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docker_build.sh10
-rw-r--r--docker_merge.sh9
-rw-r--r--docker_verify.sh9
-rwxr-xr-xfeature-controller-logging/pom.xml103
-rwxr-xr-xfeature-controller-logging/src/assembly/assemble_zip.xml68
-rw-r--r--feature-controller-logging/src/main/feature/install/disable26
-rw-r--r--feature-controller-logging/src/main/feature/install/enable29
-rwxr-xr-xfeature-controller-logging/src/main/java/org/onap/policy/drools/controller/logging/ControllerLoggingFeature.java97
-rwxr-xr-xfeature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.DroolsControllerFeatureAPI1
-rwxr-xr-xfeature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyControllerFeatureAPI1
-rwxr-xr-xfeature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureAPI1
-rwxr-xr-xfeature-controller-logging/src/test/java/org/onap/policy/drools/controller/logging/ControllerLoggingTest.java228
-rwxr-xr-xfeature-controller-logging/src/test/resources/kmodule.xml26
-rwxr-xr-xfeature-controller-logging/src/test/resources/logback-test.xml41
-rwxr-xr-xfeature-controller-logging/src/test/resources/test.drl35
-rwxr-xr-xfeature-controller-logging/src/test/resources/test.pom31
-rw-r--r--feature-eelf/src/main/feature/config/logback-eelf.xml2
-rw-r--r--feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java10
-rw-r--r--feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java6
-rw-r--r--feature-pooling-dmaap/src/main/feature/config/feature-pooling-dmaap.properties22
-rw-r--r--packages/docker/src/main/docker/Dockerfile4
-rw-r--r--packages/docker/src/main/docker/do-start.sh147
-rw-r--r--packages/install/pom.xml6
-rw-r--r--packages/install/src/files/base.conf6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java118
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java29
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java105
-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.java45
-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/logback.xml4
-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
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java149
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java13
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java16
-rw-r--r--pom.xml1
47 files changed, 1468 insertions, 579 deletions
diff --git a/docker_build.sh b/docker_build.sh
index 6f680584..64abc907 100644
--- a/docker_build.sh
+++ b/docker_build.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018-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.
@@ -22,14 +22,6 @@ TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}"
IMAGE=policy-drools
-if [ $HTTP_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
-fi
-
-if [ $HTTPS_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
-fi
-
echo $DOCKER_REPOSITORY
echo $MVN_VERSION
echo $MVN_MAJMIN_VERSION
diff --git a/docker_merge.sh b/docker_merge.sh
index 20fa184c..3cbef595 100644
--- a/docker_merge.sh
+++ b/docker_merge.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018-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.
@@ -22,13 +22,6 @@ TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}"
IMAGE=policy-drools
-if [ $HTTP_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
-fi
-if [ $HTTPS_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
-fi
-
echo $DOCKER_REPOSITORY
echo $MVN_VERSION
echo $MVN_MAJMIN_VERSION
diff --git a/docker_verify.sh b/docker_verify.sh
index 6a4d0242..e2fbe27b 100644
--- a/docker_verify.sh
+++ b/docker_verify.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018-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.
@@ -25,13 +25,6 @@ TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}"
IMAGE=policy-drools
-if [ $HTTP_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
-fi
-if [ $HTTPS_PROXY ]; then
- BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
-fi
-
echo $DOCKER_REPOSITORY
echo $MVN_VERSION
echo $MVN_MAJMIN_VERSION
diff --git a/feature-controller-logging/pom.xml b/feature-controller-logging/pom.xml
new file mode 100755
index 00000000..0798c640
--- /dev/null
+++ b/feature-controller-logging/pom.xml
@@ -0,0 +1,103 @@
+<!--
+ ============LICENSE_START=======================================================
+ feature-controller-logging
+ ================================================================================
+ 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=========================================================
+ -->
+
+<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.drools-pdp</groupId>
+ <artifactId>drools-pdp</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>feature-controller-logging</artifactId>
+
+ <name>feature-controller-logging</name>
+ <description>Loadable module that enables individual network logs per controller</description>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>zipfile</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <useRepositoryLayout>false</useRepositoryLayout>
+ <addParentPoms>false</addParentPoms>
+ <copyPom>false</copyPom>
+ <includeScope>runtime</includeScope>
+ <excludeTransitive>true</excludeTransitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/feature-controller-logging/src/assembly/assemble_zip.xml b/feature-controller-logging/src/assembly/assemble_zip.xml
new file mode 100755
index 00000000..6832604d
--- /dev/null
+++ b/feature-controller-logging/src/assembly/assemble_zip.xml
@@ -0,0 +1,68 @@
+<!--
+ ============LICENSE_START=======================================================
+ feature-controller-logging
+ ================================================================================
+ 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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>feature-controller-logging</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory>lib/feature</outputDirectory>
+ <includes>
+ <include>feature-controller-logging-${project.version}.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/assembly/lib</directory>
+ <outputDirectory>lib/dependencies</outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/config</directory>
+ <outputDirectory>config</outputDirectory>
+ <fileMode>0644</fileMode>
+ <excludes />
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0744</fileMode>
+ <excludes />
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/install</directory>
+ <outputDirectory>install</outputDirectory>
+ <fileMode>0744</fileMode>
+ <excludes />
+ </fileSet>
+ </fileSets>
+
+</assembly>
diff --git a/feature-controller-logging/src/main/feature/install/disable b/feature-controller-logging/src/main/feature/install/disable
new file mode 100644
index 00000000..698b6b3d
--- /dev/null
+++ b/feature-controller-logging/src/main/feature/install/disable
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# ============LICENSE_START=======================================================
+# feature-controller-logging
+# ================================================================================
+# 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=========================================================
+
+configDir=${POLICY_HOME}/config
+for mainConfig in ${configDir}/logback.xml ${configDir}/logback-eelf.xml; do
+ if [ -e "${mainConfig}" ]; then
+ sed -i --follow-symlinks "/\<include.*logback\-include\-.*\.xml\>/d" "${mainConfig}"
+ fi
+done \ No newline at end of file
diff --git a/feature-controller-logging/src/main/feature/install/enable b/feature-controller-logging/src/main/feature/install/enable
new file mode 100644
index 00000000..170598b3
--- /dev/null
+++ b/feature-controller-logging/src/main/feature/install/enable
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# ============LICENSE_START=======================================================
+# feature-controller-logging
+# ================================================================================
+# 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=========================================================
+
+configDir=${POLICY_HOME}/config
+for includedConfig in $(ls "${configDir}" | grep "logback-include-.*.xml"); do
+ include="\t\<include optional\=\"true\" resource\=\"${includedConfig}\"/\>"
+ for mainConfig in ${configDir}/logback.xml ${configDir}/logback-eelf.xml; do
+ if [ -e "${mainConfig}" ]; then
+ sed -i --follow-symlinks "/\<configuration.*\> /a\ ${include}" "${mainConfig}"
+ fi
+ done
+done \ No newline at end of file
diff --git a/feature-controller-logging/src/main/java/org/onap/policy/drools/controller/logging/ControllerLoggingFeature.java b/feature-controller-logging/src/main/java/org/onap/policy/drools/controller/logging/ControllerLoggingFeature.java
new file mode 100755
index 00000000..ec59ace6
--- /dev/null
+++ b/feature-controller-logging/src/main/java/org/onap/policy/drools/controller/logging/ControllerLoggingFeature.java
@@ -0,0 +1,97 @@
+/*
+ * ============LICENSE_START=======================================================
+ * feature-controller-logging
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.policy.drools.controller.logging;
+
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.features.DroolsControllerFeatureAPI;
+import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
+import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
+import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
+import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class hooks the network logging implementation into DroolsPDP. It will disable the
+ * default network logger where all topic traffic is logged and segregates the topic
+ * traffic by controller for each supported control loop use case.
+ */
+
+/*
+ * PolicyControllerFeatureAPI - the 'beforeStart' hook is used to shut off the default
+ * network logger and the 'beforeOffer' hook is used to log incoming topic messages
+ *
+ * DroolsControllerFeatureAPI - the 'afterDeliver' hook is where the outgoing topic
+ * messages are logged
+ *
+ */
+public class ControllerLoggingFeature
+ implements PolicyEngineFeatureAPI, DroolsControllerFeatureAPI, PolicyControllerFeatureAPI {
+
+ @Override
+ public int getSequenceNumber() {
+ return 1000;
+ }
+
+ /**
+ * The 'beforeOffer' hook will intercept an incoming topic message and append it to
+ * the log file that is configured for the controller logger.
+ */
+ @Override
+ public boolean beforeOffer(PolicyController controller, CommInfrastructure protocol, String topic, String event) {
+ Logger controllerLogger = LoggerFactory.getLogger(controller.getName());
+ controllerLogger.info("[IN|{}|{}]{}{}", protocol, topic, System.lineSeparator(), event);
+ return false;
+ }
+
+ /**
+ * The 'afterDeliver' hook will intercept an outgoing topic message and append it to
+ * the log file that is configured for the controller logger.
+ */
+ @Override
+ public boolean afterDeliver(DroolsController controller, TopicSink sink, Object fact, String json,
+ boolean success) {
+ if (success) {
+ Logger controllerLogger = LoggerFactory.getLogger(PolicyController.factory.get(controller).getName());
+ controllerLogger.info("[OUT|{}|{}]{}{}", sink.getTopicCommInfrastructure(), sink.getTopic(),
+ System.lineSeparator(), json);
+ }
+ return false;
+ }
+
+ /**
+ * The 'afterOnTopicEvent' hook will determine which controllers were updated and log
+ * the event to the appropriate controller logs.
+ */
+ @Override
+ public boolean afterOnTopicEvent(PolicyEngine engine, PdpdConfiguration configuration, CommInfrastructure commType,
+ String topic, String event) {
+ for (ControllerConfiguration controller : configuration.getControllers()) {
+ Logger controllerLogger = LoggerFactory.getLogger(controller.getName());
+ controllerLogger.info("[IN|{}|{}]{}{}", commType, topic, System.lineSeparator(), event);
+ }
+ return false;
+ }
+}
diff --git a/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.DroolsControllerFeatureAPI b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.DroolsControllerFeatureAPI
new file mode 100755
index 00000000..dbde0a80
--- /dev/null
+++ b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.DroolsControllerFeatureAPI
@@ -0,0 +1 @@
+org.onap.policy.drools.controller.logging.ControllerLoggingFeature
diff --git a/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyControllerFeatureAPI b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyControllerFeatureAPI
new file mode 100755
index 00000000..dbde0a80
--- /dev/null
+++ b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyControllerFeatureAPI
@@ -0,0 +1 @@
+org.onap.policy.drools.controller.logging.ControllerLoggingFeature
diff --git a/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureAPI b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureAPI
new file mode 100755
index 00000000..dbde0a80
--- /dev/null
+++ b/feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureAPI
@@ -0,0 +1 @@
+org.onap.policy.drools.controller.logging.ControllerLoggingFeature
diff --git a/feature-controller-logging/src/test/java/org/onap/policy/drools/controller/logging/ControllerLoggingTest.java b/feature-controller-logging/src/test/java/org/onap/policy/drools/controller/logging/ControllerLoggingTest.java
new file mode 100755
index 00000000..02e879fd
--- /dev/null
+++ b/feature-controller-logging/src/test/java/org/onap/policy/drools/controller/logging/ControllerLoggingTest.java
@@ -0,0 +1,228 @@
+/*
+ * ============LICENSE_START=======================================================
+ * feature-controller-logging
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.policy.drools.controller.logging;
+
+import static org.junit.Assert.assertEquals;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
+import org.onap.policy.drools.controller.DroolsController;
+import org.onap.policy.drools.controller.logging.ControllerLoggingFeature;
+import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
+import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.util.KieUtils;
+
+/**
+ * Controller Logger Tests.
+ */
+public class ControllerLoggingTest {
+
+ /**
+ * These properties are for installing a test artifact that the drools controller can
+ * fetch while testing.
+ */
+ private static final String JUNIT_KMODULE_DRL_PATH = "src/test/resources/test.drl";
+ private static final String JUNIT_KMODULE_POM_PATH = "src/test/resources/test.pom";
+ private static final String JUNIT_KMODULE_PATH = "src/test/resources/kmodule.xml";
+ private static final String JUNIT_KJAR_DRL_PATH = "src/main/resources/org/onap/policy/drools/test/test.drl";
+
+ /**
+ * These properties are used for the Policy Controller to point to the test artifact.
+ */
+ private static final String TEST_CONTROLLER_NAME = "test-controller";
+ private static final String TEST_GROUP_ID = "org.onap.policy.drools.test";
+ private static final String TEST_ARTIFACT_ID = "test";
+ private static final String TEST_VERSION = "1.4.0-SNAPSHOT";
+
+ /**
+ * A test topic used for delivery and network logging.
+ */
+ private static final String TEST_TOPIC = "test-topic";
+ private static final String TEST_SERVER = "http://test.com";
+
+ /**
+ * These are used for sending PDPD configuration notifications to a policy controller.
+ */
+ private static Properties controllerProps = null;
+ private static String message = null;
+ private static PdpdConfiguration pdpdNotification = null;
+ private static PolicyController policyController = null;
+
+ /**
+ * This is a list of events that are appended to the controller-test logger.
+ */
+ private static List<LoggingEvent> events = new ArrayList<>();
+
+ /**
+ * A custom appender used to intercept events and add them to a list of events that
+ * the junits can use to determine logging was successful.
+ */
+ public static class NetworkAppender extends AppenderBase<LoggingEvent> {
+
+ @Override
+ protected void append(LoggingEvent event) {
+ events.add(event);
+ }
+
+ }
+
+ /**
+ * Runs before all the test cases to install the drools artifact, create a policy
+ * controller, and create a PDPD configuration notification.
+ */
+ @BeforeClass
+ public static void setUp() throws IOException {
+ KieUtils.installArtifact(Paths.get(JUNIT_KMODULE_PATH).toFile(), Paths.get(JUNIT_KMODULE_POM_PATH).toFile(),
+ JUNIT_KJAR_DRL_PATH, Paths.get(JUNIT_KMODULE_DRL_PATH).toFile());
+
+ controllerProps = new Properties();
+ controllerProps.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
+ controllerProps.put(DroolsProperties.RULES_GROUPID, TEST_GROUP_ID);
+ controllerProps.put(DroolsProperties.RULES_ARTIFACTID, TEST_ARTIFACT_ID);
+ controllerProps.put(DroolsProperties.RULES_VERSION, TEST_VERSION);
+
+ policyController = PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProps);
+
+ message = "{\"requestID\":\"38adde30-cc22-11e8-a8d5-f2801f1b9fd1\",\"entity\":\"controller\",\"controllers\":"
+ + "[{\"name\":\"test-controller\",\"drools\":{\"groupId\":\"org.onap.policy.drools.test\","
+ + "\"artifactId\":\"test\",\"version\":\"0.0.1\"},\"operation\":\"update\"}]}";
+
+ Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
+ pdpdNotification = decoder.fromJson(message, PdpdConfiguration.class);
+ }
+
+ /**
+ * Runs after every test case to clean up the events added to the event list during
+ * unit test.
+ */
+ @After
+ public void cleanUpLogs() {
+ events.clear();
+ }
+
+ /**
+ * Obtains the sequence number of the controller logging feature. This should return
+ * 1000.
+ */
+ @Test
+ public void getSequenceNumberTest() {
+ ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+ assertEquals(1000, nlf.getSequenceNumber());
+ }
+
+ /**
+ * Asserts that the controller-test logger appends the incoming message to the event
+ * list.
+ */
+ @Test
+ public void beforeOffer() {
+ ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+
+ nlf.beforeOffer(policyController, Topic.CommInfrastructure.UEB, TEST_TOPIC, "{\"test\":\"test\"}");
+
+ assertEquals(1, events.size());
+ }
+
+ /**
+ * Asserts that the controller-test logger appends the outgoing message to the event
+ * list.
+ */
+ @Test
+ public void afterDeliverSuccess() {
+
+ final ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+
+ DroolsController droolsController = DroolsController.factory.get(TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION);
+
+ NoopTopicSink sinkTopic = new NoopTopicSink(Arrays.asList(TEST_SERVER), TEST_TOPIC);
+
+ nlf.afterDeliver(droolsController, sinkTopic, null, "{\"test\":\"test\"}", true);
+
+ assertEquals(1, events.size());
+
+ }
+
+ /**
+ * Asserts that the controller-test logger does not append the outgoing message to the
+ * event list if there was a failure.
+ */
+ @Test
+ public void afterDeliverFailure() {
+
+ final ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+
+ DroolsController droolsController = DroolsController.factory.get(TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION);
+
+ NoopTopicSink sinkTopic = new NoopTopicSink(Arrays.asList(TEST_SERVER), TEST_TOPIC);
+
+ nlf.afterDeliver(droolsController, sinkTopic, null, "{\"test\":\"test\"}", false);
+
+ assertEquals(0, events.size());
+ }
+
+ /**
+ * Asserts that the controller logging feature can log the messages to the proper
+ * controller based on the message containing the controller name.
+ */
+ @Test
+ public void afterOnTopicEventSuccess() {
+ final ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+
+ nlf.afterOnTopicEvent(PolicyEngine.manager, pdpdNotification, CommInfrastructure.UEB, TEST_TOPIC, message);
+
+ assertEquals(1, events.size());
+ }
+
+ /**
+ * Asserts that the controller logging feature can skip logging messages that don't
+ * contain the controller names in it.
+ */
+ @Test
+ public void afterOnTopicEventFailure() {
+ final ControllerLoggingFeature nlf = new ControllerLoggingFeature();
+
+ PdpdConfiguration notification = new PdpdConfiguration();
+ ControllerConfiguration config = new ControllerConfiguration();
+ config.setName("test-controller-2");
+ notification.setControllers(Arrays.asList(config));
+
+ nlf.afterOnTopicEvent(PolicyEngine.manager, notification, CommInfrastructure.UEB, TEST_TOPIC, message);
+
+ assertEquals(0, events.size());
+ }
+}
diff --git a/feature-controller-logging/src/test/resources/kmodule.xml b/feature-controller-logging/src/test/resources/kmodule.xml
new file mode 100755
index 00000000..2410a0f7
--- /dev/null
+++ b/feature-controller-logging/src/test/resources/kmodule.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ feature-controller-logging
+ ================================================================================
+ 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=========================================================
+ -->
+
+<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
+ <kbase name="controller-logs">
+ <ksession name="test" />
+ </kbase>
+</kmodule>
diff --git a/feature-controller-logging/src/test/resources/logback-test.xml b/feature-controller-logging/src/test/resources/logback-test.xml
new file mode 100755
index 00000000..dfe9a459
--- /dev/null
+++ b/feature-controller-logging/src/test/resources/logback-test.xml
@@ -0,0 +1,41 @@
+<!--
+ ============LICENSE_START=======================================================
+ feature-controller-logging
+ ================================================================================
+ 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=========================================================
+ -->
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
+ </Pattern>
+ </encoder>
+ </appender>
+ <logger name="org.onap.policy.drools.system.test" level="INFO" />
+
+ <appender name="network"
+ class="org.onap.policy.drools.controller.logging.ControllerLoggingTest$NetworkAppender" />
+ <logger name="test-controller" level="INFO">
+ <appender-ref ref="network" />
+ </logger>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration> \ No newline at end of file
diff --git a/feature-controller-logging/src/test/resources/test.drl b/feature-controller-logging/src/test/resources/test.drl
new file mode 100755
index 00000000..dcae7fa3
--- /dev/null
+++ b/feature-controller-logging/src/test/resources/test.drl
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * feature-controller-logging
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.policy.drools.test;
+
+rule "INIT"
+when
+then
+ insert("This is a test");
+end
+
+rule "PRINT_MSG"
+when
+ $o : Object();
+then
+ System.out.println("MSG: " + $o);
+ retract($o);
+end
diff --git a/feature-controller-logging/src/test/resources/test.pom b/feature-controller-logging/src/test/resources/test.pom
new file mode 100755
index 00000000..2226b9fd
--- /dev/null
+++ b/feature-controller-logging/src/test/resources/test.pom
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ feature-controller-logging
+ ================================================================================
+ 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=========================================================
+ -->
+
+<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>
+
+ <groupId>org.onap.policy.drools.test</groupId>
+ <artifactId>test</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+
+</project>
diff --git a/feature-eelf/src/main/feature/config/logback-eelf.xml b/feature-eelf/src/main/feature/config/logback-eelf.xml
index 4dafd45d..90b7f45e 100644
--- a/feature-eelf/src/main/feature/config/logback-eelf.xml
+++ b/feature-eelf/src/main/feature/config/logback-eelf.xml
@@ -2,7 +2,7 @@
============LICENSE_START=======================================================
feature-eelf
================================================================================
- 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.
diff --git a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
index bf0f0000..5f99d3ba 100644
--- a/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
+++ b/feature-eelf/src/main/java/org/onap/policy/drools/eelf/EelfFeature.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-eelf
* ================================================================================
- * 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.
@@ -27,8 +27,8 @@ import org.onap.policy.common.logging.eelf.Configuration;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
-import org.onap.policy.drools.system.Main;
import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
/**
* Feature EELF : Enables EELF Logging Libraries .
@@ -38,8 +38,8 @@ public class EelfFeature implements PolicyEngineFeatureAPI {
@Override
public final boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {
- String logback = System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
- Main.LOGBACK_CONFIGURATION_FILE_DEFAULT);
+ String logback = System.getProperty(LoggerUtil.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
+ LoggerUtil.LOGBACK_CONFIGURATION_FILE_DEFAULT);
Path logbackPath = Paths.get(logback);
if (System.getProperty(Configuration.PROPERTY_LOGGING_FILE_PATH) == null) {
@@ -55,7 +55,7 @@ public class EelfFeature implements PolicyEngineFeatureAPI {
Logger logger = FlexLogger.getLogger(this.getClass(), true);
if (logger.isInfoEnabled()) {
- logProperty(logger, Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
+ logProperty(logger, LoggerUtil.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY);
logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_PATH);
logProperty(logger, Configuration.PROPERTY_LOGGING_FILE_NAME);
}
diff --git a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
index 7f9e81cc..5a1645a0 100644
--- a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
+++ b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-eelf
* ================================================================================
- * 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.
@@ -36,8 +36,8 @@ import java.util.List;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.drools.eelf.EelfFeature;
-import org.onap.policy.drools.system.Main;
import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -102,7 +102,7 @@ public class EElfTest {
/* set logback configuration */
- System.setProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
+ System.setProperty(LoggerUtil.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY,
LOGBACK_CONFIGURATION_FILE_DEFAULT);
/* set up eelf throuth common loggings library */
diff --git a/feature-pooling-dmaap/src/main/feature/config/feature-pooling-dmaap.properties b/feature-pooling-dmaap/src/main/feature/config/feature-pooling-dmaap.properties
index 1d549855..2786a613 100644
--- a/feature-pooling-dmaap/src/main/feature/config/feature-pooling-dmaap.properties
+++ b/feature-pooling-dmaap/src/main/feature/config/feature-pooling-dmaap.properties
@@ -84,13 +84,15 @@ pooling.beijing.topic=${env:POOLING_TOPIC}
# the list of sources and sinks should be identical
-ueb.source.topics=${env:POOLING_TOPIC}
-ueb.sink.topics=${env:POOLING_TOPIC}
-
-ueb.source.topics.${{POOLING_TOPIC}}.servers=${env:DMAAP_SERVERS}
-ueb.source.topics.${{POOLING_TOPIC}}.apiKey=
-ueb.source.topics.${{POOLING_TOPIC}}.apiSecret=
-
-ueb.sink.topics.${{POOLING_TOPIC}}.servers=${env:DMAAP_SERVERS}
-ueb.sink.topics.${{POOLING_TOPIC}}.apiKey=
-ueb.sink.topics.${{POOLING_TOPIC}}.apiSecret=
+ueb.source.topics=POOLING_TOPIC
+ueb.sink.topics=POOLING_TOPIC
+
+ueb.source.topics.POOLING_TOPIC.servers=${env:DMAAP_SERVERS}
+ueb.source.topics.POOLING_TOPIC.effectiveTopic=${env:POOLING_TOPIC}
+ueb.source.topics.POOLING_TOPIC.apiKey=
+ueb.source.topics.POOLING_TOPIC.apiSecret=
+
+ueb.sink.topics.POOLING_TOPIC.servers=${env:DMAAP_SERVERS}
+ueb.sink.topics.POOLING_TOPIC.effectiveTopic=${env:POOLING_TOPIC}
+ueb.sink.topics.POOLING_TOPIC.apiKey=
+ueb.sink.topics.POOLING_TOPIC.apiSecret=
diff --git a/packages/docker/src/main/docker/Dockerfile b/packages/docker/src/main/docker/Dockerfile
index 087dcb47..829bb6b0 100644
--- a/packages/docker/src/main/docker/Dockerfile
+++ b/packages/docker/src/main/docker/Dockerfile
@@ -1,14 +1,10 @@
FROM ubuntu:14.04
-ARG HTTP_PROXY=${HTTP_PROXY}
-ARG HTTPS_PROXY=${HTTPS_PROXY}
ARG BUILD_VERSION=${BUILD_VERSION}
ARG POLICY_HOME=/opt/app/policy
ARG POLICY_LOGS=/var/log/onap/policy/pdpd
ARG POLICY_INSTALL=/tmp/policy-install
-ENV http_proxy $HTTP_PROXY
-ENV https_proxy $HTTPS_PROXY
ENV BUILD_VERSION ${BUILD_VERSION}
ENV POLICY_INSTALL ${POLICY_INSTALL}
ENV POLICY_HOME ${POLICY_HOME}
diff --git a/packages/docker/src/main/docker/do-start.sh b/packages/docker/src/main/docker/do-start.sh
index 91402e62..4687e421 100644
--- a/packages/docker/src/main/docker/do-start.sh
+++ b/packages/docker/src/main/docker/do-start.sh
@@ -1,9 +1,9 @@
#!/bin/bash
###
# ============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.
@@ -19,84 +19,71 @@
# ============LICENSE_END=========================================================
###
-# skip installation if build.info file is present (restarting an existing container)
-if [[ -f ${POLICY_HOME}/etc/build.info ]]; then
- echo "Found existing installation, will not reinstall"
- . ${POLICY_HOME}/etc/profile.d/env.sh
-else
- echo "installing .."
-
- # replace conf files from installer with environment-specific files
- # mounted from the hosting VM
- if [[ -d config ]]; then
- cp config/*.conf .
- fi
-
- if [[ -f config/drools-preinstall.sh ]] ; then
- echo "found preinstallation script"
- bash config/drools-preinstall.sh
- fi
-
- # remove broken symbolic links if any in data directory
- if [[ -d ${POLICY_HOME}/config ]]; then
- echo "removing dangling symbolic links"
- find -L ${POLICY_HOME}/config -type l -exec rm -- {} +
- fi
-
- apps=$(ls config/apps*.zip 2> /dev/null)
- for app in $apps
- do
- echo "Application found: ${app}"
- unzip -o ${app}
- done
-
- feats=$(ls config/feature*.zip 2> /dev/null)
- for feat in $feats
- do
- echo "Feature found: ${feat}"
- cp ${feat} .
- done
-
- echo "docker install at ${PWD}"
-
- ./docker-install.sh
-
- . ${POLICY_HOME}/etc/profile.d/env.sh
-
- # allow user to override the key or/and the trust stores
-
- if [[ -f config/policy-keystore ]]; then
- cp -f config/policy-keystore ${POLICY_HOME}/etc/ssl
- fi
-
- if [[ -f config/policy-truststore ]]; then
- cp -f config/policy-truststore ${POLICY_HOME}/etc/ssl
- fi
-
- # allow user to override all or some aaf configuration
-
- if [[ -f config/aaf.properties ]]; then
- cp -f config/aaf.properties ${POLICY_HOME}/config/aaf.properties
- fi
-
- if [[ -f config/aaf-location.properties ]]; then
- cp -f config/aaf-location.properties ${POLICY_HOME}/config/aaf-location.properties
- fi
-
- if [[ -f config/aaf-credentials.properties ]]; then
- cp -f config/aaf-credentials.properties ${POLICY_HOME}/config/aaf-credentials.properties
- fi
-
- if [[ -f config/aaf-cadi.keyfile ]]; then
- cp -f config/aaf-cadi.keyfile ${POLICY_HOME}/config/aaf-cadi.keyfile
- fi
-
- if [[ -f config/drools-tweaks.sh ]] ; then
- echo "Executing tweaks"
- # file may not be executable; running it as an
- # argument to bash avoids needing execute perms.
- bash config/drools-tweaks.sh
- fi
+echo "installing .."
+
+# replace conf files from installer with environment-specific files
+# mounted from the hosting VM
+
+if [[ -d config ]]; then
+ cp config/*.conf .
+fi
+
+if [[ -f config/drools-preinstall.sh ]] ; then
+ echo "found preinstallation script"
+ bash config/drools-preinstall.sh
+fi
+
+# remove broken symbolic links if any in data directory
+if [[ -d ${POLICY_HOME}/config ]]; then
+ echo "removing dangling symbolic links"
+ find -L ${POLICY_HOME}/config -type l -exec rm -- {} +
+fi
+
+apps=$(ls config/apps*.zip 2> /dev/null)
+for app in $apps
+do
+ echo "Application found: ${app}"
+ unzip -o ${app}
+done
+
+feats=$(ls config/feature*.zip 2> /dev/null)
+for feat in $feats
+do
+ echo "Feature found: ${feat}"
+ cp ${feat} .
+done
+
+echo "docker install at ${PWD}"
+
+./docker-install.sh
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
+
+# allow user to override the key or/and the trust stores
+
+if [[ -f config/policy-keystore ]]; then
+ cp -f config/policy-keystore ${POLICY_HOME}/etc/ssl
+fi
+
+if [[ -f config/policy-truststore ]]; then
+ cp -f config/policy-truststore ${POLICY_HOME}/etc/ssl
+fi
+
+# allow user to override all or some aaf configuration
+
+if [[ -f config/aaf.properties ]]; then
+ cp -f config/aaf.properties ${POLICY_HOME}/config/aaf.properties
+fi
+
+if [[ -f config/aaf-cadi.keyfile ]]; then
+ cp -f config/aaf-cadi.keyfile ${POLICY_HOME}/config/aaf-cadi.keyfile
+fi
+
+if [[ -f config/drools-tweaks.sh ]] ; then
+ echo "Executing tweaks"
+ # file may not be executable; running it as an
+ # argument to bash avoids needing execute perms.
+ bash config/drools-tweaks.sh
fi
echo "Starting processes"
diff --git a/packages/install/pom.xml b/packages/install/pom.xml
index 809c9e75..e603fb6f 100644
--- a/packages/install/pom.xml
+++ b/packages/install/pom.xml
@@ -118,6 +118,12 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>feature-controller-logging</artifactId>
+ <version>${project.version}</version>
+ <type>zip</type>
+ </dependency>
</dependencies>
</project>
diff --git a/packages/install/src/files/base.conf b/packages/install/src/files/base.conf
index 4d38301b..70b165f2 100644
--- a/packages/install/src/files/base.conf
+++ b/packages/install/src/files/base.conf
@@ -18,6 +18,10 @@
# ============LICENSE_END=========================================================
###
+# JVM options
+
+JVM_OPTIONS=-server -Xms512m -Xmx1024m
+
# SYSTEM software configuration
POLICY_HOME=/opt/app/policy
@@ -38,6 +42,7 @@ TELEMETRY_PASSWORD=
SNAPSHOT_REPOSITORY_ID=
SNAPSHOT_REPOSITORY_URL=
RELEASE_REPOSITORY_ID=
+RELEASE_REPOSITORY_URL=
REPOSITORY_USERNAME=
REPOSITORY_PASSWORD=
@@ -56,7 +61,6 @@ AAF_HOST=aaf-onap-test.osaaf.org
# PDP-D DMaaP configuration channel
PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
-PDPD_CONFIGURATION_SERVERS=
PDPD_CONFIGURATION_API_KEY=
PDPD_CONFIGURATION_API_SECRET=
PDPD_CONFIGURATION_CONSUMER_GROUP=
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
index 6a4b8f22..eb401eba 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
@@ -7,9 +7,9 @@
* 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.
@@ -54,7 +54,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Maven-based Drools Controller that interacts with the
+ * Maven-based Drools Controller that interacts with the
* policy-core PolicyContainer and PolicySession to manage
* Drools containers instantiated using Maven.
*/
@@ -73,7 +73,7 @@ public class MavenDroolsController implements DroolsController {
protected final PolicyContainer policyContainer;
/**
- * alive status of this drools controller,
+ * alive status of this drools controller,
* reflects invocation of start()/stop() only.
*/
protected volatile boolean alive = false;
@@ -82,7 +82,7 @@ public class MavenDroolsController implements DroolsController {
* locked status of this drools controller,
* reflects if i/o drools related operations are permitted,
* more specifically: offer() and deliver().
- * It does not affect the ability to start and stop
+ * It does not affect the ability to start and stop
* underlying drools infrastructure
*/
protected volatile boolean locked = false;
@@ -116,17 +116,17 @@ public class MavenDroolsController implements DroolsController {
/**
* Expanded version of the constructor.
- *
+ *
* @param groupId maven group id
* @param artifactId maven artifact id
* @param version maven version
* @param decoderConfigurations list of topic -> decoders -> filters mapping
* @param encoderConfigurations list of topic -> encoders -> filters mapping
- *
+ *
* @throws IllegalArgumentException invalid arguments passed in
*/
- public MavenDroolsController(String groupId,
- String artifactId,
+ public MavenDroolsController(String groupId,
+ String artifactId,
String version,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations) {
@@ -153,7 +153,7 @@ public class MavenDroolsController implements DroolsController {
/**
* init encoding/decoding configuration.
- *
+ *
* @param decoderConfigurations list of topic -> decoders -> filters mapping
* @param encoderConfigurations list of topic -> encoders -> filters mapping
*/
@@ -172,7 +172,7 @@ public class MavenDroolsController implements DroolsController {
@Override
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
- List<TopicCoderFilterConfiguration> encoderConfigurations)
+ List<TopicCoderFilterConfiguration> encoderConfigurations)
throws LinkageError {
logger.info("updating version -> [{}:{}:{}]", newGroupId, newArtifactId, newVersion);
@@ -189,27 +189,27 @@ public class MavenDroolsController implements DroolsController {
throw new IllegalArgumentException("Missing maven version coordinate");
}
- if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID)
- || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID)
+ if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID)
+ || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID)
|| newVersion.equalsIgnoreCase(DroolsController.NO_VERSION)) {
- throw new IllegalArgumentException("BRAINLESS maven coordinates provided: "
- + newGroupId + ":" + newArtifactId + ":"
+ throw new IllegalArgumentException("BRAINLESS maven coordinates provided: "
+ + newGroupId + ":" + newArtifactId + ":"
+ newVersion);
}
if (newGroupId.equalsIgnoreCase(this.getGroupId())
&& newArtifactId.equalsIgnoreCase(this.getArtifactId())
&& newVersion.equalsIgnoreCase(this.getVersion())) {
- logger.warn("Al in the right version: " + newGroupId + ":"
+ logger.warn("Al in the right version: " + newGroupId + ":"
+ newArtifactId + ":" + newVersion + " vs. " + this);
return;
}
- if (!newGroupId.equalsIgnoreCase(this.getGroupId())
+ if (!newGroupId.equalsIgnoreCase(this.getGroupId())
|| !newArtifactId.equalsIgnoreCase(this.getArtifactId())) {
throw new IllegalArgumentException(
- "Group ID and Artifact ID maven coordinates must be identical for the upgrade: "
- + newGroupId + ":" + newArtifactId + ":"
+ "Group ID and Artifact ID maven coordinates must be identical for the upgrade: "
+ + newGroupId + ":" + newArtifactId + ":"
+ newVersion + " vs. " + this);
}
@@ -238,10 +238,10 @@ public class MavenDroolsController implements DroolsController {
* initialize decoders for all the topics supported by this controller
* Note this is critical to be done after the Policy Container is
* instantiated to be able to fetch the corresponding classes.
- *
+ *
* @param coderConfigurations list of topic -> decoders -> filters mapping
*/
- protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations,
+ protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations,
boolean decoder) {
if (logger.isInfoEnabled()) {
@@ -257,7 +257,7 @@ public class MavenDroolsController implements DroolsController {
String topic = coderConfig.getTopic();
CustomGsonCoder customGsonCoder = coderConfig.getCustomGsonCoder();
- if (coderConfig.getCustomGsonCoder() != null
+ if (coderConfig.getCustomGsonCoder() != null
&& coderConfig.getCustomGsonCoder().getClassContainer() != null
&& !coderConfig.getCustomGsonCoder().getClassContainer().isEmpty()) {
@@ -281,7 +281,7 @@ public class MavenDroolsController implements DroolsController {
String potentialCodedClass = coderFilter.getCodedClass();
JsonProtocolFilter protocolFilter = coderFilter.getFilter();
- if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
+ if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
potentialCodedClass)) {
throw makeRetrieveEx(potentialCodedClass);
} else {
@@ -378,7 +378,7 @@ public class MavenDroolsController implements DroolsController {
if (modelHash == this.modelClassLoaderHash) {
if (logger.isInfoEnabled()) {
- logger.info(coderClass.getCanonicalName()
+ logger.info(coderClass.getCanonicalName()
+ this + " class loader matches original drools controller rules classloader "
+ coderClass.getClassLoader());
}
@@ -386,7 +386,7 @@ public class MavenDroolsController implements DroolsController {
} else {
if (logger.isWarnEnabled()) {
logger.warn(this + coderClass.getCanonicalName() + " class loaders don't match "
- + coderClass.getClassLoader() + " vs "
+ + coderClass.getClassLoader() + " vs "
+ this.policyContainer.getClassLoader());
}
return false;
@@ -498,11 +498,11 @@ public class MavenDroolsController implements DroolsController {
// 1. Now, check if this topic has a decoder:
- if (!EventProtocolCoder.manager.isDecodingSupported(this.getGroupId(),
- this.getArtifactId(),
+ if (!EventProtocolCoder.manager.isDecodingSupported(this.getGroupId(),
+ this.getArtifactId(),
topic)) {
- logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", this,
+ logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", this,
topic, this.getGroupId(), this.getArtifactId());
return true;
}
@@ -511,16 +511,16 @@ public class MavenDroolsController implements DroolsController {
Object anEvent;
try {
- anEvent = EventProtocolCoder.manager.decode(this.getGroupId(),
- this.getArtifactId(),
- topic,
+ anEvent = EventProtocolCoder.manager.decode(this.getGroupId(),
+ this.getArtifactId(),
+ topic,
event);
} catch (UnsupportedOperationException uoe) {
- logger.debug("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
+ logger.debug("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
event, uoe.getMessage(), uoe);
return true;
} catch (Exception e) {
- logger.warn("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
+ logger.warn("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
event, e.getMessage(), e);
return true;
}
@@ -530,12 +530,12 @@ public class MavenDroolsController implements DroolsController {
}
// increment event count for Nagios monitoring
- PdpJmx.getInstance().updateOccured();
+ PdpJmx.getInstance().updateOccured();
// Broadcast
if (logger.isInfoEnabled()) {
- logger.info("{} BROADCAST-INJECT of {} FROM {} INTO {}",
+ logger.info("{} BROADCAST-INJECT of {} FROM {} INTO {}",
this, event, topic, this.policyContainer.getName());
}
@@ -575,7 +575,19 @@ public class MavenDroolsController implements DroolsController {
if (logger.isInfoEnabled()) {
logger.info("{}DELIVER: {} FROM {} TO {}", this, event, this, sink);
}
-
+
+ for (DroolsControllerFeatureAPI feature : DroolsControllerFeatureAPI.providers.getList()) {
+ try {
+ if (feature.beforeDeliver(this, sink, event)) {
+ return true;
+ }
+ }
+ catch (Exception e) {
+ logger.error("{}: feature {} before-deliver failure because of {}", this, feature.getClass().getName(),
+ e.getMessage(), e);
+ }
+ }
+
if (sink == null) {
throw new IllegalArgumentException(this + " invalid sink");
}
@@ -583,7 +595,7 @@ public class MavenDroolsController implements DroolsController {
if (event == null) {
throw new IllegalArgumentException(this + " invalid event");
}
-
+
if (this.locked) {
throw new IllegalStateException(this + " is locked");
}
@@ -599,7 +611,21 @@ public class MavenDroolsController implements DroolsController {
this.recentSinkEvents.add(json);
}
- return sink.send(json);
+ boolean success = sink.send(json);
+
+ for (DroolsControllerFeatureAPI feature : DroolsControllerFeatureAPI.providers.getList()) {
+ try {
+ if (feature.afterDeliver(this, sink, event, json, success)) {
+ return true;
+ }
+ }
+ catch (Exception e) {
+ logger.error("{}: feature {} after-deliver failure because of {}", this, feature.getClass().getName(),
+ e.getMessage(), e);
+ }
+ }
+
+ return success;
}
@@ -620,7 +646,7 @@ public class MavenDroolsController implements DroolsController {
/**
* Get model class loader hash.
- *
+ *
* @return the modelClassLoaderHash
*/
public int getModelClassLoaderHash() {
@@ -664,7 +690,7 @@ public class MavenDroolsController implements DroolsController {
/**
* get session names.
- *
+ *
* @param abbreviated true for the short form, otherwise the long form
* @return session names
*/
@@ -699,7 +725,7 @@ public class MavenDroolsController implements DroolsController {
/**
* provides the underlying core layer container sessions.
- *
+ *
* @return the attached Policy Container
*/
protected List<PolicySession> getSessions() {
@@ -710,7 +736,7 @@ public class MavenDroolsController implements DroolsController {
/**
* provides the underlying core layer container session with name sessionName.
- *
+ *
* @param sessionName session name
* @return the attached Policy Container
* @throws IllegalArgumentException when an invalid session name is provided
@@ -783,7 +809,7 @@ public class MavenDroolsController implements DroolsController {
throw new IllegalArgumentException("Invalid Class Name: " + className);
}
- Class<?> factClass =
+ Class<?> factClass =
ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
if (factClass == null) {
throw new IllegalArgumentException("Class cannot be fetched in model's classloader: " + className);
@@ -810,7 +836,7 @@ public class MavenDroolsController implements DroolsController {
}
@Override
- public List<Object> factQuery(String sessionName, String queryName, String queriedEntity,
+ public List<Object> factQuery(String sessionName, String queryName, String queriedEntity,
boolean delete, Object... queryParams) {
if (sessionName == null || sessionName.isEmpty()) {
throw invalidSessNameEx(sessionName);
@@ -864,7 +890,7 @@ public class MavenDroolsController implements DroolsController {
/**
* Get recent source events.
- *
+ *
* @return the recentSourceEvents
*/
@Override
@@ -877,7 +903,7 @@ public class MavenDroolsController implements DroolsController {
/**
* Get recent sink events.
- *
+ *
* @return the recentSinkEvents
*/
@Override
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java
index 135e1c58..d8663f10 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/DroolsControllerFeatureAPI.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.features;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.utils.OrderedService;
import org.onap.policy.drools.utils.OrderedServiceImpl;
@@ -53,6 +54,28 @@ public interface DroolsControllerFeatureAPI extends OrderedService {
}
/**
+ * Intercept before the Drools Controller delivers (posts) an event.
+ *
+ * @return True if this feature intercepts and takes ownership
+ * of the operation preventing the invocation of
+ * lower priority features. False, otherwise
+ */
+ default boolean beforeDeliver(DroolsController controller, TopicSink sink, Object fact) {
+ return false;
+ }
+
+ /**
+ * Called after the Drools Controller delivers (posts) an event.
+ *
+ * @return True if this feature intercepts and takes ownership of the operation
+ * preventing the invocation of lower priority features. False, otherwise
+ */
+ default boolean afterDeliver(DroolsController controller, TopicSink sink, Object fact, String json,
+ boolean success) {
+ return false;
+ }
+
+ /**
* Feature providers implementing this interface.
*/
public static final OrderedServiceImpl<DroolsControllerFeatureAPI> providers =
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
index c86f6e0d..a8772117 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureAPI.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* policy-engine
* ================================================================================
- * 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.
* 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.
@@ -21,7 +21,8 @@
package org.onap.policy.drools.features;
import java.util.Properties;
-
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.utils.OrderedService;
import org.onap.policy.drools.utils.OrderedServiceImpl;
@@ -34,14 +35,14 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* Feature providers implementing this interface.
*/
- public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers =
+ public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers =
new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class);
/**
* intercept before the Policy Engine is commanded to boot.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeBoot(PolicyEngine engine, String[] cliArgs) {
@@ -50,9 +51,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is booted.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterBoot(PolicyEngine engine) {
@@ -61,9 +62,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine is configured.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeConfigure(PolicyEngine engine, Properties properties) {
@@ -72,9 +73,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is configured.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterConfigure(PolicyEngine engine) {
@@ -83,9 +84,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine goes active.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeActivate(PolicyEngine engine) {
@@ -94,9 +95,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine goes active.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterActivate(PolicyEngine engine) {
@@ -105,9 +106,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine goes standby.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeDeactivate(PolicyEngine engine) {
@@ -116,9 +117,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine goes standby.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterDeactivate(PolicyEngine engine) {
@@ -127,9 +128,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine is started.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeStart(PolicyEngine engine) {
@@ -138,9 +139,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is started.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterStart(PolicyEngine engine) {
@@ -149,9 +150,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine is stopped.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise..
*/
public default boolean beforeStop(PolicyEngine engine) {
@@ -160,9 +161,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is stopped.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.d.
*/
public default boolean afterStop(PolicyEngine engine) {
@@ -171,9 +172,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine is locked.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeLock(PolicyEngine engine) {
@@ -182,9 +183,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is locked.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise..
*/
public default boolean afterLock(PolicyEngine engine) {
@@ -193,9 +194,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept before the Policy Engine is locked.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean beforeUnlock(PolicyEngine engine) {
@@ -204,9 +205,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept after the Policy Engine is locked.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterUnlock(PolicyEngine engine) {
@@ -215,9 +216,9 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* intercept the Policy Engine is shut down.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise..
*/
public default boolean beforeShutdown(PolicyEngine engine) {
@@ -226,12 +227,34 @@ public interface PolicyEngineFeatureAPI extends OrderedService {
/**
* called after the Policy Engine is shut down.
- *
+ *
* @return true if this feature intercepts and takes ownership
- * of the operation preventing the invocation of
+ * of the operation preventing the invocation of
* lower priority features. False, otherwise.
*/
public default boolean afterShutdown(PolicyEngine engine) {
return false;
}
+
+ /**
+ * Intercept an event from UEB/DMaaP before the PolicyEngine processes it.
+ *
+ * @return True if this feature intercepts and takes ownership of the operation
+ * preventing the invocation of lower priority features. False, otherwise.
+ */
+ public default boolean beforeOnTopicEvent(PolicyEngine engine, CommInfrastructure commType, String topic,
+ String event) {
+ return false;
+ }
+
+ /**
+ * Called after the PolicyEngine processes the events.
+ *
+ * @return True if this feature intercepts and takes ownership of the operation
+ * preventing the invocation of lower priority features. False, otherwise
+ */
+ public default boolean afterOnTopicEvent(PolicyEngine engine, PdpdConfiguration configuration,
+ CommInfrastructure commType, String topic, String event) {
+ return false;
+ }
}
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..86655fff 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;
}
@@ -695,7 +699,7 @@ class PolicyEngineManager implements PolicyEngine {
throw new IllegalArgumentException(controllerName + " is invalid");
}
- logger.warn("controller being recovered. {} Reset controller's bad maven coordinates to brainless",
+ logger.warn("controller being recovered. {} Reset controller's bad maven coordinates to brainless",
controllerName);
/*
@@ -918,7 +922,7 @@ class PolicyEngineManager implements PolicyEngine {
logger.error("{}: cannot start http-server {} because of {}", this, httpServer, e.getMessage(), e);
}
}
-
+
// stop JMX?
/* policy-engine dispatch pre stop hook */
@@ -1003,7 +1007,7 @@ class PolicyEngineManager implements PolicyEngine {
exitThread.interrupt();
logger.info("{}: normal termination", this);
}
-
+
/**
* Thread that shuts down http servers.
*/
@@ -1038,13 +1042,13 @@ class PolicyEngineManager implements PolicyEngine {
doExit(0);
}
}
-
+
// these may be overridden by junit tests
protected void doSleep(long sleepMs) throws InterruptedException {
Thread.sleep(sleepMs);
}
-
+
protected void doExit(int code) {
System.exit(code);
}
@@ -1245,13 +1249,38 @@ class PolicyEngineManager implements PolicyEngine {
@Override
public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
+ /* policy-engine pre topic event hook */
+ for (final PolicyEngineFeatureAPI feature : getFeatureProviders()) {
+ try {
+ if (feature.beforeOnTopicEvent(this, commType, topic, event)) {
+ return;
+ }
+ } catch (final Exception e) {
+ logger.error("{}: feature {} beforeOnTopicEvent failure on event {} because of {}", this,
+ feature.getClass().getName(), event, e.getMessage(), e);
+ }
+ }
+
/* configuration request */
+ PdpdConfiguration configuration = null;
try {
- final PdpdConfiguration configuration = this.decoder.fromJson(event, PdpdConfiguration.class);
+ configuration = this.decoder.fromJson(event, PdpdConfiguration.class);
this.configure(configuration);
} catch (final Exception e) {
logger.error("{}: configuration-error due to {} because of {}", this, event, e.getMessage(), e);
}
+
+ /* policy-engine after topic event hook */
+ for (final PolicyEngineFeatureAPI feature : getFeatureProviders()) {
+ try {
+ if (feature.afterOnTopicEvent(this, configuration, commType, topic, event)) {
+ return;
+ }
+ } catch (final Exception e) {
+ logger.error("{}: feature {} afterOnTopicEvent failure on event {} because of {}", this,
+ feature.getClass().getName(), event, e.getMessage(), e);
+ }
+ }
}
@Override
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/logback.xml b/policy-management/src/main/server/config/logback.xml
index 538fcf80..4fb82768 100644
--- a/policy-management/src/main/server/config/logback.xml
+++ b/policy-management/src/main/server/config/logback.xml
@@ -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.
@@ -19,7 +19,7 @@
-->
<configuration scan="true" scanPeriod="30 seconds" debug="false">
-
+
<property name="logDir" value="${POLICY_LOGS}" />
<property name="errorLog" value="error" />
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"));
}
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
index 3891c858..8594995d 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
@@ -32,6 +32,7 @@ import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.configuration2.ConfigurationConverter;
+import org.apache.commons.configuration2.SystemConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,12 +78,12 @@ public class PropertyUtil {
* builders since they use the commons-beanutils (optional) library that has been
* flagged as insecured.
*/
- return ConfigurationConverter.getProperties(ConfigurationConverter.getConfiguration(rval));
+ return getInterpolatedProperties(rval);
}
/**
* Read in a properties file.
- *
+ *
* @param fileName the properties file
* @return a Properties object, containing the associated properties
* @throws IOException - subclass 'FileNotFoundException' if the file
@@ -93,6 +94,88 @@ public class PropertyUtil {
return getProperties(new File(fileName));
}
+ /**
+ * Read in a properties file, and register for update notifications.
+ * NOTE: it is possible that the first callback will occur while this
+ * method is still in progress. To avoid this problem, use 'synchronized'
+ * blocks around this invocation and in the callback -- that will ensure
+ * that the processing of the initial properties complete before any
+ * updates are processed.
+ *
+ * @param file the properties file
+ * @param listener notify if not null, this is a callback interface that is used for
+ * notifications of changes
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file
+ * does not exist or can't be opened, and 'IOException' if there is
+ * a problem loading the properties file.
+ */
+ public static Properties getProperties(File file, Listener listener)
+ throws IOException {
+ File propFile = file;
+ if (listener == null) {
+ // no listener specified -- just fetch the properties
+ return getProperties(propFile);
+ }
+
+ // Convert the file to a canonical form in order to avoid the situation
+ // where different names refer to the same file.
+ propFile = propFile.getCanonicalFile();
+
+ // See if there is an existing registration. The 'synchronized' block
+ // is needed to handle the case where a new listener is added at about
+ // the same time that another one is being removed.
+ synchronized (registrations) {
+ ListenerRegistration reg = registrations.get(propFile);
+ if (reg == null) {
+ // a new registration is needed
+ reg = new ListenerRegistration(propFile);
+ }
+ return reg.addListener(listener);
+ }
+ }
+
+ /**
+ * Read in a properties file, and register for update notifications.
+ * NOTE: it is possible that the first callback will occur while this
+ * method is still in progress. To avoid this problem, use 'synchronized'
+ * blocks around this invocation and in the callback -- that will ensure
+ * that the processing of the initial properties complete before any
+ * updates are processed.
+ *
+ * @param fileName the properties file
+ * @param listener notify if not null, this is a callback interface that is used for
+ * notifications of changes
+ * @return a Properties object, containing the associated properties
+ * @throws IOException - subclass 'FileNotFoundException' if the file
+ * does not exist or can't be opened, and 'IOException' if there is
+ * a problem loading the properties file.
+ */
+ public static Properties getProperties(String fileName, Listener listener)
+ throws IOException {
+ return getProperties(new File(fileName), listener);
+ }
+
+ /**
+ * gets interpolated properties from a properties object.
+ *
+ * @param properties object
+ * @return properties
+ */
+ public static Properties getInterpolatedProperties(Properties properties) {
+ return ConfigurationConverter.getProperties(ConfigurationConverter.getConfiguration(properties));
+ }
+
+ /**
+ * sets system properties from a properties file.
+ *
+ * @param properties properties file
+ */
+ public static void setSystemProperties(Properties properties) {
+ Properties interpolatedProps = getInterpolatedProperties(properties);
+ SystemConfiguration.setSystemProperties(ConfigurationConverter.getConfiguration(interpolatedProps));
+ }
+
/* ============================================================ */
/**
@@ -277,68 +360,6 @@ public class PropertyUtil {
}
/**
- * Read in a properties file, and register for update notifications.
- * NOTE: it is possible that the first callback will occur while this
- * method is still in progress. To avoid this problem, use 'synchronized'
- * blocks around this invocation and in the callback -- that will ensure
- * that the processing of the initial properties complete before any
- * updates are processed.
- *
- * @param file the properties file
- * @param listener notify if not null, this is a callback interface that is used for
- * notifications of changes
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(File file, Listener listener)
- throws IOException {
- File propFile = file;
- if (listener == null) {
- // no listener specified -- just fetch the properties
- return getProperties(propFile);
- }
-
- // Convert the file to a canonical form in order to avoid the situation
- // where different names refer to the same file.
- propFile = propFile.getCanonicalFile();
-
- // See if there is an existing registration. The 'synchronized' block
- // is needed to handle the case where a new listener is added at about
- // the same time that another one is being removed.
- synchronized (registrations) {
- ListenerRegistration reg = registrations.get(propFile);
- if (reg == null) {
- // a new registration is needed
- reg = new ListenerRegistration(propFile);
- }
- return reg.addListener(listener);
- }
- }
-
- /**
- * Read in a properties file, and register for update notifications.
- * NOTE: it is possible that the first callback will occur while this
- * method is still in progress. To avoid this problem, use 'synchronized'
- * blocks around this invocation and in the callback -- that will ensure
- * that the processing of the initial properties complete before any
- * updates are processed.
- *
- * @param fileName the properties file
- * @param listener notify if not null, this is a callback interface that is used for
- * notifications of changes
- * @return a Properties object, containing the associated properties
- * @throws IOException - subclass 'FileNotFoundException' if the file
- * does not exist or can't be opened, and 'IOException' if there is
- * a problem loading the properties file.
- */
- public static Properties getProperties(String fileName, Listener listener)
- throws IOException {
- return getProperties(new File(fileName), listener);
- }
-
- /**
* Stop listenening for updates.
*
* @param file the properties file
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
index 0fe848c9..1697f697 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/LoggerUtil.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.
@@ -31,6 +31,16 @@ import org.slf4j.MarkerFactory;
public class LoggerUtil {
/**
+ * Logback configuration file system property.
+ */
+ public static final String LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY = "logback.configurationFile";
+
+ /**
+ * Logback default configuration file location.
+ */
+ public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml";
+
+ /**
* Root logger.
*/
public static final String ROOT_LOGGER = "ROOT";
@@ -55,7 +65,6 @@ public class LoggerUtil {
*/
public static final Marker TRANSACTION_LOG_MARKER = MarkerFactory.getMarker(TRANSACTION_LOG_MARKER_NAME);
-
private LoggerUtil() {
// Empty constructor
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
index 2d5d356c..f05974c6 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/PropertyUtilTest.java
@@ -79,7 +79,7 @@ public class PropertyUtilTest {
* Utility method to write a properties file.
*
* @param name the file name, relative to the temporary directory
- * @param the properties to store in the file
+ * @param properties to store in the file
* @return a File instance associated with the newly-created file
* @throws IOException if the file can't be created for some reason
*/
@@ -137,10 +137,24 @@ public class PropertyUtilTest {
assertEquals(prop1, prop2);
Properties prop3 = PropertyUtil.getProperties(INTERPOLATION_PROPERTIES);
+
assertEquals("no", prop3.getProperty(INTERPOLATION_NO));
assertEquals(System.getenv("HOME"), prop3.getProperty(INTERPOLATION_ENV));
assertEquals(LoggerUtil.ROOT_LOGGER, prop3.getProperty(INTERPOLATION_CONST));
assertEquals(System.getProperty("user.home"), prop3.getProperty(INTERPOLATION_SYS));
+
+ Properties prop4 = new Properties();
+ prop4.put(INTERPOLATION_NO, "no");
+ prop4.put(INTERPOLATION_ENV, "${env:HOME}");
+ prop4.put(INTERPOLATION_CONST, "${const:org.onap.policy.drools.utils.logging.LoggerUtil.ROOT_LOGGER}");
+ prop4.put(INTERPOLATION_SYS, "${sys:user.home}");
+
+ PropertyUtil.setSystemProperties(prop4);
+
+ assertEquals("no", System.getProperty(INTERPOLATION_NO));
+ assertEquals(System.getenv("HOME"), System.getProperty(INTERPOLATION_ENV));
+ assertEquals(LoggerUtil.ROOT_LOGGER, System.getProperty(INTERPOLATION_CONST));
+ assertEquals(System.getProperty("user.home"), System.getProperty(INTERPOLATION_SYS));
}
/**
diff --git a/pom.xml b/pom.xml
index ff9cdb75..c2733c86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,7 @@
<module>feature-active-standby-management</module>
<module>feature-simulators</module>
<module>feature-distributed-locking</module>
+ <module>feature-controller-logging</module>
<module>packages</module>
</modules>