aboutsummaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/main/java
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-05-07 16:58:20 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-05-11 12:29:25 +0200
commita393ae34963a919b842127cc8943a94f2d7c1bc7 (patch)
tree666c78e8d10b0fd65e55494e2e27d52643cf92a2 /prh-aai-client/src/main/java
parent8c88efe7a0abe051e8a4c4d271c84eb8e68c29f0 (diff)
AAI client configuration & tasks changed
Change-Id: I86a2f2ed62565263f2be2c9078a092f993234a19 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-aai-client/src/main/java')
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java11
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java3
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java60
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java5
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java76
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java46
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java2
7 files changed, 80 insertions, 123 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
index 60a022b4..5a3bffc6 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
@@ -22,6 +22,8 @@ package org.onap.dcaegen2.services.config;
import java.io.Serializable;
+import java.util.Map;
+
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import org.springframework.stereotype.Component;
@@ -53,4 +55,13 @@ public abstract class AAIClientConfiguration implements Serializable {
@Value.Parameter
public abstract Boolean aaiIgnoreSSLCertificateErrors();
+ @Value.Parameter
+ public abstract String aaiBasePath();
+
+ @Value.Parameter
+ public abstract String aaiPnfPath();
+
+ @Value.Parameter
+ public abstract Map<String,String> aaiHeaders();
+
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
index c2b40b9a..f58919e5 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
@@ -34,7 +34,6 @@ import org.apache.http.ssl.TrustStrategy;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
@@ -46,7 +45,7 @@ public class AAIClientImpl implements AAIClient {
private AAIClientConfiguration aaiHttpClientConfig;
- @Autowired
+
public AAIClientImpl(AAIClientConfiguration aaiHttpClientConfiguration) {
this.aaiHttpClientConfig = aaiHttpClientConfiguration;
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
index 24790be2..ffaf1aff 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
@@ -28,7 +28,7 @@ import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,9 +36,11 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
-public class AAIConsumerClient implements AAIExtendedHttpClient {
+public class AAIConsumerClient {
Logger logger = LoggerFactory.getLogger(AAIConsumerClient.class);
@@ -46,33 +48,30 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
private final String aaiHost;
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
+ private final String aaiPath;
+ private final Map<String,String> aaiHeaders;
public AAIConsumerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
- final AAIClient aaiClient = new AAIClientImpl(aaiHttpClientConfiguration);
- closeableHttpClient = aaiClient.getAAIHttpClient();
+ closeableHttpClient = new AAIClientImpl(aaiHttpClientConfiguration).getAAIHttpClient();
aaiHost = aaiHttpClientConfiguration.aaiHost();
aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiHttpClientConfiguration.aaiHostPortNumber();
+ aaiPath = aaiHttpClientConfiguration.aaiBasePath() + aaiHttpClientConfiguration.aaiPnfPath();
+ aaiHeaders = aaiHttpClientConfiguration.aaiHeaders();
}
- @Override
- public Optional<String> getHttpResponse(HttpRequestDetails requestDetails) {
-
- Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
-
+ public Optional<String> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
- extendedDetails = closeableHttpClient.execute(request.get(), aaiResponseHandler());
+ return closeableHttpClient.execute(request.get(), aaiResponseHandler());
} catch (IOException e) {
- logger.error("Exception while executing HTTP request: {}", e);
+ logger.warn("Exception while executing http client: ", e);
+ throw new IOException();
}
-
- return extendedDetails;
}
-
- private URI createAAIExtendedURI(final String path, String pnfName) {
+ private URI createAAIExtendedURI(String pnfName) {
URI extendedURI = null;
@@ -80,13 +79,13 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
.setScheme(aaiProtocol)
.setHost(aaiHost)
.setPort(aaiHostPortNumber)
- .setPath(path + "/" + pnfName);
+ .setPath(aaiPath + "/" + pnfName);
try {
extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}", extendedURI);
+ logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ logger.warn("Exception while building extended URI: {}", e);
}
return extendedURI;
@@ -95,39 +94,34 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
private ResponseHandler<Optional<String>> aaiResponseHandler() {
return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
- logger.info("Status code of operation: {}", responseCode);
+ logger.trace("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
- logger.info("HTTP response successful.");
+ logger.trace("HTTP response successful.");
final String aaiResponse = EntityUtils.toString(responseEntity);
return Optional.of(aaiResponse);
} else {
String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
- logger.error("HTTP response not successful : {}", aaiResponse);
- return Optional.of("" + responseCode);
+ logger.warn("HTTP response not successful : {}", aaiResponse);
+ return Optional.of(String.valueOf(responseCode));
}
};
}
private HttpRequestBase createHttpRequest(URI extendedURI) {
-
- if (isExtendedURINotNull(extendedURI)) {
- return new HttpGet(extendedURI);
- } else {
- return null;
- }
+ return isExtendedURINotNull(extendedURI) ? new HttpGet(extendedURI) : null;
}
private Boolean isExtendedURINotNull(URI extendedURI) {
return extendedURI != null;
}
- private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
-
- final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
+ final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
HttpRequestBase request = createHttpRequest(extendedURI);
- requestDetails.headers().forEach(request::addHeader);
+ aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader);
+ Objects.requireNonNull(request).addHeader("Content-Type", "application/json");
return Optional.of(request);
}
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
index 24149e6d..71c94b68 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
@@ -19,12 +19,13 @@
*/
package org.onap.dcaegen2.services.service;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import java.io.IOException;
import java.util.Optional;
@FunctionalInterface
public interface AAIExtendedHttpClient {
- Optional<String> getHttpResponse(HttpRequestDetails httpRequestDetails);
+ Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException;
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
index 0b82578a..788d997e 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
@@ -30,7 +30,8 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.CommonFunctions;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +40,8 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
public class AAIProducerClient implements AAIExtendedHttpClient {
@@ -48,71 +51,69 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
private final String aaiHost;
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
+ private final String aaiPath;
+ private final Map<String,String> aaiHeaders;
public AAIProducerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
- final AAIClient aaiHttpClient = new AAIClientImpl(aaiHttpClientConfiguration);
- closeableHttpClient = aaiHttpClient.getAAIHttpClient();
+ closeableHttpClient = new AAIClientImpl(aaiHttpClientConfiguration).getAAIHttpClient();
aaiHost = aaiHttpClientConfiguration.aaiHost();
aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiHttpClientConfiguration.aaiHostPortNumber();
+ aaiPath = aaiHttpClientConfiguration.aaiBasePath() + aaiHttpClientConfiguration.aaiPnfPath();
+ aaiHeaders = aaiHttpClientConfiguration.aaiHeaders();
}
- @Override
- public Optional<String> getHttpResponse(HttpRequestDetails requestDetails) {
-
- Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
+ @Override
+ public Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
- extendedDetails = closeableHttpClient.execute(request.get(), aaiResponseHandler());
+ return closeableHttpClient.execute(request.get(), aaiResponseHandler());
} catch (IOException e) {
- logger.error("Exception while executing HTTP request: {}", e);
+ logger.warn("Exception while executing http client: ", e);
+ throw new IOException();
}
-
- return extendedDetails;
}
- private URI createAAIExtendedURI(final String path, final String pnfName) {
-
+ private URI createAAIExtendedURI(final String pnfName) {
URI extendedURI = null;
-
final URIBuilder uriBuilder = new URIBuilder()
.setScheme(aaiProtocol)
.setHost(aaiHost)
.setPort(aaiHostPortNumber)
- .setPath(path + "/" + pnfName);
-
+ .setPath(aaiPath + "/" + pnfName);
try {
extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}", extendedURI);
+ logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ logger.warn("Exception while building extended URI: ", e);
}
-
return extendedURI;
}
- private ResponseHandler<Optional<String>> aaiResponseHandler() {
+ private ResponseHandler<Optional<Integer>> aaiResponseHandler() {
return (HttpResponse httpResponse) -> {
- final int responseCode = httpResponse.getStatusLine().getStatusCode();
- logger.info("Status code of operation: {}", responseCode);
+ final Integer responseCode = httpResponse.getStatusLine().getStatusCode();
+ logger.trace("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
- logger.info("HTTP response successful.");
- return Optional.of("" + responseCode);
+ logger.trace("HTTP response successful.");
+ return Optional.of(responseCode);
} else {
String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
- logger.error("HTTP response not successful : {}", aaiResponse);
- return Optional.of("" + responseCode);
+ logger.warn("HTTP response not successful : {}", aaiResponse);
+ return Optional.of(responseCode);
}
};
}
- private HttpRequestBase createHttpRequest(URI extendedURI, HttpRequestDetails httpRequestDetails) {
- if (isExtendedURINotNull(extendedURI) && httpRequestDetails.jsonBody().isPresent()) {
- return createHttpPatch(extendedURI, httpRequestDetails.jsonBody());
+ private HttpRequestBase createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
+ String jsonBody = CommonFunctions.createJsonBody(consumerDmaapModel);
+
+ if (isExtendedURINotNull(extendedURI) && jsonBody != null && !"".equals(jsonBody)) {
+ return createHttpPatch(extendedURI, Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)));
} else {
return null;
}
@@ -122,6 +123,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
return extendedURI != null;
}
+
private Optional<StringEntity> createStringEntity(Optional<String> jsonBody) {
return Optional.of(parseJson(jsonBody).get());
}
@@ -135,21 +137,19 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
private Optional<StringEntity> parseJson(Optional<String> jsonBody) {
Optional<StringEntity> stringEntity = Optional.empty();
-
try {
stringEntity = Optional.of(new StringEntity(jsonBody.get()));
} catch (UnsupportedEncodingException e) {
- logger.error("Exception while parsing JSON: {}", e);
+ logger.warn("Exception while parsing JSON: ", e);
}
-
return stringEntity;
}
- private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
-
- final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
- HttpRequestBase request = createHttpRequest(extendedURI, requestDetails);
- requestDetails.headers().forEach(request::addHeader);
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
+ final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
+ HttpRequestBase request = createHttpRequest(extendedURI, consumerDmaapModel);
+ aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader);
+ Objects.requireNonNull(request).addHeader("Content-Type", "application/merge-patch+json");
return Optional.of(request);
}
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
deleted file mode 100644
index 37e6b860..00000000
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.dcaegen2.services.utils;
-
-
-import org.immutables.value.Value;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Optional;
-
-@Value.Immutable(prehash = true)
-@Value.Style(stagedBuilder = true)
-public abstract class HttpRequestDetails implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Value.Parameter
- public abstract String aaiAPIPath();
-
- @Value.Parameter
- public abstract Optional<String> jsonBody();
-
- @Value.Parameter
- public abstract String pnfName();
-
- @Value.Parameter
- public abstract Map<String,String> headers();
-}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
index eac7f83a..20bc7e00 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
@@ -23,8 +23,6 @@ import org.apache.http.HttpStatus;
public final class HttpUtils implements HttpStatus {
- public static final String JSON_APPLICATION_TYPE = "application/json";
-
private HttpUtils() {}
public static boolean isSuccessfulResponseCode(Integer statusCode) {