From 62e4281c0b76ecfde85d094533edd6693c2c1c5b Mon Sep 17 00:00:00 2001 From: Daniel Cruz Date: Fri, 22 Feb 2019 11:31:17 -0600 Subject: 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 --- feature-controller-logging/pom.xml | 103 ++++++++++ .../src/assembly/assemble_zip.xml | 68 ++++++ .../src/main/feature/install/disable | 26 +++ .../src/main/feature/install/enable | 29 +++ .../logging/ControllerLoggingFeature.java | 97 +++++++++ ...licy.drools.features.DroolsControllerFeatureAPI | 1 + ...licy.drools.features.PolicyControllerFeatureAPI | 1 + ...p.policy.drools.features.PolicyEngineFeatureAPI | 1 + .../controller/logging/ControllerLoggingTest.java | 228 +++++++++++++++++++++ .../src/test/resources/kmodule.xml | 26 +++ .../src/test/resources/logback-test.xml | 41 ++++ .../src/test/resources/test.drl | 35 ++++ .../src/test/resources/test.pom | 31 +++ .../src/main/feature/config/logback-eelf.xml | 2 +- packages/install/pom.xml | 6 + .../controller/internal/MavenDroolsController.java | 118 ++++++----- .../features/DroolsControllerFeatureAPI.java | 29 ++- .../drools/features/PolicyEngineFeatureAPI.java | 105 ++++++---- .../onap/policy/drools/system/PolicyEngine.java | 37 +++- .../src/main/server/config/logback.xml | 4 +- pom.xml | 1 + 21 files changed, 890 insertions(+), 99 deletions(-) create mode 100755 feature-controller-logging/pom.xml create mode 100755 feature-controller-logging/src/assembly/assemble_zip.xml create mode 100644 feature-controller-logging/src/main/feature/install/disable create mode 100644 feature-controller-logging/src/main/feature/install/enable create mode 100755 feature-controller-logging/src/main/java/org/onap/policy/drools/controller/logging/ControllerLoggingFeature.java create mode 100755 feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.DroolsControllerFeatureAPI create mode 100755 feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyControllerFeatureAPI create mode 100755 feature-controller-logging/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureAPI create mode 100755 feature-controller-logging/src/test/java/org/onap/policy/drools/controller/logging/ControllerLoggingTest.java create mode 100755 feature-controller-logging/src/test/resources/kmodule.xml create mode 100755 feature-controller-logging/src/test/resources/logback-test.xml create mode 100755 feature-controller-logging/src/test/resources/test.drl create mode 100755 feature-controller-logging/src/test/resources/test.pom 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 @@ + + + + 4.0.0 + + + org.onap.policy.drools-pdp + drools-pdp + 1.4.0-SNAPSHOT + + + feature-controller-logging + + feature-controller-logging + Loadable module that enables individual network logs per controller + + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + + + zipfile + + single + + package + + true + ${project.artifactId}-${project.version} + + src/assembly/assemble_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + ${project.build.directory}/assembly/lib + false + true + true + false + false + false + runtime + true + + + + + + + + + + org.onap.policy.drools-pdp + policy-management + ${project.version} + provided + + + junit + junit + test + + + 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 @@ + + + + + + feature-controller-logging + + zip + + + false + + + + target + lib/feature + + feature-controller-logging-${project.version}.jar + + + + target/assembly/lib + lib/dependencies + + *.jar + + + + src/main/feature/config + config + 0644 + + + + src/main/feature/bin + bin + 0744 + + + + src/main/feature/install + install + 0744 + + + + + 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 "/\/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\" + for mainConfig in ${configDir}/logback.xml ${configDir}/logback-eelf.xml; do + if [ -e "${mainConfig}" ]; then + sed -i --follow-symlinks "/\ /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 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 { + + @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 @@ + + + + + + + + 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 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n + + + + + + + + + + + + + + + \ 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 @@ + + + + + + 4.0.0 + + org.onap.policy.drools.test + test + 1.4.0-SNAPSHOT + + 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 @@ ${project.version} zip + + org.onap.policy.drools-pdp + feature-controller-logging + ${project.version} + zip + 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 decoderConfigurations, List 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 decoderConfigurations, - List encoderConfigurations) + List 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 coderConfigurations, + protected void initCoders(List 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 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 factQuery(String sessionName, String queryName, String queriedEntity, + public List 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; @@ -52,6 +53,28 @@ public interface DroolsControllerFeatureAPI extends OrderedService { return false; } + /** + * 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. */ 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 providers = + public static final OrderedServiceImpl 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 959114a2..740a119b 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 @@ -695,7 +695,7 @@ class PolicyEngineManager implements PolicyEngine { throw new IllegalArgumentException(controllerName + " is invalid"); } - logger.warn("controller being recovered. {} Reset controller's bad maven coordinates to brainless", + logger.warn("controller being recovered. {} Reset controller's bad maven coordinates to brainless", controllerName); /* @@ -918,7 +918,7 @@ class PolicyEngineManager implements PolicyEngine { logger.error("{}: cannot start http-server {} because of {}", this, httpServer, e.getMessage(), e); } } - + // stop JMX? /* policy-engine dispatch pre stop hook */ @@ -1003,7 +1003,7 @@ class PolicyEngineManager implements PolicyEngine { exitThread.interrupt(); logger.info("{}: normal termination", this); } - + /** * Thread that shuts down http servers. */ @@ -1038,13 +1038,13 @@ class PolicyEngineManager implements PolicyEngine { doExit(0); } } - + // these may be overridden by junit tests protected void doSleep(long sleepMs) throws InterruptedException { Thread.sleep(sleepMs); } - + protected void doExit(int code) { System.exit(code); } @@ -1245,13 +1245,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 @@ --> - + diff --git a/pom.xml b/pom.xml index ff9cdb75..c2733c86 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ feature-active-standby-management feature-simulators feature-distributed-locking + feature-controller-logging packages -- cgit 1.2.3-korg