aboutsummaryrefslogtreecommitdiffstats
path: root/feature-controller-logging
diff options
context:
space:
mode:
authorDaniel Cruz <dc443y@att.com>2019-02-22 11:31:17 -0600
committerDaniel Cruz <dc443y@att.com>2019-03-01 18:44:07 -0600
commit62e4281c0b76ecfde85d094533edd6693c2c1c5b (patch)
tree2baa4f571756c90cbbf806afa53d7ff17865935a /feature-controller-logging
parent5ac447f758d9b7a7baaf0e24a0e8621a15b8c5ff (diff)
Add Controller Logging Feature
This features provides a mechanism to extend the logback.xml properties to add controller specific loggers. The controller's logger will log messages from topics that the controller listens to in a controller specific network log. The original network log is preserved and still logs every message from every controller. Note that the way a logger is associated with a controller is by having the logger name match the controller's name. Any configuration file that has "logback-include-" prepended and a ".xml" extension will be added to the logback.xml and logback-eelf.xml files as extensions to the base configuration. Issue-ID: POLICY-1427 Change-Id: Iaeb823421eadb7ee413b6b03ae3dfe862f230612 Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'feature-controller-logging')
-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
13 files changed, 687 insertions, 0 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>