diff options
author | wasala <przemyslaw.wasala@nokia.com> | 2018-04-16 12:59:26 +0200 |
---|---|---|
committer | wasala <przemyslaw.wasala@nokia.com> | 2018-04-16 14:54:35 +0200 |
commit | 58a67d37441b8af808b792418e07448e30556bbd (patch) | |
tree | da77e1b1e09c7a3ad829a3f59f1fa1a8d3d0f52c /prh-app-server/src/main/java | |
parent | b0ef04537df52322f1d51148ef612c19d7b23696 (diff) |
Already added flow control for tasks.
*The next step will be get common model for all
request/response message based on HTTPClient implementation
Change-Id: I76af15ab06cae783b6cec5099510d7f97e9d65c2
Issue-ID: DCAEGEN2-445
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java')
11 files changed, 117 insertions, 53 deletions
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 1b530e5a..d6ca423b 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 @@ -21,7 +21,7 @@ package org.onap.dcaegen2.services.prh.configuration; import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.config.DmaapProducerConfiguration; +import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 @@ -32,6 +32,6 @@ public interface AppConfig { AAIHttpClientConfiguration getAAIHttpClientConfiguration(); - DmaapProducerConfiguration getDmaapProducerConfiguration(); + DmaapPublisherConfiguration getDmaapPublisherConfiguration(); } 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 19fcb8b8..37b17f61 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 @@ -37,10 +37,10 @@ import java.util.Optional; import javax.validation.constraints.NotEmpty; import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.config.DmaapProducerConfiguration; +import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration; import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration; -import org.onap.dcaegen2.services.config.ImmutableDmaapProducerConfiguration; +import org.onap.dcaegen2.services.config.ImmutableDmaapPublisherConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -65,11 +65,11 @@ public class PrhAppConfig implements AppConfig { private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private ImmutableAAIHttpClientConfiguration immutableAAIHttpClientConfiguration; + private AAIHttpClientConfiguration aaiHttpClientConfiguration; - private ImmutableDmaapConsumerConfiguration immutableDmaapConsumerConfiguration; + private DmaapConsumerConfiguration dmaapConsumerConfiguration; - private ImmutableDmaapProducerConfiguration immutableDmaapProducerConfiguration; + private DmaapPublisherConfiguration dmaapPublisherConfiguration; @NotEmpty private String filepath; @@ -81,16 +81,16 @@ public class PrhAppConfig implements AppConfig { try (InputStream inputStream = getInputStream(filepath)) { ObjectNode root = (ObjectNode) jsonObjectMapper.readTree(inputStream); jsonNode = Optional.ofNullable(root.get(CONFIG).get(AAI).get(AAI_CONFIG)).orElse(NullNode.getInstance()); - immutableAAIHttpClientConfiguration = jsonObjectMapper + aaiHttpClientConfiguration = jsonObjectMapper .treeToValue(jsonNode, ImmutableAAIHttpClientConfiguration.class); jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_CONSUMER)) .orElse(NullNode.getInstance()); - immutableDmaapConsumerConfiguration = jsonObjectMapper + dmaapConsumerConfiguration = jsonObjectMapper .treeToValue(jsonNode, ImmutableDmaapConsumerConfiguration.class); jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_PRODUCER)) .orElse(NullNode.getInstance()); - immutableDmaapProducerConfiguration = jsonObjectMapper - .treeToValue(jsonNode, ImmutableDmaapProducerConfiguration.class); + dmaapPublisherConfiguration = jsonObjectMapper + .treeToValue(jsonNode, ImmutableDmaapPublisherConfiguration.class); } catch (FileNotFoundException e) { logger .error( @@ -132,16 +132,16 @@ public class PrhAppConfig implements AppConfig { @Override public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { - return immutableDmaapConsumerConfiguration; + return dmaapConsumerConfiguration; } @Override public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { - return immutableAAIHttpClientConfiguration; + return aaiHttpClientConfiguration; } @Override - public DmaapProducerConfiguration getDmaapProducerConfiguration() { - return immutableDmaapProducerConfiguration; + public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { + return dmaapPublisherConfiguration; } }
\ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java index 646ca7e7..33193609 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java @@ -24,7 +24,7 @@ package org.onap.dcaegen2.services.prh.exceptions; */ public class PrhTaskException extends Exception { - public PrhTaskException(String message) { + PrhTaskException(String message) { super(message); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java index 87a70810..8ea4ac8f 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java @@ -24,7 +24,9 @@ import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ -public abstract class AAIPublisherTask implements Task { +public abstract class AAIPublisherTask<T> extends Task { protected abstract void publish() throws AAINotFoundException; + + protected abstract T resolveConfiguration(); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java index d4efea4f..c524b990 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java @@ -21,40 +21,54 @@ package org.onap.dcaegen2.services.prh.tasks; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; 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; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @Component -public class AAIPublisherTaskImpl extends AAIPublisherTask { +public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfiguration> { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + private final AppConfig prhAppConfig; + @Autowired - public AppConfig prhAppConfig; + public AAIPublisherTaskImpl(AppConfig prhAppConfig) { + this.prhAppConfig = prhAppConfig; + + } @Override - protected void publish() { + protected void publish() throws AAINotFoundException { logger.debug("Start task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - logger.debug("End task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); + } @Override - public void execute() { + public ResponseEntity execute(Object object) throws AAINotFoundException { logger.debug("Start task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - + publish(); logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); + return null; + } + @Override + protected AAIHttpClientConfiguration resolveConfiguration() { + return prhAppConfig.getAAIHttpClientConfiguration(); } + } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java index 41031664..68a79e01 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java @@ -24,7 +24,9 @@ import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ -public abstract class DmaapConsumerTask implements Task { +public abstract class DmaapConsumerTask<T> extends Task { protected abstract void consume() throws DmaapNotFoundException; + + protected abstract T resolveConfiguration(); } 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 57f97778..1ee85d03 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 @@ -21,41 +21,53 @@ package org.onap.dcaegen2.services.prh.tasks; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; 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; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ @Component -public class DmaapConsumerTaskImpl extends DmaapConsumerTask { +public class DmaapConsumerTaskImpl extends DmaapConsumerTask<DmaapConsumerConfiguration> { private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + private final AppConfig prhAppConfig; + @Autowired - public AppConfig prhAppConfig; + public DmaapConsumerTaskImpl(AppConfig prhAppConfig) { + this.prhAppConfig = prhAppConfig; + } @Override - public void execute() { - logger.debug("Start task DmaapConsumerTask::execute() :: Execution Time - {}", dateTimeFormatter.format( + protected void consume() { + logger.debug("Start task DmaapConsumerTask::consume() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - logger.debug("End task DmaapConsumerTask::execute() :: Execution Time - {}", + logger.debug("End task DmaapConsumerTask::consume() :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); + } @Override - protected void consume() { - logger.debug("Start task DmaapConsumerTask::consume() :: Execution Time - {}", dateTimeFormatter.format( + public ResponseEntity execute(Object object) { + logger.debug("Start task DmaapConsumerTask::execute() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - - logger.debug("End task DmaapConsumerTask::consume() :: Execution Time - {}", + consume(); + logger.debug("End task DmaapConsumerTask::execute() :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); + return null; + } + @Override + protected DmaapConsumerConfiguration resolveConfiguration() { + return prhAppConfig.getDmaapConsumerConfiguration(); } }
\ No newline at end of file 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 d203c8c5..239d36a9 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 @@ -24,8 +24,10 @@ import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ -public abstract class DmaapPublisherTask implements Task { +public abstract class DmaapPublisherTask<T> extends Task { protected abstract void publish() 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 92eb875c..b14d8d37 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,39 +21,51 @@ package org.onap.dcaegen2.services.prh.tasks; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; 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; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @Component -public class DmaapPublisherTaskImpl extends DmaapPublisherTask { +public class DmaapPublisherTaskImpl extends DmaapPublisherTask<DmaapPublisherConfiguration> { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + private final AppConfig prhAppConfig; + @Autowired - public AppConfig prhAppConfig; + public DmaapPublisherTaskImpl(AppConfig prhAppConfig) { + this.prhAppConfig = prhAppConfig; + } @Override - public void execute() { - logger.debug("Start task DmaapPublisherTask::consume() :: Execution Time - {}", dateTimeFormatter.format( + protected void publish() { + logger.debug("Start task DmaapPublisherTask::publish() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - logger.debug("End task DmaapPublisherTask::consume() :: Execution Time - {}", + logger.debug("End task DmaapPublisherTask::publish() :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); } @Override - protected void publish() { - logger.debug("Start task DmaapPublisherTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + public ResponseEntity execute(Object object) { + logger.debug("Start task DmaapPublisherTask::consume() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - - logger.debug("End task DmaapPublisherTask::publish() :: Execution Time - {}", + publish(); + logger.debug("End task DmaapPublisherTask::consume() :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); + return null; + } + + @Override + protected DmaapPublisherConfiguration resolveConfiguration() { + return prhAppConfig.getDmaapPublisherConfiguration(); } } 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 713f5d48..a9c53ccc 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 @@ -36,25 +36,24 @@ public class ScheduledTasks { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private final DmaapConsumerTask dmaapConsumerTask; - private final DmaapPublisherTask dmaapPublisherTask; - private final AAIPublisherTask aaiPublisherTask; + private final Task dmaapConsumerTask; + private final Task dmaapProducerTask; + private final Task aaiPublisherTask; @Autowired public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask, AAIPublisherTask aaiPublisherTask) { this.dmaapConsumerTask = dmaapConsumerTask; - this.dmaapPublisherTask = dmaapPublisherTask; + this.dmaapProducerTask = dmaapPublisherTask; this.aaiPublisherTask = aaiPublisherTask; } public void scheduleMainPrhEventTask() { logger.debug("Task scheduledTaskAskingDMaaPOfConsumeEvent() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); + setTaskExecutionFlow(); try { - dmaapConsumerTask.execute(); - dmaapPublisherTask.execute(); - aaiPublisherTask.execute(); + dmaapConsumerTask.receiveRequest(null); } catch (PrhTaskException e) { logger .error("Task scheduledTaskAskingDMaaPOfConsumeEvent()::PrhTaskException :: Execution Time - {}:{}", @@ -63,4 +62,9 @@ public class ScheduledTasks { } } + private void setTaskExecutionFlow() { + dmaapConsumerTask.setNext(aaiPublisherTask); + aaiPublisherTask.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 1bf8f6d3..f5e8b39e 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,13 +20,29 @@ 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 */ -@FunctionalInterface -public interface Task { - void execute() throws PrhTaskException; +public abstract class Task { + + private Task taskProcess; + + public void setNext(Task task) { + this.taskProcess = task; + } + + public void receiveRequest(Object body) throws PrhTaskException { + Object responseEntity = execute(body); + if (taskProcess != null) { + taskProcess.receiveRequest(responseEntity); + } + } + + abstract ResponseEntity execute(Object object) throws PrhTaskException; + + } |