aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-06-13 11:39:14 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-06-15 11:34:41 +0200
commit5b38b56d8b6a7fca299e0243a7dc91d460f4735c (patch)
treebcdca27ef1443b633d0b540f36bbb593de7fec9d /prh-app-server/src/main/java
parent3b630ca529d11bf6f158a71898583395e5c3ef75 (diff)
Added simply logs from tasks.
*Logging responsed object from DmaaP *Logging parsed oject from DmaaP *Logging sended object to AAI *Logging sended object and topic To DmaaP Change-Id: I33de0cd751762ac004f9d8a09beee921f4026af6 Issue-ID: DCAEGEN2-545 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/configuration/AppConfig.java42
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java2
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java16
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java12
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java8
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java30
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java4
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java18
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java13
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java17
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java4
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java31
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java16
-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.java20
15 files changed, 156 insertions, 79 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 7f36a51b..f24dd177 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
@@ -19,6 +19,7 @@
*/
package org.onap.dcaegen2.services.prh.configuration;
+import java.util.function.Predicate;
import org.onap.dcaegen2.services.prh.config.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@@ -34,6 +35,7 @@ import java.util.Optional;
@Configuration
public class AppConfig extends PrhAppConfig {
+ private static Predicate<String> isEmpty = String::isEmpty;
@Value("${dmaap.dmaapConsumerConfiguration.dmaapHostName:}")
public String consumerDmaapHostName;
@@ -116,34 +118,34 @@ public class AppConfig extends PrhAppConfig {
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return new ImmutableDmaapConsumerConfiguration.Builder()
.dmaapUserPassword(
- Optional.ofNullable(consumerDmaapUserPassword).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapUserPassword).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapUserPassword()))
.dmaapUserName(
- Optional.ofNullable(consumerDmaapUserName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapUserName).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapUserName()))
.dmaapHostName(
- Optional.ofNullable(consumerDmaapHostName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapHostName).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapHostName()))
.dmaapPortNumber(
Optional.ofNullable(consumerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapPortNumber()))
.dmaapProtocol(
- Optional.ofNullable(consumerDmaapProtocol).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapProtocol).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapProtocol()))
.dmaapContentType(
- Optional.ofNullable(consumerDmaapContentType).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapContentType).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapContentType()))
.dmaapTopicName(
- Optional.ofNullable(consumerDmaapTopicName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(consumerDmaapTopicName).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.dmaapTopicName()))
.messageLimit(
Optional.ofNullable(consumerMessageLimit).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.messageLimit()))
.timeoutMS(Optional.ofNullable(consumerTimeoutMS).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.timeoutMS()))
- .consumerGroup(Optional.ofNullable(consumerGroup).filter(p -> !p.isEmpty())
+ .consumerGroup(Optional.ofNullable(consumerGroup).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.consumerGroup()))
- .consumerId(Optional.ofNullable(consumerId).filter(p -> !p.isEmpty())
+ .consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.consumerId()))
.build();
}
@@ -151,7 +153,7 @@ public class AppConfig extends PrhAppConfig {
@Override
public AAIClientConfiguration getAAIClientConfiguration() {
return new ImmutableAAIClientConfiguration.Builder()
- .aaiHost(Optional.ofNullable(aaiHost).filter(p -> !p.isEmpty()).orElse(aaiClientConfiguration.aaiHost()))
+ .aaiHost(Optional.ofNullable(aaiHost).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiHost()))
.aaiHostPortNumber(
Optional.ofNullable(aaiHostPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(aaiClientConfiguration.aaiHostPortNumber()))
@@ -159,15 +161,15 @@ public class AppConfig extends PrhAppConfig {
Optional.ofNullable(aaiIgnoreSSLCertificateErrors).filter(p -> !p.toString().isEmpty())
.orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors()))
.aaiProtocol(
- Optional.ofNullable(aaiProtocol).filter(p -> !p.isEmpty()).orElse(aaiClientConfiguration.aaiProtocol()))
+ Optional.ofNullable(aaiProtocol).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiProtocol()))
.aaiUserName(
- Optional.ofNullable(aaiUserName).filter(p -> !p.isEmpty()).orElse(aaiClientConfiguration.aaiUserName()))
- .aaiUserPassword(Optional.ofNullable(aaiUserPassword).filter(p -> !p.isEmpty())
+ Optional.ofNullable(aaiUserName).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiUserName()))
+ .aaiUserPassword(Optional.ofNullable(aaiUserPassword).filter(isEmpty.negate())
.orElse(aaiClientConfiguration.aaiUserPassword()))
- .aaiBasePath(Optional.ofNullable(aaiBasePath).filter(p -> !p.isEmpty())
+ .aaiBasePath(Optional.ofNullable(aaiBasePath).filter(isEmpty.negate())
.orElse(aaiClientConfiguration.aaiBasePath()))
.aaiPnfPath(
- Optional.ofNullable(aaiPnfPath).filter(p -> !p.isEmpty()).orElse(aaiClientConfiguration.aaiPnfPath()))
+ Optional.ofNullable(aaiPnfPath).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiPnfPath()))
.aaiHeaders(aaiClientConfiguration.aaiHeaders())
.build();
}
@@ -176,25 +178,25 @@ public class AppConfig extends PrhAppConfig {
public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
return new ImmutableDmaapPublisherConfiguration.Builder()
.dmaapContentType(
- Optional.ofNullable(producerDmaapContentType).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapContentType).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapContentType()))
.dmaapHostName(
- Optional.ofNullable(producerDmaapHostName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapHostName).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapHostName()))
.dmaapPortNumber(
Optional.ofNullable(producerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapPortNumber()))
.dmaapProtocol(
- Optional.ofNullable(producerDmaapProtocol).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapProtocol).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapProtocol()))
.dmaapTopicName(
- Optional.ofNullable(producerDmaapTopicName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapTopicName).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapTopicName()))
.dmaapUserName(
- Optional.ofNullable(producerDmaapUserName).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapUserName).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapUserName()))
.dmaapUserPassword(
- Optional.ofNullable(producerDmaapUserPassword).filter(p -> !p.isEmpty())
+ Optional.ofNullable(producerDmaapUserPassword).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
.build();
}
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 6d24ade6..ab850044 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
@@ -49,7 +49,7 @@ public abstract class PrhAppConfig implements Config {
private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
- private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
AAIClientConfiguration aaiClientConfiguration;
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java
index ffa6b465..cb598226 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java
@@ -38,14 +38,14 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Profile("prod")
public class SwaggerConfig extends WebMvcConfigurationSupport {
- public static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh";
- public static final String API_TITLE = "PRH app server";
- public static final String DESCRIPTION = "This page lists all the rest apis for PRH app server.";
- public static final String VERSION = "1.0";
- public static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
- public static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
- public static final String SWAGGER_UI = "swagger-ui.html";
- public static final String WEBJARS = "/webjars/**";
+ private static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh";
+ private static final String API_TITLE = "PRH app server";
+ private static final String DESCRIPTION = "This page lists all the rest apis for PRH app server.";
+ private static final String VERSION = "1.0";
+ private static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
+ private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
+ private static final String SWAGGER_UI = "swagger-ui.html";
+ private static final String WEBJARS = "/webjars/**";
@Bean
public Docket api() {
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 8db4f0b6..989c6fb2 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
@@ -39,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(HeartbeatController.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
@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<>("alive", 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 a55cb108..418d7667 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
@@ -22,22 +22,16 @@ package org.onap.dcaegen2.services.prh.controllers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.onap.dcaegen2.services.prh.configuration.SchedulerConfig;
-import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.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
*/
@@ -45,7 +39,7 @@ import java.util.concurrent.ScheduledFuture;
@Api(value = "ScheduleController", description = "Schedule Controller")
public class ScheduleController {
- private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final SchedulerConfig schedulerConfig;
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java
new file mode 100644
index 00000000..e83a96e2
--- /dev/null
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java
@@ -0,0 +1,30 @@
+/*
+ * ============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.prh.exceptions;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/13/18
+ */
+public class DmaapEmptyResponseException extends PrhTaskException {
+
+ public DmaapEmptyResponseException() {
+ super();
+ }
+}
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..45597d05 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,6 +24,10 @@ package org.onap.dcaegen2.services.prh.exceptions;
*/
public class PrhTaskException extends Exception {
+ public PrhTaskException() {
+ super();
+ }
+
public PrhTaskException(String message) {
super(message);
}
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 ab4ec633..a62321ca 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
@@ -24,15 +24,20 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.Optional;
import java.util.stream.StreamSupport;
+import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException;
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.model.ImmutableConsumerDmaapModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
*/
public class DmaapConsumerJsonParser {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private static final String EVENT = "event";
private static final String OTHER_FIELDS = "otherFields";
private static final String PNF_OAM_IPV_4_ADDRESS = "pnfOamIpv4Address";
@@ -40,16 +45,21 @@ public class DmaapConsumerJsonParser {
private static final String PNF_VENDOR_NAME = "pnfVendorName";
private static final String PNF_SERIAL_NUMBER = "pnfSerialNumber";
- public Optional<ConsumerDmaapModel> getJsonObject(String message) throws DmaapNotFoundException {
+
+ public Optional<ConsumerDmaapModel> getJsonObject(String message)
+ throws PrhTaskException {
JsonElement jsonElement = new JsonParser().parse(message);
+ Optional<ConsumerDmaapModel> consumerDmaapModel;
if (jsonElement.isJsonObject()) {
- return Optional.of(create(jsonElement.getAsJsonObject()));
+ consumerDmaapModel = Optional.of(create(jsonElement.getAsJsonObject()));
} else {
- return Optional
+ consumerDmaapModel = Optional
.of(create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
.flatMap(this::getJsonObjectFromAnArray)
- .orElse(null)));
+ .orElseThrow(DmaapEmptyResponseException::new)));
}
+ logger.info("Parsed model from DmaaP after getting it: {}", consumerDmaapModel);
+ return consumerDmaapModel;
}
public Optional<JsonObject> getJsonObjectFromAnArray(JsonElement element) {
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 d0948aea..4c35b2ee 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
@@ -25,6 +25,7 @@ import org.onap.dcaegen2.services.prh.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.service.AAIConsumerClient;
import org.slf4j.Logger;
@@ -36,7 +37,7 @@ import org.springframework.stereotype.Component;
public class AAIConsumerTaskImpl extends
AAIConsumerTask<ConsumerDmaapModel, String, AAIClientConfiguration> {
- private static final Logger logger = LoggerFactory.getLogger(AAIConsumerTaskImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
private AAIConsumerClient aaiConsumerClient;
@@ -58,6 +59,14 @@ public class AAIConsumerTaskImpl extends
}
@Override
+ protected void receiveRequest(ConsumerDmaapModel body) throws PrhTaskException {
+ String response = execute(body);
+ if (taskProcess != null && response != null && !response.isEmpty()) {
+ taskProcess.receiveRequest(response);
+ }
+ }
+
+ @Override
public String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
.orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
@@ -67,7 +76,7 @@ public class AAIConsumerTaskImpl extends
}
@Override
- AAIClientConfiguration resolveConfiguration() {
+ protected AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
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 ba3fade7..b637bb29 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
@@ -23,6 +23,7 @@ import org.onap.dcaegen2.services.prh.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.service.AAIProducerClient;
import org.onap.dcaegen2.services.prh.service.HttpUtils;
@@ -41,7 +42,7 @@ import java.util.Optional;
public class AAIProducerTaskImpl extends
AAIProducerTask<ConsumerDmaapModel, ConsumerDmaapModel, AAIClientConfiguration> {
- private static final Logger logger = LoggerFactory.getLogger(AAIProducerTaskImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
private AAIProducerClient aaiProducerClient;
@@ -53,18 +54,26 @@ public class AAIProducerTaskImpl extends
@Override
ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
- logger.trace("Method called with arg {}", consumerDmaapModel);
+ logger.info("Sending PNF model to AAI {}", consumerDmaapModel);
try {
return aaiProducerClient.getHttpResponse(consumerDmaapModel)
.filter(HttpUtils::isSuccessfulResponseCode).map(response -> consumerDmaapModel).orElseThrow(() ->
new AAINotFoundException("Incorrect response code for continuation of tasks workflow"));
- } catch ( URISyntaxException e) {
+ } catch (URISyntaxException e) {
logger.warn("Patch request not successful", e);
throw new AAINotFoundException("Patch request not successful");
}
}
@Override
+ protected void receiveRequest(ConsumerDmaapModel body) throws PrhTaskException {
+ ConsumerDmaapModel response = execute(body);
+ if (taskProcess != null && response != null) {
+ taskProcess.receiveRequest(response);
+ }
+ }
+
+ @Override
public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
.orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
@@ -73,7 +82,7 @@ public class AAIProducerTaskImpl extends
return publish(consumerDmaapModel);
}
- AAIClientConfiguration resolveConfiguration() {
+ protected AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
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 fcadc483..3e36bcdd 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
@@ -19,7 +19,7 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
-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.consumer.ExtendedDmaapConsumerHttpClientImpl;
@@ -28,7 +28,7 @@ import org.onap.dcaegen2.services.prh.service.consumer.ExtendedDmaapConsumerHttp
*/
abstract class DmaapConsumerTask<R, S, C> extends Task<R, S, C> {
- abstract ConsumerDmaapModel consume(String message) throws DmaapNotFoundException;
+ abstract ConsumerDmaapModel consume(String message) throws PrhTaskException;
abstract ExtendedDmaapConsumerHttpClientImpl resolveClient();
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 9d818366..43eb9eaa 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
@@ -20,13 +20,13 @@
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;
import org.onap.dcaegen2.services.prh.configuration.Config;
+import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException;
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.prh.service.consumer.ExtendedDmaapConsumerHttpClientImpl;
import org.slf4j.Logger;
@@ -41,7 +41,7 @@ import org.springframework.stereotype.Component;
public class DmaapConsumerTaskImpl extends
DmaapConsumerTask<String, ConsumerDmaapModel, DmaapConsumerConfiguration> {
- private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
private ExtendedDmaapConsumerHttpClientImpl extendedDmaapConsumerHttpClient;
private DmaapConsumerJsonParser dmaapConsumerJsonParser;
@@ -57,12 +57,27 @@ public class DmaapConsumerTaskImpl extends
this.dmaapConsumerJsonParser = dmaapConsumerJsonParser;
}
+
@Override
- ConsumerDmaapModel consume(String message) throws DmaapNotFoundException {
- logger.trace("Method called with arg {}", message);
+ ConsumerDmaapModel consume(String message) throws PrhTaskException {
+ logger.info("Consumed model from DmaaP: {}", message);
return dmaapConsumerJsonParser.getJsonObject(message)
- .orElseThrow(() -> new DmaapNotFoundException(String.format("Nothing to consume from DmaaP %s topic.",
- resolveConfiguration().dmaapTopicName())));
+ .orElseThrow(() -> new DmaapNotFoundException("Null response from JSONObject in single reqeust"));
+
+ }
+
+ @Override
+ protected void receiveRequest(String body) throws PrhTaskException {
+ try {
+ ConsumerDmaapModel response = execute(body);
+ if (taskProcess != null && response != null) {
+ taskProcess.receiveRequest(response);
+ }
+ } catch (DmaapEmptyResponseException e) {
+ logger.warn("Nothing to consume from DmaaP {} topic.",
+ resolveConfiguration().dmaapTopicName());
+ }
+
}
@Override
@@ -79,7 +94,7 @@ public class DmaapConsumerTaskImpl extends
}
@Override
- DmaapConsumerConfiguration resolveConfiguration() {
+ protected DmaapConsumerConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapConsumerConfiguration();
}
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 6a514747..1a522921 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
@@ -24,6 +24,7 @@ import org.onap.dcaegen2.services.prh.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.prh.service.producer.ExtendedDmaapProducerHttpClientImpl;
import org.slf4j.Logger;
@@ -39,7 +40,7 @@ import org.springframework.stereotype.Component;
public class DmaapPublisherTaskImpl extends
DmaapPublisherTask<ConsumerDmaapModel, Integer, DmaapPublisherConfiguration> {
- private static final Logger logger = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
private ExtendedDmaapProducerHttpClientImpl extendedDmaapProducerHttpClient;
@@ -50,13 +51,22 @@ public class DmaapPublisherTaskImpl extends
@Override
Integer publish(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
- logger.trace("Method called with arg {}", consumerDmaapModel);
+ logger.info("Publishing on DmaaP topic {} object {}", resolveConfiguration().dmaapTopicName(),
+ consumerDmaapModel);
return extendedDmaapProducerHttpClient.getHttpProducerResponse(consumerDmaapModel)
.filter(response -> response == HttpStatus.OK.value())
.orElseThrow(() -> new DmaapNotFoundException("Incorrect response from Dmaap"));
}
@Override
+ protected void receiveRequest(ConsumerDmaapModel body) throws PrhTaskException {
+ Integer response = execute(body);
+ if (taskProcess != null && response != null) {
+ taskProcess.receiveRequest(response);
+ }
+ }
+
+ @Override
public Integer execute(ConsumerDmaapModel consumerDmaapModel) throws DmaapNotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
.orElseThrow(() -> new DmaapNotFoundException("Invoked null object to Dmaap task"));
@@ -66,7 +76,7 @@ public class DmaapPublisherTaskImpl extends
}
@Override
- DmaapPublisherConfiguration resolveConfiguration() {
+ 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 052de058..f7767101 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
@@ -31,7 +31,7 @@ import org.springframework.stereotype.Component;
@Component
public class ScheduledTasks {
- private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final DmaapConsumerTask dmaapConsumerTask;
private final DmaapPublisherTask 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 8aa01446..e2b11fdc 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
@@ -28,21 +28,15 @@ import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
public abstract class Task<R, S, C> {
- private Task taskProcess;
+ Task taskProcess;
- public void setNext(Task task) {
- this.taskProcess = task;
- }
-
- public void receiveRequest(R body) throws PrhTaskException {
+ abstract protected void receiveRequest(R body) throws PrhTaskException;
- S response = execute(body);
- if (taskProcess != null) {
- taskProcess.receiveRequest(response);
- }
- }
+ abstract protected S execute(R object) throws PrhTaskException;
- abstract S execute(R object) throws PrhTaskException;
+ abstract protected C resolveConfiguration();
- abstract C resolveConfiguration();
+ void setNext(Task task) {
+ this.taskProcess = task;
+ }
}