diff options
9 files changed, 41 insertions, 24 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java index b13f1824..0dfe1f9e 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java @@ -93,6 +93,7 @@ public class AaiReactiveWebClient { LOGGER.info("Request: {} {}", clientRequest.method(), clientRequest.url()); clientRequest.headers() .forEach((name, values) -> values.forEach(value -> LOGGER.info("{}={}", name, value))); + MDC.remove(SERVICE_NAME); return Mono.just(clientRequest); }); } @@ -101,6 +102,7 @@ public class AaiReactiveWebClient { return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { MDC.put(RESPONSE_CODE, String.valueOf(clientResponse.statusCode())); LOGGER.info("Response Status {}", clientResponse.statusCode()); + MDC.remove(RESPONSE_CODE); return Mono.just(clientResponse); }); } 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(""); }); diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java index 28692af3..5aa63e00 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.Mockito.spy; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,9 +43,12 @@ public class ScheduleControllerSpy { @Autowired private AaiProducerTask aaiPublisherTaskImplSpy; + @Autowired + private Map<String, String> mdcContextMap; + @Bean @Primary public ScheduledTasks registerSimpleScheduledTask() { - return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy)); + return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy, mdcContextMap)); } } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java index d34728ce..242a4251 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java @@ -20,6 +20,9 @@ package org.onap.dcaegen2.services.prh.service; +import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.RESPONSE_CODE; +import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.SERVICE_NAME; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -48,18 +51,20 @@ public class DMaaPReactiveWebClient { private ExchangeFilterFunction logResponse() { return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { - MDC.put("ResponseCode", String.valueOf(clientResponse.statusCode())); + MDC.put(RESPONSE_CODE, String.valueOf(clientResponse.statusCode())); logger.info("Response Status {}", clientResponse.statusCode()); + MDC.remove(RESPONSE_CODE); return Mono.just(clientResponse); }); } private ExchangeFilterFunction logRequest() { return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> { - MDC.put("ServiceName", String.valueOf(clientRequest.url())); + MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url())); logger.info("Request: {} {}", clientRequest.method(), clientRequest.url()); clientRequest.headers() .forEach((name, values) -> values.forEach(value -> logger.info("{}={}", name, value))); + MDC.remove(SERVICE_NAME); return Mono.just(clientRequest); }); } |