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;
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;
* @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 {
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;
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> {
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;
}
@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
*/
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();
}
*/
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
}
@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
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
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;
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;
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;
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);
}
};