From f9f112f5fd5b193e79e38442cc566b7b437f87d2 Mon Sep 17 00:00:00 2001 From: noahs Date: Wed, 6 Dec 2017 13:11:38 +0200 Subject: Duplicate logging frameworks merging There was two copies of the SDC logging framework Change-Id: I55c94c9817a83162c6d90e504dfd91e4858c7269 Issue-ID: SDC-703 Signed-off-by: noahs --- .../openecomp-sdc-healing-core/pom.xml | 6 - .../openecomp-sdc-healing-impl/pom.xml | 12 +- .../sdc/healing/healers/util/TestUtil.java | 5 +- .../openecomp-sdc-logging-api/pom.xml | 51 --- .../org/openecomp/sdc/logging/api/BaseFactory.java | 58 --- .../java/org/openecomp/sdc/logging/api/Logger.java | 107 ----- .../sdc/logging/api/LoggerCreationService.java | 35 -- .../openecomp/sdc/logging/api/LoggerFactory.java | 234 ----------- .../sdc/logging/api/annotations/Debug.java | 29 -- .../sdc/logging/api/annotations/Metrics.java | 31 -- .../api/context/ContextPropagationService.java | 32 -- .../sdc/logging/api/context/TaskFactory.java | 75 ---- .../org/openecomp/sdc/logging/context/MdcData.java | 59 --- .../sdc/logging/messages/AuditMessages.java | 42 -- .../sdc/logging/messages/DebugMessages.java | 34 -- .../sdc/logging/types/DebugConstants.java | 32 -- .../sdc/logging/types/LoggerConstants.java | 41 -- .../sdc/logging/types/LoggerErrorCategory.java | 30 -- .../sdc/logging/types/LoggerErrorCode.java | 45 -- .../sdc/logging/types/LoggerErrorDescription.java | 111 ----- .../sdc/logging/types/LoggerServiceName.java | 182 --------- .../sdc/logging/types/LoggerTragetServiceName.java | 206 ---------- .../src/main/resources/factoryConfiguration.json | 3 - .../src/main/resources/logback.xml | 284 ------------- .../openecomp-sdc-logging-core/pom.xml | 45 -- .../java/org/openecomp/sdc/logging/Markers.java | 50 --- .../sdc/logging/SLF4JLoggerCreationService.java | 240 ----------- .../openecomp/sdc/logging/aspects/DebugAspect.java | 70 ---- .../sdc/logging/aspects/MetricsAspect.java | 70 ---- .../sdc/logging/context/MDCPropagationService.java | 74 ---- .../org/openecomp/sdc/logging/context/MdcUtil.java | 59 --- .../logging/context/impl/MdcDataDebugMessage.java | 88 ---- .../logging/context/impl/MdcDataErrorMessage.java | 76 ---- .../sdc/logging/logback/DispatchingAppender.java | 148 ------- .../logging/logback/EventTypeDiscriminator.java | 121 ------ .../logging/method/LoggingInvocationHandler.java | 45 -- .../sdc/logging/servlet/LoggingFilter.java | 144 ------- .../openecomp/sdc/logging/util/LoggingUtils.java | 35 -- ...openecomp.sdc.logging.api.LoggerCreationService | 1 - ...c.logging.api.context.ContextPropagationService | 1 - openecomp-be/lib/openecomp-logging-lib/pom.xml | 25 -- .../openecomp-sdc-logging-api/pom.xml | 36 ++ .../org/openecomp/sdc/logging/api/BaseFactory.java | 58 +++ .../java/org/openecomp/sdc/logging/api/Logger.java | 107 +++++ .../sdc/logging/api/LoggerCreationService.java | 35 ++ .../openecomp/sdc/logging/api/LoggerFactory.java | 234 +++++++++++ .../sdc/logging/api/annotations/Metrics.java | 31 ++ .../api/context/ContextPropagationService.java | 32 ++ .../sdc/logging/api/context/TaskFactory.java | 75 ++++ .../org/openecomp/sdc/logging/context/MdcData.java | 59 +++ .../sdc/logging/messages/AuditMessages.java | 42 ++ .../sdc/logging/messages/DebugMessages.java | 34 ++ .../sdc/logging/types/DebugConstants.java | 32 ++ .../sdc/logging/types/LoggerConstants.java | 41 ++ .../sdc/logging/types/LoggerErrorCategory.java | 30 ++ .../sdc/logging/types/LoggerErrorCode.java | 45 ++ .../sdc/logging/types/LoggerErrorDescription.java | 111 +++++ .../sdc/logging/types/LoggerServiceName.java | 182 +++++++++ .../sdc/logging/types/LoggerTragetServiceName.java | 206 ++++++++++ .../src/main/resources/factoryConfiguration.json | 3 + .../sdc/logging/api/LoggerFactoryTest.java | 72 ++++ .../sdc/logging/api/context/TaskFactoryTest.java | 30 ++ .../openecomp-sdc-logging-core/README | 29 ++ .../openecomp-sdc-logging-core/pom.xml | 70 ++++ .../java/org/openecomp/sdc/logging/Markers.java | 50 +++ .../sdc/logging/SLF4JLoggerCreationService.java | 240 +++++++++++ .../sdc/logging/aspects/MetricsAspect.java | 68 ++++ .../sdc/logging/context/MDCPropagationService.java | 74 ++++ .../org/openecomp/sdc/logging/context/MdcUtil.java | 57 +++ .../logging/context/impl/MdcDataDebugMessage.java | 88 ++++ .../logging/context/impl/MdcDataErrorMessage.java | 76 ++++ .../sdc/logging/logback/DispatchingAppender.java | 148 +++++++ .../logging/logback/EventTypeDiscriminator.java | 121 ++++++ .../sdc/logging/servlet/LoggingFilter.java | 143 +++++++ .../openecomp/sdc/logging/util/LoggingUtils.java | 35 ++ ...openecomp.sdc.logging.api.LoggerCreationService | 1 + ...c.logging.api.context.ContextPropagationService | 1 + .../openecomp/sdc/logging/LoggerFactoryTest.java | 25 ++ .../org/openecomp/sdc/logging/RoutingTest.java | 155 +++++++ .../org/openecomp/sdc/logging/api/LoggerTest.java | 65 +++ .../sdc/logging/aspects/MetricsAspectTest.java | 451 +++++++++++++++++++++ .../logging/context/MDCPropagationFactoryTest.java | 223 ++++++++++ .../sdc/logging/context/TaskFactoryTest.java | 26 ++ .../logback/EventTypeDiscriminatorTest.java | 220 ++++++++++ .../sdc/logging/servlet/LoggingFilterTest.java | 314 ++++++++++++++ .../src/test/resources/README | 8 + .../src/test/resources/dispatching-logback.xml | 335 +++++++++++++++ .../src/test/resources/logback-test.xml | 41 ++ .../src/test/resources/sifting-logback.xml | 42 ++ openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml | 22 + openecomp-be/lib/pom.xml | 2 +- 91 files changed, 4632 insertions(+), 3029 deletions(-) delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService delete mode 100644 openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService delete mode 100644 openecomp-be/lib/openecomp-logging-lib/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml create mode 100644 openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml index 5766fdfd4c..4472cfe477 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml @@ -3,7 +3,6 @@ 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"> 4.0.0 - org.openecomp.sdc openecomp-sdc-healing-core @@ -23,11 +22,6 @@ openecomp-sdc-validation-api ${project.version} - - org.openecomp.sdc - openecomp-sdc-vendor-software-product-api - ${project.version} - diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml index d5e3e9e0b7..c54f724b9a 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml @@ -17,6 +17,12 @@ openecomp-sdc-healing-api ${project.version} + + junit + junit + ${junit.version} + test + org.openecomp.sdc openecomp-sdc-vendor-software-product-api @@ -33,12 +39,6 @@ openecomp-sdc-vendor-license-api ${project.version} - - junit - junit - ${junit.version} - test - diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java index 20ba5ebf19..da44ec422f 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.healing.healers.util; +import org.junit.Assert; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -7,7 +8,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; -import org.springframework.util.Assert; import java.io.File; import java.io.FileInputStream; @@ -98,8 +98,7 @@ public class TestUtil { ServiceTemplate actualServiceTemplate = actualServiceTemplates.get(serviceTemplateName); - Assert.notNull(actualServiceTemplate, - "Missing service template in service model : " + serviceTemplateName); + Assert.assertNotNull("Missing service template in service model : " + serviceTemplateName, actualServiceTemplate); org.junit.Assert.assertEquals("Difference in file " + serviceTemplateName, JsonUtil.object2Json(expectedServiceTemplateEntry.getValue()), JsonUtil.object2Json(actualServiceTemplate)); diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml deleted file mode 100644 index 8623552aff..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - openecomp-sdc-logging-api - openecomp-sdc-logging-api - - - org.openecomp.sdc - openecomp-logging-lib - 1.2.0-SNAPSHOT - - - - - org.slf4j - slf4j-api - - - org.aspectj - aspectjrt - ${aspectj.version} - - - - - - - diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java deleted file mode 100644 index 3be67dfde2..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api; - -import java.util.Iterator; -import java.util.ServiceLoader; - -/** - * Contains common functionality for factories used in the logging framework. - * - *

In order to use the factory, a particular (e.g. framework-specific) implementation of a service must be - * configured as described in - * java.util.ServiceLoader).

