aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-05-18 12:01:47 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-05-21 12:51:31 +0200
commit0a0ea1becceb6d02de90570789232f1ddb759ac1 (patch)
tree05e236a76e13341b07b523852c6633d976f29007 /prh-app-server/src/main/java
parent1e1468a8c7dcf86ff8104d4d1b7246b076c8d18d (diff)
Code refactor
*DmaapTasks *AAITasks Change-Id: I62d2ae758b58435ca8930354cb86172236646c20 Issue-ID: DCAEGEN2-396 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java9
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java27
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java8
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java31
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java8
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java22
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java8
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java27
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java2
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java10
10 files changed, 71 insertions, 81 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
index ffc81324..09de5cca 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java
@@ -20,11 +20,14 @@
package org.onap.dcaegen2.services.prh.tasks;
+import java.util.Optional;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.AAIConsumerClient;
-public abstract class AAIConsumerTask<T, U, V, Z> extends Task<Z> {
+public abstract class AAIConsumerTask<Request, Response, Conf> extends Task<Request, Response, Conf> {
- protected abstract V consume(U message) throws AAINotFoundException;
+ abstract Optional<String> consume(ConsumerDmaapModel message) throws AAINotFoundException;
- protected abstract T resolveClient();
+ abstract AAIConsumerClient resolveClient();
}
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 3c2b2974..d0948aea 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
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -17,10 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.onap.dcaegen2.services.prh.tasks;
import java.io.IOException;
+import java.util.Optional;
import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
@@ -34,7 +34,7 @@ import org.springframework.stereotype.Component;
@Component
public class AAIConsumerTaskImpl extends
- AAIConsumerTask<AAIConsumerClient, ConsumerDmaapModel, Object, AAIClientConfiguration> {
+ AAIConsumerTask<ConsumerDmaapModel, String, AAIClientConfiguration> {
private static final Logger logger = LoggerFactory.getLogger(AAIConsumerTaskImpl.class);
@@ -47,7 +47,7 @@ public class AAIConsumerTaskImpl extends
}
@Override
- protected Object consume(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
logger.trace("Method called with arg {}", consumerDmaapModel);
try {
return aaiConsumerClient.getHttpResponse(consumerDmaapModel);
@@ -58,17 +58,12 @@ public class AAIConsumerTaskImpl extends
}
@Override
- public Object execute(Object object) throws AAINotFoundException {
- setAAIClientConfig();
- logger.trace("Method called with arg {}", object);
- if (object instanceof ConsumerDmaapModel) {
- return consume((ConsumerDmaapModel) object);
- }
- throw new AAINotFoundException("Incorrect object type");
- }
-
- protected void setAAIClientConfig() {
+ public String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
+ .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
+ logger.trace("Method called with arg {}", consumerDmaapModel);
aaiConsumerClient = resolveClient();
+ return consume(consumerDmaapModel).orElseThrow(() -> new AAINotFoundException("Null response code"));
}
@Override
@@ -77,7 +72,7 @@ public class AAIConsumerTaskImpl extends
}
@Override
- protected AAIConsumerClient resolveClient() {
- return new AAIConsumerClient(resolveConfiguration());
+ AAIConsumerClient resolveClient() {
+ return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AAIConsumerClient(resolveConfiguration()));
}
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java
index 23d5e93d..82362809 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java
@@ -20,13 +20,15 @@
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.AAIProducerClient;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
*/
-public abstract class AAIProducerTask<T, U, V> extends Task {
+public abstract class AAIProducerTask<Request, Response, Config> extends Task<Request, Response, Config> {
- protected abstract V publish(U message) throws AAINotFoundException;
+ abstract ConsumerDmaapModel publish(ConsumerDmaapModel message) throws AAINotFoundException;
- protected abstract T resolveClient();
+ abstract AAIProducerClient resolveClient();
}
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 79d9b88d..7487d084 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
@@ -20,7 +20,9 @@
package org.onap.dcaegen2.services.prh.tasks;
import java.io.IOException;
+import java.util.Optional;
import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
@@ -36,7 +38,8 @@ 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 AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, ConsumerDmaapModel, Object> {
+public class AAIProducerTaskImpl extends
+ AAIProducerTask<ConsumerDmaapModel, ConsumerDmaapModel, AAIClientConfiguration> {
private static final Logger logger = LoggerFactory.getLogger(AAIProducerTaskImpl.class);
@@ -49,9 +52,8 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, Cons
}
@Override
- protected Object publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
logger.trace("Method called with arg {}", consumerDmaapModel);
-
try {
return aaiProducerClient.getHttpResponse(consumerDmaapModel)
.filter(HttpUtils::isSuccessfulResponseCode).map(response -> consumerDmaapModel).orElseThrow(() ->
@@ -63,19 +65,12 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, Cons
}
@Override
- public Object execute(Object object) throws AAINotFoundException {
- setAAIClientConfig();
- logger.trace("Method called with arg {}", object);
-
- if (object instanceof ConsumerDmaapModel) {
- return publish((ConsumerDmaapModel) object);
- }
-
- throw new AAINotFoundException("Incorrect object type");
- }
-
- void setAAIClientConfig() {
+ public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
+ .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
+ logger.trace("Method called with arg {}", consumerDmaapModel);
aaiProducerClient = resolveClient();
+ return publish(consumerDmaapModel);
}
AAIClientConfiguration resolveConfiguration() {
@@ -83,7 +78,7 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, Cons
}
@Override
- protected AAIProducerClient resolveClient() {
- return new AAIProducerClient(resolveConfiguration());
+ AAIProducerClient resolveClient() {
+ return Optional.ofNullable(aaiProducerClient).orElseGet(() -> new AAIProducerClient(resolveConfiguration()));
}
-}
+} \ No newline at end of file
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 195eee7c..4bd8731c 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
@@ -20,15 +20,17 @@
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.consumer.ExtendedDmaapConsumerHttpClientImpl;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
*/
-public abstract class DmaapConsumerTask<T, U, V, Z> extends Task<Z> {
+abstract class DmaapConsumerTask<Request, Response, Config> extends Task<Request, Response, Config> {
- protected abstract V consume(U message) throws DmaapNotFoundException;
+ abstract ConsumerDmaapModel consume(String message) throws DmaapNotFoundException;
- protected abstract T resolveClient();
+ abstract ExtendedDmaapConsumerHttpClientImpl resolveClient();
abstract void initConfigs();
}
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 dc868b3e..a78d33b2 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,6 +19,7 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
+import java.util.Optional;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
@@ -38,11 +39,9 @@ import org.springframework.stereotype.Component;
*/
@Component
public class DmaapConsumerTaskImpl extends
- DmaapConsumerTask<ExtendedDmaapConsumerHttpClientImpl, String, ConsumerDmaapModel, DmaapConsumerConfiguration> {
-
+ DmaapConsumerTask<String, ConsumerDmaapModel, DmaapConsumerConfiguration> {
private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class);
-
private final Config prhAppConfig;
private ExtendedDmaapConsumerHttpClientImpl extendedDmaapConsumerHttpClient;
@@ -52,14 +51,14 @@ public class DmaapConsumerTaskImpl extends
}
@Override
- protected ConsumerDmaapModel consume(String message) throws DmaapNotFoundException {
+ ConsumerDmaapModel consume(String message) throws DmaapNotFoundException {
logger.trace("Method called with arg {}", message);
return DmaapConsumerJsonParser.getJsonObject(message);
}
@Override
- public Object execute(Object object) throws PrhTaskException {
- setDmaapClientConfig();
+ public ConsumerDmaapModel execute(String object) throws PrhTaskException {
+ extendedDmaapConsumerHttpClient = resolveClient();
logger.trace("Method called with arg {}", object);
return consume((extendedDmaapConsumerHttpClient.getHttpConsumerResponse().orElseThrow(() ->
new PrhTaskException("DmaapConsumerTask has returned null"))));
@@ -75,14 +74,9 @@ public class DmaapConsumerTaskImpl extends
return prhAppConfig.getDmaapConsumerConfiguration();
}
- protected void setDmaapClientConfig() {
- extendedDmaapConsumerHttpClient = resolveClient();
- }
-
@Override
- protected ExtendedDmaapConsumerHttpClientImpl resolveClient() {
- return new ExtendedDmaapConsumerHttpClientImpl(resolveConfiguration());
+ ExtendedDmaapConsumerHttpClientImpl resolveClient() {
+ return Optional.ofNullable(extendedDmaapConsumerHttpClient)
+ .orElseGet(() -> new ExtendedDmaapConsumerHttpClientImpl(resolveConfiguration()));
}
-
-
} \ 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 8985133a..ab3e4696 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
@@ -20,13 +20,15 @@
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.producer.ExtendedDmaapProducerHttpClientImpl;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
*/
-public abstract class DmaapPublisherTask<T, U, V> extends Task<V> {
+abstract class DmaapPublisherTask<Request, Response, Config> extends Task<Request, Response, Config> {
- protected abstract String publish(U message) throws DmaapNotFoundException;
+ abstract String publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException;
- protected abstract T resolveClient();
+ abstract ExtendedDmaapProducerHttpClientImpl resolveClient();
}
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 6450b18a..1a8f60fc 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,6 +19,7 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
+import java.util.Optional;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
@@ -37,7 +38,7 @@ import org.springframework.stereotype.Component;
*/
@Component
public class DmaapPublisherTaskImpl extends
- DmaapPublisherTask<ExtendedDmaapProducerHttpClientImpl, ConsumerDmaapModel, DmaapPublisherConfiguration> {
+ DmaapPublisherTask<ConsumerDmaapModel, String, DmaapPublisherConfiguration> {
private static final Logger logger = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class);
private final Config prhAppConfig;
@@ -49,7 +50,7 @@ public class DmaapPublisherTaskImpl extends
}
@Override
- protected String publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
+ String publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
logger.trace("Method called with arg {}", consumerDmaapModel);
return extendedDmaapProducerHttpClient.getHttpProducerResponse(consumerDmaapModel)
.filter(response -> !response.isEmpty() && response.equals(String.valueOf(HttpStatus.OK.value())))
@@ -57,13 +58,12 @@ public class DmaapPublisherTaskImpl extends
}
@Override
- public Object execute(Object object) throws PrhTaskException {
- if (object instanceof ConsumerDmaapModel) {
- setDmaapClientConfig();
- logger.trace("Method called with arg {}", object);
- return publish((ConsumerDmaapModel) object);
- }
- throw new DmaapNotFoundException("Incorrect object type");
+ public String execute(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
+ consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
+ .orElseThrow(() -> new DmaapNotFoundException("Invoked null object to Dmaap task"));
+ extendedDmaapProducerHttpClient = resolveClient();
+ logger.trace("Method called with arg {}", consumerDmaapModel);
+ return publish(consumerDmaapModel);
}
@Override
@@ -72,11 +72,8 @@ public class DmaapPublisherTaskImpl extends
}
@Override
- protected ExtendedDmaapProducerHttpClientImpl resolveClient() {
- return null;
- }
-
- protected void setDmaapClientConfig() {
- extendedDmaapProducerHttpClient = resolveClient();
+ ExtendedDmaapProducerHttpClientImpl resolveClient() {
+ return Optional.ofNullable(extendedDmaapProducerHttpClient)
+ .orElseGet(() -> new ExtendedDmaapProducerHttpClientImpl(resolveConfiguration()));
}
} \ 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 6b868d67..052de058 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
@@ -50,7 +50,7 @@ public class ScheduledTasks {
setTaskExecutionFlow();
try {
dmaapConsumerTask.initConfigs();
- dmaapConsumerTask.receiveRequest(null);
+ dmaapConsumerTask.receiveRequest("");
} catch (PrhTaskException e) {
logger
.warn("Chain of tasks have been aborted, because some errors occur in prh workflow ", e);
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 42f0405c..46e19dad 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
@@ -26,7 +26,7 @@ import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
*/
-public abstract class Task<T> {
+public abstract class Task<Request, Response, Config> {
private Task taskProcess;
@@ -34,15 +34,15 @@ public abstract class Task<T> {
this.taskProcess = task;
}
- public void receiveRequest(Object body) throws PrhTaskException {
+ public void receiveRequest(Request body) throws PrhTaskException {
- Object response = execute(body);
+ Response response = execute(body);
if (taskProcess != null) {
taskProcess.receiveRequest(response);
}
}
- abstract Object execute(Object object) throws PrhTaskException;
+ abstract Response execute(Request object) throws PrhTaskException;
- abstract T resolveConfiguration();
+ abstract Config resolveConfiguration();
}