summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api
diff options
context:
space:
mode:
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/ContextData.java25
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java5
3 files changed, 41 insertions, 3 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java
index 43f0143774..6eb747f9d9 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.logging.api;
+import java.util.Objects;
+
/**
* Builder to populate logging <i>context</i> data, i.e. data that should be available to any log writing event
* throughout an application. This includes only data known at some point to the application (e.g. at an API call),
@@ -64,9 +66,30 @@ public class ContextData {
}
@Override
+ public boolean equals(Object o) {
+
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ ContextData that = (ContextData) o;
+ return Objects.equals(requestId, that.requestId) && Objects.equals(serviceName, that.serviceName)
+ && Objects.equals(partnerName, that.partnerName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(requestId, serviceName, partnerName);
+ }
+
+ @Override
public String toString() {
return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName
- + ", clientIpAddress=" + partnerName + '}';
+ + ", clientIpAddress=" + partnerName + '}';
}
public static ContextDataBuilder builder() {
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 2dc4afdf58..c17149e98e 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
@@ -36,8 +36,7 @@ import org.openecomp.sdc.logging.spi.LoggingContextService;
public class LoggingContext {
private static final LoggingContextService SERVICE =
- ServiceBinder.getContextServiceBinding().orElse(
- new NoOpLoggingContextService());
+ ServiceBinder.getContextServiceBinding().orElse(new NoOpLoggingContextService());
private LoggingContext() {
// prevent instantiation
@@ -47,6 +46,10 @@ public class LoggingContext {
SERVICE.put(contextData);
}
+ public static ContextData get() {
+ return SERVICE.get();
+ }
+
public static void clear() {
SERVICE.clear();
}
@@ -61,12 +64,19 @@ public class LoggingContext {
private static class NoOpLoggingContextService implements LoggingContextService {
+ private static final ContextData EMPTY_CONTEXT = ContextData.builder().build();
+
@Override
public void put(ContextData contextData) {
Objects.requireNonNull(contextData, "Context data cannot be null");
}
@Override
+ public ContextData get() {
+ return EMPTY_CONTEXT;
+ }
+
+ @Override
public void clear() {
// no-op
}
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 b90ce63982..37e212ac54 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
@@ -40,6 +40,11 @@ public interface LoggingContextService {
void put(ContextData contextData);
/**
+ * Return logging context's data.
+ */
+ ContextData get();
+
+ /**
* Clear logging thread context.
*/
void clear();