From 5b38b56d8b6a7fca299e0243a7dc91d460f4735c Mon Sep 17 00:00:00 2001 From: wasala Date: Wed, 13 Jun 2018 11:39:14 +0200 Subject: Added simply logs from tasks. *Logging responsed object from DmaaP *Logging parsed oject from DmaaP *Logging sended object to AAI *Logging sended object and topic To DmaaP Change-Id: I33de0cd751762ac004f9d8a09beee921f4026af6 Issue-ID: DCAEGEN2-545 Signed-off-by: wasala --- .../services/prh/service/AAIClientImpl.java | 8 +++--- .../services/prh/service/AAIConsumerClient.java | 2 +- .../services/prh/service/AAIProducerClient.java | 29 ++++++++++++---------- 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'prh-aai-client/src/main/java') diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java index 5e938528..04652020 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java @@ -41,7 +41,7 @@ import java.security.NoSuchAlgorithmException; public class AAIClientImpl implements AAIClient { - private Logger logger = LoggerFactory.getLogger(AAIClientImpl.class); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private AAIClientConfiguration aaiClientConfig; @@ -62,10 +62,10 @@ public class AAIClientImpl implements AAIClient { try { logger.info("Setting SSL Context for AAI HTTP Client"); httpClientBuilder.setSSLContext(new SSLContextBuilder() - .loadTrustMaterial(null, acceptingTrustStrategy) - .build()); + .loadTrustMaterial(null, acceptingTrustStrategy) + .build()); - } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e ) { + } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { logger.error("Exception while setting SSL Context for AAI HTTP Client: {}", e); } diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java index dfacc6b1..fafe6e04 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java @@ -42,7 +42,7 @@ import java.util.Optional; public class AAIConsumerClient { - private Logger logger = LoggerFactory.getLogger(AAIConsumerClient.class); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final CloseableHttpClient closeableHttpClient; private final String aaiHost; diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java index f85ac8aa..0c2a12a3 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java @@ -20,6 +20,7 @@ package org.onap.dcaegen2.services.prh.service; +import java.util.function.Predicate; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPatch; @@ -46,14 +47,14 @@ import java.util.Optional; public class AAIProducerClient implements AAIExtendedHttpClient { private static final String EXCEPTION_MESSAGE = "Exception while executing http client: "; - private Logger logger = LoggerFactory.getLogger(AAIProducerClient.class); - + private static Predicate isEmpty = String::isEmpty; + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final CloseableHttpClient closeableHttpClient; private final String aaiHost; private final String aaiProtocol; private final Integer aaiHostPortNumber; private final String aaiPath; - private final Map aaiHeaders; + private final Map aaiHeaders; private final String aaiUserName; private final String aaiUserPassword; @@ -96,19 +97,21 @@ public class AAIProducerClient implements AAIExtendedHttpClient { } Optional createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) { - return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(x-> !x.isEmpty()).flatMap(myJson -> { - try { - return Optional.of(createHttpPatch(extendedURI, myJson)); - } catch (UnsupportedEncodingException e) { - logger.warn(EXCEPTION_MESSAGE, e); - } - return Optional.empty(); - }); + return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(isEmpty.negate()) + .flatMap(myJson -> { + try { + logger.info("AAI: sending json {}", myJson); + return Optional.of(createHttpPatch(extendedURI, myJson)); + } catch (UnsupportedEncodingException e) { + logger.warn(EXCEPTION_MESSAGE, e); + } + return Optional.empty(); + }); } HttpPatch createHttpPatch(URI extendedURI, String jsonBody) throws UnsupportedEncodingException { HttpPatch httpPatch = new HttpPatch(extendedURI); - httpPatch.setEntity( new StringEntity(jsonBody)); + httpPatch.setEntity(new StringEntity(jsonBody)); aaiHeaders.forEach(httpPatch::addHeader); httpPatch.addHeader("Content-Type", "application/merge-patch+json"); httpPatch.addHeader("Authorization", "Basic " + encode()); @@ -117,7 +120,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient { String encode() throws UnsupportedEncodingException { return Base64.getEncoder().encodeToString((this.aaiUserName + ":" + this.aaiUserPassword) - .getBytes("UTF-8")); + .getBytes("UTF-8")); } Optional handleResponse(HttpResponse response) throws IOException { -- cgit 1.2.3-korg