aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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--packages/install/pom.xml6
-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/system/PolicyEngine.java37
-rw-r--r--policy-management/src/main/server/config/logback.xml4
-rw-r--r--pom.xml1
21 files changed, 890 insertions, 99 deletions
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/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/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/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
index bedd8d48..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
@@ -699,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);
/*
@@ -922,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 */
@@ -1007,7 +1007,7 @@ class PolicyEngineManager implements PolicyEngine {
exitThread.interrupt();
logger.info("{}: normal termination", this);
}
-
+
/**
* Thread that shuts down http servers.
*/
@@ -1042,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);
}
@@ -1249,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/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/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>