summaryrefslogtreecommitdiffstats
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
parent8c88efe7a0abe051e8a4c4d271c84eb8e68c29f0 (diff)
AAI client configuration & tasks changed
Change-Id: I86a2f2ed62565263f2be2c9078a092f993234a19 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
-rw-r--r--pom.xml1
-rw-r--r--prh-aai-client/pom.xml5
-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/HttpUtils.java2
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java17
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java29
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java4
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java61
-rw-r--r--prh-app-server/config/prh_endpoints.json13
-rw-r--r--prh-app-server/pom.xml7
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java31
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java4
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java15
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java12
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java4
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java10
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java35
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java6
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java20
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java11
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java1
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java6
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java6
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java4
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java1
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java1
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java5
-rw-r--r--prh-app-server/src/test/resources/prh_endpoints.json14
-rw-r--r--prh-commons/pom.xml30
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/model/CommonFunctions.java (renamed from prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java)22
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModel.java (renamed from prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java)3
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModelForUnitTest.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java)32
-rw-r--r--prh-dmaap-client/pom.xml5
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java29
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java12
39 files changed, 295 insertions, 318 deletions
diff --git a/pom.xml b/pom.xml
index 2f750fc3..20d01aae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -583,6 +583,7 @@
<module>prh-app-server</module>
<module>prh-aai-client</module>
<module>prh-dmaap-client</module>
+ <module>prh-commons</module>
</modules>
</project>
diff --git a/prh-aai-client/pom.xml b/prh-aai-client/pom.xml
index 1b2b1991..8d4161fd 100644
--- a/prh-aai-client/pom.xml
+++ b/prh-aai-client/pom.xml
@@ -66,6 +66,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onap.dcaegen2.services.commons</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
<!-- LOGGING DEPENDENCIES-->
<dependency>
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/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) {
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
index b95cc8d6..5e45d844 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -44,8 +44,9 @@ public class AAIConsumerClientTest {
private static AAIConsumerClient testedObject;
private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }";
+ private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class);
+ private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
@BeforeAll
public static void setup() throws NoSuchFieldException, IllegalAccessException {
@@ -54,7 +55,7 @@ public class AAIConsumerClientTest {
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "9999");
aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("authentication", "Basic QUFJOkFBSQ==");
+ aaiHeaders.put("Authorization", "Basic QUFJOkFBSQ==");
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/json");
@@ -63,11 +64,11 @@ public class AAIConsumerClientTest {
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
- when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.pnfName()).thenReturn("pnf-nokia-45fsfcx");
- when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE));
+ when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME);
testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
setField();
@@ -79,7 +80,7 @@ public class AAIConsumerClientTest {
when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
thenReturn(Optional.of(JSON_MESSAGE));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
index 7f3978bd..59c90dc8 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
@@ -27,7 +27,9 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
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.model.ConsumerDmaapModelForUnitTest;
+
import java.io.IOException;
import java.lang.reflect.Field;
@@ -41,17 +43,17 @@ import static org.mockito.Mockito.when;
public class AAIProducerClientTest {
+ private static final Integer SUCCESS = 200;
private static AAIProducerClient testedObject;
private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
- private static final String JsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}";
- private static final String SUCCESS = "200";
- private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
+ private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
+
@BeforeAll
public static void init() throws NoSuchFieldException, IllegalAccessException {
+ //given
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "vv-temp");
@@ -59,29 +61,28 @@ public class AAIProducerClientTest {
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/merge-patch+json");
+ //when
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net");
when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
-
- when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
-
- when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.pnfName()).thenReturn(PNF_NAME);
- when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JsonBody));
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
setField();
}
@Test
- public void getHttpResponsePatch_success() throws IOException {
-
+ public void getHttpResponsePatch_shouldReturnSuccessStatusCode() throws IOException {
+ //when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
.thenReturn(Optional.of(SUCCESS));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel);
+ //then
Assertions.assertEquals(SUCCESS, actualResult.get());
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
index 29a00927..447e0ecc 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
@@ -33,6 +33,8 @@ public class AAIHttpClientConfigurationTest {
private static final Integer PORT = 1234;
private static final String PROTOCOL = "https";
private static final String USER_NAME_PASSWORD = "PRH";
+ private static final String BASE_PATH = "/aai/v11";
+ private static final String PNF_PATH = "/network/pnfs/pnf";
@BeforeAll
public static void init() {
@@ -43,6 +45,8 @@ public class AAIHttpClientConfigurationTest {
.aaiUserName(USER_NAME_PASSWORD)
.aaiUserPassword(USER_NAME_PASSWORD)
.aaiIgnoreSSLCertificateErrors(true)
+ .aaiBasePath(BASE_PATH)
+ .aaiPnfPath(PNF_PATH)
.build();
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
deleted file mode 100644
index 0deb8adb..00000000
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
+++ /dev/null
@@ -1,61 +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.service.utils;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
-import org.onap.dcaegen2.services.utils.ImmutableHttpRequestDetails;
-import org.onap.dcaegen2.services.utils.RequestVerbs;
-
-import java.util.Optional;
-
-
-public class HttpRequestDetailsTest {
-
- private static HttpRequestDetails testObject;
-
- private static final String AAI_PATH = "aaiPathTest";
- private static final String HEADERS_KEY1 = "headersKey1";
- private static final String HEADERS_VALUE1 = "headersValue1";
- private static final String JSON_MESSAGE = "{\"dare_to\": \"dream_big\"}";
- private static final String PNF_NAME = "pnf-nokia-5454885485";
-
- @BeforeAll
- public static void init() {
- testObject = ImmutableHttpRequestDetails.builder()
- .aaiAPIPath(AAI_PATH)
- .pnfName(PNF_NAME)
- .putHeaders(HEADERS_KEY1,HEADERS_VALUE1)
- .jsonBody(JSON_MESSAGE)
- .build();
- }
-
- @Test
- public void testGetters_success() {
- Assertions.assertEquals(AAI_PATH, testObject.aaiAPIPath());
- Assertions.assertEquals(HEADERS_VALUE1, testObject.headers().get(HEADERS_KEY1));
- Assertions.assertEquals(PNF_NAME, testObject.pnfName());
- Assertions.assertEquals(Optional.of(JSON_MESSAGE), testObject.jsonBody());
- }
-}
diff --git a/prh-app-server/config/prh_endpoints.json b/prh-app-server/config/prh_endpoints.json
index 2e709e99..1a3ebad5 100644
--- a/prh-app-server/config/prh_endpoints.json
+++ b/prh-app-server/config/prh_endpoints.json
@@ -17,7 +17,7 @@
"dmaapProducerConfiguration": {
"dmaapHostName": "localhost",
"dmaapPortNumber": 2223,
- "dmaapTopicName": "temp",
+ "dmaapTopicName": "/events/pnfReady",
"dmaapProtocol": "http",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin",
@@ -31,7 +31,16 @@
"aaiProtocol": "https",
"aaiUserName": "admin",
"aaiUserPassword": "admin",
- "aaiIgnoreSSLCertificateErrors": true
+ "aaiIgnoreSSLCertificateErrors": true,
+ "aaiBasePath": "/aai/v11",
+ "aaiPnfPath": "/network/pnfs/pnf",
+ "aaiHeaders": {
+ "X-FromAppId": "prh",
+ "X-TransactionId": "9999",
+ "Accept": "application/json",
+ "Real-Time": "true",
+ "Authorization": "Basic QUFJOkFBSQ=="
+ }
}
}
}
diff --git a/prh-app-server/pom.xml b/prh-app-server/pom.xml
index f9d53c22..d1345c5f 100644
--- a/prh-app-server/pom.xml
+++ b/prh-app-server/pom.xml
@@ -182,6 +182,12 @@
<groupId>org.immutables</groupId>
<artifactId>gson</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onap.dcaegen2.services.commons</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
<!-- LOGGING DEPENDENCIES-->
<dependency>
@@ -268,6 +274,7 @@
<version>1.0.0-SNAPSHOT</version>
</dependency>
+
</dependencies>
<dependencyManagement>
<dependencies>
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
index fba8985f..19c8d492 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
@@ -106,6 +106,12 @@ public class AppConfig extends PrhAppConfig {
@Value("${aai.aaiHttpClientConfiguration.aaiIgnoreSSLCertificateErrors:}")
public Boolean aaiIgnoreSSLCertificateErrors;
+ @Value("${aai.aaiHttpClientConfiguration.aaiBasePath:}")
+ public String aaiBasePath;
+
+ @Value("${aai.aaiHttpClientConfiguration.aaiPnfPath:}")
+ public String aaiPnfPath;
+
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return new ImmutableDmaapConsumerConfiguration.Builder()
@@ -134,18 +140,19 @@ public class AppConfig extends PrhAppConfig {
@Override
public AAIClientConfiguration getAAIClientConfiguration() {
return new ImmutableAAIClientConfiguration.Builder()
- .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiClientConfiguration.aaiHost()))
- .aaiHostPortNumber(
- Optional.ofNullable(aaiHostPortNumber).orElse(aaiClientConfiguration.aaiHostPortNumber()))
- .aaiIgnoreSSLCertificateErrors(
- Optional.ofNullable(aaiIgnoreSSLCertificateErrors)
- .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors()))
- .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiClientConfiguration.aaiProtocol()))
- .aaiUserName(
- Optional.ofNullable(aaiUserName).orElse(aaiClientConfiguration.aaiUserName()))
- .aaiUserPassword(Optional.ofNullable(
- aaiUserPassword).orElse(aaiClientConfiguration.aaiUserPassword()))
- .build();
+ .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiClientConfiguration.aaiHost()))
+ .aaiHostPortNumber(
+ Optional.ofNullable(aaiHostPortNumber).orElse(aaiClientConfiguration.aaiHostPortNumber()))
+ .aaiIgnoreSSLCertificateErrors(
+ Optional.ofNullable(aaiIgnoreSSLCertificateErrors)
+ .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors()))
+ .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiClientConfiguration.aaiProtocol()))
+ .aaiUserName(Optional.ofNullable(aaiUserName).orElse(aaiClientConfiguration.aaiUserName()))
+ .aaiUserPassword(Optional.ofNullable(aaiUserPassword).orElse(aaiClientConfiguration.aaiUserPassword()))
+ .aaiBasePath(Optional.ofNullable(aaiBasePath).orElse(aaiClientConfiguration.aaiBasePath()))
+ .aaiPnfPath(Optional.ofNullable(aaiPnfPath).orElse(aaiClientConfiguration.aaiPnfPath()))
+ .aaiHeaders(aaiClientConfiguration.aaiHeaders())
+ .build();
}
@Override
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 3df25d00..c4cb20de 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
@@ -32,8 +32,6 @@ import org.springframework.context.annotation.Configuration;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.*;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
import java.util.ServiceLoader;
/**
@@ -47,7 +45,7 @@ public abstract class PrhAppConfig implements Config {
private static final String CONFIG = "configs";
private static final String AAI = "aai";
private static final String DMAAP = "dmaap";
- private static final String AAI_CONFIG = "aaiHttpClientConfiguration";
+ private static final String AAI_CONFIG = "aaiClientConfiguration";
private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
index 269e7a2a..8db4f0b6 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
@@ -23,7 +23,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@@ -40,21 +39,21 @@ import reactor.core.publisher.Mono;
@Api(value = "HeartbeatController", description = "Check liveness of PRH service")
public class HeartbeatController {
- private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class);
+ private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
@RequestMapping(value = "heartbeat", method = RequestMethod.GET)
@ApiOperation(value = "Returns liveness of PRH service")
@ApiResponses(value = {
- @ApiResponse(code = 200, message = "PRH sevice is living"),
- @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
- @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
- @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
+ @ApiResponse(code = 200, message = "PRH sevice is living"),
+ @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
+ @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
+ @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
}
)
public Mono<ResponseEntity<String>> heartbeat() {
logger.trace("Receiving heartbeat request");
return Mono.defer(() ->
- Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK))
+ Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK))
);
}
-}
+} \ No newline at end of file
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
index cd3347fe..96b69b7b 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
@@ -21,10 +21,6 @@ package org.onap.dcaegen2.services.prh.controllers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ScheduledFuture;
-import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,21 +28,23 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
-import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ScheduledFuture;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/5/18
*/
@RestController
-@Component
@Api(value = "ScheduleController", description = "Schedule Controller")
public class ScheduleController {
- private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class);
+ private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
private static final int SCHEDULING_DELAY = 20000;
private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<>();
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
index 0ef7e4fe..ae5d922e 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
@@ -23,8 +23,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ImmutableConsumerDmaapModel;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
index 95352d44..136f5b7f 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java
@@ -20,21 +20,21 @@
package org.onap.dcaegen2.services.prh.tasks;
-import java.util.Optional;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
-import org.onap.dcaegen2.services.service.AAIProducerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.Optional;
+
@Component
public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration> {
- private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
+ private static final Logger logger = LoggerFactory.getLogger(AAIConsumerTaskImpl.class);
private final Config prhAppConfig;
private Optional<String> response;
@@ -46,15 +46,11 @@ public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration>
@Override
protected void consume() throws AAINotFoundException {
- //TODO: @Piotr Wielebski
- AAIProducerClient producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration());
-
}
@Override
public Object execute(Object object) throws AAINotFoundException {
consume();
- //TODO: @Piotr Wielebski
return null;
}
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 4a7d9282..505d2a9a 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
@@ -19,25 +19,19 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
-import com.google.gson.Gson;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
-import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.services.service.AAIProducerClient;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.service.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Optional;
+import java.io.IOException;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
@@ -45,11 +39,10 @@ import java.util.Optional;
@Component
public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration, ConsumerDmaapModel, Object> {
- private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
+ private static final Logger logger = LoggerFactory.getLogger(AAIProducerTaskImpl.class);
private final Config prhAppConfig;
- private AAIProducerClient producerClient;
- private Optional<String> response;
+
@Autowired
public AAIProducerTaskImpl(AppConfig prhAppConfig) {
@@ -59,19 +52,24 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration,
@Override
protected Object publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
logger.trace("Method %M called with arg {}", consumerDmaapModel);
- producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration());
- //TODO: @Piotr Wielebski
- response = producerClient.getHttpResponse(null);
- return response.get();
+ AAIProducerClient producerClient = new AAIProducerClient(resolveConfiguration());
+ try {
+ return producerClient.getHttpResponse(consumerDmaapModel)
+ .filter(HttpUtils::isSuccessfulResponseCode);
+ } catch (IOException e) {
+ logger.warn("Patch request not successful", e);
+ throw new AAINotFoundException("Patch request not successful");
+ }
}
@Override
- public Object execute(Object object) throws PrhTaskException {
+ public Object execute(Object object) throws AAINotFoundException {
logger.trace("Method %M called with arg {}", object);
+
if (object instanceof ConsumerDmaapModel) {
- //TODO: @Piotr Wielebski
return publish((ConsumerDmaapModel) object);
}
+
throw new AAINotFoundException("Incorrect object type");
}
@@ -84,5 +82,4 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration,
protected AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
-
}
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 a2129fcd..69911f33 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
@@ -19,12 +19,13 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+
import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
import org.onap.dcaegen2.services.service.consumer.ExtendedDmaapConsumerHttpClientImpl;
import org.slf4j.Logger;
@@ -32,9 +33,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
*/
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 60ab64fd..4fef0353 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
@@ -21,14 +21,12 @@ package org.onap.dcaegen2.services.prh.tasks;
import com.google.gson.Gson;
import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.service.producer.DmaapPublisherRequestDetails;
import org.onap.dcaegen2.services.service.producer.ExtendedDmaapProducerHttpClientImpl;
-import org.onap.dcaegen2.services.service.producer.ImmutableDmaapPublisherRequestDetails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,9 +38,9 @@ import org.springframework.stereotype.Component;
*/
@Component
public class DmaapPublisherTaskImpl extends
- DmaapPublisherTask<DmaapPublisherConfiguration, ConsumerDmaapModel> {
+ DmaapPublisherTask<DmaapPublisherConfiguration, ConsumerDmaapModel> {
- private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
+ private static final Logger logger = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class);
private static final Gson gson = new Gson();
private final Config prhAppConfig;
@@ -55,13 +53,11 @@ public class DmaapPublisherTaskImpl extends
protected String publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
logger.trace("Method %M called with arg {}", consumerDmaapModel);
ExtendedDmaapProducerHttpClientImpl dmaapProducerHttpClient = new ExtendedDmaapProducerHttpClientImpl(
- resolveConfiguration());
- DmaapPublisherRequestDetails dmaapPublisherRequestDetails = new ImmutableDmaapPublisherRequestDetails.Builder()
- .dmaapAPIPath("events").jsonBody(gson.toJson(consumerDmaapModel)).build();
- return dmaapProducerHttpClient.getHttpProducerResponse(dmaapPublisherRequestDetails)
- .filter(x -> !x.isEmpty() && x.equals(String.valueOf(HttpStatus.OK.value())))
- .orElseThrow(() -> new DmaapNotFoundException("Incorrect response from Dmmap"));
+ resolveConfiguration());
+ return dmaapProducerHttpClient.getHttpProducerResponse(consumerDmaapModel)
+ .filter(x -> !x.isEmpty() && x.equals(String.valueOf(HttpStatus.OK.value())))
+ .orElseThrow(() -> new DmaapNotFoundException("Incorrect response from Dmaap"));
}
@Override
@@ -82,4 +78,4 @@ public class DmaapPublisherTaskImpl extends
protected DmaapPublisherConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapPublisherConfiguration();
}
-}
+} \ No newline at end of file
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 84c75e08..07c0a58a 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
@@ -25,9 +25,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
*/
@@ -39,15 +36,13 @@ public class ScheduledTasks {
private final Task dmaapConsumerTask;
private final Task dmaapProducerTask;
private final Task aaiProducerTask;
- private final Task aaiConsumerTask;
@Autowired
public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask,
- AAIProducerTask aaiPublisherTask, AAIConsumerTask aaiConsumerTask) {
+ AAIProducerTask aaiPublisherTask) {
this.dmaapConsumerTask = dmaapConsumerTask;
this.dmaapProducerTask = dmaapPublisherTask;
this.aaiProducerTask = aaiPublisherTask;
- this.aaiConsumerTask = aaiConsumerTask;
}
public void scheduleMainPrhEventTask() {
@@ -64,8 +59,6 @@ public class ScheduledTasks {
private void setTaskExecutionFlow() {
dmaapConsumerTask.setNext(aaiProducerTask);
- aaiProducerTask.setNext(aaiConsumerTask);
- aaiConsumerTask.setNext(dmaapProducerTask);
+ aaiProducerTask.setNext(dmaapProducerTask);
}
-
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java
index a9b10d40..97202146 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java
@@ -20,7 +20,6 @@
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
-import org.springframework.http.ResponseEntity;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java
index 8094c993..38a4436d 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java
@@ -28,10 +28,10 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension;
import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -75,8 +75,8 @@ class ServiceMockProvider {
}
@Bean
- public HttpRequestDetails getRequestDetails() {
- return mock(HttpRequestDetails.class);
+ public ConsumerDmaapModel getRequestDetails() {
+ return mock(ConsumerDmaapModel.class);
}
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
index e7d55419..2efffd80 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
@@ -44,8 +44,8 @@ import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension;
class PrhAppConfigTest {
private static final String PRH_ENDPOINTS = "prh_endpoints.json";
- private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiHttpClientConfiguration\":{\"aaiHost\":\"\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\"}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
- private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiHttpClientConfiguration\":{\"aaiHost\":\"\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\"}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
+ private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
+ private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
private static PrhAppConfig prhAppConfig;
private static AppConfig appConfig;
@@ -107,7 +107,7 @@ class PrhAppConfigTest {
}
@Test
- public void whenFileIsNotExist_ThrowFileNotFoundExcepton() {
+ public void whenFileIsNotExist_ThrowFileNotFoundException() {
//
// Given
//
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
index a0970374..aad3c2fc 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
@@ -22,8 +22,8 @@ package org.onap.dcaegen2.services.prh.service;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ImmutableConsumerDmaapModel;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java
index 929e5a48..288a8961 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java
@@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java
index 9564bf9e..77323ab2 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java
@@ -21,7 +21,6 @@ package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
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 73f21a26..27083c04 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
@@ -42,13 +42,10 @@ public class ScheduleControllerSpy {
@Autowired
private AAIProducerTask aaiPublisherTaskImplSpy;
- @Autowired
- private AAIConsumerTask aaiConsumerTaskImplSpy;
@Bean
@Primary
public ScheduledTasks registerSimpleScheduledTask() {
- return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy,
- aaiConsumerTaskImplSpy));
+ return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy));
}
}
diff --git a/prh-app-server/src/test/resources/prh_endpoints.json b/prh-app-server/src/test/resources/prh_endpoints.json
index b401b90d..a67ee02b 100644
--- a/prh-app-server/src/test/resources/prh_endpoints.json
+++ b/prh-app-server/src/test/resources/prh_endpoints.json
@@ -7,7 +7,15 @@
"aaiIgnoreSSLCertificateErrors": true,
"aaiProtocol": "https",
"aaiUserName": "admin",
- "aaiUserPassword": "admin"
+ "aaiUserPassword": "admin",
+ "aaiBasePath": "/aai/v11",
+ "aaiPnfPath": "/network/pnfs/pnf",
+ "aaiHeaders": {
+ "X-FromAppId": "prh",
+ "X-TransactionId": "9999",
+ "Accept": "application/json",
+ "Real-Time": "true"
+ }
}
},
"dmaap": {
@@ -18,7 +26,7 @@
"dmaapHostName": "localhost",
"dmaapPortNumber": 2222,
"dmaapProtocol": "http",
- "dmaapTopicName": "temp",
+ "dmaapTopicName": "/events/pnfReady",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin",
"messageLimit": 1000,
@@ -29,7 +37,7 @@
"dmaapHostName": "localhost",
"dmaapPortNumber": 2223,
"dmaapProtocol": "http",
- "dmaapTopicName": "temp",
+ "dmaapTopicName": "/events/pnfReady",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin"
}
diff --git a/prh-commons/pom.xml b/prh-commons/pom.xml
new file mode 100644
index 00000000..08ce5fdb
--- /dev/null
+++ b/prh-commons/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>prh</artifactId>
+ <groupId>org.onap.dcaegen2.services</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.dcaegen2.services.commons</groupId>
+ <artifactId>commons</artifactId>
+
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.immutables</groupId>
+ <artifactId>value</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.immutables</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/CommonFunctions.java
index a0877feb..d10ab320 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/CommonFunctions.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -18,19 +18,19 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.service.producer;
+package org.onap.dcaegen2.services.model;
-import org.immutables.value.Value;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
-import java.util.Optional;
+public class CommonFunctions {
-@Value.Immutable(prehash = true)
-@Value.Style(builder = "new")
-public abstract class DmaapPublisherRequestDetails {
+ private static Gson gson = new GsonBuilder().create();
- @Value.Parameter
- public abstract String dmaapAPIPath();
- @Value.Parameter
- public abstract String jsonBody();
+ private CommonFunctions() {}
+
+ public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
+ return gson.toJson(consumerDmaapModel);
+ }
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModel.java
index c6879948..3143362a 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModel.java
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.model;
+package org.onap.dcaegen2.services.model;
import com.google.gson.annotations.SerializedName;
import org.immutables.gson.Gson;
@@ -39,5 +39,4 @@ public interface ConsumerDmaapModel {
@SerializedName("ipaddress-v6-oam")
String getIpv6();
-
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModelForUnitTest.java
index 37e6b860..df691fc9 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/model/ConsumerDmaapModelForUnitTest.java
@@ -17,30 +17,28 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.utils;
+package org.onap.dcaegen2.services.model;
-import org.immutables.value.Value;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Optional;
+public class ConsumerDmaapModelForUnitTest implements ConsumerDmaapModel {
-@Value.Immutable(prehash = true)
-@Value.Style(stagedBuilder = true)
-public abstract class HttpRequestDetails implements Serializable {
+ private String pnfName = "NOKnhfsadhff";
+ private String ipv4 = "11.22.33.155";
+ private String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
- private static final long serialVersionUID = 1L;
- @Value.Parameter
- public abstract String aaiAPIPath();
+ public String getPnfName() {
+ return pnfName;
+ }
- @Value.Parameter
- public abstract Optional<String> jsonBody();
+ public String getIpv4() {
+ return ipv4;
+ }
- @Value.Parameter
- public abstract String pnfName();
+ public String getIpv6() {
+ return ipv6;
+ }
- @Value.Parameter
- public abstract Map<String,String> headers();
}
diff --git a/prh-dmaap-client/pom.xml b/prh-dmaap-client/pom.xml
index ff6a0b30..40d4df91 100644
--- a/prh-dmaap-client/pom.xml
+++ b/prh-dmaap-client/pom.xml
@@ -99,5 +99,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.dcaegen2.services.commons</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
index 98c9a83e..def9dd85 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
@@ -29,6 +29,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.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.model.CommonFunctions;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.service.DmaapHttpClientImpl;
import org.onap.dcaegen2.services.service.HttpUtils;
import org.slf4j.Logger;
@@ -61,17 +63,14 @@ public class ExtendedDmaapProducerHttpClientImpl {
this.dmaapContentType = configuration.dmaapContentType();
}
- public Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
-
+ public Optional<String> getHttpProducerResponse(ConsumerDmaapModel consumerDmaapModel) {
Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
-
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
extendedDetails = closeableHttpClient.execute(request.get(), dmaapProducerResponseHandler());
} catch (IOException | NullPointerException e) {
logger.warn("Exception while executing HTTP request: ", e);
}
-
return extendedDetails;
}
@@ -81,51 +80,45 @@ public class ExtendedDmaapProducerHttpClientImpl {
private Optional<StringEntity> parseJson(Optional<String> jsonBody) {
Optional<StringEntity> stringEntity = Optional.empty();
-
try {
stringEntity = Optional.of(new StringEntity(jsonBody.get()));
} catch (UnsupportedEncodingException e) {
logger.warn("Exception while parsing JSON: ", e);
}
-
return stringEntity;
}
- private Optional<HttpRequestBase> createRequest(DmaapPublisherRequestDetails requestDetails) {
-
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
Optional<HttpRequestBase> request = Optional.empty();
- final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails);
+ final URI extendedURI = createDmaapPublisherExtendedURI();
if ("application/json".equals(dmaapContentType)) {
- request = Optional.ofNullable(createRequest(extendedURI, requestDetails));
+ request = Optional.ofNullable(createRequest(extendedURI, consumerDmaapModel));
request.get().addHeader("Content-type", dmaapContentType);
}
return request;
}
- private URI createDmaapPublisherExtendedURI(DmaapPublisherRequestDetails requestDetails) {
+ private URI createDmaapPublisherExtendedURI() {
URI extendedURI = null;
-
final URIBuilder uriBuilder = new URIBuilder()
.setScheme(dmaapProtocol)
.setHost(dmaapHostName)
.setPort(dmaapPortNumber)
- .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName);
-
+ .setPath(dmaapTopicName);
try {
extendedURI = uriBuilder.build();
logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
logger.warn("Exception while building extended URI: ", e);
}
-
return extendedURI;
}
- private HttpRequestBase createRequest(URI extendedURI, DmaapPublisherRequestDetails requestDetails) {
+ private HttpRequestBase createRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
if (extendedURI != null) {
- return createHttpPost(extendedURI, Optional.ofNullable(requestDetails.jsonBody()));
+ return createHttpPost(extendedURI, Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)));
} else {
return null;
}
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
index 3f64fd5f..6ca815ae 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModelForUnitTest;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -43,10 +45,9 @@ public class ExtendedDmaapProducerHttpClientImplTest {
private static DmaapPublisherConfiguration configurationMock = mock(DmaapPublisherConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static DmaapPublisherRequestDetails requestDetailsMock = mock(DmaapPublisherRequestDetails.class);
+ private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
private static Optional<String> expectedResult = Optional.empty();
- private static final String JSON_MESSAGE = "{ \"ipaddress-v4-oam\": \"11.22.33.44\" }";
private static final String RESPONSE_SUCCESS = "200";
private static final String RESPONSE_FAILURE = "404";
@@ -61,9 +62,6 @@ public class ExtendedDmaapProducerHttpClientImplTest {
when(configurationMock.dmaapContentType()).thenReturn("application/json");
when(configurationMock.dmaapTopicName()).thenReturn("pnfReady");
- when(requestDetailsMock.dmaapAPIPath()).thenReturn("events");
- when(requestDetailsMock.jsonBody()).thenReturn(JSON_MESSAGE);
-
objectUnderTest = new ExtendedDmaapProducerHttpClientImpl(configurationMock);
setField();
@@ -77,7 +75,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
.thenReturn(expectedResult);
- Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
+ Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel);
Assertions.assertEquals(expectedResult.get(), actualResult.get());
}
@@ -87,7 +85,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
expectedResult = Optional.of(RESPONSE_FAILURE);
when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
.thenReturn(Optional.empty());
- Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
+ Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel);
Assertions.assertEquals(Optional.empty(), actualResult);
}