summaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client/src/main
diff options
context:
space:
mode:
authormicdzied <michal.1.dziedzic@nokia.com>2018-08-30 10:25:19 +0200
committermicdzied <michal.1.dziedzic@nokia.com>2018-08-30 14:53:20 +0200
commit6fd8c7770fbea30ad2ec6e3f7645b8baab5a49a1 (patch)
tree78d572b5df8c88047d74edf3c75b28fcab3d0dc6 /prh-dmaap-client/src/main
parent82a6fc31d1905f380fbbae1d0b4a34b67d8258e3 (diff)
add MDC's
Change-Id: Ie4fe86791f46b790ae42088a5d2b93f491e4549d Issue-ID: DCAEGEN2-730 Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src/main')
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java9
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java2
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java8
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java10
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java11
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java11
6 files changed, 34 insertions, 17 deletions
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java
index 6663554e..287ebfd8 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java
@@ -35,6 +35,10 @@ public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig {
private static final long serialVersionUID = 1L;
+ public static DmaapConsumerConfiguration.Builder builder() {
+ return ImmutableDmaapConsumerConfiguration.builder();
+ }
+
@Value.Parameter
public abstract String consumerId();
@@ -47,7 +51,6 @@ public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig {
@Value.Parameter
public abstract Integer messageLimit();
-
public interface Builder extends
DmaapCustomConfig.Builder<DmaapConsumerConfiguration, DmaapConsumerConfiguration.Builder> {
@@ -60,8 +63,4 @@ public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig {
Builder messageLimit(Integer messageLimit);
}
- public static DmaapConsumerConfiguration.Builder builder() {
- return ImmutableDmaapConsumerConfiguration.builder();
- }
-
} \ No newline at end of file
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java
index 6e7f538a..3c9bd99a 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java
@@ -21,6 +21,7 @@
package org.onap.dcaegen2.services.prh.config;
import java.io.Serializable;
+import java.util.Map;
import org.immutables.value.Value;
/**
@@ -49,7 +50,6 @@ public interface DmaapCustomConfig extends Serializable {
@Value.Parameter
String dmaapContentType();
-
interface Builder<T extends DmaapCustomConfig, B extends Builder<T, B>> {
B dmaapHostName(String dmaapHostName);
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java
index e353056f..28b1786a 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java
@@ -33,12 +33,12 @@ public abstract class DmaapPublisherConfiguration implements DmaapCustomConfig {
private static final long serialVersionUID = 1L;
+ public static DmaapPublisherConfiguration.Builder builder() {
+ return ImmutableDmaapPublisherConfiguration.builder();
+ }
+
interface Builder extends
DmaapCustomConfig.Builder<DmaapPublisherConfiguration, DmaapPublisherConfiguration.Builder> {
}
-
- public static DmaapPublisherConfiguration.Builder builder() {
- return ImmutableDmaapPublisherConfiguration.builder();
- }
}
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 65834b54..8ce81757 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,11 +20,12 @@
package org.onap.dcaegen2.services.prh.service;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
+import java.util.HashMap;
+import java.util.Map;
import org.onap.dcaegen2.services.prh.config.DmaapCustomConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
@@ -37,9 +38,9 @@ public class DMaaPReactiveWebClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private String dmaaPContentType;
private String dmaaPUserName;
private String dmaaPUserPassword;
+ private String dmaaPContentType;
/**
* Creating DMaaPReactiveWebClient passing to them basic DMaaPConfig.
@@ -51,6 +52,7 @@ public class DMaaPReactiveWebClient {
this.dmaaPUserName = dmaapCustomConfig.dmaapUserName();
this.dmaaPUserPassword = dmaapCustomConfig.dmaapUserPassword();
this.dmaaPContentType = dmaapCustomConfig.dmaapContentType();
+
return this;
}
@@ -69,6 +71,7 @@ public class DMaaPReactiveWebClient {
private ExchangeFilterFunction logResponse() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
+ MDC.put("ResponseCode", String.valueOf(clientResponse.statusCode()));
logger.info("Response Status {}", clientResponse.statusCode());
return Mono.just(clientResponse);
});
@@ -76,6 +79,7 @@ public class DMaaPReactiveWebClient {
private ExchangeFilterFunction logRequest() {
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
+ MDC.put("ServiceName", String.valueOf(clientRequest.url()));
logger.info("Request: {} {}", clientRequest.method(), clientRequest.url());
clientRequest.headers()
.forEach((name, values) -> values.forEach(value -> logger.info("{}={}", name, value)));
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java
index e04c07cf..ac13dd61 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java
@@ -20,12 +20,18 @@
package org.onap.dcaegen2.services.prh.service.consumer;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.REQUEST_ID;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_INVOCATION_ID;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_ONAP_REQUEST_ID;
+
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.UUID;
import org.apache.http.client.utils.URIBuilder;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
@@ -36,14 +42,13 @@ import reactor.core.publisher.Mono;
public class DMaaPConsumerReactiveHttpClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- private WebClient webClient;
private final String dmaapHostName;
private final String dmaapProtocol;
private final Integer dmaapPortNumber;
private final String dmaapTopicName;
private final String consumerGroup;
private final String consumerId;
+ private WebClient webClient;
/**
* Constructor of DMaaPConsumerReactiveHttpClient.
@@ -69,6 +74,8 @@ public class DMaaPConsumerReactiveHttpClient {
return webClient
.get()
.uri(getUri())
+ .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
+ .header(X_INVOCATION_ID, UUID.randomUUID().toString())
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse ->
Mono.error(new Exception("DmaaPConsumer HTTP " + clientResponse.statusCode()))
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java
index b06ebfdd..d049d380 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java
@@ -20,13 +20,19 @@
package org.onap.dcaegen2.services.prh.service.producer;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.REQUEST_ID;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_INVOCATION_ID;
+import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_ONAP_REQUEST_ID;
+
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.UUID;
import org.apache.http.client.utils.URIBuilder;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
@@ -38,12 +44,11 @@ import reactor.core.publisher.Mono;
public class DMaaPProducerReactiveHttpClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- private WebClient webClient;
private final String dmaapHostName;
private final Integer dmaapPortNumber;
private final String dmaapProtocol;
private final String dmaapTopicName;
+ private WebClient webClient;
/**
* Constructor DMaaPProducerReactiveHttpClient.
@@ -68,6 +73,8 @@ public class DMaaPProducerReactiveHttpClient {
return webClient
.post()
.uri(getUri())
+ .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
+ .header(X_INVOCATION_ID, UUID.randomUUID().toString())
.body(BodyInserters.fromObject(consumerDmaapModelMono))
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse ->