diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2022-09-29 11:27:25 +0200 |
---|---|---|
committer | PatrikBuhr <patrik.buhr@est.tech> | 2022-09-29 13:18:06 +0200 |
commit | 390e82aa57f6a563d274fd0e3c26ca858c5abebc (patch) | |
tree | 073c6598cc2c6fdbe6ef049e56e734c68e125dd1 | |
parent | 36f9bf4305ef193089330242c94d229f9310f69d (diff) |
Minor logging improvement
Debug logging of REST response body in case of error.
Removed some irrelevant logs.
Issue-ID: CCSDK-3766
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I3c7b62acd1736f9447e3494c655d85372a4c521f
4 files changed, 20 insertions, 7 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java index c4afdb2f..e3d99426 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java @@ -39,6 +39,7 @@ import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; @@ -138,7 +139,16 @@ public class AsyncRestClient { request.headers(h -> h.setBearerAuth(securityContext.getBearerAuthToken())); } return request.retrieve() // - .toEntity(String.class); + .toEntity(String.class) // + .doOnError(this::onError); + + } + + private void onError(Throwable t) { + if (t instanceof WebClientResponseException) { + WebClientResponseException e = (WebClientResponseException) t; + logger.debug("Response error: {}", e.getResponseBodyAsString()); + } } private static Object createTraceTag() { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java index a6679e05..82a21ae2 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java @@ -26,7 +26,11 @@ import com.google.gson.annotations.SerializedName; import io.swagger.v3.oas.annotations.media.Schema; +import java.lang.invoke.MethodHandles; + import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -36,6 +40,7 @@ import reactor.core.publisher.Mono; public class ErrorResponse { private static Gson gson = new GsonBuilder() // .create(); // + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Returned as body for all failed REST calls @Schema(name = "error_information", description = "Problem as defined in https://tools.ietf.org/html/rfc7807") @@ -90,6 +95,7 @@ public class ErrorResponse { } static ResponseEntity<Object> create(String text, HttpStatus code) { + logger.debug("Error response: {}, {}", code, text); ErrorInfo p = new ErrorInfo(text, code.value()); String json = gson.toJson(p); HttpHeaders headers = new HttpHeaders(); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java index 1224d00b..47c73506 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java @@ -95,14 +95,12 @@ public class DmaapMessageConsumer { } void onRequest(long no) { - logger.debug("InfiniteFlux.onRequest {}", no); for (long i = 0; i < no; ++i) { sink.next(counter++); } } void next(FluxSink<Integer> sink) { - logger.debug("InfiniteFlux.next"); this.sink = sink; sink.next(counter++); } @@ -213,7 +211,6 @@ public class DmaapMessageConsumer { private Mono<String> fetchFromDmaap() { if (!this.isDmaapConfigured()) { - logger.debug("fetchFromDmaap, no action DMAAP not configured"); return delay().flatMap(o -> Mono.empty()); } logger.debug("fetchFromDmaap"); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java index 04845244..ab58027a 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java @@ -181,7 +181,7 @@ class ApplicationTest { @AfterEach void verifyNoRicLocks() { for (Ric ric : this.rics.getRics()) { - Lock.Grant grant = ric.getLock().lockBlocking(LockType.EXCLUSIVE, ""); + Lock.Grant grant = ric.getLock().lockBlocking(LockType.EXCLUSIVE, "verifyNoRicLocks"); grant.unlockBlocking(); assertThat(ric.getLock().getLockCounter()).isZero(); assertThat(ric.getState()).isEqualTo(Ric.RicState.AVAILABLE); @@ -931,8 +931,8 @@ class ApplicationTest { for (int i = 0; i < 10; ++i) { AsyncRestClient restClient = restClient(); - ConcurrencyTestRunnable test = new ConcurrencyTestRunnable(restClient, supervision, a1ClientFactory, rics, - policyTypes); + ConcurrencyTestRunnable test = + new ConcurrencyTestRunnable(restClient, supervision, a1ClientFactory, rics, policyTypes); Thread thread = new Thread(test, "TestThread_" + i); thread.start(); threads.add(thread); |