diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2018-09-04 11:24:53 +0200 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2018-09-04 12:11:12 +0200 |
commit | c22f8a49db802a8087b6e05318db766be7e141fd (patch) | |
tree | 3a39806aec3f4cc1f29b535b2a7b445a503cebe4 /prh-app-server/src/main/java | |
parent | be3127220aed103d1c1bb495080d62593d61b835 (diff) |
MDC fix
Change-Id: I4b12f9b9914d93ee2969b4b3cf48a47837330a6d
Issue-ID: DCAEGEN2-745
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java')
6 files changed, 27 insertions, 21 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java index 96d47e34..39f2ea1a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java @@ -20,6 +20,13 @@ package org.onap.dcaegen2.services.prh; +import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.INVOCATION_ID; +import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.REQUEST_ID; + +import java.util.Map; +import java.util.UUID; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; @@ -42,6 +49,13 @@ public class MainApp { } @Bean + Map<String, String> mdcContextMap(){ + MDC.put(REQUEST_ID, "SampleRequestID"); + MDC.put(INVOCATION_ID, UUID.randomUUID().toString()); + return MDC.getCopyOfContextMap(); + } + + @Bean TaskScheduler concurrentTaskScheduler() { return new ConcurrentTaskScheduler(); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java index 882e4d7e..58f96938 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java @@ -137,12 +137,4 @@ public abstract class PrhAppConfig implements Config { InputStream getInputStream(@NotNull String filepath) throws IOException { return new BufferedInputStream(new FileInputStream(filepath)); } - - public void setXOnapRequestId(String xonaprequestid) { - MDC.put(REQUEST_ID, xonaprequestid); - } - - public void setXInvocationId(String xinvocationid) { - MDC.put(INVOCATION_ID, xinvocationid); - } }
\ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java index 5bf3e408..328f3897 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java @@ -45,7 +45,6 @@ import reactor.core.publisher.Mono; public class AaiProducerTaskImpl extends AaiProducerTask { - private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private static final Logger LOGGER = LoggerFactory.getLogger(AaiProducerTaskImpl.class); private final Config config; @@ -86,7 +85,7 @@ public class AaiProducerTaskImpl extends throw new DmaapNotFoundException("Invoked null object to DMaaP task"); } aaiProducerReactiveHttpClient = resolveClient(); - LOGGER.debug(INVOKE, "Method called with arg {}", consumerDmaapModel); + LOGGER.debug("Method called with arg {}", consumerDmaapModel); return publish(consumerDmaapModel); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index 0d4be08e..b05ec9fd 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -40,8 +40,6 @@ import reactor.core.publisher.Mono; @Component public class DmaapConsumerTaskImpl extends DmaapConsumerTask { - private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); - private static final Logger LOGGER = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class); private final Config config; private DmaapConsumerJsonParser dmaapConsumerJsonParser; @@ -65,7 +63,7 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask { @Override public Mono<ConsumerDmaapModel> execute(String object) { DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient = resolveClient(); - LOGGER.debug(INVOKE, "Method called with arg {}", object); + LOGGER.debug("Method called with arg {}", object); return consume(dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java index 733b8651..d7e6a322 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java @@ -42,7 +42,6 @@ import reactor.core.publisher.Mono; public class DmaapPublisherTaskImpl extends DmaapPublisherTask { private static final Logger LOGGER = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class); - private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private final Config config; private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient; @@ -62,7 +61,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask { throw new DmaapNotFoundException("Invoked null object to DMaaP task"); } dmaapProducerReactiveHttpClient = resolveClient(); - LOGGER.info(INVOKE, "Method called with arg {}", consumerDmaapModel); + LOGGER.info("Method called with arg {}", consumerDmaapModel); return publish(consumerDmaapModel); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java index 92d810ff..862c1f13 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java @@ -34,6 +34,8 @@ import org.onap.dcaegen2.services.prh.model.logging.MdcVariables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @@ -46,11 +48,11 @@ import reactor.core.publisher.Mono; public class ScheduledTasks { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); - + private final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private final DmaapConsumerTask dmaapConsumerTask; private final DmaapPublisherTask dmaapProducerTask; private final AaiProducerTask aaiProducerTask; - private Map<String, String> contextMap = MDC.getCopyOfContextMap(); + private Map<String, String> mdcContextMap; /** * Constructor for tasks registration in PRHWorkflow. @@ -61,17 +63,18 @@ public class ScheduledTasks { */ @Autowired public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask, - AaiProducerTask aaiPublisherTask) { + AaiProducerTask aaiPublisherTask, Map<String, String> mdcContextMap) { this.dmaapConsumerTask = dmaapConsumerTask; this.dmaapProducerTask = dmaapPublisherTask; this.aaiProducerTask = aaiPublisherTask; + this.mdcContextMap = mdcContextMap; } /** * Main function for scheduling prhWorkflow. */ public void scheduleMainPrhEventTask() { - MdcVariables.setMdcContextMap(contextMap); + MdcVariables.setMdcContextMap(mdcContextMap); try { logger.trace("Execution of tasks was registered"); CountDownLatch mainCountDownLatch = new CountDownLatch(1); @@ -100,6 +103,7 @@ public class ScheduledTasks { MDC.put(RESPONSE_CODE, responseCode.getStatusCode().toString()); logger.info("Prh consumed tasks successfully. HTTP Response code from DMaaPProducer {}", responseCode.getStatusCode().value()); + MDC.remove(RESPONSE_CODE); } private void onError(Throwable throwable) { @@ -111,9 +115,9 @@ public class ScheduledTasks { private Mono<ConsumerDmaapModel> consumeFromDMaaPMessage() { return Mono.defer(() -> { - MdcVariables.setMdcContextMap(contextMap); + MdcVariables.setMdcContextMap(mdcContextMap); MDC.put(INSTANCE_UUID, UUID.randomUUID().toString()); - logger.info("Init configs"); + logger.info(INVOKE, "Init configs"); dmaapConsumerTask.initConfigs(); return dmaapConsumerTask.execute(""); }); |