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-logging-api/pom.xml | 18 -- .../openecomp/core/logging/api/BaseFactory.java | 54 ----- .../org/openecomp/core/logging/api/Logger.java | 103 --------- .../core/logging/api/LoggerCreationService.java | 11 - .../openecomp/core/logging/api/LoggerFactory.java | 232 --------------------- .../core/logging/api/annotations/Metrics.java | 15 -- .../api/context/ContextPropagationService.java | 10 - .../core/logging/api/context/TaskFactory.java | 73 ------- .../core/logging/api/LoggerFactoryTest.java | 74 ------- .../core/logging/api/context/TaskFactoryTest.java | 30 --- 10 files changed, 620 deletions(-) delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/pom.xml delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/BaseFactory.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/Logger.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/LoggerCreationService.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/LoggerFactory.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/annotations/Metrics.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/ContextPropagationService.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/TaskFactory.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/LoggerFactoryTest.java delete mode 100644 common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/context/TaskFactoryTest.java (limited to 'common/openecomp-logging-lib/openecomp-logging-api') diff --git a/common/openecomp-logging-lib/openecomp-logging-api/pom.xml b/common/openecomp-logging-lib/openecomp-logging-api/pom.xml deleted file mode 100644 index 62fe5c5cb4..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/pom.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - 4.0.0 - - openecomp-configuration-management-test - org.openecomp.sdc.common - openecomp-logging-api - - - openecomp-logging-lib - org.openecomp.sdc.common - 1.2.0-SNAPSHOT - .. - - - diff --git a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/BaseFactory.java b/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/BaseFactory.java deleted file mode 100644 index 14943805cc..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/BaseFactory.java +++ /dev/null @@ -1,54 +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.core.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).

- * - * @see java.util.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/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/Logger.java b/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/Logger.java deleted file mode 100644 index 0fe3d8f230..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/Logger.java +++ /dev/null @@ -1,103 +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.core.logging.api; - -/** - *

This interface defines logging as specified by OPENECOMP logging requirements.

Formatted - * messages must follow the 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.

- * - * @see BaseFactory - * @see LoggerCreationService - */ -@SuppressWarnings("ThrowableInstanceNeverThrown") -public class LoggerFactory extends BaseFactory { - - private static final LoggerCreationService SERVICE; - - static { - - LoggerCreationService service; - - try { - service = locateService(LoggerCreationService.class); - } catch (Exception e) { - new RuntimeException("Failed to instantiate logger factory", e).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 throwable) { - } - - @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 throwable) { - } - - @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 throwable) { - } - - @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 throwable) { - } - - @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 throwable) { - } - - @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 throwable) { - } - }; - - @Override - public Logger getLogger(String className) { - return NO_OP_LOGGER; - } - - @Override - public Logger getLogger(Class clazz) { - return NO_OP_LOGGER; - } - } -} diff --git a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/annotations/Metrics.java b/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/annotations/Metrics.java deleted file mode 100644 index 1588bcafc0..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/annotations/Metrics.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.openecomp.core.logging.api.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates a method whose execution time should be measured and logged as required for OPENECOMP - * metrics. - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Metrics { -} diff --git a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/ContextPropagationService.java b/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/ContextPropagationService.java deleted file mode 100644 index 8e9c2dfa28..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/ContextPropagationService.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.openecomp.core.logging.api.context; - -/** - * Should be used to implement a framework-specific mechanism of propagation of a diagnostic context - * to child threads. - */ -public interface ContextPropagationService { - - Runnable create(Runnable task); -} diff --git a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/TaskFactory.java b/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/TaskFactory.java deleted file mode 100644 index 30bc7372c6..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/main/java/org/openecomp/core/logging/api/context/TaskFactory.java +++ /dev/null @@ -1,73 +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.core.logging.api.context; - -import org.openecomp.core.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}.

- * - * @see ContextPropagationService - */ -@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 e) { - error = new RuntimeException("Failed to instantiate task factory", e); - } - - 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/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/LoggerFactoryTest.java b/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/LoggerFactoryTest.java deleted file mode 100644 index 7158db7ab4..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/LoggerFactoryTest.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.core.logging.api; - -import org.testng.annotations.Test; - -import java.lang.reflect.Field; -import java.util.ServiceLoader; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; - -/** - * @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.core.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/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/context/TaskFactoryTest.java b/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/context/TaskFactoryTest.java deleted file mode 100644 index 111a30de1a..0000000000 --- a/common/openecomp-logging-lib/openecomp-logging-api/src/test/java/org/openecomp/core/logging/api/context/TaskFactoryTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.openecomp.core.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 -- cgit 1.2.3-korg