diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-06-26 08:05:30 -0500 |
---|---|---|
committer | Jorge Hernandez <jh1730@att.com> | 2017-06-26 08:16:10 -0500 |
commit | 9e69cc20f40f8ec89aa8a1487c2f6b3e687ded40 (patch) | |
tree | b8851c6243f09575132e4a1a99bc0ad5233c4263 | |
parent | b61e46ab34a649b29f788e9e0e0db3fb018b6fcd (diff) |
[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 <jh1730@att.com>
18 files changed, 740 insertions, 96 deletions
diff --git a/feature-eelf/pom.xml b/feature-eelf/pom.xml new file mode 100644 index 00000000..3138c8d3 --- /dev/null +++ b/feature-eelf/pom.xml @@ -0,0 +1,125 @@ +<!-- + ============LICENSE_START======================================================= + ECOMP Policy Engine - Drools PDP + ================================================================================ + 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========================================================= + --> + +<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.openecomp.policy.drools-pdp</groupId> + <artifactId>drools-pdp</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> + + <artifactId>feature-eelf</artifactId> + + <name>feature-eelf</name> + <description>Loadable module that uses EELF and common module logging infrastructure</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> + <version>2.6</version> + <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> + <version>2.8</version> + <executions> + <execution> + <id>copy-dependencies</id> + <goals> + <goal>copy-dependencies</goal> + </goals> + <phase>prepare-package</phase> + <configuration> + <transitive>false</transitive> + <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> + <excludeScope>provided</excludeScope> + <excludeTransitive>true</excludeTransitive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.att.eelf</groupId> + <artifactId>eelf-core</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>org.openecomp.policy.common</groupId> + <artifactId>ECOMP-Logging</artifactId> + <version>${common-modules.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.policy.drools-pdp</groupId> + <artifactId>policy-management</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> diff --git a/feature-eelf/src/assembly/assemble_zip.xml b/feature-eelf/src/assembly/assemble_zip.xml new file mode 100644 index 00000000..001d3c66 --- /dev/null +++ b/feature-eelf/src/assembly/assemble_zip.xml @@ -0,0 +1,67 @@ +<!-- + ============LICENSE_START======================================================= + feature-eelf + ================================================================================ + 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========================================================= + --> + +<!-- 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-eelf-package</id> + <formats> + <format>zip</format> + </formats> + + <includeBaseDirectory>false</includeBaseDirectory> + + <fileSets> + <fileSet> + <directory>target</directory> + <outputDirectory>lib/opt</outputDirectory> + <includes> + <include>feature-eelf-${project.version}.jar</include> + </includes> + </fileSet> + <fileSet> + <directory>target/assembly/</directory> + <outputDirectory>.</outputDirectory> + <excludes/> + </fileSet> + <fileSet> + <directory>.</directory> + <outputDirectory>lib</outputDirectory> + <includes> + <include>*.jar</include> + </includes> + </fileSet> + <fileSet> + <directory>src/main/install/config</directory> + <outputDirectory>config</outputDirectory> + </fileSet> + <fileSet> + <directory>src/main/install/bin</directory> + <outputDirectory>bin</outputDirectory> + <fileMode>0744</fileMode> + <excludes/> + </fileSet> + </fileSets> + +</assembly> diff --git a/feature-eelf/src/main/install/config/logback.xml b/feature-eelf/src/main/install/config/logback.xml new file mode 100644 index 00000000..f4295628 --- /dev/null +++ b/feature-eelf/src/main/install/config/logback.xml @@ -0,0 +1,185 @@ +<!-- + ============LICENSE_START======================================================= + feature-eelf + ================================================================================ + 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========================================================= + --> + +<configuration scan="true" scanPeriod="30 seconds" debug="false"> + + <property name="errorLogName" value="error" /> + <property name="metricsLogName" value="metrics" /> + <property name="auditLogName" value="audit" /> + <property name="debugLogName" value="debug" /> + <property name="networkLogName" value="network" /> + + <property name="defaultPattern" + value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" /> + <property name="defaultMetricPattern" + value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" /> + <property name="defaultAuditPattern" + value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" /> + <property name="defaultErrorPattern" + value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDesciption}|%msg%n" /> + <property name="networkPattern" value="[%d|%t]%m%n" /> + <property name="debugPattern" value="[%date|%level|%logger{0}|%thread] %msg%n" /> + + <property name="logDirectory" value="logs/Policy" /> + <property name="debugLogDirectory" value="logs/Policy" /> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="EELFAudit" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${auditLogName}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>5</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>10MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultAuditPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFAudit" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="EELFAudit" /> + </appender> + + <appender name="EELFMetrics" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${metricsLogName}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${metricsLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>5</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>15MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultMetricPattern}</pattern> + </encoder> + </appender> + + + <appender name="asyncEELFMetrics" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="EELFMetrics" /> + </appender> + + <appender name="EELFError" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${errorLogName}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>5</maxIndex> + </rollingPolicy> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>ERROR</level> + </filter> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>20MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultErrorPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="EELFError" /> + </appender> + + <appender name="EELFDebug" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${debugLogDirectory}/${debugLogName}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${debugLogDirectory}/${debugLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>5</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>20MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${debugPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFDebug" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="EELFDebug" /> + </appender> + + <appender name="NetworkOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${networkLogName}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>logs/network.log.%i.zip</fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>5</maxIndex> + </rollingPolicy> + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>15MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${networkPattern}</pattern> + </encoder> + </appender> + + <appender name="AsyncNetworkOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="NetworkOut" /> + </appender> + + <logger name="com.att.eelf.audit" level="info" additivity="false"> + <appender-ref ref="asyncEELFAudit" /> + </logger> + + <logger name="com.att.eelf.metrics" level="info" additivity="false"> + <appender-ref ref="asyncEELFMetrics" /> + </logger> + + <logger name="com.att.eelf.error" level="error" additivity="false"> + <appender-ref ref="asyncEELFError" /> + </logger> + + <logger name="com.att.eelf.debug" level="info" additivity="false"> + <appender-ref ref="asyncEELFDebug" /> + </logger> + + <logger name="network" level="INFO" additivity="false"> + <appender-ref ref="AsyncNetworkOut" /> + </logger> + + <root level="INFO"> + <appender-ref ref="asyncEELFDebug" /> + <appender-ref ref="asyncEELFError" /> + </root> + +</configuration> diff --git a/feature-eelf/src/main/install/config/policyLogger.properties b/feature-eelf/src/main/install/config/policyLogger.properties new file mode 100644 index 00000000..d8987252 --- /dev/null +++ b/feature-eelf/src/main/install/config/policyLogger.properties @@ -0,0 +1,49 @@ +### +# ============LICENSE_START======================================================= +# feature-eelf +# ================================================================================ +# 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========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +# Set override flag. Set TRUE for override the level setups in logback.xml. Set FALSE for using the level setups of logback.xml +override.logback.level.setup=FALSE +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON +#################################### Set Policy Component ################################## +# Set DROOLS for drools PDP. Set XACML to xacml PDP +policy.component=DROOLS diff --git a/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java b/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java new file mode 100644 index 00000000..de39f3a3 --- /dev/null +++ b/feature-eelf/src/main/java/org/openecomp/policy/drools/eelf/EelfFeature.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * feature-eelf + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.policy.drools.eelf; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI; +import org.openecomp.policy.drools.system.Main; +import org.openecomp.policy.drools.system.PolicyEngine; + +public class EelfFeature implements PolicyEngineFeatureAPI { + + /** + * 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 + */ + 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"; + + @Override + public boolean beforeBoot(PolicyEngine engine, String cliArgs[]) { + + String logback = System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, + Main.LOGBACK_CONFIGURATION_FILE_DEFAULT); + + Path logbackPath = Paths.get(logback); + + if (System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY) == null) + System.setProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY, logbackPath.getFileName().toString()); + + if (System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY) == null) + System.setProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY, + logbackPath.toAbsolutePath().getParent().toString()); + + Logger logger = FlexLogger.getLogger(this.getClass(), true); + + logger.warn("EELF/Common Frameworks Logging Enabled"); + if (logger.isInfoEnabled()) { + logger.info("EELFFeature: Property " + Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY + "=" + + System.getProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY)); + logger.info("EELFFeature: Property " + EELF_LOGBACK_PATH_SYSTEM_PROPERTY + "=" + + System.getProperty(EELF_LOGBACK_PATH_SYSTEM_PROPERTY)); + logger.info("EELFFeature: Property " + EELF_LOGBACK_FILE_SYSTEM_PROPERTY + "=" + + System.getProperty(EELF_LOGBACK_FILE_SYSTEM_PROPERTY)); + } + + return false; + }; + + @Override + public int getSequenceNumber() { + return 0; + } + +} diff --git a/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI b/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI new file mode 100644 index 00000000..70d1bb8e --- /dev/null +++ b/feature-eelf/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI @@ -0,0 +1 @@ +org.openecomp.policy.drools.eelf.EelfFeature diff --git a/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java b/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java new file mode 100644 index 00000000..2ded0d0d --- /dev/null +++ b/feature-eelf/src/test/java/org/openecomp/policy/drools/eelf/test/EElfTest.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * feature-eelf + * ================================================================================ + * 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========================================================= + */ +package org.openecomp.policy.drools.eelf.test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.drools.eelf.EelfFeature; +import org.openecomp.policy.drools.system.Main; +import org.openecomp.policy.drools.system.PolicyEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFLogger.Level; +import com.att.eelf.configuration.EELFManager; + +import ch.qos.logback.classic.LoggerContext; + +/** + * Logger Tests + */ +public class EElfTest { + + /** + * logback configuration location + */ + public final static String LOGBACK_CONFIGURATION_FILE_DEFAULT = "src/main/install/config/logback.xml"; + + /** + * SLF4J Logger + */ + private final Logger slf4jLogger = LoggerFactory.getLogger(EElfTest.class); + + /** + * get all loggers + * @return list of all loggers + */ + protected List<String> loggers() { + List<String> loggers = new ArrayList<String>(); + LoggerContext context = + (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory(); + for (org.slf4j.Logger logger: context.getLoggerList()) { + loggers.add(logger.getName()); + } + slf4jLogger.info(loggers.toString()); + return loggers; + } + + /** + * Assert Log Levels are the same between an EELF Logger and an SLF4J Logger + * + * @param eelfAuditLogger + * @param slf4jAuditLogger + */ + protected void assertLogLevels(EELFLogger eelfAuditLogger, Logger slf4jAuditLogger) { + assertTrue(slf4jAuditLogger.isDebugEnabled() == eelfAuditLogger.isDebugEnabled()); + assertTrue(slf4jAuditLogger.isInfoEnabled() == eelfAuditLogger.isInfoEnabled()); + assertTrue(slf4jAuditLogger.isErrorEnabled() == eelfAuditLogger.isErrorEnabled()); + assertTrue(slf4jAuditLogger.isWarnEnabled() == eelfAuditLogger.isWarnEnabled()); + assertTrue(slf4jAuditLogger.isTraceEnabled() == eelfAuditLogger.isTraceEnabled()); + } + + @Test + public void slf4jLog() { + + /* standard slf4j using defaults */ + + slf4jLogger.info("slf4j info"); + + List<String> loggers = loggers(); + + assertFalse(loggers.contains(Configuration.DEBUG_LOGGER_NAME)); + assertFalse(loggers.contains(Configuration.AUDIT_LOGGER_NAME)); + assertFalse(loggers.contains(Configuration.ERROR_LOGGER_NAME)); + assertFalse(loggers.contains(Configuration.METRICS_LOGGER_NAME)); + + /* set logback configuration */ + + System.setProperty(Main.LOGBACK_CONFIGURATION_FILE_SYSTEM_PROPERTY, + LOGBACK_CONFIGURATION_FILE_DEFAULT); + + /* set up eelf throuth common loggings library */ + + EelfFeature feature = new EelfFeature(); + feature.beforeBoot(PolicyEngine.manager, null); + + loggers = loggers(); + assertTrue(loggers.contains(Configuration.DEBUG_LOGGER_NAME)); + assertTrue(loggers.contains(Configuration.AUDIT_LOGGER_NAME)); + assertTrue(loggers.contains(Configuration.ERROR_LOGGER_NAME)); + assertTrue(loggers.contains(Configuration.METRICS_LOGGER_NAME)); + + EELFLogger eelfAuditLogger = EELFManager.getInstance().getAuditLogger(); + Logger slf4jAuditLogger = org.slf4j.LoggerFactory.getLogger(Configuration.AUDIT_LOGGER_NAME); + org.openecomp.policy.common.logging.flexlogger.Logger flexLogger = + FlexLogger.getLogger(EElfTest.class); + + /* generate an audit entry through both logs */ + + flexLogger.audit("flexlogger audit"); + eelfAuditLogger.info("eelf audit"); + slf4jAuditLogger.info("slf4j audit"); + + /* check log levels in eelf and standard slf4j change in both directions */ + + /* eelf initiated */ + eelfAuditLogger.setLevel(Level.ERROR); + assertLogLevels(eelfAuditLogger, slf4jAuditLogger); + + /* slf4j initiated */ + ((ch.qos.logback.classic.Logger) slf4jLogger).setLevel((ch.qos.logback.classic.Level.INFO)); + assertLogLevels(eelfAuditLogger, slf4jAuditLogger); + } +} diff --git a/packages/install/pom.xml b/packages/install/pom.xml index 60da88a4..4f9b6cec 100644 --- a/packages/install/pom.xml +++ b/packages/install/pom.xml @@ -77,6 +77,12 @@ <version>${project.version}</version> <type>zip</type> </dependency> + <dependency> + <groupId>org.openecomp.policy.drools-pdp</groupId> + <artifactId>feature-eelf</artifactId> + <version>${project.version}</version> + <type>zip</type> + </dependency> </dependencies> </project> diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java index f041b079..6cbabb2c 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * policy-healthcheck + * policy-endpoints * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ 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 @@ <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> + + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + </dependency> <dependency> <groupId>junit</groupId> 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 @@ -33,6 +33,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. * * @return true if this feature intercepts and takes ownership @@ -180,5 +198,5 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * Feature providers implementing this interface */ public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers = - new OrderedServiceImpl<PolicyEngineFeatureAPI>(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; @@ -83,6 +84,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 * * @param properties Policy Engine 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/packages/base/src/files/bin/telemetry.sh b/policy-management/src/main/server-gen/bin/telemetry.sh index 397c2508..397c2508 100644 --- a/packages/base/src/files/bin/telemetry.sh +++ b/policy-management/src/main/server-gen/bin/telemetry.sh 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 @@ <property name="logDir" value="logs" /> <property name="errorLog" value="error" /> - <property name="metricLog" value="metric" /> - <property name="auditLog" value="audit" /> <property name="debugLog" value="debug" /> <property name="networkLog" value="network" /> - <property name="metricPattern" - value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" /> - <property name="auditPattern" - value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" /> - <property name="errorPattern" - value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDesciption}|%msg%n" /> - <property name="debugPattern" value="[%date|%level|%logger{0}|%thread] %msg%n" /> + <property name="errorPattern" value="${debugPattern}" /> <property name="networkPattern" value="[%d|%t]%m%n" /> - <appender name="AuditOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${logDir}/${auditLog}.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDir}/${auditLog}.%i.log.zip</fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${auditPattern}</pattern> - </encoder> - </appender> - - <appender name="AsyncAuditOut" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="AuditOut" /> - </appender> - - <appender name="MetricOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${logDir}/${metricLog}.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDir}/${metricLog}.%i.log.zip</fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${metricPattern}</pattern> - </encoder> - </appender> - - <appender name="AsyncMetricOut" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="MetricOut" /> - </appender> - <appender name="ErrorOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDir}/${errorLog}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <fileNamePattern>${logDir}/${errorLog}.%i.log.zip</fileNamePattern> <minIndex>1</minIndex> - <maxIndex>9</maxIndex> + <maxIndex>5</maxIndex> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> @@ -136,14 +90,6 @@ <appender name="AsyncNetworkOut" class="ch.qos.logback.classic.AsyncAppender"> <appender-ref ref="NetworkOut" /> </appender> - - <logger name="com.att.eelf.audit" level="INFO"> - <appender-ref ref="AsyncAuditOut" /> - </logger> - - <logger name="com.att.eelf.metrics" level="INFO"> - <appender-ref ref="AsyncMetricOut" /> - </logger> <logger name="network" level="INFO" additivity="false"> <appender-ref ref="AsyncNetworkOut" /> @@ -65,6 +65,7 @@ <module>policy-endpoints</module> <module>policy-management</module> <module>policy-healthcheck</module> + <module>feature-eelf</module> <module>packages</module> </modules> |