From 9e69cc20f40f8ec89aa8a1487c2f6b3e687ded40 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Mon, 26 Jun 2017 08:05:30 -0500 Subject: [POLICY-30] optional loadable eelf feature for backwards compatibility purposes or if desired to use EELF and common-framework (from policy-common) for logging purposes in miscellaneous environments. It supports EELF/Common Framework style logging at the same time than traditional logging. This functionality is an optional loadable module. policy-docker changes need to be made to optionally unpack to make it active (in a different submission). started marking feature projects with feature prefix in project name to give a clear picture to the community which modules are features vs. code base. Change-Id: I5076c462409f03415ce54f0c9b5f50b78abb18f9 Signed-off-by: Jorge Hernandez --- policy-management/pom.xml | 5 ++ .../controller/internal/MavenDroolsController.java | 4 +- .../drools/features/PolicyEngineFeatureAPI.java | 20 +++++++- .../drools/protocol/coders/EventProtocolCoder.java | 2 +- .../org/openecomp/policy/drools/system/Main.java | 40 +++------------ .../policy/drools/system/PolicyEngine.java | 44 +++++++++++++++- .../src/main/server-gen/bin/telemetry.sh | 44 ++++++++++++++++ .../src/main/server/config/logback.xml | 58 +--------------------- 8 files changed, 122 insertions(+), 95 deletions(-) create mode 100644 policy-management/src/main/server-gen/bin/telemetry.sh (limited to 'policy-management') diff --git a/policy-management/pom.xml b/policy-management/pom.xml index 3ca8bc22..e7d83851 100644 --- a/policy-management/pom.xml +++ b/policy-management/pom.xml @@ -242,6 +242,11 @@ commons-lang3 3.4 + + + ch.qos.logback + logback-classic + junit diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java index 06d2aaf7..bc577649 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java @@ -521,8 +521,8 @@ public class MavenDroolsController implements DroolsController { topic, event); } catch (UnsupportedOperationException uoe) { - logger.info("{}: DECODE FAILED: {} <- {} because of {}", this, topic, - event, uoe.getMessage(), uoe); + 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, diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java index 30e3a14c..df2ddd6f 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java @@ -32,6 +32,24 @@ import org.openecomp.policy.drools.utils.OrderedServiceImpl; */ public interface PolicyEngineFeatureAPI extends OrderedService { + /** + * 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 + * lower priority features. False, otherwise. + */ + public default boolean beforeBoot(PolicyEngine engine, String cliArgs[]) {return false;}; + + /** + * intercept after the Policy Engine is booted. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterBoot(PolicyEngine engine) {return false;}; + /** * intercept before the Policy Engine is configured. * @@ -180,5 +198,5 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * Feature providers implementing this interface */ public static final OrderedServiceImpl providers = - new OrderedServiceImpl(PolicyEngineFeatureAPI.class); + new OrderedServiceImpl<>(PolicyEngineFeatureAPI.class); } diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java index 1030186b..819ee812 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java @@ -937,7 +937,7 @@ abstract class GenericEventProtocolCoder { if (event != null) return event; } catch (Exception e) { - logger.info("{}, cannot decode {}", this, json, e); + logger.debug("{}, cannot decode {}", this, json, e); } if (multipleToolsetRetries) { diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java index 3b12514c..1bb9a320 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java @@ -25,11 +25,10 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.openecomp.policy.drools.core.PolicyContainer; import org.openecomp.policy.drools.persistence.SystemPersistence; import org.openecomp.policy.drools.utils.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Programmatic entry point to the management layer @@ -47,25 +46,9 @@ public class Main { public static final String LOGBACK_CONFIGURATION_FILE_DEFAULT = "config/logback.xml"; /** - * EELF logback configuration path system property - */ - public static final String EELF_LOGBACK_PATH_SYSTEM_PROPERTY = "com.att.eelf.logging.file"; - - /** - * EELF logback configuration path value - */ - public static final String EELF_LOGBACK_PATH_DEFAULT = "config"; - - /** - * EELF logback configuration file system property + * constructor (hides public default one) */ - public static final String EELF_LOGBACK_FILE_SYSTEM_PROPERTY = "com.att.eelf.logging.path"; - - /** - * EELF logback configuration file default value - */ - public static final String EELF_LOGBACK_FILE_DEFAULT = "logback.xml"; - + private Main() {} /** * main @@ -79,11 +62,9 @@ public class Main { if (System.getProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY) == null) System.setProperty(LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, LOGBACK_CONFIGURATION_FILE_DEFAULT); - if (System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY) == null) - System.setProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY, EELF_LOGBACK_PATH_DEFAULT); + /* 0. boot */ - if (System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY) == null) - System.setProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY, EELF_LOGBACK_FILE_DEFAULT); + PolicyEngine.manager.boot(args); Logger logger = LoggerFactory.getLogger(Main.class); @@ -95,15 +76,6 @@ public class Main { " not found"); } - - /* 0. Start the CORE layer first */ - - try { - PolicyContainer.globalInit(args); - } catch (Exception e) { - logger.warn("Main: cannot init policy-container because of {}", e.getMessage(), e); - } - /* 1. Configure the Engine */ try { diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java index 974a7260..633d2379 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java @@ -27,6 +27,7 @@ import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.core.PolicyContainer; import org.openecomp.policy.drools.core.jmx.PdpJmxListener; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; @@ -82,6 +83,13 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { */ public static final String CONFIG_SERVER_DEFAULT_HOST = "localhost"; + /** + * Boot the engine + * + * @param cliArgs command line arguments + */ + public void boot(String cliArgs[]); + /** * configure the policy engine according to the given properties * @@ -318,7 +326,7 @@ class PolicyEngineManager implements PolicyEngine { /** * logger */ - private static Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class); + private static Logger logger = LoggerFactory.getLogger(PolicyEngineManager.class); /** * Is the Policy Engine running? @@ -355,6 +363,40 @@ class PolicyEngineManager implements PolicyEngine { */ protected Gson decoder = new GsonBuilder().disableHtmlEscaping().create(); + + /** + * {@inheritDoc} + */ + @Override + public synchronized void boot(String cliArgs[]) { + + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeBoot(this, cliArgs)) + return; + } catch (Exception e) { + logger.error("{}: feature {} before-boot failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); + } + } + + try { + PolicyContainer.globalInit(cliArgs); + } catch (Exception e) { + logger.error("{}: cannot init policy-container because of {}", this, e.getMessage(), e); + } + + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterBoot(this)) + return; + } catch (Exception e) { + logger.error("{}: feature {} after-boot failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); + } + } + } + /** * {@inheritDoc} */ diff --git a/policy-management/src/main/server-gen/bin/telemetry.sh b/policy-management/src/main/server-gen/bin/telemetry.sh new file mode 100644 index 00000000..397c2508 --- /dev/null +++ b/policy-management/src/main/server-gen/bin/telemetry.sh @@ -0,0 +1,44 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# ONAP POLICY +# ================================================================================ +# Copyright (C) 2017 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========================================================= +## + +REST_TOOL="http-prompt" +TELEMETRY_SPEC="${POLICY_HOME}/config/telemetry-spec.json" + +if ! type -p "${REST_TOOL}" > /dev/null 2>&1; then + echo "error: prerequisite software not found: http-prompt" + exit 1 +fi + +if ! "${POLICY_HOME}"/bin/policy-management-controller status > /dev/null 2>&1; then + echo "error: pdp-d is not running" + exit 2 +fi + +if [[ ! -r ${TELEMETRY_SPEC} ]]; then + echo "generating new spec .." + if ! http -a "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" :9696/swagger.json > ${TELEMETRY_SPEC} 2> /dev/null; then + echo "error: cannot generate telemetry spec" + exit 3 + fi +fi + +exec http-prompt http://localhost:9696/policy/pdp/engine --auth "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" --spec ${TELEMETRY_SPEC} diff --git a/policy-management/src/main/server/config/logback.xml b/policy-management/src/main/server/config/logback.xml index 58092cc2..53d73434 100644 --- a/policy-management/src/main/server/config/logback.xml +++ b/policy-management/src/main/server/config/logback.xml @@ -23,65 +23,19 @@ - - - - - - + - - ${logDir}/${auditLog}.log - - ${logDir}/${auditLog}.%i.log.zip - 1 - 9 - - - 5MB - - - ${auditPattern} - - - - - - - - - ${logDir}/${metricLog}.log - - ${logDir}/${metricLog}.%i.log.zip - 1 - 9 - - - 5MB - - - ${metricPattern} - - - - - - - ${logDir}/${errorLog}.log ${logDir}/${errorLog}.%i.log.zip 1 - 9 + 5 WARN @@ -136,14 +90,6 @@ - - - - - - - - -- cgit 1.2.3-korg