diff options
author | wasala <przemyslaw.wasala@nokia.com> | 2018-05-10 13:08:00 +0200 |
---|---|---|
committer | wasala <przemyslaw.wasala@nokia.com> | 2018-05-10 13:32:17 +0200 |
commit | 8c88efe7a0abe051e8a4c4d271c84eb8e68c29f0 (patch) | |
tree | 073e23915e20e3bff2717cde0d76913d58ce7e82 | |
parent | 44ce56cf2e6bfae17c443901ac6ded8ba8cdd414 (diff) |
Added DmaapProducer in task workflow scheduler
Change-Id: I46c8ff37ca758525e6647d5057d50595f5739208
Issue-ID: DCAEGEN2-474
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
10 files changed, 36 insertions, 35 deletions
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 275685fe..269e7a2a 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,9 +23,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 4cde51bf..cd3347fe 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,12 +21,9 @@ package org.onap.dcaegen2.services.prh.controllers; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; 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; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java index a3c7d1d3..c6879948 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java @@ -27,7 +27,7 @@ import org.immutables.value.Value; * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18 */ -@Value.Immutable(prehash = true) +@Value.Immutable @Gson.TypeAdapters public interface ConsumerDmaapModel { 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 e2d9816e..0ef7e4fe 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 @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.prh.service; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import java.util.Optional; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; 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 1c80d3f9..95352d44 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,22 +20,17 @@ 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.onap.dcaegen2.services.utils.HttpRequestDetails; 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; - @Component public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration> { 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 a254890f..4a7d9282 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 @@ -24,6 +24,7 @@ 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.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; @@ -65,10 +66,13 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration, } @Override - public Object execute(Object object) throws AAINotFoundException { + public Object execute(Object object) throws PrhTaskException { logger.trace("Method %M called with arg {}", object); - //TODO: @Piotr Wielebski - return publish((ConsumerDmaapModel) object); + if (object instanceof ConsumerDmaapModel) { + //TODO: @Piotr Wielebski + return publish((ConsumerDmaapModel) object); + } + throw new AAINotFoundException("Incorrect object type"); } @Override diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java index 7b9fd5db..2329274b 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java @@ -26,7 +26,7 @@ import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; */ public abstract class DmaapPublisherTask<T, U> extends Task { - protected abstract U publish(U message) throws DmaapNotFoundException; + protected abstract String publish(U message) throws DmaapNotFoundException; protected abstract T resolveConfiguration(); } 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 906bd428..60ab64fd 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 @@ -19,29 +19,31 @@ */ package org.onap.dcaegen2.services.prh.tasks; +import com.google.gson.Gson; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; 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; -import org.springframework.http.ResponseEntity; +import org.springframework.http.HttpStatus; 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 4/13/18 */ @Component -public class DmaapPublisherTaskImpl extends DmaapPublisherTask<DmaapPublisherConfiguration, String> { +public class DmaapPublisherTaskImpl extends + DmaapPublisherTask<DmaapPublisherConfiguration, ConsumerDmaapModel> { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final Gson gson = new Gson(); private final Config prhAppConfig; @Autowired @@ -50,17 +52,25 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask<DmaapPublisherCon } @Override - protected String publish(String message) { - logger.trace("Method %M called with arg {}", message); + protected String publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException { + logger.trace("Method %M called with arg {}", consumerDmaapModel); ExtendedDmaapProducerHttpClientImpl dmaapProducerHttpClient = new ExtendedDmaapProducerHttpClientImpl( resolveConfiguration()); - return null; + 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")); + } @Override public Object execute(Object object) throws PrhTaskException { - logger.trace("Method %M called with arg {}", object); - return publish((String) object); + if (object instanceof ConsumerDmaapModel) { + logger.trace("Method %M called with arg {}", object); + return publish((ConsumerDmaapModel) object); + } + throw new DmaapNotFoundException("Incorrect object type"); } @Override diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java index ac26ea97..6f5f17c4 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java @@ -21,7 +21,6 @@ package org.onap.dcaegen2.services.config; import org.immutables.gson.Gson; import org.immutables.value.Value; -import org.springframework.stereotype.Component; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 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 af7534c6..98c9a83e 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 @@ -69,7 +69,7 @@ public class ExtendedDmaapProducerHttpClientImpl { try { extendedDetails = closeableHttpClient.execute(request.get(), dmaapProducerResponseHandler()); } catch (IOException | NullPointerException e) { - logger.error("Exception while executing HTTP request: {}", e); + logger.warn("Exception while executing HTTP request: ", e); } return extendedDetails; @@ -85,7 +85,7 @@ public class ExtendedDmaapProducerHttpClientImpl { 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; @@ -115,9 +115,9 @@ public class ExtendedDmaapProducerHttpClientImpl { 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; @@ -144,11 +144,11 @@ public class ExtendedDmaapProducerHttpClientImpl { final HttpEntity responseEntity = httpResponse.getEntity(); if (HttpUtils.isSuccessfulResponseCode(responseCode)) { - logger.info("HTTP response successful."); + logger.trace("HTTP response successful."); return Optional.of("" + responseCode); } else { String response = responseEntity != null ? EntityUtils.toString(responseEntity) : ""; - logger.error("HTTP response not successful : {}", response); + logger.warn("HTTP response not successful : {}", response); return Optional.of("" + responseCode); } }; |