- * - * @author evitaliy - * @since 13/09/2016. - * - * @see ServiceLoader - */ -public class BaseFactory { - - protected static T locateService(Class clazz) throws Exception { - - T service; - ServiceLoader loader = ServiceLoader.load(clazz); - Iterator iterator = loader.iterator(); - if (iterator.hasNext()) { - - service = iterator.next(); - if (iterator.hasNext()) { - System.err.println(String.format("Warning! Configured more than one implementation of %s", - clazz.getName())); - } - - return service; - } - - throw new IllegalArgumentException((String.format("No implementations configured for %s", clazz.getName()))); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java deleted file mode 100644 index 9055e64f8b..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api; - -/** - *

This interface defines logging as specified by Open OPENECOMP logging requirements.

- * - *

Formatted messages must follow the clazz); -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java deleted file mode 100644 index 68365fd857..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java +++ /dev/null @@ -1,234 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api; - - -/** - * Factory to hide a concrete, framework-specific implementation of logger creation. - *

The service used by this factory must implement {@link LoggerCreationService}. If no - * implementation has been configured or could not be instantiated, a no-op logger will be - * used, and no events will be logged. This is done to prevent recursion if attempts are - * being made to log exceptions that resulted from logger initialization.

- * - * @author evitaliy - * @see BaseFactory - * @see LoggerCreationService - * @since 13/09/2016. - */ -@SuppressWarnings("ThrowableInstanceNeverThrown") -public class LoggerFactory extends BaseFactory { - - private static final LoggerCreationService SERVICE; - - static { - LoggerCreationService service; - - try { - service = locateService(LoggerCreationService.class); - } catch (Exception ex) { - new RuntimeException("Failed to instantiate logger factory", ex).printStackTrace(); - // use the no-op service to prevent recursion in case of an attempt to log an exception as a - // result of a logger initialization error - service = new NoOpLoggerCreationService(); - } - - SERVICE = service; - } - - public static Logger getLogger(String clazzName) { - return SERVICE.getLogger(clazzName); - } - - public static Logger getLogger(Class clazz) { - return SERVICE.getLogger(clazz); - } - - private static class NoOpLoggerCreationService implements LoggerCreationService { - - private static final Logger NO_OP_LOGGER = new Logger() { - - @Override - public String getName() { - return "No-Op Logger"; - } - - @Override - public boolean isMetricsEnabled() { - return false; - } - - @Override - public void metrics(String msg) { - } - - @Override - public void metrics(String msg, Object arg) { - } - - @Override - public void metrics(String msg, Object arg1, Object arg2) { - } - - @Override - public void metrics(String msg, Object... arguments) { - } - - @Override - public void metrics(String msg, Throwable t) { - } - - @Override - public boolean isAuditEnabled() { - return false; - } - - @Override - public void audit(String msg) { - } - - @Override - public void audit(String msg, Object arg) { - } - - @Override - public void audit(String msg, Object arg1, Object arg2) { - } - - @Override - public void audit(String msg, Object... arguments) { - } - - @Override - public void audit(String msg, Throwable t) { - } - - @Override - public boolean isDebugEnabled() { - return false; - } - - @Override - public void debug(String msg) { - } - - @Override - public void debug(String msg, Object arg) { - } - - @Override - public void debug(String msg, Object arg1, Object arg2) { - } - - @Override - public void debug(String msg, Object... arguments) { - } - - @Override - public void debug(String msg, Throwable t) { - } - - @Override - public boolean isInfoEnabled() { - return false; - } - - @Override - public void info(String msg) { - } - - @Override - public void info(String msg, Object arg) { - } - - @Override - public void info(String msg, Object arg1, Object arg2) { - } - - @Override - public void info(String msg, Object... arguments) { - } - - @Override - public void info(String msg, Throwable t) { - } - - @Override - public boolean isWarnEnabled() { - return false; - } - - @Override - public void warn(String msg) { - } - - @Override - public void warn(String msg, Object arg) { - } - - @Override - public void warn(String msg, Object... arguments) { - } - - @Override - public void warn(String msg, Object arg1, Object arg2) { - } - - @Override - public void warn(String msg, Throwable t) { - } - - @Override - public boolean isErrorEnabled() { - return false; - } - - @Override - public void error(String msg) { - } - - @Override - public void error(String msg, Object arg) { - } - - @Override - public void error(String msg, Object arg1, Object arg2) { - } - - @Override - public void error(String msg, Object... arguments) { - } - - @Override - public void error(String msg, Throwable t) { - } - }; - - @Override - public Logger getLogger(String className) { - return NO_OP_LOGGER; - } - - @Override - public Logger getLogger(Class clazz) { - return NO_OP_LOGGER; - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java deleted file mode 100644 index 049481141a..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api.annotations; - -/** - * Created by TALIO on 12/26/2016. - */ - -public @interface Debug { - -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java deleted file mode 100644 index 2bcad91e38..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api.annotations; - -/** - * Indicates a method whose execution time should be measured and logged as required for Open OPENECOMP metrics. - * - * @author evitaliy - * @since 27/07/2016. - */ - -public @interface Metrics { -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java deleted file mode 100644 index 98200da337..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api.context; - -/** - * Should be used to implement a framework-specific mechanism of propagation of a diagnostic context to child threads. - * - * @author evitaliy - * @since 12/09/2016. - */ -public interface ContextPropagationService { - - Runnable create(Runnable task); -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java deleted file mode 100644 index e2b31c3202..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.api.context; - -import org.openecomp.sdc.logging.api.BaseFactory; - -/** - *

Should be used to propagate a diagnostic context (for instance MDC) to other threads.

- *

Applicable when creating a child thread directly, or submitting tasks for potentially - * postponed execution via an Executor - * (including any of the executor - * services and ForkJoinPool).

- *

The service used by this factory must implement {@link ContextPropagationService}.

- * - * @author evitaliy - * @see ContextPropagationService - * @since 12/09/2016. - */ -@SuppressWarnings("ThrowableInstanceNeverThrown") -public class TaskFactory extends BaseFactory { - - private static final ContextPropagationService SERVICE; - private static final RuntimeException ERROR; - - static { - - ContextPropagationService service = null; - RuntimeException error = null; - - try { - service = locateService(ContextPropagationService.class); - } catch (Exception ex) { - error = new RuntimeException("Failed to instantiate task factory", ex); - } - - SERVICE = service; - ERROR = error; - } - - /** - * Modify a task so that a diagnostic context is propagated to the thread when the task runs. Done - * in a logging-framework specific way. - * - * @param task any Runnable that will run in a thread - * @return modified (wrapped) original task that runs the same business logic, but also takes care - * of copying the diagnostic context for logging - */ - public static Runnable create(Runnable task) { - - if (SERVICE == null) { - throw ERROR; - } - - return SERVICE.create(task); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java deleted file mode 100644 index a6a673d9dc..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.context; - -import org.openecomp.sdc.logging.types.LoggerConstants; -import org.slf4j.MDC; - - -public abstract class MdcData { - private String level; - private String errorCode; - - MdcData() { - } - - public MdcData(String level, String errorCode) { - this.level = level; - this.errorCode = errorCode; - } - - public void setMdcValues() { - MDC.put(LoggerConstants.ERROR_CATEGORY, this.level); - MDC.put(LoggerConstants.ERROR_CODE, this.errorCode); - } - - public String getLevel() { - return level; - } - - public void setLevel(String level) { - this.level = level; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java deleted file mode 100644 index d562ae5dd8..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.openecomp.sdc.logging.messages; - -/** - * Created by ayalaben on 4/20/2017. - */ -public class AuditMessages { - - public static final String AUDIT_MSG = " --Audit-- "; - - public static final String CREATE_VLM = "Create VLM. VLM Name: "; - public static final String CHECK_IN_VLM = "Check in VLM. VLM Id: "; - public static final String CHECK_OUT_VLM = "Check out VLM. VLM Id: "; - public static final String SUBMIT_VLM = "submit VLM. VLM Name: "; - - public static final String CREATE_VSP = "Create VSP. VSP Name: "; - public static final String CHECK_IN_VSP = "Check in VSP. VSP Id: "; - public static final String CHECK_OUT_VSP = "Check out VSP. VSP Id: "; - public static final String RESUBMIT_ALL_FINAL_VSPS = "Check out, check in and submit all " + - "submitted VSPs, see ids below "; - public static final String SUBMIT_VSP = "Submit VSP. VSP Id: "; - public static final String SUBMIT_VSP_FAIL = "Submit VSP failed!. VSP Id: "; - public static final String SUBMIT_VSP_ERROR = "Submit VSP error: %s. VSP Id: %s"; - - public static final String UPLOAD_HEAT = "Upload HEAT. VSP Id: "; - public static final String UPLOAD_PROCESS_ARTIFACT = "Upload Process Artifact. VSP Id: "; - public static final String UPLOAD_MONITORING_FILE = "Upload Monitoring File of type %s " - + ". VSP Id: %s, component id: %s"; - - public static final String IMPORT_SUCCESS = "VSP import to VF success. VSP Id: "; - public static final String IMPORT_FAIL = "VSP import to VF fail. VSP Id: "; - - public static final String HEAT_VALIDATION_STARTED = "HEAT validation started. VSP Id: "; - public static final String HEAT_VALIDATION_COMPLETED = "HEAT validation completed. VSP Id: "; - public static final String HEAT_VALIDATION_ERROR = "HEAT validation error: %s. VSP Id: %s"; - public static final String CSAR_VALIDATION_STARTED = "CSAR validation started. VSP Id: "; - public static final String HEAT_TRANSLATION_STARTED = "HEAT translation started. VSP Id: "; - public static final String HEAT_TRANSLATION_COMPLETED = "HEAT translation completed. VSP Id: "; - public static final String ENRICHMENT_ERROR = "Enrichment error: %s. VSP Id: %s"; - public static final String ENRICHMENT_COMPLETED = "Enrichment completed. VSP Id: "; - public static final String CREATE_PACKAGE = "Created package. VSP Id: "; - -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java deleted file mode 100644 index c3e5f977cc..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.messages; - - -public class DebugMessages { - public static final String DEFAULT_ENTER_METHOD = "Entering %s"; - public static final String DEFAULT_EXIT_METHOD = "Exiting %s"; - - public static final String ENTER_METHOD = "Entering %s with %s = %s"; - public static final String EXIT_METHOD = "Exiting %s with %s = %s"; - - public static final String ENTER_METHOD_FORMATTED = "Entering %s with %s"; - public static final String EXIT_METHOD_FORMATTED = "Exiting %s with %s"; - -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java deleted file mode 100644 index 71884cff70..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - -/** - * Created by TALIO on 1/10/2017. - */ -public class DebugConstants { - public static final String EXIT = "Exit"; - public static final String EXIT_DEFAULT = "Exit_Default"; - public static final String ENTER = "Enter"; - public static final String ENTER_DEFAULT = "Enter_Default"; - public static final String DEFAULT = "Default"; -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java deleted file mode 100644 index 0d591be095..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public class LoggerConstants { - - public static final String REQUEST_ID = "RequestId"; - public static final String PARTNER_NAME = "PartnerName"; - public static final String SERVICE_NAME = "ServiceName"; - public static final String INSTANCE_UUID = "InstanceUUID"; - public static final String CATEGORY_LOG_LEVEL = "level"; - public static final String STATUS_CODE = "StatusCode"; - public static final String RESPONSE_CODE = "ResponseCode"; - public static final String RESPONSE_DESCRIPTION = "ResponseDescription"; - public static final String TARGET_SERVICE_NAME = "TargetServiceName"; - public static final String TARGET_ENTITY = "TargetEntity"; - public static final String TARGET_ENTITY_API = "API"; - public static final String TARGET_ENTITY_DB = "DB"; - public static final String ERROR_CATEGORY = "ErrorCategory"; - public static final String ERROR_CODE = "ErrorCode"; - public static final String ERROR_DESCRIPTION = "ErrorDescription"; -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java deleted file mode 100644 index 5addccde7d..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public enum LoggerErrorCategory { - ERROR, - WARN, - DEBUG, - INFO, - FATAL; -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java deleted file mode 100644 index 3f48991c7f..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public enum LoggerErrorCode { - PERMISSION_ERROR("100"), - AVAILABILITY_ERROR("200"), - DATA_ERROR("300"), - SCHEMA_ERROR("400"), - BUSINESS_PROCESS_ERROR("500"), - UNKNOWN_ERROR("900"), ; - - private String errorCode; - - LoggerErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java deleted file mode 100644 index 7e502d55f2..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public class LoggerErrorDescription { - public static final String ARTIFACT_NOT_REFERENCED = "Artifact not referenced"; - public static final String WRONG_FILE_EXTENSION = "Wrong file extention"; - public static final String INVALID_HEAT_FORMAT = "Invalid HEAT format"; - public static final String PARAMETER_NOT_FOUND = "Referenced parameter not found"; - public static final String ENV_PARAMETER_NOT_IN_HEAT = "env includes parameter not in HEAT"; - public static final String PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE = - "Parameter default value not alinged with type"; - public static final String INVALID_RESOURCE_TYPE = "Invalid resource type"; - public static final String INVALID_GET_RESOURCE_SYNTAX = "Invalid get resource syntax"; - public static final String RESOURCE_NOT_FOUND = "Resource not found"; - public static final String INVALID_INDEX_VAR = "Invalid Resource Group index var"; - public static final String MISSING_FILE = "Missing file"; - public static final String MISSING_NOVA_PROPERTIES = "Missing NOVA server properties"; - public static final String NESTED_LOOP = "Found nested loop"; - public static final String MISSING_PARAMETER_IN_NESTED = "Missing parameter in nested file"; - public static final String WRONG_VALUE_ASSIGNED_NESTED_PARAMETER = - "Wrong value assigned in nested parameters"; - public static final String SERVER_NOT_DEFINED_NOVA = "Server not defined from nova"; - public static final String WRONG_POLICY_SERVER_GROUP = "Wrong policy in server group"; - public static final String SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE = - "Server group or security group is not in use"; - public static final String NETWORK_ATTACH_POLICY_NOT_IN_USE = - "Network Attach Policy is not in use"; - public static final String NO_BIND_FROM_PORT_TO_NOVA = "No bind from port to nova sever"; - public static final String PORT_BINDS_MORE_THAN_ONE_NOVA = - "Port binds to more than one nova sever"; - public static final String MISSING_RESOURCE_DEPENDS_ON = "Missing resource in depends_on"; - public static final String GET_ATTR_NOT_FOUND = "get_attr not found"; - public static final String MISSING_GET_PARAM = "Missing get_param"; - public static final String EMPTY_FILE = "Empty file"; - public static final String VALIDATE_FILE = "Can't validate file"; - public static final String INVALID_FILE_TYPE = "Invalid file type"; - public static final String INVALID_ZIP = "Invalid zip file"; - public static final String INVALID_VES_FILE = "Invalid VES file"; - - - - public static final String RESOURCE_UNIQUE_NETWORK_ROLE = - "Resource connects to two networks with the same role"; - public static final String NAME_NOT_ALIGNED_WITH_GUIDELINES = "Name not aligned with guidelines"; - public static final String VOLUME_FILE_NOT_EXPOSED = "Volume file not exposed"; - public static final String RESOURCE_NOT_DEFINED_AS_OUTPUT = "Resource is not defined as output"; - public static final String FLOATING_IP_IN_USE = "Floating IP resource type is in use"; - public static final String MISSING_BASE_HEAT = "Missing base HEAT file"; - public static final String MULTI_BASE_HEAT = "Multi base HEAT file"; - - public static final String EXTRACT_COMPOSITION_DATA = "Can't extract composition data"; - - public static final String MERGE_CONTRAIL_2_AND_3 = - "Merge of Contrail 2 and Contrail 3 resources"; - public static final String CONTRAIL_2_IN_USE = "Contrail 2 resource is in use"; - - public static final String INVALID_MANIFEST = "Invalid manifest file"; - - public static final String INVALID_YAML_FORMAT = "Invalid YAML format"; - - public static final String CREATE_SERVICE_ARTIFACT = "Can't create service artifact"; - public static final String CREATE_ENRICH_SERVICE_ARTIFACT = - "Can't create enriched service artifact"; - public static final String CREATE_SERVICE_TEMPLATE = "Can't create service template"; - public static final String CREATE_ENRICH_SERVICE_TEMPLATE = - "Can't create enriched service template"; - public static final String GET_SERVICE_MODEL = "Can't get service model"; - public static final String MISSING_MANDATORY_PROPERTY = "Missing mandatory property"; - public static final String INVALID_PROPERTY = "Invalid Property"; - public static final String INVALID_ADD_ACTION = "Invalid add action"; - public static final String UNSUPPORTED_ENTITY = "Unsupported entity"; - public static final String CREATE_CSAR = "Can't create CSAR file"; - public static final String PACK_ARTIFACTS = "Can't pack artifacts into CSAR file"; - - public static final String TRANSLATE_HEAT = "Can't translate HEAT file"; - public static final String RESOURCE_FILE_READ_ERROR = "Can't read resource file from class path."; - public static final String FAILED_TO_GENERATE_GLOBAL_TYPES = "Failed to generate globalTypes"; - - public static final String CHECKOUT_ENTITY = "Can't checkout versionable entity"; - public static final String SUBMIT_ENTITY = "Can't submit versionable entity"; - public static final String ENTITY_NOT_FOUND = "Versionable entity not found"; - public static final String INVALID_VALUE = "Invalid value"; - - public static final String UNSUPPORTED_OPERATION = "Unsupported operation"; - public static final String INVALID_JSON = "Invalid JSON format"; - - public static final String INSERT_INTO_APPLICATION_CONFIG = - "Can't insert value into application config table"; - - public static final String CANT_HEAL = "Can't perform healing operation"; -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java deleted file mode 100644 index e72d66aac9..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java +++ /dev/null @@ -1,182 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public enum LoggerServiceName { - - Create_VLM, - Get_VLM, - Checkout_VLM, - Checkin_VLM, - Undo_Checkout_VLM, - Submit_VLM, - Update_VLM, - List_VLM, - - List_EP, - Create_EP, - Update_EP, - Get_EP, - Delete_EP, - - Create_LIMIT, - Delete_LIMIT, - Update_LIMIT, - Get_LIMIT, - - List_FG, - Create_FG, - Update_FG, - Get_FG, - Delete_FG, - - List_LA, - Create_LA, - Update_LA, - Get_LA, - Delete_LA, - - List_LKG, - Create_LKG, - Update_LKG, - Get_LKG, - Delete_LKG, - - List_VSPs, - List_Packages, - Create_VSP, - Get_VSP, - Checkout_VSP, - Checkin_VSP, - Undo_Checkout_VSP, - Submit_VSP, - Update_VSP, - Re_Submit_ALL_Final_VSPs, - Create_Package, - List_VSP, - Upload_File, - Get_Uploaded_File, - Get_Translated_File, - Get_Questionnaire_VSP, - Update_Questionnaire_VSP, - Get_Information_Artifact, - - - List_Component_Processes, - Delete_List_Component_Processes, - Create_Component_Processes, - Update_Component_Processes, - Get_Component_Processes, - Delete_Component_Processes, - Upload_File_Component_Processes, - Get_Uploaded_File_Component_Processes, - Delete_Uploaded_File_Component_Processes, - - List_Processes, - Delete_List_Processes, - Create_Processes, - Update_Processes, - Get_Processes, - Delete_Processes, - Upload_File_Processes, - Get_Uploaded_File_Processes, - Delete_Uploaded_File_Processes, - - List_Components, - Delete_List_Components, - Create_Component, - Update_Component, - Get_Component, - Delete_Component, - Get_Questionnaire_Component, - Update_Questionnaire_Component, - - Upload_Monitoring_Artifact, - Delete_Monitoring_Artifact, - List_Monitoring_Artifacts, - - List_Network, - Create_Network, - Update_Network, - Get_Network, - Delete_Network, - - List_nics, - Delete_List_nics, - Create_nic, - Update_nic, - Get_nic, - Delete_nic, - Get_Questionnaire_nic, - Update_Questionnaire_nic, - - Create_Process, - Update_Process, - - Create_Compute, - List_Computes, - Get_Compute, - Update_Compute, - Delete_Compute, - Get_Questionnaire_Compute, - Update_Questionnaire_Compute, - - Insert_To_ApplicationConfig_Table, - Get_From_ApplicationConfig_Table, - Get_List_From_ApplicationConfig_Table_By_Namespace, - - Create_Deployment_Flavor, - Get_List_Deployment_flavor, - Get_Deployment_flavor, - Delete_Deployment_flavor, - Update_Deployment_flavor, - - Get_List_Activity_Log, - - Validate, - Enrich, Delete_VSP, Get_Process_Artifact, Create_Entity, Checkout_Entity, Undo_Checkout_Entity, - Checkin_Entity, Submit_Entity, Get_Entity_Version, Delete_Entity, Undo_Delete_Entity, - Translate_Resource, Translate_HEAT, LoggerServiceName, Get_VSP_List, Delete_VLM, Update_Manifest, - Create_Image, - GET_Image_Schema, - List_Images, - GET_Image, - Delete_Image, - Update_Image, - - CREATE_COMPONENT_DEPENDENCY_MODEL, - GET_COMPONENT_DEPENDENCY_MODEL, - - Health_check - ; - - public static String getServiceName(LoggerServiceName serviceName) { - return serviceName.name().replace("_", " "); - } - - @Override - public String toString(){ - return this.name().replace("_", " "); - } - - -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java deleted file mode 100644 index 6b0570eb29..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java +++ /dev/null @@ -1,206 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.types; - - -public class LoggerTragetServiceName { - /*HEAT validator*/ - public static final String VALIDATE_HEAT_BASE_STRUCTURE = "Validate Heat Base Structure"; - public static final String VALIDATE_ARTIFACTS_EXISTENCE = "Validate Artifacts Existence"; - public static final String VALIDATE_RESOURCE_REFERENCE_EXISTENCE = - "Validate Resource Reference Existence"; - public static final String VALIDATE_PARAMETER_REFERENCE_EXITENCE = - "Validate Parameter Reference Existence"; - public static final String VALIDATE_GET_ATTR_FROM_NESTED = "Validate get_attr From Nested"; - public static final String VALIDATE_ENV_FILE = "Validate env File"; - public static final String VALIDATE_BASE_PORTS_EXISTENCE = "Validate Base Ports Existence"; - public static final String VALIDATE_ASSIGNED_VALUES_FOR_NOVA_IMAGE_FLAVOR = - "Validate Assigned Value For Nova Server Image Or Flavor"; - public static final String VALIDATE_NOVA_SERVER_PORT_BINDING = - "Validate Ports Binding From Nova Server"; - public static final String VALIDATE_SERVER_GROUP_EXISTENCE = - "Validate Nova Server Group Existence"; - public static final String VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS = - "Validate All Properties Match Nested Parameters"; - public static final String VALIDATE_NESTING_LOOPS = "Validate Nested Loops"; - public static final String VALIDATE_NOVA_SEVER_GROUP_POLICY = "Validate Nova Server Group Policy"; - public static final String VALIDATE_RESOURCE_GROUP_TYPE = "Validate Resource Group Resource Type"; - public static final String VALIDATE_ALL_SECURITY_GROUP_USED = - "Validate All Security Group Are Used From Neutron Port Resource"; - public static final String VALIDATE_CONTRAIL_ATTACH_POLICY_TYPE = - "Validate Contrail Attach Policy Type"; - public static final String VALIDATE_SECURITY_GROUP_FROM_BASE_OUTPUT = - "Validate Security Groups From Base File Outputs"; - public static final String CHECK_FOR_ORPHAN_PORTS = "Validate All Referenced Ports Are Used"; - public static final String CHECK_FOR_ORPHAN_ARTIFACTS = "Validate All Artifacts Are Referenced"; - public static final String CHECK_FOR_VALID_FILE_EXTENTION = "Validate File Extention"; - public static final String VALIDATE_PARAMTER_DEFAULT_MATCH_TYPE = - "Validate Parameter Default Aligns With Type"; - public static final String VALIDATE_ENV_PARAMETER_MATCH_TYPE = - "Validate env Parameter Matches Type"; - public static final String VALIDATE_RESOURCE_TYPE = "Validate Resource Type"; - public static final String VALIDATE_FILE_EXISTENCE = "Validate File Exitence"; - public static final String GET_RESOURCE_LIST_BY_TYPE = - "Get All Resources By Specific Resource Type"; - public static final String VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE = - "Validate All Security Group Or Server Group Are In Use"; - public static final String VALIDATE_ATTACH_POLICY_IN_USE = - "Validate All Network Attach Policies Are In Use"; - public static final String CHECK_RESOURCE_DEPENDS_ON = "Check Resource dependes_on"; - public static final String GET_SHARED_RESOURCES_FROM_OUTPUTS = - "Get Shared Resources From Outputs"; - public static final String VALIDATE_GET_RESOURCE = "Validate get_resource Syntax"; - public static final String VALIDATE_FILE = "Validate File"; - - /*manifest validator*/ - public static final String VALIDATE_MANIFEST_CONTENT = "Validate Manifest Content"; - public static final String VALIDATE_FILE_IN_ZIP = "Validate File In Zip"; - public static final String VALIDATE_FILE_IN_MANIFEST = "Validate File In Manifest"; - public static final String VALIDATE_FILE_TYPE_AND_NAME = - "Validate File Type And Name In Manifest"; - public static final String SCAN_MANIFEST_STRUCTURE = "Scan Manifest Structure"; - public static final String VALIDATE_FILE_TYPE = "Validate File Type"; - - /*YAML validator*/ - public static final String VALIDATE_YAML_CONTENT = "Validate YAML Content"; - - - /*OPENECOMP guide line validator*/ - public static final String VALIDATE_BASE_FILE = - "Validate If All Resources In Base File Are Exposed"; - public static final String VALIDATE_FORBIDDEN_RESOURCE = "Validate If Resource Type Is Forbidden"; - public static final String VALIDATE_FIXED_IPS_NAME = "Validate fixed_ips Naming Convention"; - public static final String VALIDATE_IMAGE_AND_FLAVOR_NAME = - "Validate image And flavor Naming Convention"; - public static final String VALIDATE_NOVA_SERVER_NAME = "Validate Nova Server Naming Convention"; - public static final String VALIDATE_AVAILABILITY_ZONE_NAME = - "Validate availability_zone Naming Convention"; - public static final String VALIDATE_NOVA_META_DATA_NAME = - "Validate Nova Server Meta Data Naming Convention"; - public static final String VALIDATE_PORT_NETWORK_NAME = "Validate Port Network Naming Convention"; - public static final String VALIDATE_VM_SYNC_IN_IMAGE_FLAVOR = - "Validate VM Name Is Sync In Image And Flavor"; - public static final String VALIDATE_RESOURCE_NETWORK_UNIQUE_ROLW = - "Validate Nova Server Unique Role"; - public static final String VALIDATE_VOLUME_FILE = "Validate HEAT Volume File"; - - - public static final String VALIDATE_CONTRAIL_VM_NAME = - "Validate Contrail VM Name Aligned With Guidelines"; - public static final String MERGE_OF_CONTRAIL_2_AND_3 = "Merge Of Contrail 2 And Contrail 3"; - public static final String CONTRAIL_2_IN_USE = "Validate Contrail 2 Resource Is In Use"; - - - public static final String VALIDATE_MANIFEST_PRE_CONDITION = "Validate Manifest Pre-Condition"; - public static final String VALIDATE_HEAT_FORMAT = "Validate HEAT Format"; - - public static final String CREATE_ENTITY = "Create Entity"; - public static final String CHECKOUT_ENTITY = "Checkout Entity"; - public static final String UNDO_CHECKOUT_ENTITY = "Undo Checkout Entity"; - public static final String CHECKIN_ENTITY = "Checkin Entity"; - public static final String SUBMIT_ENTITY = "Submit Entity"; - public static final String DELETE_ENTITY = "Delete Entity"; - public static final String UNDO_DELETE_ENTITY = "Undo Delete Entity"; - - public static final String SUBMIT_VSP = "Submit VSP"; - public static final String GET_VSP = "Get VSP"; - public static final String ADD_VSP = "Add VSP"; - public static final String DELETE_VSP = "Delete VSP"; - public static final String UPDATE_VSP = "Update VSP"; - public static final String ENRICH = "Enrich"; - public static final String UPLOAD_FILE = "Upload file"; - public static final String GET_UPLOADED_HEAT = "Get Uploaded HEAT File"; - public static final String GET_TRANSLATED_FILE = "Get Translated File"; - public static final String CREATE_TRANSLATED_FILE = "Create Translated File"; - public static final String CREATE_PACKAGE = "Create Package"; - - public static final String SELF_HEALING = "Self Healing"; - public static final String WRITE_ARTIFACT_XML = "Write Artifact To XML File"; - - public static final String GET_VLM = "Get VLM"; - - public static final String VALIDATE_MONITORING_FILE = "Validate Monitoring File"; - public static final String UPLOAD_MONITORING_FILE = "Upload Monitoring file"; - - public static final String GET_VERSION_INFO = "Get version info"; - - public static final String CREATE_NETWORK = "Create Network"; - public static final String DELETE_NETWORK = "Delete Network"; - - public static final String CREATE_COMPONENT = "Create Component"; - public static final String DELETE_COMPONENT = "Delete Component"; - public static final String UPDATE_COMPONENT = "Update Component"; - - public static final String GET_PROCESS_ARTIFACT = "Get Process Artifact"; - public static final String UPLOAD_PROCESS_ARTIFACT = "Upload Process Artifact"; - - public static final String CREATE_NIC = "Create Nic"; - public static final String DELETE_NIC = "Delete Nic"; - public static final String UPDATE_NIC = "Update Nic"; - - public static final String CREATE_DEPLOYMENT_FLAVOR = "Create Deployment Flavor"; - public static final String DELETE_DEPLOYMENT_FLAVOR = "Delete Deployment Flavor"; - public static final String UPDATE_DEPLOYMENT_FLAVOR = "Update Deployment Flavor"; - - public static final String EXTRACT_COMPOSITION_DATA = "Extract Composition Data"; - - public static final String TRANSLATE_RESOURCE = "Translate Resource"; - public static final String GET_RESOURCE = "Get Resource"; - public static final String VALIDATE_HEAT_BEFORE_TRANSLATE = "Validate HEAT Before Translate"; - - public static final String CREATE_SERVICE_ARTIFACT = "Create Service Artifact In DB"; - public static final String CREATE_SERVICE_ENRICH_ARTIFACT = - "Create Service Enriched Artifact In DB"; - public static final String CREATE_SERVICE_TEMPLATE = "Create Service Template In DB"; - public static final String CREATE_ENRICH_SERVICE_TEMPLATE = - "Create Enriched Service Template In DB"; - public static final String GET_SERVICE_MODEL = "Get service model"; - public static final String GET_SERVICE_TEMPLATE = "Get Service Template"; - public static final String CREATE_REQUIREMENT_ASSIGNMENT = "Create Requierment Assignment"; - public static final String GENERATE_TRANSLATED_ID = "Generate Translated Id"; - public static final String ADD_ENTITIES_TO_TOSCA = "Add Entities To TOSCA"; - public static final String CREATE_CSAR = "Create CSAR"; - public static final String PACK_ARTIFACTS = "Pack Artifacts Into CSAR File"; - - public static final String VALIDATE_CHOICE_VALUE = "Check Chosen Value"; - - public static final String INSERT_INTO_APPLICATION_CONFIG = - "Insert Value Into Application Config"; - - public static final String VALIDATE_FILE_DATA_STRUCTURE = "Validate Manifest Sent From User"; - public static final String CREATE_IMAGE = "Create Image"; - public static final String DELETE_IMAGE = "Delete Image"; - public static final String UPDATE_IMAGE = "Update Image"; - - public static final String CREATE_COMPUTE = "Create Compute"; - public static final String UPDATE_COMPUTE = "Update Compute"; - public static final String DELETE_COMPUTE = "Delete Compute"; - - public static final String COLLECT_MANUAL_VSP_TOSCA_DATA = "Collect Manual Vsp Tosca data"; - public static final String GENERATE_MANUAL_VSP_TOSCA = "Generate Manual Vsp Tosca"; - - public static final String VALIDATE_DATE_RANGE = "Validate Date Range"; - - public static final String CREATE_COMPONENT_DEPENDENCY_MODEL = "Create Component Dependency " - + "Model"; - - public static final String READ_RESOURCE_FILE = "Read Resource File"; -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json deleted file mode 100644 index 33163b32bb..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "org.openecomp.sdc.logging.api.BaseFactory": "org.openecomp.sdc.logging.api.LoggerFactory" -} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml deleted file mode 100644 index 8eb22bda96..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml +++ /dev/null @@ -1,284 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log - - - - - - AUDIT_MARKER - - NEUTRAL - DENY - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - INFO - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log - - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - - - e.level.toInt() <= DEBUG.toInt() - - - DENY - NEUTRAL - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log - - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - - - e.level.toInt() <= DEBUG.toInt() - - - DENY - NEUTRAL - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log.%i - - 1 - 10 - - - - 20MB - - - ${asdc-debug-log-pattern} - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log - - - - - - AUDIT_MARKER - - DENY - ACCEPT - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log - - - - - - TRANSACTION_MARKER - - DENY - ACCEPT - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml deleted file mode 100644 index be8e5521a3..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - 4.0.0 - openecomp-sdc-logging-core - org.openecomp.sdc - openecomp-sdc-logging-core - - - org.openecomp.sdc - openecomp-logging-lib - 1.2.0-SNAPSHOT - - - - - org.openecomp.sdc - openecomp-sdc-logging-api - ${project.version} - - - org.springframework - spring-context - ${spring.framework.version} - - - org.springframework - spring-webmvc - ${spring.framework.version} - provided - - - ch.qos.logback - logback-classic - ${logback.version} - - - javax.servlet - servlet-api - ${servlet.version} - - - - diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java deleted file mode 100644 index 711e6d1559..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging; - -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -/** - *

The list of markers that can be used for special logging such as metrics, audit, etc.

- * - *

Although markers can be easily instantiated whenever needed, having constants for them helps eliminate mistakes - - * misspelling, using a marker that is not handled, etc.

- * - *

Usage:

- * - *
- *
- *     Logger log = LogFactory.getLogger(this.getClass());
- *     log.info(Markers.AUDIT, "User '{}' logged out", user);
- *
- * 
- * - * @author EVITALIY - * @since 13/09/2016. - * - * @see Marker - */ -public class Markers { - - public static final Marker AUDIT = MarkerFactory.getMarker("AUDIT"); - public static final Marker METRICS = MarkerFactory.getMarker("METRICS"); -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java deleted file mode 100644 index 5b7ed5ef4d..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java +++ /dev/null @@ -1,240 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging; - -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerCreationService; -import org.slf4j.LoggerFactory; - -/** - * @author evitaliy - * @since 13/09/2016. - */ -public class SLF4JLoggerCreationService implements LoggerCreationService { - - @Override - public Logger getLogger(String className) { - return new SFL4JWrapper(className); - } - - @Override - public Logger getLogger(Class clazz) { - return new SFL4JWrapper(clazz); - } - - private class SFL4JWrapper implements Logger { - - private final org.slf4j.Logger logger; - - public SFL4JWrapper(Class clazz) { - logger = LoggerFactory.getLogger(clazz); - } - - public SFL4JWrapper(String className) { - logger = LoggerFactory.getLogger(className); - } - - @Override - public String getName() { - return logger.getName(); - } - - @Override - public boolean isMetricsEnabled() { - return logger.isInfoEnabled(Markers.METRICS); - } - - @Override - public void metrics(String msg) { - logger.info(Markers.METRICS, msg); - } - - @Override - public void metrics(String msg, Object arg) { - logger.info(Markers.METRICS, msg, arg); - } - - @Override - public void metrics(String msg, Object arg1, Object arg2) { - logger.info(Markers.METRICS, msg, arg1, arg2); - } - - @Override - public void metrics(String msg, Object... arguments) { - logger.info(Markers.METRICS, msg, arguments); - } - - @Override - public void metrics(String msg, Throwable t) { - logger.info(Markers.METRICS, msg, t); - } - - @Override - public boolean isAuditEnabled() { - return logger.isInfoEnabled(Markers.AUDIT); - } - - @Override - public void audit(String msg) { - logger.info(Markers.AUDIT, msg); - } - - @Override - public void audit(String msg, Object arg) { - logger.info(Markers.AUDIT, msg, arg); - } - - @Override - public void audit(String msg, Object arg1, Object arg2) { - logger.info(Markers.AUDIT, msg, arg1, arg2); - } - - @Override - public void audit(String msg, Object... arguments) { - logger.info(Markers.AUDIT, msg, arguments); - } - - @Override - public void audit(String msg, Throwable t) { - logger.info(Markers.AUDIT, msg, t); - } - - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - @Override - public void debug(String msg) { - logger.debug(msg); - } - - @Override - public void debug(String format, Object arg) { - logger.debug(format, arg); - } - - @Override - public void debug(String format, Object arg1, Object arg2) { - logger.debug(format, arg1, arg2); - } - - @Override - public void debug(String format, Object... arguments) { - logger.debug(format, arguments); - } - - @Override - public void debug(String msg, Throwable t) { - logger.debug(msg, t); - } - - @Override - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - @Override - public void info(String msg) { - logger.info(msg); - } - - @Override - public void info(String format, Object arg) { - logger.info(format, arg); - } - - @Override - public void info(String format, Object arg1, Object arg2) { - logger.info(format, arg1, arg2); - } - - @Override - public void info(String format, Object... arguments) { - logger.info(format, arguments); - } - - @Override - public void info(String msg, Throwable t) { - logger.info(msg, t); - } - - @Override - public boolean isWarnEnabled() { - return logger.isWarnEnabled(); - } - - @Override - public void warn(String msg) { - logger.warn(msg); - } - - @Override - public void warn(String format, Object arg) { - logger.warn(format, arg); - } - - @Override - public void warn(String format, Object... arguments) { - logger.warn(format, arguments); - } - - @Override - public void warn(String format, Object arg1, Object arg2) { - logger.warn(format, arg1, arg2); - } - - @Override - public void warn(String msg, Throwable t) { - logger.warn(msg, t); - } - - @Override - public boolean isErrorEnabled() { - return logger.isErrorEnabled(); - } - - @Override - public void error(String msg) { - logger.error(msg); - } - - @Override - public void error(String format, Object arg) { - logger.error(format, arg); - } - - @Override - public void error(String format, Object arg1, Object arg2) { - logger.error(format, arg1, arg2); - } - - @Override - public void error(String format, Object... arguments) { - logger.error(format, arguments); - } - - @Override - public void error(String msg, Throwable t) { - logger.error(msg, t); - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java deleted file mode 100644 index 7ac5be0591..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.aspects; - -import org.aspectj.lang.JoinPoint; -import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -import java.lang.reflect.Method; - - -/** - * Created by TALIO on 12/26/2016. - */ -public class DebugAspect { - - private static final String MESSAGE_TEMPLATE = "'{}' '{}' with '{}'"; - private static final Marker DEBUG = MarkerFactory.getMarker("DEBUG"); - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - -// @Autowired -// private ParameterNameDiscoverer parameterNameDiscoverer; - - public void debugEnterMethod(final JoinPoint joinPoint){ - - Class type = joinPoint.getSignature().getDeclaringType(); - Method currentMethod = null; - for(Method method : type.getMethods()){ - if(method.getName().equals(joinPoint.getSignature().getName())){ - currentMethod = method; - break; - } - } - -// String[] parameterNames = parameterNameDiscoverer.getParameterNames(currentMethod); -// Object[] args = joinPoint.getArgs(); -// Parameter[] parameters = currentMethod.getParameters(); -// StringBuilder str = new StringBuilder(joinPoint.getSignature().getName() + " with parameters:" + -// " "); -// if(args.length == parameters.length) { -// for (int i = 0; i < args.length; i++) { -// str.append(parameters[i].getName()).append('=').append(args[i]); -// } -// } - mdcDataDebugMessage.debugEntryMessage(null, null); - } - - public void debugExitMethod(final JoinPoint joinPoint){ - mdcDataDebugMessage.debugExitMessage(null, null); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java deleted file mode 100644 index 782362b912..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.aspects; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -/** - *

Wraps around any method annotated with {@link Metrics} to measure and log its execution time - * in milliseconds.

- *

In order for the aspect to be used, AspectJ annotation processing must be tuned on and this - * particular aspect enabled. Conversely, it can be disabled completely if the application does not - * need to log metrics.

- *

See, for example, - * Aspect Oriented Programming with Spring.

- * - * @author evitaliy - * @see Metrics - * @since 27/07/2016. - */ -@Aspect -public class MetricsAspect { - - private static final String MESSAGE_TEMPLATE = "'{}' took {} milliseconds"; - private static final Marker METRICS = MarkerFactory.getMarker("METRICS"); - - @Around("@annotation(org.openecomp.sdc.logging.api.annotations.Metrics)") - public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable { - - final Logger logger = LoggerFactory.getLogger(pjp.getSignature().getDeclaringTypeName()); - // measure and log only if the logger for this class is enabled - if (logger.isInfoEnabled()) { - - final String method = pjp.getSignature().getName(); - final long start = System.currentTimeMillis(); - - try { - return pjp.proceed(); - } finally { - logger.info(METRICS, MESSAGE_TEMPLATE, method, System.currentTimeMillis() - start); - } - - } else { - return pjp.proceed(); - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java deleted file mode 100644 index 7e29f3c093..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.context; - -import org.openecomp.sdc.logging.api.context.ContextPropagationService; -import org.slf4j.MDC; - -import java.util.Map; - -/** - * Propagates the SLF4J Mapped Diagnostic Context (MDC) - * of a thread onto a runnable created by that thread, so that the context is available when the runnable is executed - * in a new thread. - * - * @author evitaliy - * @since 12/09/2016. - */ -public class MDCPropagationService implements ContextPropagationService { - - public Runnable create(Runnable task) { - return new MDCCopyingWrapper(task); - } - - private static class MDCCopyingWrapper implements Runnable { - - private final Runnable task; - private final Map context; - - private MDCCopyingWrapper(Runnable task) { - this.task = task; - this.context = MDC.getCopyOfContextMap(); - } - - @Override - public void run() { - - Map oldContext = MDC.getCopyOfContextMap(); - replaceMDC(this.context); - - try { - task.run(); - } finally { - replaceMDC(oldContext); - } - } - - private static void replaceMDC(Map context) { - - if (context == null) { - MDC.clear(); - } else { - MDC.setContextMap(context); - } - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java deleted file mode 100644 index 24d47162f4..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.context; - -import org.openecomp.sdc.logging.types.LoggerConstants; -import org.slf4j.MDC; - -import java.util.UUID; - - -public class MdcUtil { - - /** - * Sets values for mdc. - * - * @param targetEntity the target entity - * @param targetServiceName the target service name - * @param errorCategory the error category - * @param errorCode the error code - * @param errorDescription the error description - */ - public static void setValuesForMdc(String targetEntity, String targetServiceName, - String errorCategory, String errorCode, - String errorDescription) { - MDC.put(LoggerConstants.TARGET_ENTITY, targetEntity); - MDC.put(LoggerConstants.TARGET_SERVICE_NAME, targetServiceName); - MDC.put(LoggerConstants.ERROR_CATEGORY, errorCategory); - MDC.put(LoggerConstants.ERROR_CODE, errorCode); - MDC.put(LoggerConstants.ERROR_DESCRIPTION, errorDescription); - } - - - /** - * Init mdc. - * @param serviceName the service name - * - */ - public static void initMdc(String serviceName) { - MDC.put(LoggerConstants.SERVICE_NAME, serviceName); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java deleted file mode 100644 index b21504d752..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.context.impl; - -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.logging.context.MdcData; -import org.openecomp.sdc.logging.messages.DebugMessages; -import org.openecomp.sdc.logging.types.DebugConstants; -import org.openecomp.sdc.logging.types.LoggerErrorCategory; -import org.openecomp.sdc.logging.util.LoggingUtils; - -import java.util.HashMap; -import java.util.Map; - -public class MdcDataDebugMessage extends MdcData { - - private Logger logger; - private static Map mapExitOrEntryToMessage; - - static { - mapExitOrEntryToMessage = new HashMap<>(); - mapExitOrEntryToMessage.put(DebugConstants.ENTER, DebugMessages.ENTER_METHOD); - mapExitOrEntryToMessage.put(DebugConstants.ENTER_DEFAULT, DebugMessages.DEFAULT_ENTER_METHOD); - mapExitOrEntryToMessage.put(DebugConstants.EXIT, DebugMessages.EXIT_METHOD); - mapExitOrEntryToMessage.put(DebugConstants.EXIT_DEFAULT, DebugMessages.DEFAULT_EXIT_METHOD); - } - - public MdcDataDebugMessage() { - super(LoggerErrorCategory.DEBUG.name(), null); - } - - //todo add more explanations as to the first parameter structure in case of multiples and in - // case of no params in method - /** - * Debug entry message. - * - * @param entityParameter the entity parameter - * @param ids the ids - */ - public void debugEntryMessage(String entityParameter, String... ids) { - logDebugMessage(entityParameter, DebugConstants.ENTER, ids); - } - - /** - * Debug exit message. - * - * @param entityParameter the entity parameter - * @param ids the ids - */ - public void debugExitMessage(String entityParameter, String... ids) { - logDebugMessage(entityParameter, DebugConstants.EXIT, ids); - } - - public void logDebugMessage(String entityParameter, String enterOrExit, String... ids) { - String methodName = LoggingUtils.getCallingMethodNameForDebugging(); - String declaringClass = LoggingUtils.getDeclaringClass(); - logger = (Logger) LoggerFactory.getLogger(declaringClass); - String messageToWrite; - - if (entityParameter == null || ids == null) { - messageToWrite = mapExitOrEntryToMessage.get(enterOrExit + "_" + DebugConstants.DEFAULT); - logger.debug(String.format(messageToWrite, methodName)); - } else { - messageToWrite = mapExitOrEntryToMessage.get(enterOrExit); - logger.debug(String - .format(messageToWrite, methodName, entityParameter, String.join(",", ids))); - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java deleted file mode 100644 index 190c37d2b6..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.context.impl; - -import org.openecomp.sdc.logging.context.MdcData; -import org.openecomp.sdc.logging.types.LoggerConstants; -import org.slf4j.MDC; - - -public class MdcDataErrorMessage extends MdcData { - private String targetEntity; - private String targetServiceName; - private String errorDescription; - - /** - * Instantiates a new Mdc data error message. - * - * @param targetEntity the target entity - * @param targetServiceName the target service name - * @param errorCategory the error category - * @param errorCode the error code - * @param errorDescription the error description - */ - public MdcDataErrorMessage(String targetEntity, String targetServiceName, String errorCategory, - String errorCode, String errorDescription) { - super(errorCategory, errorCode); - this.targetEntity = targetEntity; - this.targetServiceName = targetServiceName; - this.errorDescription = errorDescription; - - this.setMdcValues(); - } - - /** - * Create error message and update mdc. - * - * @param targetEntity the target entity - * @param targetServiceName the target service name - * @param level the level - * @param errorCode the error code - * @param errorDescription the error description - */ - public static void createErrorMessageAndUpdateMdc(String targetEntity, String targetServiceName, - String level, String errorCode, - String errorDescription) { - MdcDataErrorMessage mdcDataErrorMessage = - new MdcDataErrorMessage(targetEntity, targetServiceName, level, errorCode, - errorDescription); - } - - @Override - public void setMdcValues() { - super.setMdcValues(); - MDC.put(LoggerConstants.TARGET_ENTITY, this.targetEntity); - MDC.put(LoggerConstants.TARGET_SERVICE_NAME, this.targetServiceName); - MDC.put(LoggerConstants.ERROR_DESCRIPTION, this.errorDescription); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java deleted file mode 100644 index 2273e1c7ef..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.logback; - -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.sift.MDCBasedDiscriminator; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.AppenderBase; -import ch.qos.logback.core.joran.spi.DefaultClass; -import ch.qos.logback.core.sift.Discriminator; -import org.slf4j.LoggerFactory; - -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - *

Allows to use EELF logging configuration almost as is, by using a custom routing function, but pre-configured - * appenders attached to the standard EELF loggers.

- * - *

Changes that must be made in logback.xml supplied with EELF:

- * - *
- *     <appender name="DISPATCHER" class="org.openecomp.sdc.logging.logback.DispatchingAppender">
- *          <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/>
- *          <appenderNamePattern>asyncEELF%s</appenderNamePattern>
- *     </appender>
- *
- *     <root level="INFO" additivity="false">
- *          <appender-ref ref="DISPATCHER" />
- *      </root>
- * 
- * - * @author EVITALIY - * @since 17/08/2016. - */ -public class DispatchingAppender extends AppenderBase { - - // "magic" appender to indicate a missing appender - private static final Appender NO_APPENDER = new DispatchingAppender(); - - private Map> appenders = new ConcurrentHashMap<>(); - - private Discriminator discriminator; - private String appenderNamePattern; - - @DefaultClass(MDCBasedDiscriminator.class) - public void setDiscriminator(Discriminator discriminator) { - this.discriminator = discriminator; - } - - public Discriminator getDiscriminator() { - return this.discriminator; - } - - public void setAppenderNamePattern(String pattern) { - this.appenderNamePattern = pattern; - } - - public String getAppenderNamePattern() { - return this.appenderNamePattern; - } - - @Override - protected void append(ILoggingEvent event) { - - if (this.isStarted()) { - - String discriminatingValue = this.discriminator.getDiscriminatingValue(event); - String appenderName = String.format(this.appenderNamePattern, discriminatingValue); - Appender appender = this.lookupAppender(appenderName); - if (appender == NO_APPENDER) { - this.addError(String.format("Appender %s does not exist", appenderName)); - } else { - appender.doAppend(event); - } - } - } - - private Appender lookupAppender(String key) { - - Appender appender = appenders.get(key); - if (appender != null) { - return appender; - } - - LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); - for (Logger log : context.getLoggerList()) { - - Iterator> iterator = log.iteratorForAppenders(); - while (iterator.hasNext()) { - - Appender element = iterator.next(); - if (key.equals(element.getName())) { - this.appenders.putIfAbsent(key, element); - return element; - } - } - } - - // to avoid consecutive lookups if the required appender does not exist - this.appenders.putIfAbsent(key, NO_APPENDER); - return NO_APPENDER; - } - - @Override - public void start() { - - int errors = 0; - if (this.discriminator == null) { - this.addError("Missing discriminator. Aborting"); - } - - if (!this.discriminator.isStarted()) { - this.addError("Discriminator has not started successfully. Aborting"); - ++errors; - } - - if (this.appenderNamePattern == null) { - this.addError("Missing name pattern. Aborting"); - ++errors; - } - - if (errors == 0) { - super.start(); - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java deleted file mode 100644 index 5aa36656af..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.logback; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.sift.AbstractDiscriminator; -import org.openecomp.sdc.logging.Markers; -import org.slf4j.Marker; - -/** - * Can be used with {@link ch.qos.logback.classic.sift.SiftingAppender} to route events of different types to - * separate log files. For example, - * - *
- *     <configuration>
- *         <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
- *             <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/>
- *             <sift>
- *                  <appender name="{EventType}" class="ch.qos.logback.core.rolling.RollingFileAppender">
- *                      <file>${logDirectory}/${eventType}.log</file>
- *                      <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- *                          <fileNamePattern>${logDirectory}/${eventType}.%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>${defaultPattern}</pattern>
- *                      </encoder>
- *                  </appender>
- *             </sift>
- *         </appender>
- *
- *         <root level="INFO">
- *             <appender-ref ref="SIFT" />
- *         </root>
- *     </configuration>
- * 
- * - * @author evitaliy - * @since 21/07/2016. - */ -public class EventTypeDiscriminator extends AbstractDiscriminator { - - private static final String KEY = "eventType"; - - private static final String AUDIT = "Audit"; - private static final String METRICS = "Metrics"; - private static final String ERROR = "Error"; - private static final String DEBUG = "Debug"; - private static final String DEFAULT = DEBUG; - - private static final int MIN_ERROR_LEVEL = Level.WARN_INT; - private static final int MAX_ERROR_LEVEL = Level.ERROR_INT; - private static final int DEFAULT_LEVEL = Level.DEBUG_INT; - - @Override - public String getDiscriminatingValue(ILoggingEvent event) { - - Level level = event.getLevel(); - final int levelInt = level == null ? DEFAULT_LEVEL : level.toInt(); - if ((levelInt > MIN_ERROR_LEVEL - 1) && (levelInt < MAX_ERROR_LEVEL + 1)) { - return ERROR; - } - - if (levelInt == Level.DEBUG_INT) { - return DEBUG; - } - - /* - * After DEBUG, ERROR, and WARNING have been filtered out, - * only TRACE and INFO are left. TRACE is less than DEBUG - * and therefore cannot be used. So, INFO should be used for - * custom routing like AUDIT and METRICS - */ - if (levelInt == Level.INFO_INT) { - - final Marker marker = event.getMarker(); - if (marker != null) { - - if (marker.contains(Markers.AUDIT)) { - return AUDIT; - } - - if (marker.contains(Markers.METRICS)) { - return METRICS; - } - } - - return ERROR; - } - - return DEFAULT; - } - - @Override - public String getKey() { - return KEY; - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java deleted file mode 100644 index 87184455c3..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.method; - -import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -/** - * Created by TALIO on 1/8/2017. - */ -public class LoggingInvocationHandler implements InvocationHandler { - - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - private final Object invocImpl; - - public LoggingInvocationHandler(final Object invocImpl){ - this.invocImpl = invocImpl; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - mdcDataDebugMessage.debugEntryMessage(null, null); - return method.invoke(invocImpl, args); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java deleted file mode 100644 index 31b89464c9..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.servlet; - -import org.omg.CORBA.Request; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.slf4j.MDC; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; - - -/** - * - *

Pushes information required by EELF onto MDC (Mapped Diagnostic Context).

- * - *

This is servlet filter that should be configured in web.xml to be used. Example:

- * - *
- *
- *  <filter>
- *      <filter-name>LoggingServletFilter</filter-name>
- *      <filter-class>org.openecomp.sdc.logging.servlet.LoggingFilter</filter-class>
- *  </filter>
- *
- *  <filter-mapping>
- *      <filter-name>LoggingServletFilter</filter-name>
- *      <url-pattern>/*</url-pattern>
- *  </filter-mapping>
- *
- * 
- * - * @author evitaliy - * @since 25/07/2016. - */ -public class LoggingFilter implements Filter { - - // should be cashed to avoid low-level call, but with a timeout to account for IP or FQDN changes - private static final HostAddressCache HOST_ADDRESS = new HostAddressCache(); - private static final String UNKNOWN = "UNKNOWN"; - - private final static Logger log = (Logger) LoggerFactory.getLogger(LoggingFilter.class.getName()); - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - try { - - MDC.clear(); - - MDC.put("RequestId", UUID.randomUUID().toString()); - MDC.put("ServiceInstanceId", "N/A"); // not applicable - MDC.put("ServiceName", "ASDC"); - MDC.put("InstanceUUID", "N/A"); - - // For some reason chooses IPv4 or IPv6 in a random way - MDC.put("RemoteHost", request.getRemoteHost()); - - InetAddress host = HOST_ADDRESS.get(); - - String ipAddress, hostName; - if (host == null) { - ipAddress = UNKNOWN; - hostName = UNKNOWN; - } else { - ipAddress = host.getHostAddress(); - hostName = host.getHostName(); - } - - MDC.put("ServerIPAddress", ipAddress); - MDC.put("ServerFQDN", hostName); - - if(request instanceof HttpServletRequest) { - String userName = ((HttpServletRequest) request).getHeader("USER_ID"); - MDC.put("PartnerName", userName); - } - // TODO: Clarify what these stand for - // MDC.put("AlertSeverity", ); - // MDC.put("Timer", ); - - chain.doFilter(request, response); - - } finally { - MDC.clear(); - } - } - - public void init(FilterConfig config) throws ServletException { } - - private static class HostAddressCache { - - private static final long REFRESH_TIME = 1000L; - - private AtomicLong lastUpdated = new AtomicLong(0L); - private InetAddress hostAddress; - - public InetAddress get() { - - long current = System.currentTimeMillis(); - if (current - lastUpdated.get() > REFRESH_TIME) { - - synchronized (this) { - - try { - lastUpdated.set(current); // set now to register the attempt even if failed - hostAddress = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - log.debug("",e); - hostAddress = null; - } - } - } - - return hostAddress; - } - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java deleted file mode 100644 index 06b0d5b2bc..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.logging.util; - -/** - * Created by TALIO on 1/10/2017. - */ -public class LoggingUtils { - - public static String getCallingMethodNameForDebugging() { - return Thread.currentThread().getStackTrace()[4].getMethodName(); - } - - public static String getDeclaringClass(){ - return Thread.currentThread().getStackTrace()[4].getClassName(); - } -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService deleted file mode 100644 index ee01c4d871..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService +++ /dev/null @@ -1 +0,0 @@ -org.openecomp.sdc.logging.SLF4JLoggerCreationService \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService deleted file mode 100644 index 2c401614ae..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService +++ /dev/null @@ -1 +0,0 @@ -org.openecomp.sdc.logging.context.MDCPropagationService \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/pom.xml b/openecomp-be/lib/openecomp-logging-lib/pom.xml deleted file mode 100644 index ffc91b8d89..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - org.openecomp.sdc - openecomp-logging-lib - openecomp-logging-lib - pom - - - org.openecomp.sdc - openecomp-sdc-lib - 1.2.0-SNAPSHOT - .. - - - - /openecomp-sdc-logging-api - /openecomp-sdc-logging-core - - - - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml new file mode 100644 index 0000000000..3158995cb8 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + openecomp-sdc-logging-api + openecomp-sdc-logging-api + + + org.openecomp.sdc + openecomp-sdc-logging-lib + 1.2.0-SNAPSHOT + + + + + org.slf4j + slf4j-api + ${slf4j-api.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + test + + + org.testng + testng + ${testng.version} + test + + + + diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java new file mode 100644 index 0000000000..918818adb0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api; + +import java.util.Iterator; +import java.util.ServiceLoader; + +/** + * Contains common functionality for factories used in the logging framework. + * + *

In order to use the factory, a particular (e.g. framework-specific) implementation of a service must be + * configured as described in + * java.util.ServiceLoader).

+ * + * @author evitaliy + * @since 13/09/2016. + * + * @see ServiceLoader + */ +public class BaseFactory { + + protected static T locateService(Class clazz) { + + T service; + ServiceLoader loader = ServiceLoader.load(clazz); + Iterator iterator = loader.iterator(); + if (iterator.hasNext()) { + + service = iterator.next(); + if (iterator.hasNext()) { + System.err.println(String.format("Warning! Configured more than one implementation of %s", + clazz.getName())); + } + + return service; + } + + throw new IllegalArgumentException((String.format("No implementations configured for %s", clazz.getName()))); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java new file mode 100644 index 0000000000..9055e64f8b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api; + +/** + *

This interface defines logging as specified by Open OPENECOMP logging requirements.

+ * + *

Formatted messages must follow the clazz); +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java new file mode 100644 index 0000000000..68365fd857 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java @@ -0,0 +1,234 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api; + + +/** + * Factory to hide a concrete, framework-specific implementation of logger creation. + *

The service used by this factory must implement {@link LoggerCreationService}. If no + * implementation has been configured or could not be instantiated, a no-op logger will be + * used, and no events will be logged. This is done to prevent recursion if attempts are + * being made to log exceptions that resulted from logger initialization.

+ * + * @author evitaliy + * @see BaseFactory + * @see LoggerCreationService + * @since 13/09/2016. + */ +@SuppressWarnings("ThrowableInstanceNeverThrown") +public class LoggerFactory extends BaseFactory { + + private static final LoggerCreationService SERVICE; + + static { + LoggerCreationService service; + + try { + service = locateService(LoggerCreationService.class); + } catch (Exception ex) { + new RuntimeException("Failed to instantiate logger factory", ex).printStackTrace(); + // use the no-op service to prevent recursion in case of an attempt to log an exception as a + // result of a logger initialization error + service = new NoOpLoggerCreationService(); + } + + SERVICE = service; + } + + public static Logger getLogger(String clazzName) { + return SERVICE.getLogger(clazzName); + } + + public static Logger getLogger(Class clazz) { + return SERVICE.getLogger(clazz); + } + + private static class NoOpLoggerCreationService implements LoggerCreationService { + + private static final Logger NO_OP_LOGGER = new Logger() { + + @Override + public String getName() { + return "No-Op Logger"; + } + + @Override + public boolean isMetricsEnabled() { + return false; + } + + @Override + public void metrics(String msg) { + } + + @Override + public void metrics(String msg, Object arg) { + } + + @Override + public void metrics(String msg, Object arg1, Object arg2) { + } + + @Override + public void metrics(String msg, Object... arguments) { + } + + @Override + public void metrics(String msg, Throwable t) { + } + + @Override + public boolean isAuditEnabled() { + return false; + } + + @Override + public void audit(String msg) { + } + + @Override + public void audit(String msg, Object arg) { + } + + @Override + public void audit(String msg, Object arg1, Object arg2) { + } + + @Override + public void audit(String msg, Object... arguments) { + } + + @Override + public void audit(String msg, Throwable t) { + } + + @Override + public boolean isDebugEnabled() { + return false; + } + + @Override + public void debug(String msg) { + } + + @Override + public void debug(String msg, Object arg) { + } + + @Override + public void debug(String msg, Object arg1, Object arg2) { + } + + @Override + public void debug(String msg, Object... arguments) { + } + + @Override + public void debug(String msg, Throwable t) { + } + + @Override + public boolean isInfoEnabled() { + return false; + } + + @Override + public void info(String msg) { + } + + @Override + public void info(String msg, Object arg) { + } + + @Override + public void info(String msg, Object arg1, Object arg2) { + } + + @Override + public void info(String msg, Object... arguments) { + } + + @Override + public void info(String msg, Throwable t) { + } + + @Override + public boolean isWarnEnabled() { + return false; + } + + @Override + public void warn(String msg) { + } + + @Override + public void warn(String msg, Object arg) { + } + + @Override + public void warn(String msg, Object... arguments) { + } + + @Override + public void warn(String msg, Object arg1, Object arg2) { + } + + @Override + public void warn(String msg, Throwable t) { + } + + @Override + public boolean isErrorEnabled() { + return false; + } + + @Override + public void error(String msg) { + } + + @Override + public void error(String msg, Object arg) { + } + + @Override + public void error(String msg, Object arg1, Object arg2) { + } + + @Override + public void error(String msg, Object... arguments) { + } + + @Override + public void error(String msg, Throwable t) { + } + }; + + @Override + public Logger getLogger(String className) { + return NO_OP_LOGGER; + } + + @Override + public Logger getLogger(Class clazz) { + return NO_OP_LOGGER; + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java new file mode 100644 index 0000000000..2bcad91e38 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api.annotations; + +/** + * Indicates a method whose execution time should be measured and logged as required for Open OPENECOMP metrics. + * + * @author evitaliy + * @since 27/07/2016. + */ + +public @interface Metrics { +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java new file mode 100644 index 0000000000..98200da337 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api.context; + +/** + * Should be used to implement a framework-specific mechanism of propagation of a diagnostic context to child threads. + * + * @author evitaliy + * @since 12/09/2016. + */ +public interface ContextPropagationService { + + Runnable create(Runnable task); +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java new file mode 100644 index 0000000000..e2b31c3202 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api.context; + +import org.openecomp.sdc.logging.api.BaseFactory; + +/** + *

Should be used to propagate a diagnostic context (for instance MDC) to other threads.

+ *

Applicable when creating a child thread directly, or submitting tasks for potentially + * postponed execution via an Executor + * (including any of the executor + * services and ForkJoinPool).

+ *

The service used by this factory must implement {@link ContextPropagationService}.

+ * + * @author evitaliy + * @see ContextPropagationService + * @since 12/09/2016. + */ +@SuppressWarnings("ThrowableInstanceNeverThrown") +public class TaskFactory extends BaseFactory { + + private static final ContextPropagationService SERVICE; + private static final RuntimeException ERROR; + + static { + + ContextPropagationService service = null; + RuntimeException error = null; + + try { + service = locateService(ContextPropagationService.class); + } catch (Exception ex) { + error = new RuntimeException("Failed to instantiate task factory", ex); + } + + SERVICE = service; + ERROR = error; + } + + /** + * Modify a task so that a diagnostic context is propagated to the thread when the task runs. Done + * in a logging-framework specific way. + * + * @param task any Runnable that will run in a thread + * @return modified (wrapped) original task that runs the same business logic, but also takes care + * of copying the diagnostic context for logging + */ + public static Runnable create(Runnable task) { + + if (SERVICE == null) { + throw ERROR; + } + + return SERVICE.create(task); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java new file mode 100644 index 0000000000..a6a673d9dc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context; + +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.slf4j.MDC; + + +public abstract class MdcData { + private String level; + private String errorCode; + + MdcData() { + } + + public MdcData(String level, String errorCode) { + this.level = level; + this.errorCode = errorCode; + } + + public void setMdcValues() { + MDC.put(LoggerConstants.ERROR_CATEGORY, this.level); + MDC.put(LoggerConstants.ERROR_CODE, this.errorCode); + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java new file mode 100644 index 0000000000..d562ae5dd8 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java @@ -0,0 +1,42 @@ +package org.openecomp.sdc.logging.messages; + +/** + * Created by ayalaben on 4/20/2017. + */ +public class AuditMessages { + + public static final String AUDIT_MSG = " --Audit-- "; + + public static final String CREATE_VLM = "Create VLM. VLM Name: "; + public static final String CHECK_IN_VLM = "Check in VLM. VLM Id: "; + public static final String CHECK_OUT_VLM = "Check out VLM. VLM Id: "; + public static final String SUBMIT_VLM = "submit VLM. VLM Name: "; + + public static final String CREATE_VSP = "Create VSP. VSP Name: "; + public static final String CHECK_IN_VSP = "Check in VSP. VSP Id: "; + public static final String CHECK_OUT_VSP = "Check out VSP. VSP Id: "; + public static final String RESUBMIT_ALL_FINAL_VSPS = "Check out, check in and submit all " + + "submitted VSPs, see ids below "; + public static final String SUBMIT_VSP = "Submit VSP. VSP Id: "; + public static final String SUBMIT_VSP_FAIL = "Submit VSP failed!. VSP Id: "; + public static final String SUBMIT_VSP_ERROR = "Submit VSP error: %s. VSP Id: %s"; + + public static final String UPLOAD_HEAT = "Upload HEAT. VSP Id: "; + public static final String UPLOAD_PROCESS_ARTIFACT = "Upload Process Artifact. VSP Id: "; + public static final String UPLOAD_MONITORING_FILE = "Upload Monitoring File of type %s " + + ". VSP Id: %s, component id: %s"; + + public static final String IMPORT_SUCCESS = "VSP import to VF success. VSP Id: "; + public static final String IMPORT_FAIL = "VSP import to VF fail. VSP Id: "; + + public static final String HEAT_VALIDATION_STARTED = "HEAT validation started. VSP Id: "; + public static final String HEAT_VALIDATION_COMPLETED = "HEAT validation completed. VSP Id: "; + public static final String HEAT_VALIDATION_ERROR = "HEAT validation error: %s. VSP Id: %s"; + public static final String CSAR_VALIDATION_STARTED = "CSAR validation started. VSP Id: "; + public static final String HEAT_TRANSLATION_STARTED = "HEAT translation started. VSP Id: "; + public static final String HEAT_TRANSLATION_COMPLETED = "HEAT translation completed. VSP Id: "; + public static final String ENRICHMENT_ERROR = "Enrichment error: %s. VSP Id: %s"; + public static final String ENRICHMENT_COMPLETED = "Enrichment completed. VSP Id: "; + public static final String CREATE_PACKAGE = "Created package. VSP Id: "; + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java new file mode 100644 index 0000000000..c3e5f977cc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.messages; + + +public class DebugMessages { + public static final String DEFAULT_ENTER_METHOD = "Entering %s"; + public static final String DEFAULT_EXIT_METHOD = "Exiting %s"; + + public static final String ENTER_METHOD = "Entering %s with %s = %s"; + public static final String EXIT_METHOD = "Exiting %s with %s = %s"; + + public static final String ENTER_METHOD_FORMATTED = "Entering %s with %s"; + public static final String EXIT_METHOD_FORMATTED = "Exiting %s with %s"; + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java new file mode 100644 index 0000000000..71884cff70 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + +/** + * Created by TALIO on 1/10/2017. + */ +public class DebugConstants { + public static final String EXIT = "Exit"; + public static final String EXIT_DEFAULT = "Exit_Default"; + public static final String ENTER = "Enter"; + public static final String ENTER_DEFAULT = "Enter_Default"; + public static final String DEFAULT = "Default"; +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java new file mode 100644 index 0000000000..0d591be095 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public class LoggerConstants { + + public static final String REQUEST_ID = "RequestId"; + public static final String PARTNER_NAME = "PartnerName"; + public static final String SERVICE_NAME = "ServiceName"; + public static final String INSTANCE_UUID = "InstanceUUID"; + public static final String CATEGORY_LOG_LEVEL = "level"; + public static final String STATUS_CODE = "StatusCode"; + public static final String RESPONSE_CODE = "ResponseCode"; + public static final String RESPONSE_DESCRIPTION = "ResponseDescription"; + public static final String TARGET_SERVICE_NAME = "TargetServiceName"; + public static final String TARGET_ENTITY = "TargetEntity"; + public static final String TARGET_ENTITY_API = "API"; + public static final String TARGET_ENTITY_DB = "DB"; + public static final String ERROR_CATEGORY = "ErrorCategory"; + public static final String ERROR_CODE = "ErrorCode"; + public static final String ERROR_DESCRIPTION = "ErrorDescription"; +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java new file mode 100644 index 0000000000..e00c282b97 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public enum LoggerErrorCategory { + ERROR, + WARN, + DEBUG, + INFO, + FATAL +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java new file mode 100644 index 0000000000..3f48991c7f --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public enum LoggerErrorCode { + PERMISSION_ERROR("100"), + AVAILABILITY_ERROR("200"), + DATA_ERROR("300"), + SCHEMA_ERROR("400"), + BUSINESS_PROCESS_ERROR("500"), + UNKNOWN_ERROR("900"), ; + + private String errorCode; + + LoggerErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java new file mode 100644 index 0000000000..7e502d55f2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public class LoggerErrorDescription { + public static final String ARTIFACT_NOT_REFERENCED = "Artifact not referenced"; + public static final String WRONG_FILE_EXTENSION = "Wrong file extention"; + public static final String INVALID_HEAT_FORMAT = "Invalid HEAT format"; + public static final String PARAMETER_NOT_FOUND = "Referenced parameter not found"; + public static final String ENV_PARAMETER_NOT_IN_HEAT = "env includes parameter not in HEAT"; + public static final String PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE = + "Parameter default value not alinged with type"; + public static final String INVALID_RESOURCE_TYPE = "Invalid resource type"; + public static final String INVALID_GET_RESOURCE_SYNTAX = "Invalid get resource syntax"; + public static final String RESOURCE_NOT_FOUND = "Resource not found"; + public static final String INVALID_INDEX_VAR = "Invalid Resource Group index var"; + public static final String MISSING_FILE = "Missing file"; + public static final String MISSING_NOVA_PROPERTIES = "Missing NOVA server properties"; + public static final String NESTED_LOOP = "Found nested loop"; + public static final String MISSING_PARAMETER_IN_NESTED = "Missing parameter in nested file"; + public static final String WRONG_VALUE_ASSIGNED_NESTED_PARAMETER = + "Wrong value assigned in nested parameters"; + public static final String SERVER_NOT_DEFINED_NOVA = "Server not defined from nova"; + public static final String WRONG_POLICY_SERVER_GROUP = "Wrong policy in server group"; + public static final String SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE = + "Server group or security group is not in use"; + public static final String NETWORK_ATTACH_POLICY_NOT_IN_USE = + "Network Attach Policy is not in use"; + public static final String NO_BIND_FROM_PORT_TO_NOVA = "No bind from port to nova sever"; + public static final String PORT_BINDS_MORE_THAN_ONE_NOVA = + "Port binds to more than one nova sever"; + public static final String MISSING_RESOURCE_DEPENDS_ON = "Missing resource in depends_on"; + public static final String GET_ATTR_NOT_FOUND = "get_attr not found"; + public static final String MISSING_GET_PARAM = "Missing get_param"; + public static final String EMPTY_FILE = "Empty file"; + public static final String VALIDATE_FILE = "Can't validate file"; + public static final String INVALID_FILE_TYPE = "Invalid file type"; + public static final String INVALID_ZIP = "Invalid zip file"; + public static final String INVALID_VES_FILE = "Invalid VES file"; + + + + public static final String RESOURCE_UNIQUE_NETWORK_ROLE = + "Resource connects to two networks with the same role"; + public static final String NAME_NOT_ALIGNED_WITH_GUIDELINES = "Name not aligned with guidelines"; + public static final String VOLUME_FILE_NOT_EXPOSED = "Volume file not exposed"; + public static final String RESOURCE_NOT_DEFINED_AS_OUTPUT = "Resource is not defined as output"; + public static final String FLOATING_IP_IN_USE = "Floating IP resource type is in use"; + public static final String MISSING_BASE_HEAT = "Missing base HEAT file"; + public static final String MULTI_BASE_HEAT = "Multi base HEAT file"; + + public static final String EXTRACT_COMPOSITION_DATA = "Can't extract composition data"; + + public static final String MERGE_CONTRAIL_2_AND_3 = + "Merge of Contrail 2 and Contrail 3 resources"; + public static final String CONTRAIL_2_IN_USE = "Contrail 2 resource is in use"; + + public static final String INVALID_MANIFEST = "Invalid manifest file"; + + public static final String INVALID_YAML_FORMAT = "Invalid YAML format"; + + public static final String CREATE_SERVICE_ARTIFACT = "Can't create service artifact"; + public static final String CREATE_ENRICH_SERVICE_ARTIFACT = + "Can't create enriched service artifact"; + public static final String CREATE_SERVICE_TEMPLATE = "Can't create service template"; + public static final String CREATE_ENRICH_SERVICE_TEMPLATE = + "Can't create enriched service template"; + public static final String GET_SERVICE_MODEL = "Can't get service model"; + public static final String MISSING_MANDATORY_PROPERTY = "Missing mandatory property"; + public static final String INVALID_PROPERTY = "Invalid Property"; + public static final String INVALID_ADD_ACTION = "Invalid add action"; + public static final String UNSUPPORTED_ENTITY = "Unsupported entity"; + public static final String CREATE_CSAR = "Can't create CSAR file"; + public static final String PACK_ARTIFACTS = "Can't pack artifacts into CSAR file"; + + public static final String TRANSLATE_HEAT = "Can't translate HEAT file"; + public static final String RESOURCE_FILE_READ_ERROR = "Can't read resource file from class path."; + public static final String FAILED_TO_GENERATE_GLOBAL_TYPES = "Failed to generate globalTypes"; + + public static final String CHECKOUT_ENTITY = "Can't checkout versionable entity"; + public static final String SUBMIT_ENTITY = "Can't submit versionable entity"; + public static final String ENTITY_NOT_FOUND = "Versionable entity not found"; + public static final String INVALID_VALUE = "Invalid value"; + + public static final String UNSUPPORTED_OPERATION = "Unsupported operation"; + public static final String INVALID_JSON = "Invalid JSON format"; + + public static final String INSERT_INTO_APPLICATION_CONFIG = + "Can't insert value into application config table"; + + public static final String CANT_HEAL = "Can't perform healing operation"; +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java new file mode 100644 index 0000000000..e72d66aac9 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public enum LoggerServiceName { + + Create_VLM, + Get_VLM, + Checkout_VLM, + Checkin_VLM, + Undo_Checkout_VLM, + Submit_VLM, + Update_VLM, + List_VLM, + + List_EP, + Create_EP, + Update_EP, + Get_EP, + Delete_EP, + + Create_LIMIT, + Delete_LIMIT, + Update_LIMIT, + Get_LIMIT, + + List_FG, + Create_FG, + Update_FG, + Get_FG, + Delete_FG, + + List_LA, + Create_LA, + Update_LA, + Get_LA, + Delete_LA, + + List_LKG, + Create_LKG, + Update_LKG, + Get_LKG, + Delete_LKG, + + List_VSPs, + List_Packages, + Create_VSP, + Get_VSP, + Checkout_VSP, + Checkin_VSP, + Undo_Checkout_VSP, + Submit_VSP, + Update_VSP, + Re_Submit_ALL_Final_VSPs, + Create_Package, + List_VSP, + Upload_File, + Get_Uploaded_File, + Get_Translated_File, + Get_Questionnaire_VSP, + Update_Questionnaire_VSP, + Get_Information_Artifact, + + + List_Component_Processes, + Delete_List_Component_Processes, + Create_Component_Processes, + Update_Component_Processes, + Get_Component_Processes, + Delete_Component_Processes, + Upload_File_Component_Processes, + Get_Uploaded_File_Component_Processes, + Delete_Uploaded_File_Component_Processes, + + List_Processes, + Delete_List_Processes, + Create_Processes, + Update_Processes, + Get_Processes, + Delete_Processes, + Upload_File_Processes, + Get_Uploaded_File_Processes, + Delete_Uploaded_File_Processes, + + List_Components, + Delete_List_Components, + Create_Component, + Update_Component, + Get_Component, + Delete_Component, + Get_Questionnaire_Component, + Update_Questionnaire_Component, + + Upload_Monitoring_Artifact, + Delete_Monitoring_Artifact, + List_Monitoring_Artifacts, + + List_Network, + Create_Network, + Update_Network, + Get_Network, + Delete_Network, + + List_nics, + Delete_List_nics, + Create_nic, + Update_nic, + Get_nic, + Delete_nic, + Get_Questionnaire_nic, + Update_Questionnaire_nic, + + Create_Process, + Update_Process, + + Create_Compute, + List_Computes, + Get_Compute, + Update_Compute, + Delete_Compute, + Get_Questionnaire_Compute, + Update_Questionnaire_Compute, + + Insert_To_ApplicationConfig_Table, + Get_From_ApplicationConfig_Table, + Get_List_From_ApplicationConfig_Table_By_Namespace, + + Create_Deployment_Flavor, + Get_List_Deployment_flavor, + Get_Deployment_flavor, + Delete_Deployment_flavor, + Update_Deployment_flavor, + + Get_List_Activity_Log, + + Validate, + Enrich, Delete_VSP, Get_Process_Artifact, Create_Entity, Checkout_Entity, Undo_Checkout_Entity, + Checkin_Entity, Submit_Entity, Get_Entity_Version, Delete_Entity, Undo_Delete_Entity, + Translate_Resource, Translate_HEAT, LoggerServiceName, Get_VSP_List, Delete_VLM, Update_Manifest, + Create_Image, + GET_Image_Schema, + List_Images, + GET_Image, + Delete_Image, + Update_Image, + + CREATE_COMPONENT_DEPENDENCY_MODEL, + GET_COMPONENT_DEPENDENCY_MODEL, + + Health_check + ; + + public static String getServiceName(LoggerServiceName serviceName) { + return serviceName.name().replace("_", " "); + } + + @Override + public String toString(){ + return this.name().replace("_", " "); + } + + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java new file mode 100644 index 0000000000..6b0570eb29 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java @@ -0,0 +1,206 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.types; + + +public class LoggerTragetServiceName { + /*HEAT validator*/ + public static final String VALIDATE_HEAT_BASE_STRUCTURE = "Validate Heat Base Structure"; + public static final String VALIDATE_ARTIFACTS_EXISTENCE = "Validate Artifacts Existence"; + public static final String VALIDATE_RESOURCE_REFERENCE_EXISTENCE = + "Validate Resource Reference Existence"; + public static final String VALIDATE_PARAMETER_REFERENCE_EXITENCE = + "Validate Parameter Reference Existence"; + public static final String VALIDATE_GET_ATTR_FROM_NESTED = "Validate get_attr From Nested"; + public static final String VALIDATE_ENV_FILE = "Validate env File"; + public static final String VALIDATE_BASE_PORTS_EXISTENCE = "Validate Base Ports Existence"; + public static final String VALIDATE_ASSIGNED_VALUES_FOR_NOVA_IMAGE_FLAVOR = + "Validate Assigned Value For Nova Server Image Or Flavor"; + public static final String VALIDATE_NOVA_SERVER_PORT_BINDING = + "Validate Ports Binding From Nova Server"; + public static final String VALIDATE_SERVER_GROUP_EXISTENCE = + "Validate Nova Server Group Existence"; + public static final String VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS = + "Validate All Properties Match Nested Parameters"; + public static final String VALIDATE_NESTING_LOOPS = "Validate Nested Loops"; + public static final String VALIDATE_NOVA_SEVER_GROUP_POLICY = "Validate Nova Server Group Policy"; + public static final String VALIDATE_RESOURCE_GROUP_TYPE = "Validate Resource Group Resource Type"; + public static final String VALIDATE_ALL_SECURITY_GROUP_USED = + "Validate All Security Group Are Used From Neutron Port Resource"; + public static final String VALIDATE_CONTRAIL_ATTACH_POLICY_TYPE = + "Validate Contrail Attach Policy Type"; + public static final String VALIDATE_SECURITY_GROUP_FROM_BASE_OUTPUT = + "Validate Security Groups From Base File Outputs"; + public static final String CHECK_FOR_ORPHAN_PORTS = "Validate All Referenced Ports Are Used"; + public static final String CHECK_FOR_ORPHAN_ARTIFACTS = "Validate All Artifacts Are Referenced"; + public static final String CHECK_FOR_VALID_FILE_EXTENTION = "Validate File Extention"; + public static final String VALIDATE_PARAMTER_DEFAULT_MATCH_TYPE = + "Validate Parameter Default Aligns With Type"; + public static final String VALIDATE_ENV_PARAMETER_MATCH_TYPE = + "Validate env Parameter Matches Type"; + public static final String VALIDATE_RESOURCE_TYPE = "Validate Resource Type"; + public static final String VALIDATE_FILE_EXISTENCE = "Validate File Exitence"; + public static final String GET_RESOURCE_LIST_BY_TYPE = + "Get All Resources By Specific Resource Type"; + public static final String VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE = + "Validate All Security Group Or Server Group Are In Use"; + public static final String VALIDATE_ATTACH_POLICY_IN_USE = + "Validate All Network Attach Policies Are In Use"; + public static final String CHECK_RESOURCE_DEPENDS_ON = "Check Resource dependes_on"; + public static final String GET_SHARED_RESOURCES_FROM_OUTPUTS = + "Get Shared Resources From Outputs"; + public static final String VALIDATE_GET_RESOURCE = "Validate get_resource Syntax"; + public static final String VALIDATE_FILE = "Validate File"; + + /*manifest validator*/ + public static final String VALIDATE_MANIFEST_CONTENT = "Validate Manifest Content"; + public static final String VALIDATE_FILE_IN_ZIP = "Validate File In Zip"; + public static final String VALIDATE_FILE_IN_MANIFEST = "Validate File In Manifest"; + public static final String VALIDATE_FILE_TYPE_AND_NAME = + "Validate File Type And Name In Manifest"; + public static final String SCAN_MANIFEST_STRUCTURE = "Scan Manifest Structure"; + public static final String VALIDATE_FILE_TYPE = "Validate File Type"; + + /*YAML validator*/ + public static final String VALIDATE_YAML_CONTENT = "Validate YAML Content"; + + + /*OPENECOMP guide line validator*/ + public static final String VALIDATE_BASE_FILE = + "Validate If All Resources In Base File Are Exposed"; + public static final String VALIDATE_FORBIDDEN_RESOURCE = "Validate If Resource Type Is Forbidden"; + public static final String VALIDATE_FIXED_IPS_NAME = "Validate fixed_ips Naming Convention"; + public static final String VALIDATE_IMAGE_AND_FLAVOR_NAME = + "Validate image And flavor Naming Convention"; + public static final String VALIDATE_NOVA_SERVER_NAME = "Validate Nova Server Naming Convention"; + public static final String VALIDATE_AVAILABILITY_ZONE_NAME = + "Validate availability_zone Naming Convention"; + public static final String VALIDATE_NOVA_META_DATA_NAME = + "Validate Nova Server Meta Data Naming Convention"; + public static final String VALIDATE_PORT_NETWORK_NAME = "Validate Port Network Naming Convention"; + public static final String VALIDATE_VM_SYNC_IN_IMAGE_FLAVOR = + "Validate VM Name Is Sync In Image And Flavor"; + public static final String VALIDATE_RESOURCE_NETWORK_UNIQUE_ROLW = + "Validate Nova Server Unique Role"; + public static final String VALIDATE_VOLUME_FILE = "Validate HEAT Volume File"; + + + public static final String VALIDATE_CONTRAIL_VM_NAME = + "Validate Contrail VM Name Aligned With Guidelines"; + public static final String MERGE_OF_CONTRAIL_2_AND_3 = "Merge Of Contrail 2 And Contrail 3"; + public static final String CONTRAIL_2_IN_USE = "Validate Contrail 2 Resource Is In Use"; + + + public static final String VALIDATE_MANIFEST_PRE_CONDITION = "Validate Manifest Pre-Condition"; + public static final String VALIDATE_HEAT_FORMAT = "Validate HEAT Format"; + + public static final String CREATE_ENTITY = "Create Entity"; + public static final String CHECKOUT_ENTITY = "Checkout Entity"; + public static final String UNDO_CHECKOUT_ENTITY = "Undo Checkout Entity"; + public static final String CHECKIN_ENTITY = "Checkin Entity"; + public static final String SUBMIT_ENTITY = "Submit Entity"; + public static final String DELETE_ENTITY = "Delete Entity"; + public static final String UNDO_DELETE_ENTITY = "Undo Delete Entity"; + + public static final String SUBMIT_VSP = "Submit VSP"; + public static final String GET_VSP = "Get VSP"; + public static final String ADD_VSP = "Add VSP"; + public static final String DELETE_VSP = "Delete VSP"; + public static final String UPDATE_VSP = "Update VSP"; + public static final String ENRICH = "Enrich"; + public static final String UPLOAD_FILE = "Upload file"; + public static final String GET_UPLOADED_HEAT = "Get Uploaded HEAT File"; + public static final String GET_TRANSLATED_FILE = "Get Translated File"; + public static final String CREATE_TRANSLATED_FILE = "Create Translated File"; + public static final String CREATE_PACKAGE = "Create Package"; + + public static final String SELF_HEALING = "Self Healing"; + public static final String WRITE_ARTIFACT_XML = "Write Artifact To XML File"; + + public static final String GET_VLM = "Get VLM"; + + public static final String VALIDATE_MONITORING_FILE = "Validate Monitoring File"; + public static final String UPLOAD_MONITORING_FILE = "Upload Monitoring file"; + + public static final String GET_VERSION_INFO = "Get version info"; + + public static final String CREATE_NETWORK = "Create Network"; + public static final String DELETE_NETWORK = "Delete Network"; + + public static final String CREATE_COMPONENT = "Create Component"; + public static final String DELETE_COMPONENT = "Delete Component"; + public static final String UPDATE_COMPONENT = "Update Component"; + + public static final String GET_PROCESS_ARTIFACT = "Get Process Artifact"; + public static final String UPLOAD_PROCESS_ARTIFACT = "Upload Process Artifact"; + + public static final String CREATE_NIC = "Create Nic"; + public static final String DELETE_NIC = "Delete Nic"; + public static final String UPDATE_NIC = "Update Nic"; + + public static final String CREATE_DEPLOYMENT_FLAVOR = "Create Deployment Flavor"; + public static final String DELETE_DEPLOYMENT_FLAVOR = "Delete Deployment Flavor"; + public static final String UPDATE_DEPLOYMENT_FLAVOR = "Update Deployment Flavor"; + + public static final String EXTRACT_COMPOSITION_DATA = "Extract Composition Data"; + + public static final String TRANSLATE_RESOURCE = "Translate Resource"; + public static final String GET_RESOURCE = "Get Resource"; + public static final String VALIDATE_HEAT_BEFORE_TRANSLATE = "Validate HEAT Before Translate"; + + public static final String CREATE_SERVICE_ARTIFACT = "Create Service Artifact In DB"; + public static final String CREATE_SERVICE_ENRICH_ARTIFACT = + "Create Service Enriched Artifact In DB"; + public static final String CREATE_SERVICE_TEMPLATE = "Create Service Template In DB"; + public static final String CREATE_ENRICH_SERVICE_TEMPLATE = + "Create Enriched Service Template In DB"; + public static final String GET_SERVICE_MODEL = "Get service model"; + public static final String GET_SERVICE_TEMPLATE = "Get Service Template"; + public static final String CREATE_REQUIREMENT_ASSIGNMENT = "Create Requierment Assignment"; + public static final String GENERATE_TRANSLATED_ID = "Generate Translated Id"; + public static final String ADD_ENTITIES_TO_TOSCA = "Add Entities To TOSCA"; + public static final String CREATE_CSAR = "Create CSAR"; + public static final String PACK_ARTIFACTS = "Pack Artifacts Into CSAR File"; + + public static final String VALIDATE_CHOICE_VALUE = "Check Chosen Value"; + + public static final String INSERT_INTO_APPLICATION_CONFIG = + "Insert Value Into Application Config"; + + public static final String VALIDATE_FILE_DATA_STRUCTURE = "Validate Manifest Sent From User"; + public static final String CREATE_IMAGE = "Create Image"; + public static final String DELETE_IMAGE = "Delete Image"; + public static final String UPDATE_IMAGE = "Update Image"; + + public static final String CREATE_COMPUTE = "Create Compute"; + public static final String UPDATE_COMPUTE = "Update Compute"; + public static final String DELETE_COMPUTE = "Delete Compute"; + + public static final String COLLECT_MANUAL_VSP_TOSCA_DATA = "Collect Manual Vsp Tosca data"; + public static final String GENERATE_MANUAL_VSP_TOSCA = "Generate Manual Vsp Tosca"; + + public static final String VALIDATE_DATE_RANGE = "Validate Date Range"; + + public static final String CREATE_COMPONENT_DEPENDENCY_MODEL = "Create Component Dependency " + + "Model"; + + public static final String READ_RESOURCE_FILE = "Read Resource File"; +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json new file mode 100644 index 0000000000..33163b32bb --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json @@ -0,0 +1,3 @@ +{ + "org.openecomp.sdc.logging.api.BaseFactory": "org.openecomp.sdc.logging.api.LoggerFactory" +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java new file mode 100644 index 0000000000..846425059e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api; + +import org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.util.ServiceLoader; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 14/09/2016. + */ +public class LoggerFactoryTest { + + @Test + public void testNoOpLoggerService() throws Exception { + + assertFalse(ServiceLoader.load(LoggerCreationService.class).iterator().hasNext()); + + LoggerFactory.getLogger(LoggerFactoryTest.class); + Field factory = LoggerFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object impl = factory.get(null); + assertEquals("org.openecomp.sdc.logging.api.LoggerFactory$NoOpLoggerCreationService", + impl.getClass().getName()); + } + + @Test + public void testNoOpLoggerByClass() throws Exception { + Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class); + verifyLogger(logger); + } + + @Test + public void testNoOpLoggerByName() throws Exception { + Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class.getName()); + verifyLogger(logger); + } + + private void verifyLogger(Logger logger) { + assertNotNull(logger); + + // make sure no exceptions are thrown + logger.error(""); + logger.warn(""); + logger.info(""); + logger.debug(""); + logger.audit(""); + logger.metrics(""); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java new file mode 100644 index 0000000000..61e1819b3b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java @@ -0,0 +1,30 @@ +package org.openecomp.sdc.logging.api.context; + +import org.testng.annotations.Test; + +import java.util.ServiceLoader; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 14/09/2016. + */ +public class TaskFactoryTest { + + @Test(expectedExceptions = RuntimeException.class) + public void testNoImplementation() throws Exception { + + assertFalse(ServiceLoader.load(ContextPropagationService.class).iterator().hasNext()); + + try { + TaskFactory.create(() -> { + }); + } catch (RuntimeException e) { + Throwable cause = e.getCause(); + assertNotNull(cause); + assertTrue(cause.getMessage().contains(ContextPropagationService.class.getName())); + throw e; + } + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README new file mode 100644 index 0000000000..779c5d99df --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README @@ -0,0 +1,29 @@ +The purpose of this module is to make a Web application meet the OPENECOMP logging requirements described in +OPENECOMP platform application logging guidelines. + +The default out-of-the box solution is based on SLF4J. + +It introduces three major areas of functionality as follows: + +1. Routing of logging messages for the Logback library, so that all logging events are written to separate files +according to their type. + +2. An AOP aspect for measuring execution time and logging it, so that the application code is not contaminated with +this type of logging. + +3. Collecting and populating the context of a Web API request and propagating it to every logging event. + +TODO: + +1. MetricsAspect + - Configurable metrics message + - Make sure there are no exceptions but applicative ones + +2. EventTypeDiscriminator + - Make event types configurable to make the names of log files easily customizable + +3. DispatchingAppender + - Read appenders from configuration, so that there is no need in EELF loggers + - Simpler use of discriminator or an entirely different mechanism + - Better appender name pattern, or mapping between a discriminating value and an appender name + - Discard the appenders cache on configuration changes diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml new file mode 100644 index 0000000000..e9e66b2fe2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + openecomp-sdc-logging-core + openecomp-sdc-logging-core + + + org.openecomp.sdc + openecomp-sdc-logging-lib + 1.2.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-logging-api + ${project.version} + + + org.aspectj + aspectjrt + ${aspectj.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + javax.servlet + servlet-api + ${servlet.version} + + + + + org.testng + testng + ${testng.version} + test + + + org.easymock + easymock + ${easymock.version} + test + + + org.powermock + powermock-api-easymock + ${powermock.version} + test + + + org.powermock + powermock-core + ${powermock.version} + test + + + org.powermock + powermock-module-testng + ${powermock.version} + test + + + + diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java new file mode 100644 index 0000000000..711e6d1559 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging; + +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +/** + *

The list of markers that can be used for special logging such as metrics, audit, etc.

+ * + *

Although markers can be easily instantiated whenever needed, having constants for them helps eliminate mistakes - + * misspelling, using a marker that is not handled, etc.

+ * + *

Usage:

+ * + *
+ *
+ *     Logger log = LogFactory.getLogger(this.getClass());
+ *     log.info(Markers.AUDIT, "User '{}' logged out", user);
+ *
+ * 
+ * + * @author EVITALIY + * @since 13/09/2016. + * + * @see Marker + */ +public class Markers { + + public static final Marker AUDIT = MarkerFactory.getMarker("AUDIT"); + public static final Marker METRICS = MarkerFactory.getMarker("METRICS"); +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java new file mode 100644 index 0000000000..7f9ada142a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java @@ -0,0 +1,240 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging; + +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerCreationService; +import org.slf4j.LoggerFactory; + +/** + * @author evitaliy + * @since 13/09/2016. + */ +public class SLF4JLoggerCreationService implements LoggerCreationService { + + @Override + public Logger getLogger(String className) { + return new SLF4JWrapper(className); + } + + @Override + public Logger getLogger(Class clazz) { + return new SLF4JWrapper(clazz); + } + + private class SLF4JWrapper implements Logger { + + private final org.slf4j.Logger logger; + + SLF4JWrapper(Class clazz) { + logger = LoggerFactory.getLogger(clazz); + } + + SLF4JWrapper(String className) { + logger = LoggerFactory.getLogger(className); + } + + @Override + public String getName() { + return logger.getName(); + } + + @Override + public boolean isMetricsEnabled() { + return logger.isInfoEnabled(Markers.METRICS); + } + + @Override + public void metrics(String msg) { + logger.info(Markers.METRICS, msg); + } + + @Override + public void metrics(String msg, Object arg) { + logger.info(Markers.METRICS, msg, arg); + } + + @Override + public void metrics(String msg, Object arg1, Object arg2) { + logger.info(Markers.METRICS, msg, arg1, arg2); + } + + @Override + public void metrics(String msg, Object... arguments) { + logger.info(Markers.METRICS, msg, arguments); + } + + @Override + public void metrics(String msg, Throwable t) { + logger.info(Markers.METRICS, msg, t); + } + + @Override + public boolean isAuditEnabled() { + return logger.isInfoEnabled(Markers.AUDIT); + } + + @Override + public void audit(String msg) { + logger.info(Markers.AUDIT, msg); + } + + @Override + public void audit(String msg, Object arg) { + logger.info(Markers.AUDIT, msg, arg); + } + + @Override + public void audit(String msg, Object arg1, Object arg2) { + logger.info(Markers.AUDIT, msg, arg1, arg2); + } + + @Override + public void audit(String msg, Object... arguments) { + logger.info(Markers.AUDIT, msg, arguments); + } + + @Override + public void audit(String msg, Throwable t) { + logger.info(Markers.AUDIT, msg, t); + } + + @Override + public boolean isDebugEnabled() { + return logger.isDebugEnabled(); + } + + @Override + public void debug(String msg) { + logger.debug(msg); + } + + @Override + public void debug(String format, Object arg) { + logger.debug(format, arg); + } + + @Override + public void debug(String format, Object arg1, Object arg2) { + logger.debug(format, arg1, arg2); + } + + @Override + public void debug(String format, Object... arguments) { + logger.debug(format, arguments); + } + + @Override + public void debug(String msg, Throwable t) { + logger.debug(msg, t); + } + + @Override + public boolean isInfoEnabled() { + return logger.isInfoEnabled(); + } + + @Override + public void info(String msg) { + logger.info(msg); + } + + @Override + public void info(String format, Object arg) { + logger.info(format, arg); + } + + @Override + public void info(String format, Object arg1, Object arg2) { + logger.info(format, arg1, arg2); + } + + @Override + public void info(String format, Object... arguments) { + logger.info(format, arguments); + } + + @Override + public void info(String msg, Throwable t) { + logger.info(msg, t); + } + + @Override + public boolean isWarnEnabled() { + return logger.isWarnEnabled(); + } + + @Override + public void warn(String msg) { + logger.warn(msg); + } + + @Override + public void warn(String format, Object arg) { + logger.warn(format, arg); + } + + @Override + public void warn(String format, Object... arguments) { + logger.warn(format, arguments); + } + + @Override + public void warn(String format, Object arg1, Object arg2) { + logger.warn(format, arg1, arg2); + } + + @Override + public void warn(String msg, Throwable t) { + logger.warn(msg, t); + } + + @Override + public boolean isErrorEnabled() { + return logger.isErrorEnabled(); + } + + @Override + public void error(String msg) { + logger.error(msg); + } + + @Override + public void error(String format, Object arg) { + logger.error(format, arg); + } + + @Override + public void error(String format, Object arg1, Object arg2) { + logger.error(format, arg1, arg2); + } + + @Override + public void error(String format, Object... arguments) { + logger.error(format, arguments); + } + + @Override + public void error(String msg, Throwable t) { + logger.error(msg, t); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java new file mode 100644 index 0000000000..2b46802a2e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.aspects; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.api.annotations.Metrics; + +/** + *

Wraps around any method annotated with {@link Metrics} to measure and log its execution time + * in milliseconds.

+ *

In order for the aspect to be used, AspectJ annotation processing must be tuned on and this + * particular aspect enabled. Conversely, it can be disabled completely if the application does not + * need to log metrics.

+ *

See, for example, + * Aspect Oriented Programming with Spring.

+ * + * @author evitaliy + * @see Metrics + * @since 27/07/2016. + */ +@Aspect +public class MetricsAspect { + + private static final String MESSAGE_TEMPLATE = "'{}' took {} milliseconds"; + + @Around("@annotation(org.openecomp.sdc.logging.api.annotations.Metrics)") + public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable { + + final Logger logger = LoggerFactory.getLogger(pjp.getSignature().getDeclaringTypeName()); + // measure and log only if the logger for this class is enabled + if (logger.isMetricsEnabled()) { + + final String method = pjp.getSignature().getName(); + final long start = System.currentTimeMillis(); + + try { + return pjp.proceed(); + } finally { + logger.metrics(MESSAGE_TEMPLATE, method, System.currentTimeMillis() - start); + } + + } else { + return pjp.proceed(); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java new file mode 100644 index 0000000000..7e29f3c093 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context; + +import org.openecomp.sdc.logging.api.context.ContextPropagationService; +import org.slf4j.MDC; + +import java.util.Map; + +/** + * Propagates the SLF4J Mapped Diagnostic Context (MDC) + * of a thread onto a runnable created by that thread, so that the context is available when the runnable is executed + * in a new thread. + * + * @author evitaliy + * @since 12/09/2016. + */ +public class MDCPropagationService implements ContextPropagationService { + + public Runnable create(Runnable task) { + return new MDCCopyingWrapper(task); + } + + private static class MDCCopyingWrapper implements Runnable { + + private final Runnable task; + private final Map context; + + private MDCCopyingWrapper(Runnable task) { + this.task = task; + this.context = MDC.getCopyOfContextMap(); + } + + @Override + public void run() { + + Map oldContext = MDC.getCopyOfContextMap(); + replaceMDC(this.context); + + try { + task.run(); + } finally { + replaceMDC(oldContext); + } + } + + private static void replaceMDC(Map context) { + + if (context == null) { + MDC.clear(); + } else { + MDC.setContextMap(context); + } + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java new file mode 100644 index 0000000000..81a22adb07 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context; + +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.slf4j.MDC; + + +public class MdcUtil { + + /** + * Sets values for mdc. + * + * @param targetEntity the target entity + * @param targetServiceName the target service name + * @param errorCategory the error category + * @param errorCode the error code + * @param errorDescription the error description + */ + public static void setValuesForMdc(String targetEntity, String targetServiceName, + String errorCategory, String errorCode, + String errorDescription) { + MDC.put(LoggerConstants.TARGET_ENTITY, targetEntity); + MDC.put(LoggerConstants.TARGET_SERVICE_NAME, targetServiceName); + MDC.put(LoggerConstants.ERROR_CATEGORY, errorCategory); + MDC.put(LoggerConstants.ERROR_CODE, errorCode); + MDC.put(LoggerConstants.ERROR_DESCRIPTION, errorDescription); + } + + + /** + * Init mdc. + * @param serviceName the service name + * + */ + public static void initMdc(String serviceName) { + MDC.put(LoggerConstants.SERVICE_NAME, serviceName); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java new file mode 100644 index 0000000000..11d3fd3f5b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context.impl; + +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.MdcData; +import org.openecomp.sdc.logging.messages.DebugMessages; +import org.openecomp.sdc.logging.types.DebugConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCategory; +import org.openecomp.sdc.logging.util.LoggingUtils; + +import java.util.HashMap; +import java.util.Map; + +public class MdcDataDebugMessage extends MdcData { + + private Logger logger; + private static Map mapExitOrEntryToMessage; + + static { + mapExitOrEntryToMessage = new HashMap<>(); + mapExitOrEntryToMessage.put(DebugConstants.ENTER, DebugMessages.ENTER_METHOD); + mapExitOrEntryToMessage.put(DebugConstants.ENTER_DEFAULT, DebugMessages.DEFAULT_ENTER_METHOD); + mapExitOrEntryToMessage.put(DebugConstants.EXIT, DebugMessages.EXIT_METHOD); + mapExitOrEntryToMessage.put(DebugConstants.EXIT_DEFAULT, DebugMessages.DEFAULT_EXIT_METHOD); + } + + public MdcDataDebugMessage() { + super(LoggerErrorCategory.DEBUG.name(), null); + } + + //todo add more explanations as to the first parameter structure in case of multiples and in + // case of no params in method + /** + * Debug entry message. + * + * @param entityParameter the entity parameter + * @param ids the ids + */ + public void debugEntryMessage(String entityParameter, String... ids) { + logDebugMessage(entityParameter, DebugConstants.ENTER, ids); + } + + /** + * Debug exit message. + * + * @param entityParameter the entity parameter + * @param ids the ids + */ + public void debugExitMessage(String entityParameter, String... ids) { + logDebugMessage(entityParameter, DebugConstants.EXIT, ids); + } + + private void logDebugMessage(String entityParameter, String enterOrExit, String... ids) { + String methodName = LoggingUtils.getCallingMethodNameForDebugging(); + String declaringClass = LoggingUtils.getDeclaringClass(); + logger = LoggerFactory.getLogger(declaringClass); + String messageToWrite; + + if (entityParameter == null || ids == null) { + messageToWrite = mapExitOrEntryToMessage.get(enterOrExit + "_" + DebugConstants.DEFAULT); + logger.debug(String.format(messageToWrite, methodName)); + } else { + messageToWrite = mapExitOrEntryToMessage.get(enterOrExit); + logger.debug(String + .format(messageToWrite, methodName, entityParameter, String.join(",", ids))); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java new file mode 100644 index 0000000000..190c37d2b6 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context.impl; + +import org.openecomp.sdc.logging.context.MdcData; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.slf4j.MDC; + + +public class MdcDataErrorMessage extends MdcData { + private String targetEntity; + private String targetServiceName; + private String errorDescription; + + /** + * Instantiates a new Mdc data error message. + * + * @param targetEntity the target entity + * @param targetServiceName the target service name + * @param errorCategory the error category + * @param errorCode the error code + * @param errorDescription the error description + */ + public MdcDataErrorMessage(String targetEntity, String targetServiceName, String errorCategory, + String errorCode, String errorDescription) { + super(errorCategory, errorCode); + this.targetEntity = targetEntity; + this.targetServiceName = targetServiceName; + this.errorDescription = errorDescription; + + this.setMdcValues(); + } + + /** + * Create error message and update mdc. + * + * @param targetEntity the target entity + * @param targetServiceName the target service name + * @param level the level + * @param errorCode the error code + * @param errorDescription the error description + */ + public static void createErrorMessageAndUpdateMdc(String targetEntity, String targetServiceName, + String level, String errorCode, + String errorDescription) { + MdcDataErrorMessage mdcDataErrorMessage = + new MdcDataErrorMessage(targetEntity, targetServiceName, level, errorCode, + errorDescription); + } + + @Override + public void setMdcValues() { + super.setMdcValues(); + MDC.put(LoggerConstants.TARGET_ENTITY, this.targetEntity); + MDC.put(LoggerConstants.TARGET_SERVICE_NAME, this.targetServiceName); + MDC.put(LoggerConstants.ERROR_DESCRIPTION, this.errorDescription); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java new file mode 100644 index 0000000000..2273e1c7ef --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.logback; + +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.sift.MDCBasedDiscriminator; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.Appender; +import ch.qos.logback.core.AppenderBase; +import ch.qos.logback.core.joran.spi.DefaultClass; +import ch.qos.logback.core.sift.Discriminator; +import org.slf4j.LoggerFactory; + +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + *

Allows to use EELF logging configuration almost as is, by using a custom routing function, but pre-configured + * appenders attached to the standard EELF loggers.

+ * + *

Changes that must be made in logback.xml supplied with EELF:

+ * + *
+ *     <appender name="DISPATCHER" class="org.openecomp.sdc.logging.logback.DispatchingAppender">
+ *          <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/>
+ *          <appenderNamePattern>asyncEELF%s</appenderNamePattern>
+ *     </appender>
+ *
+ *     <root level="INFO" additivity="false">
+ *          <appender-ref ref="DISPATCHER" />
+ *      </root>
+ * 
+ * + * @author EVITALIY + * @since 17/08/2016. + */ +public class DispatchingAppender extends AppenderBase { + + // "magic" appender to indicate a missing appender + private static final Appender NO_APPENDER = new DispatchingAppender(); + + private Map> appenders = new ConcurrentHashMap<>(); + + private Discriminator discriminator; + private String appenderNamePattern; + + @DefaultClass(MDCBasedDiscriminator.class) + public void setDiscriminator(Discriminator discriminator) { + this.discriminator = discriminator; + } + + public Discriminator getDiscriminator() { + return this.discriminator; + } + + public void setAppenderNamePattern(String pattern) { + this.appenderNamePattern = pattern; + } + + public String getAppenderNamePattern() { + return this.appenderNamePattern; + } + + @Override + protected void append(ILoggingEvent event) { + + if (this.isStarted()) { + + String discriminatingValue = this.discriminator.getDiscriminatingValue(event); + String appenderName = String.format(this.appenderNamePattern, discriminatingValue); + Appender appender = this.lookupAppender(appenderName); + if (appender == NO_APPENDER) { + this.addError(String.format("Appender %s does not exist", appenderName)); + } else { + appender.doAppend(event); + } + } + } + + private Appender lookupAppender(String key) { + + Appender appender = appenders.get(key); + if (appender != null) { + return appender; + } + + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + for (Logger log : context.getLoggerList()) { + + Iterator> iterator = log.iteratorForAppenders(); + while (iterator.hasNext()) { + + Appender element = iterator.next(); + if (key.equals(element.getName())) { + this.appenders.putIfAbsent(key, element); + return element; + } + } + } + + // to avoid consecutive lookups if the required appender does not exist + this.appenders.putIfAbsent(key, NO_APPENDER); + return NO_APPENDER; + } + + @Override + public void start() { + + int errors = 0; + if (this.discriminator == null) { + this.addError("Missing discriminator. Aborting"); + } + + if (!this.discriminator.isStarted()) { + this.addError("Discriminator has not started successfully. Aborting"); + ++errors; + } + + if (this.appenderNamePattern == null) { + this.addError("Missing name pattern. Aborting"); + ++errors; + } + + if (errors == 0) { + super.start(); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java new file mode 100644 index 0000000000..5aa36656af --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.logback; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.sift.AbstractDiscriminator; +import org.openecomp.sdc.logging.Markers; +import org.slf4j.Marker; + +/** + * Can be used with {@link ch.qos.logback.classic.sift.SiftingAppender} to route events of different types to + * separate log files. For example, + * + *
+ *     <configuration>
+ *         <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
+ *             <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/>
+ *             <sift>
+ *                  <appender name="{EventType}" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ *                      <file>${logDirectory}/${eventType}.log</file>
+ *                      <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ *                          <fileNamePattern>${logDirectory}/${eventType}.%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>${defaultPattern}</pattern>
+ *                      </encoder>
+ *                  </appender>
+ *             </sift>
+ *         </appender>
+ *
+ *         <root level="INFO">
+ *             <appender-ref ref="SIFT" />
+ *         </root>
+ *     </configuration>
+ * 
+ * + * @author evitaliy + * @since 21/07/2016. + */ +public class EventTypeDiscriminator extends AbstractDiscriminator { + + private static final String KEY = "eventType"; + + private static final String AUDIT = "Audit"; + private static final String METRICS = "Metrics"; + private static final String ERROR = "Error"; + private static final String DEBUG = "Debug"; + private static final String DEFAULT = DEBUG; + + private static final int MIN_ERROR_LEVEL = Level.WARN_INT; + private static final int MAX_ERROR_LEVEL = Level.ERROR_INT; + private static final int DEFAULT_LEVEL = Level.DEBUG_INT; + + @Override + public String getDiscriminatingValue(ILoggingEvent event) { + + Level level = event.getLevel(); + final int levelInt = level == null ? DEFAULT_LEVEL : level.toInt(); + if ((levelInt > MIN_ERROR_LEVEL - 1) && (levelInt < MAX_ERROR_LEVEL + 1)) { + return ERROR; + } + + if (levelInt == Level.DEBUG_INT) { + return DEBUG; + } + + /* + * After DEBUG, ERROR, and WARNING have been filtered out, + * only TRACE and INFO are left. TRACE is less than DEBUG + * and therefore cannot be used. So, INFO should be used for + * custom routing like AUDIT and METRICS + */ + if (levelInt == Level.INFO_INT) { + + final Marker marker = event.getMarker(); + if (marker != null) { + + if (marker.contains(Markers.AUDIT)) { + return AUDIT; + } + + if (marker.contains(Markers.METRICS)) { + return METRICS; + } + } + + return ERROR; + } + + return DEFAULT; + } + + @Override + public String getKey() { + return KEY; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java new file mode 100644 index 0000000000..7294b9b5d6 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java @@ -0,0 +1,143 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.servlet; + +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.slf4j.MDC; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; + + +/** + * + *

Pushes information required by EELF onto MDC (Mapped Diagnostic Context).

+ * + *

This is servlet filter that should be configured in web.xml to be used. Example:

+ * + *
+ *
+ *  <filter>
+ *      <filter-name>LoggingServletFilter</filter-name>
+ *      <filter-class>org.openecomp.sdc.logging.servlet.LoggingFilter</filter-class>
+ *  </filter>
+ *
+ *  <filter-mapping>
+ *      <filter-name>LoggingServletFilter</filter-name>
+ *      <url-pattern>/*</url-pattern>
+ *  </filter-mapping>
+ *
+ * 
+ * + * @author evitaliy + * @since 25/07/2016. + */ +public class LoggingFilter implements Filter { + + // should be cashed to avoid low-level call, but with a timeout to account for IP or FQDN changes + private static final HostAddressCache HOST_ADDRESS = new HostAddressCache(); + private static final String UNKNOWN = "UNKNOWN"; + + private final static Logger LOGGER = LoggerFactory.getLogger(LoggingFilter.class); + + public void destroy() { + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + try { + + MDC.clear(); + + MDC.put("RequestId", UUID.randomUUID().toString()); + MDC.put("ServiceInstanceId", "N/A"); // not applicable + MDC.put("ServiceName", "ASDC"); + MDC.put("InstanceUUID", "N/A"); + + // For some reason chooses IPv4 or IPv6 in a random way + MDC.put("RemoteHost", request.getRemoteHost()); + + InetAddress host = HOST_ADDRESS.get(); + + String ipAddress, hostName; + if (host == null) { + ipAddress = UNKNOWN; + hostName = UNKNOWN; + } else { + ipAddress = host.getHostAddress(); + hostName = host.getHostName(); + } + + MDC.put("ServerIPAddress", ipAddress); + MDC.put("ServerFQDN", hostName); + + if(request instanceof HttpServletRequest) { + String userName = ((HttpServletRequest) request).getHeader("USER_ID"); + MDC.put("PartnerName", userName); + } + // TODO: Clarify what these stand for + // MDC.put("AlertSeverity", ); + // MDC.put("Timer", ); + + chain.doFilter(request, response); + + } finally { + MDC.clear(); + } + } + + public void init(FilterConfig config) throws ServletException { } + + private static class HostAddressCache { + + private static final long REFRESH_TIME = 1000L; + + private final AtomicLong lastUpdated = new AtomicLong(0L); + private InetAddress hostAddress; + + public InetAddress get() { + + long current = System.currentTimeMillis(); + if (current - lastUpdated.get() > REFRESH_TIME) { + + synchronized (this) { + + try { + lastUpdated.set(current); // set now to register the attempt even if failed + hostAddress = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + LOGGER.error("Failed to retrieve local hostname for logging", e); + hostAddress = null; + } + } + } + + return hostAddress; + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java new file mode 100644 index 0000000000..06b0d5b2bc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.util; + +/** + * Created by TALIO on 1/10/2017. + */ +public class LoggingUtils { + + public static String getCallingMethodNameForDebugging() { + return Thread.currentThread().getStackTrace()[4].getMethodName(); + } + + public static String getDeclaringClass(){ + return Thread.currentThread().getStackTrace()[4].getClassName(); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService new file mode 100644 index 0000000000..ee01c4d871 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService @@ -0,0 +1 @@ +org.openecomp.sdc.logging.SLF4JLoggerCreationService \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService new file mode 100644 index 0000000000..2c401614ae --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService @@ -0,0 +1 @@ +org.openecomp.sdc.logging.context.MDCPropagationService \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java new file mode 100644 index 0000000000..fe81a4626a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.logging; + +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; + +import static org.testng.Assert.assertEquals; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class LoggerFactoryTest { + + @Test + public void testCreate() throws Exception { + // test that the service loader loads the right implementation + LoggerFactory.getLogger(LoggerFactoryTest.class); + Field factory = LoggerFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object implementation = factory.get(null); + assertEquals(SLF4JLoggerCreationService.class, implementation.getClass()); + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java new file mode 100644 index 0000000000..87f2f17ba0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.sift.SiftingAppender; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; +import org.openecomp.sdc.logging.logback.EventTypeDiscriminator; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Predicate; + +/** + * TODO: Add more negative tests + * + * @author EVITALIY + * @since 17/08/2016. + */ +public class RoutingTest { + + private static final String ERROR = "Error"; + private static final String DEBUG = "Debug"; + private static final String AUDIT = "Audit"; + private static final String METRICS = "Metrics"; + + private Logger logger; + private Map result = new ConcurrentHashMap<>(); + + @BeforeClass + public void setUp() { + + SiftingAppender appender = new SiftingAppender(); + + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + discriminator.start(); + + appender.setDiscriminator(discriminator); + appender.setAppenderFactory((context, discriminatingValue) -> + result.computeIfAbsent(discriminatingValue, f -> { + TestAppender tmp = new TestAppender(); + tmp.start(); + return tmp; + })); + + appender.start(); + + logger = (Logger) LoggerFactory.getLogger(RoutingTest.class.getName()); + // prevent from writing into appenders attached via parent loggers + logger.setAdditive(false); + logger.addAppender(appender); + logger.setLevel(Level.DEBUG); + } + + @Test + public void testWarning() { + String msg = "This is a test warning"; + logger.warn(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.WARN.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testError() { + String msg = "This is a test error"; + logger.error(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.ERROR.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testDebug() { + String msg = "This is a test debug"; + logger.debug(msg); + TestAppender appender = result.get(DEBUG); + Assert.assertTrue(appender.contains((event) -> + Level.DEBUG.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testInfo() { + String msg = "This is a test info"; + logger.info(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testAudit() { + String msg = "This is a test audit"; + logger.info(Markers.AUDIT, msg); + TestAppender appender = result.get(AUDIT); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testMetrics() { + String msg = "This is a test metrics"; + logger.info(Markers.METRICS, msg); + TestAppender appender = result.get(METRICS); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + /** + * An appender that just accumulates messages in a list and enables to inspect them + * + * @author EVITALIY + * @since 17/08/2016. + */ + private static class TestAppender extends AppenderBase { + + private List events = Collections.synchronizedList(new ArrayList<>(10)); + + @Override + protected void append(ILoggingEvent event) { + this.events.add(event); + } + + public boolean contains(Predicate predicate) { + return events.stream().anyMatch(predicate); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java new file mode 100644 index 0000000000..a191c80a98 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.api; + +import org.testng.annotations.Test; + +/** + * This is only for manual testing - change ENABLE to 'true' + * + * @author evitaliy + * @since 13/09/2016. + */ +public class LoggerTest { + + private static final boolean ENABLED = false; + private static final Logger LOGGER = LoggerFactory.getLogger(LoggerTest.class); + + @Test(enabled = ENABLED) + public void testMetrics() throws Exception { + LOGGER.metrics("This is metrics"); + } + + @Test(enabled = ENABLED) + public void testAudit() throws Exception { + LOGGER.audit("This is audit"); + } + + @Test(enabled = ENABLED) + public void testDebug() throws Exception { + LOGGER.debug("This is debug"); + } + + @Test(enabled = ENABLED) + public void testInfo() throws Exception { + LOGGER.info("This is info"); + } + + @Test(enabled = ENABLED) + public void testWarn() throws Exception { + LOGGER.warn("This is warning"); + } + + @Test(enabled = ENABLED) + public void testError() throws Exception { + LOGGER.error("This is error"); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java new file mode 100644 index 0000000000..8b9ee3ee08 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java @@ -0,0 +1,451 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.aspects; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.reflect.SourceLocation; +import org.aspectj.runtime.internal.AroundClosure; +import org.easymock.EasyMock; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.testng.PowerMockTestCase; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; + +/** + * @author EVITALIY + * @since 17/08/2016. + */ +@PrepareForTest(LoggerFactory.class) +public class MetricsAspectTest extends PowerMockTestCase { + + private static final Object OBJ_TO_RETURN = new Object(); + private static final String EXPECTED_MESSAGE = "'{}' took {} milliseconds"; + + @Test + public void testLogExecutionTime() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + TestLogger logger = initLogging(className, true); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPoint(className, methodName); + Object returned = aspect.logExecutionTime(pjp); + + Assert.assertEquals(OBJ_TO_RETURN, returned); + assertExecution(methodName, pjp, logger); + } + + @Test + public void testMetricsDisabled() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + TestLogger logger = initLogging(className, false); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPoint(className, methodName); + Object returned = aspect.logExecutionTime(pjp); + + Assert.assertEquals(OBJ_TO_RETURN, returned); + Assert.assertEquals(1, pjp.getCount()); + // return any event - must be empty + Assert.assertFalse(logger.contains((event) -> true)); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testThrowingError() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + final TestLogger logger = initLogging(className, true); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPointWithException(className, methodName); + + try { + aspect.logExecutionTime(pjp); + } finally { + assertExecution(methodName, pjp, logger); + } + } + + private TestLogger initLogging(String className, boolean enabled) { + TestLogger logger = new TestLogger(enabled); + PowerMock.mockStatic(LoggerFactory.class); + EasyMock.expect(LoggerFactory.getLogger(className)).andReturn(logger); + PowerMock.replay(LoggerFactory.class); + return logger; + } + + private void assertExecution(String methodName, MockProceedingJoinPoint pjp, TestLogger logger) { + + Assert.assertEquals(1, pjp.getCount()); + Assert.assertTrue(logger.contains((event) -> + (event != null) && (event.length == 3) && EXPECTED_MESSAGE.equals(event[0]) + && methodName.equals(event[1]) && (event[2] instanceof Long))); + } + + private static class MockSignature implements Signature { + + private final String className; + private final String methodName; + + private MockSignature(String className, String methodName) { + this.className = className; + this.methodName = methodName; + } + + @Override + public String toShortString() { + return null; + } + + @Override + public String toLongString() { + return null; + } + + @Override + public String getName() { + return methodName; + } + + @Override + public int getModifiers() { + return 0; + } + + @Override + public Class getDeclaringType() { + return null; + } + + @Override + public String getDeclaringTypeName() { + return className; + } + } + + private static class MockProceedingJoinPoint implements ProceedingJoinPoint { + + private AtomicInteger count = new AtomicInteger(0); + private Signature signature; + + MockProceedingJoinPoint(String className, String methodName) { + this.signature = new MockSignature(className, methodName); + } + + int getCount() { + return count.get(); + } + + @Override + public Object proceed() throws Throwable { + count.incrementAndGet(); + return OBJ_TO_RETURN; + } + + @Override + public void set$AroundClosure(AroundClosure aroundClosure) { + + } + + @Override + public Object proceed(Object[] objects) throws Throwable { + return null; + } + + @Override + public String toShortString() { + return null; + } + + @Override + public String toLongString() { + return null; + } + + @Override + public Object getThis() { + return null; + } + + @Override + public Object getTarget() { + return null; + } + + @Override + public Object[] getArgs() { + return new Object[0]; + } + + @Override + public Signature getSignature() { + return this.signature; + } + + @Override + public SourceLocation getSourceLocation() { + return null; + } + + @Override + public String getKind() { + return null; + } + + @Override + public StaticPart getStaticPart() { + return null; + } + } + + private static class MockProceedingJoinPointWithException extends MockProceedingJoinPoint { + + MockProceedingJoinPointWithException(String className, String methodName) { + super(className, methodName); + } + + @Override + public Object proceed() throws Throwable { + super.proceed(); + throw new IllegalArgumentException(); + } + } + + private class TestLogger implements Logger { + + private final boolean enabled; + private List events = Collections.synchronizedList(new ArrayList<>(10)); + + TestLogger(boolean enabled) { + this.enabled = enabled; + } + + @Override + public String getName() { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isMetricsEnabled() { + return this.enabled; + } + + @Override + public void metrics(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Object var2, Object var3) { + + if (this.enabled) { + events.add(new Object[]{var1, var2, var3}); + } + } + + @Override + public void metrics(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isAuditEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isDebugEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isInfoEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isWarnEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isErrorEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + public boolean contains(Predicate predicate) { + return events.stream().anyMatch(predicate); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java new file mode 100644 index 0000000000..c0aa1d018a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java @@ -0,0 +1,223 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.context; + +import org.slf4j.MDC; +import org.testng.annotations.Test; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class MDCPropagationFactoryTest { + + // Disable if an old version of MDC implementation is being used. + // MDCPropagationFactory should be used when MDC is not propagated to child threads. + // See https://jira.qos.ch/browse/LOGBACK-422 and https://jira.qos.ch/browse/LOGBACK-624 + private static final boolean ENABLED = false; + + @Test(enabled = ENABLED) + public void testNoPropagation() throws InterruptedException { + + String uuid = UUID.randomUUID().toString(); + AtomicBoolean complete = new AtomicBoolean(false); + MDC.put("data", uuid); + + Runnable runnable = () -> { + assertNull(MDC.get("data"), "Data unexpectedly copied to a child thread. " + + "Are you using an old version of MDC implementation (e.g. logback)?"); + complete.set(true); + }; + + Thread thread = new Thread(runnable); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), uuid, "Expected data to be retained in this thread"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testPropagation() throws InterruptedException { + + String uuid = UUID.randomUUID().toString(); + AtomicBoolean complete = new AtomicBoolean(false); + MDC.put("data", uuid); + + MDCPropagationService factory = new MDCPropagationService(); + Runnable runnable = factory.create(() -> { + assertEquals(MDC.get("data"), uuid, "Expected data to be propagated to the child thread's MDC"); + complete.set(true); + }); + + Thread thread = new Thread(runnable); + thread.start(); + + thread.join(); + + assertEquals(MDC.get("data"), uuid, "Expected data to be retained in this thread"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testReplacement() throws InterruptedException { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + String outerUuid = UUID.randomUUID().toString(); + MDC.put("data", outerUuid); + inner.run(); + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be replaced with stored data"); + outerComplete.set(true); + }; + + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected data to be retained in this thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testEmpty() throws InterruptedException { + + final AtomicBoolean complete = new AtomicBoolean(false); + + MDC.remove("data"); + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + + MDCPropagationService factory = new MDCPropagationService(); + Runnable runnable = factory.create(() -> { + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + complete.set(true); + }); + + Thread thread = new Thread(runnable); + thread.start(); + thread.join(); + + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testCleanup() throws Exception { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + assertNull(MDC.get("data"), "Expected MDC data not to be copied to this thread"); + inner.run(); + assertNull(MDC.get("data"), "Expected MDC data to remain empty in this thread"); + outerComplete.set(true); + }; + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected MDC data to be retained in parent thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testCleanupAfterError() throws Exception { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + AtomicBoolean exceptionThrown = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + throw new RuntimeException(); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + + String outerUuid = UUID.randomUUID().toString(); + MDC.put("data", outerUuid); + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be populated in this thread"); + + try { + inner.run(); + } catch (RuntimeException e) { + exceptionThrown.set(true); + } finally { + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be reverted even in case of exception"); + outerComplete.set(true); + } + }; + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected MDC data to be retained in parent thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + assertTrue(exceptionThrown.get(), "Expected the inner class to throw exception"); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java new file mode 100644 index 0000000000..dad60d44d5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java @@ -0,0 +1,26 @@ +package org.openecomp.sdc.logging.context; + +import org.openecomp.sdc.logging.api.context.TaskFactory; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; + +import static org.testng.Assert.assertEquals; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class TaskFactoryTest { + + @Test + public void testCreate() throws Exception { + // test that the service loader loads the right implementation + TaskFactory.create(() -> { + }); + Field factory = TaskFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object implementation = factory.get(null); + assertEquals(MDCPropagationService.class, implementation.getClass()); + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java new file mode 100644 index 0000000000..39b3170a5b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java @@ -0,0 +1,220 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.logback; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.LoggingEvent; +import org.openecomp.sdc.logging.Markers; +import org.slf4j.MarkerFactory; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * @author EVITALIY + * @since 17/08/2016. + */ +public class EventTypeDiscriminatorTest { + + private static final String DEBUG = "Debug"; + private static final String ERROR = "Error"; + + @Test + public void testGetDefaultDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetInfoDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetTraceDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetErrorWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetDebugWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetDebugWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetDebugWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetInfoWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), "Audit"); + } + + @Test + public void testGetMetricsMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), "Metrics"); + } + + @Test + public void testGetKey() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + assertEquals("eventType", discriminator.getKey()); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java new file mode 100644 index 0000000000..0779e38055 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java @@ -0,0 +1,314 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.sdc.logging.servlet; + +import org.slf4j.MDC; +import org.testng.Assert; +import org.testng.annotations.Test; + +import javax.servlet.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.InetAddress; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +/** + * TODO: Add more tests + * + * @author EVITALIY + * @since 17/08/2016. + */ +public class LoggingFilterTest { + + private static final String REMOTE_HOST = UUID.randomUUID().toString(); + + @Test + public void testDoFilter() throws Exception { + LoggingFilter loggingFilter = new LoggingFilter(); + ServletRequest mockRequest = new TestServletRequest(); + ServletResponse mockResponse = new TestServletResponse(); + TestFilterChain mockChain = new TestFilterChain(); + loggingFilter.doFilter(mockRequest, mockResponse, mockChain); + assertEquals(1, mockChain.getCount()); + assertNull(MDC.getCopyOfContextMap()); + } + + private static class TestServletRequest implements ServletRequest { + + @Override + public Object getAttribute(String s) { + return null; + } + + @Override + public Enumeration getAttributeNames() { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { + + } + + @Override + public int getContentLength() { + return 0; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + return null; + } + + @Override + public String getParameter(String s) { + return null; + } + + @Override + public Enumeration getParameterNames() { + return null; + } + + @Override + public String[] getParameterValues(String s) { + return new String[0]; + } + + @Override + public Map getParameterMap() { + return null; + } + + @Override + public String getProtocol() { + return null; + } + + @Override + public String getScheme() { + return null; + } + + @Override + public String getServerName() { + return null; + } + + @Override + public int getServerPort() { + return 0; + } + + @Override + public BufferedReader getReader() throws IOException { + return null; + } + + @Override + public String getRemoteAddr() { + return null; + } + + @Override + public String getRemoteHost() { + return REMOTE_HOST; + } + + @Override + public void setAttribute(String s, Object o) { + + } + + @Override + public void removeAttribute(String s) { + + } + + @Override + public Locale getLocale() { + return null; + } + + @Override + public Enumeration getLocales() { + return null; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public RequestDispatcher getRequestDispatcher(String s) { + return null; + } + + @Override + public String getRealPath(String s) { + return null; + } + + @Override + public int getRemotePort() { + return 0; + } + + @Override + public String getLocalName() { + return null; + } + + @Override + public String getLocalAddr() { + return null; + } + + @Override + public int getLocalPort() { + return 0; + } + } + + private static class TestFilterChain implements FilterChain { + + private AtomicInteger count = new AtomicInteger(0); + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) + throws IOException, ServletException { + + Assert.assertNotNull(MDC.get("RequestId")); + Assert.assertEquals(MDC.get("ServiceInstanceId"), "N/A"); + Assert.assertEquals(MDC.get("ServiceName"), "ASDC"); + Assert.assertEquals(MDC.get("InstanceUUID"), "N/A"); + Assert.assertEquals(MDC.get("RemoteHost"), REMOTE_HOST); + + InetAddress host = InetAddress.getLocalHost(); + Assert.assertEquals(MDC.get("ServerIPAddress"), host.getHostAddress()); + Assert.assertEquals(MDC.get("ServerFQDN"), host.getHostName()); + + count.incrementAndGet(); + } + + public int getCount() { + return count.get(); + } + } + + private static class TestServletResponse implements ServletResponse { + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public void setCharacterEncoding(String s) { + + } + + @Override + public String getContentType() { + return null; + } + + @Override + public void setContentType(String s) { + + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + @Override + public PrintWriter getWriter() throws IOException { + return null; + } + + @Override + public void setContentLength(int i) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void setBufferSize(int i) { + + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public Locale getLocale() { + return null; + } + + @Override + public void setLocale(Locale locale) { + + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README new file mode 100644 index 0000000000..430f36d760 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README @@ -0,0 +1,8 @@ +Different routing/dispatching mechanisms can be tested using -Dlogback.configurationFile and a custom configuration +file, for example + +-Dlogback.configurationFile=/dispatching-logback.xml + +or + +-Dlogback.configurationFile=/sifting-logback.xml \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml new file mode 100644 index 0000000000..c6c51f14c1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml @@ -0,0 +1,335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + ${logDirectory}/${generalLogName}.log + + ${logDirectory}/${generalLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + + 256 + + + + + + ${logDirectory}/${securityLogName}.log + + ${logDirectory}/${securityLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + + 256 + 0 + + + + + + ${logDirectory}/${performanceLogName}.log + + ${logDirectory}/${performanceLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + true + ${defaultPattern} + + + + 256 + + + + + + ${logDirectory}/${serverLogName}.log + + ${logDirectory}/${serverLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + 256 + + + + + + + ${logDirectory}/${policyLogName}.log + + ${logDirectory}/${policyLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + 256 + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + 256 + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultPattern} + + + + + + 256 + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + + 256 + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + asyncEELF%s + + + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..4029db2215 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + ${defaultPattern} + + + + + + + + ${logDirectory}/${eventType}.log + + ${logDirectory}/${eventType}.%i.log.zip + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + + + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml new file mode 100644 index 0000000000..b713b54b75 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + ${logDirectory}/${eventType}.log + + ${logDirectory}/${eventType}.%i.log.zip + 1 + 9 + + + 5MB + + + ${defaultPattern} + + + + + + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml new file mode 100644 index 0000000000..589b8bbdbc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + openecomp-sdc-logging-lib + openecomp-sdc-logging-lib + pom + + + org.openecomp.sdc + openecomp-sdc-lib + 1.2.0-SNAPSHOT + + + + openecomp-sdc-logging-api + openecomp-sdc-logging-core + + + diff --git a/openecomp-be/lib/pom.xml b/openecomp-be/lib/pom.xml index 868d0c6353..ea1faaec4b 100644 --- a/openecomp-be/lib/pom.xml +++ b/openecomp-be/lib/pom.xml @@ -28,7 +28,7 @@ openecomp-tosca-lib openecomp-sdc-action-lib openecomp-sdc-enrichment-lib - openecomp-logging-lib + openecomp-sdc-logging-lib openecomp-healing-lib openecomp-sdc-activity-log-lib openecomp-tosca-converter-lib -- cgit 1.2.3-korg