summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api
diff options
context:
space:
mode:
authorolegb <olegb@amdocs.com>2018-02-19 16:19:17 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-03-15 08:27:59 +0000
commit9c40f569b817e0886d95ad8b1ac235d8644873da (patch)
tree8613cc536ab0b30b2e96a70d94bdff52944295e7 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api
parent5979cf87e450fc2b47360cdfced44808dc2d82bf (diff)
Changed logging context API
Issue-ID: SDC-772 Change-Id: I9dce63f3a1bb7df067cf06a96158afa7d799319e Signed-off-by: olegb <olegb@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java48
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java48
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggingContextTest.java37
3 files changed, 49 insertions, 84 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java
index f827fec50f..879d9cf098 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2016-2017 European Support Limited
+ * Copyright © 2016-2018 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,37 +22,38 @@ import java.util.Objects;
import java.util.concurrent.Callable;
/**
- * <a>Factory to hide a concrete, framework-specific implementation of diagnostic context.</a>
- * <p>The service used by this factory must implement {@link LoggingContextService}. If no
- * implementation has been configured or could be instantiated, a <b>no-op context service</b> will be
- * used, and <b>no context</b> will be stored or propagated. No errors will be generated, so that the application can
- * still work (albeit without proper logging).</p>
+ * <p>Factory to hide a concrete, framework-specific implementation of diagnostic context.</p>
*
- * @author evitaliy
- * @since 07/01/2018.
+ * <p>The service used by this factory must implement {@link LoggingContextService}. If no implementation has been
+ * configured or could be instantiated, a <b>no-op context service</b> will be used, and <b>no context</b> will be
+ * stored or propagated. No errors will be generated, so that the application can still work (albeit without proper
+ * logging).</p>
*
+ * @author evitaliy
* @see ServiceBinder
* @see LoggingContextService
+ * @since 07 Jan 2018
*/
public class LoggingContext {
- private static final LoggingContextService SERVICE = ServiceBinder.getContextServiceBinding().orElse(
+ private static final LoggingContextService SERVICE =
+ ServiceBinder.getContextServiceBinding().orElse(
new NoOpLoggingContextService());
private LoggingContext() {
// prevent instantiation
}
- public static void put(String key, String value) {
- SERVICE.put(key, value);
+ public static void putRequestId(String requestId) {
+ SERVICE.putRequestId(requestId);
}
- public static String get(String key) {
- return SERVICE.get(key);
+ public static void putServiceName(String serviceName) {
+ SERVICE.putServiceName(serviceName);
}
- public static void remove(String key) {
- SERVICE.remove(key);
+ public static void putPartnerName(String partnerName) {
+ SERVICE.putPartnerName(partnerName);
}
public static void clear() {
@@ -69,24 +70,19 @@ public class LoggingContext {
private static class NoOpLoggingContextService implements LoggingContextService {
- private static final String KEY_CANNOT_BE_NULL = "Key cannot be null";
-
@Override
- public void put(String key, String value) {
- Objects.requireNonNull(key, KEY_CANNOT_BE_NULL);
- // no-op
+ public void putRequestId(String requestId) {
+ Objects.requireNonNull(requestId, "Request ID cannot be null");
}
@Override
- public String get(String key) {
- Objects.requireNonNull(key, KEY_CANNOT_BE_NULL);
- return null;
+ public void putServiceName(String serviceName) {
+ Objects.requireNonNull(serviceName, "Service name cannot be null");
}
@Override
- public void remove(String key) {
- Objects.requireNonNull(key, KEY_CANNOT_BE_NULL);
- // no-op
+ public void putPartnerName(String partnerName) {
+ Objects.requireNonNull(partnerName, "Partner name cannot be null");
}
@Override
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java
index 7aed0fc7dc..07b93c1468 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java
@@ -1,12 +1,12 @@
/*
- * Copyright © 2016-2017 European Support Limited
+ * Copyright © 2016-2018 European Support Limited
*
* 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.
@@ -19,37 +19,25 @@ package org.openecomp.sdc.logging.spi;
import java.util.concurrent.Callable;
/**
- * Should be used to implement a framework-specific mechanism of managing a per-thread diagnostic context
- * (for instance <a href="http://www.slf4j.org/manual.html#mdc">MDC</a>), and propagating it to child threads if needed.
- * Context propagation should be used when creating a child thread directly, or submitting tasks for potentially
- * postponed execution via an
- * <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a> (including any of
- * the
- * <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html">executor services</a>
- * and <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html">ForkJoinPool</a>).
+ * Should be used to implement a framework-specific mechanism of managing a per-thread diagnostic context (for instance
+ * <a href="http://www.slf4j.org/manual.html#mdc">MDC</a>), and propagating it to child threads if needed. Context
+ * propagation should be used when creating a child thread directly, or submitting tasks for potentially postponed
+ * execution via an <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a>
+ * (including any of the <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html">
+ * executor services</a> and <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html">
+ * ForkJoinPool</a>).
*
* @author evitaliy
- * @since 07/01/2018.
+ * @since 07 Jan 2018
*/
public interface LoggingContextService {
- /**
- * Allows to store a key-value pair on thread context
- */
- void put(String key, String value);
+ void putRequestId(String requestId);
- /**
- * Returns the value associated with a key stored on thread context
- *
- * @return value or <code>null</code> if the key does not exits
- */
- String get(String key);
+ void putServiceName(String serviceName);
- /**
- * Removes a particular key from thread context
- */
- void remove(String key);
+ void putPartnerName(String partnerName);
/**
* Clear logging thread context
@@ -57,14 +45,14 @@ public interface LoggingContextService {
void clear();
/**
- * Copies logging context of current thread onto a {@link Runnable}, so that the context is available
- * when this {@link Runnable} runs in another thread.
+ * Copies logging context of current thread onto a {@link Runnable}, so that the context is available when this
+ * {@link Runnable} runs in another thread.
*/
Runnable copyToRunnable(Runnable runnable);
/**
- * Copies logging context of current thread onto a {@link Callable}, so that the context is available
- * when this {@link Callable} runs in another thread
+ * Copies logging context of current thread onto a {@link Callable}, so that the context is available when this
+ * {@link Callable} runs in another thread
*/
<V> Callable<V> copyToCallable(Callable<V> callable);
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggingContextTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggingContextTest.java
index 79252cde0b..bfc53a3146 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggingContextTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggingContextTest.java
@@ -16,14 +16,12 @@
package org.openecomp.sdc.logging.api;
-import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
/**
* @author EVITALIY
@@ -40,36 +38,19 @@ public class LoggingContextTest {
"org.openecomp.sdc.logging.api.LoggingContext$NoOpLoggingContextService");
}
- @Test
- public void putDoesNotHaveEffectWhenNoBinding() {
- final String key = "Key";
- LoggingContext.put(key, "Dummy");
- assertNull(LoggingContext.get(key));
- }
-
@Test(expectedExceptions = NullPointerException.class)
- public void throwNpeWhenPutWithKeyNull() {
- LoggingContext.put(null, "value");
- }
-
- @Test
- public void getAlwaysReturnsNull() {
- assertNull(LoggingContext.get("GetKey"));
+ public void throwNpeWhenPartnerNameIsNull() {
+ LoggingContext.putPartnerName(null);
}
@Test(expectedExceptions = NullPointerException.class)
- public void throwNpeWhenGetWithKeyNull() {
- LoggingContext.get(null);
- }
-
- @Test
- public void removeDoesNotFail() {
- LoggingContext.remove("RemoveKey");
+ public void throwNpeWhenServiceNameIsNull() {
+ LoggingContext.putServiceName(null);
}
@Test(expectedExceptions = NullPointerException.class)
- public void throwNpWhenRemoveWithKeyNull() {
- LoggingContext.remove(null);
+ public void throwNpeWhenRequestIdIsNull() {
+ LoggingContext.putRequestId(null);
}
@Test