diff options
author | pwielebs <piotr.wielebski@nokia.com> | 2018-04-26 17:04:09 +0200 |
---|---|---|
committer | pwielebs <piotr.wielebski@nokia.com> | 2018-04-27 15:38:11 +0200 |
commit | bf6fa5deff9190c14bba2b15271e44f1e3c21ee7 (patch) | |
tree | 2cd9ef8312df735e1fb00961911f417d6db86270 /prh-app-server | |
parent | c215daf12e5047f7292dfac124a7fac0411b169d (diff) |
AAI tasks added
- aaiClients spllitted for consuming and producing
- http removed from names of all clients and interfaces
- HttpRequestDetails added as a second parameter for tasks
- parameters required from dmaap consumer
- pnf-name for URI (get request -> aaiConsumer)
- pnf-name and ipv4-oam (and or ipv6-oam)
(patch request -> aaiProducer)
Change-Id: I87a1b46ab419cd00e9573e08c4d89cb384dd75b5
Issue-ID: DCAEGEN2-451
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-app-server')
18 files changed, 349 insertions, 169 deletions
diff --git a/prh-app-server/pom.xml b/prh-app-server/pom.xml index e804c3e6..cb85db11 100644 --- a/prh-app-server/pom.xml +++ b/prh-app-server/pom.xml @@ -232,6 +232,11 @@ <artifactId>prh-dmaap-client</artifactId> <version>${project.parent.version}</version> </dependency> + <dependency> + <groupId>org.onap.dcaegen2.services.prh</groupId> + <artifactId>prh-aai-client</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> </dependencies> <dependencyManagement> 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 76633d26..15db50e1 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,17 +19,13 @@ */ package org.onap.dcaegen2.services.prh.configuration; -import java.util.Optional; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; -import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; -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.ImmutableDmaapPublisherConfiguration; +import org.onap.dcaegen2.services.config.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; +import java.util.Optional; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 */ @@ -38,26 +34,26 @@ import org.springframework.stereotype.Component; @Configuration public class AppConfig extends PrhAppConfig { - @Value("${dmaap.dmaapConsumerConfiguration.dmmapHostName:}") - public String consumerDmmapHostName; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapHostName:}") + public String consumerDmaapHostName; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapPortNumber:}") - public Integer consumerDmmapPortNumber; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapPortNumber:}") + public Integer consumerDmaapPortNumber; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapTopicName:}") - public String consumerDmmapTopicName; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapTopicName:}") + public String consumerDmaapTopicName; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapProtocol:}") - public String consumerDmmapProtocol; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapProtocol:}") + public String consumerDmaapProtocol; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserName:}") - public String consumerDmmapUserName; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserName:}") + public String consumerDmaapUserName; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserPassword:}") - public String consumerDmmapUserPassword; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserPassword:}") + public String consumerDmaapUserPassword; - @Value("${dmaap.dmaapConsumerConfiguration.dmmapContentType:}") - public String consumerDmmapContentType; + @Value("${dmaap.dmaapConsumerConfiguration.dmaapContentType:}") + public String consumerDmaapContentType; @Value("${dmaap.dmaapConsumerConfiguration.consumerId:}") public String consumerId; @@ -71,26 +67,26 @@ public class AppConfig extends PrhAppConfig { @Value("${dmaap.dmaapConsumerConfiguration.message-limit:}") public Integer consumerMessageLimit; - @Value("${dmaap.dmaapProducerConfiguration.dmmapHostName:}") - public String producerDmmapHostName; + @Value("${dmaap.dmaapProducerConfiguration.dmaapHostName:}") + public String producerDmaapHostName; - @Value("${dmaap.dmaapProducerConfiguration.dmmapPortNumber:}") - public Integer producerDmmapPortNumber; + @Value("${dmaap.dmaapProducerConfiguration.dmaapPortNumber:}") + public Integer producerDmaapPortNumber; - @Value("${dmaap.dmaapProducerConfiguration.dmmapTopicName:}") - public String producerDmmapTopicName; + @Value("${dmaap.dmaapProducerConfiguration.dmaapTopicName:}") + public String producerDmaapTopicName; - @Value("${dmaap.dmaapProducerConfiguration.dmmapProtocol:}") - public String producerDmmapProtocol; + @Value("${dmaap.dmaapProducerConfiguration.dmaapProtocol:}") + public String producerDmaapProtocol; - @Value("${dmaap.dmaapProducerConfiguration.dmmapUserName:}") - public String producerDmmapUserName; + @Value("${dmaap.dmaapProducerConfiguration.dmaapUserName:}") + public String producerDmaapUserName; - @Value("${dmaap.dmaapProducerConfiguration.dmmapUserPassword:}") - public String producerDmmapUserPassword; + @Value("${dmaap.dmaapProducerConfiguration.dmaapUserPassword:}") + public String producerDmaapUserPassword; - @Value("${dmaap.dmaapProducerConfiguration.dmmapContentType:}") - public String producerDmmapContentType; + @Value("${dmaap.dmaapProducerConfiguration.dmaapContentType:}") + public String producerDmaapContentType; @Value("${aai.aaiHttpClientConfiguration.aaiHost:}") public String aaiHost; @@ -113,63 +109,63 @@ public class AppConfig extends PrhAppConfig { @Override public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { return new ImmutableDmaapConsumerConfiguration.Builder() - .dmaapUserPassword( - Optional.ofNullable(consumerDmmapUserPassword).orElse(dmaapConsumerConfiguration.dmaapUserPassword())) - .dmaapUserName( - Optional.ofNullable(consumerDmmapUserName).orElse(dmaapConsumerConfiguration.dmaapUserName())) - .dmaapHostName( - Optional.ofNullable(consumerDmmapHostName).orElse(dmaapConsumerConfiguration.dmaapHostName())) - .dmaapPortNumber( - Optional.ofNullable(consumerDmmapPortNumber).orElse(dmaapConsumerConfiguration.dmaapPortNumber())) - .dmaapProtocol( - Optional.ofNullable(consumerDmmapProtocol).orElse(dmaapConsumerConfiguration.dmaapProtocol())) - .dmaapContentType( - Optional.ofNullable(consumerDmmapContentType).orElse(dmaapConsumerConfiguration.dmaapContentType())) - .dmaapTopicName( - Optional.ofNullable(consumerDmmapTopicName).orElse(dmaapConsumerConfiguration.dmaapTopicName())) - .messageLimit( - Optional.ofNullable(consumerMessageLimit).orElse(dmaapConsumerConfiguration.messageLimit())) - .timeoutMS(Optional.ofNullable(consumerTimeoutMS).orElse(dmaapConsumerConfiguration.timeoutMS())) - .consumerGroup(Optional.ofNullable(consumerGroup).orElse(dmaapConsumerConfiguration.consumerGroup())) - .consumerId(Optional.ofNullable(consumerId).orElse(dmaapConsumerConfiguration.consumerId())) - .build(); + .dmaapUserPassword( + Optional.ofNullable(consumerDmaapUserPassword).orElse(dmaapConsumerConfiguration.dmaapUserPassword())) + .dmaapUserName( + Optional.ofNullable(consumerDmaapUserName).orElse(dmaapConsumerConfiguration.dmaapUserName())) + .dmaapHostName( + Optional.ofNullable(consumerDmaapHostName).orElse(dmaapConsumerConfiguration.dmaapHostName())) + .dmaapPortNumber( + Optional.ofNullable(consumerDmaapPortNumber).orElse(dmaapConsumerConfiguration.dmaapPortNumber())) + .dmaapProtocol( + Optional.ofNullable(consumerDmaapProtocol).orElse(dmaapConsumerConfiguration.dmaapProtocol())) + .dmaapContentType( + Optional.ofNullable(consumerDmaapContentType).orElse(dmaapConsumerConfiguration.dmaapContentType())) + .dmaapTopicName( + Optional.ofNullable(consumerDmaapTopicName).orElse(dmaapConsumerConfiguration.dmaapTopicName())) + .messageLimit( + Optional.ofNullable(consumerMessageLimit).orElse(dmaapConsumerConfiguration.messageLimit())) + .timeoutMS(Optional.ofNullable(consumerTimeoutMS).orElse(dmaapConsumerConfiguration.timeoutMS())) + .consumerGroup(Optional.ofNullable(consumerGroup).orElse(dmaapConsumerConfiguration.consumerGroup())) + .consumerId(Optional.ofNullable(consumerId).orElse(dmaapConsumerConfiguration.consumerId())) + .build(); } @Override - public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { - return new ImmutableAAIHttpClientConfiguration.Builder() - .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiHttpClientConfiguration.aaiHost())) - .aaiHostPortNumber( - Optional.ofNullable(aaiHostPortNumber).orElse(aaiHttpClientConfiguration.aaiHostPortNumber())) - .aaiIgnoreSSLCertificateErrors( - Optional.ofNullable(aaiIgnoreSSLCertificateErrors) - .orElse(aaiHttpClientConfiguration.aaiIgnoreSSLCertificateErrors())) - .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiHttpClientConfiguration.aaiProtocol())) - .aaiUserName( - Optional.ofNullable(aaiUserName).orElse(aaiHttpClientConfiguration.aaiUserName())) - .aaiUserPassword(Optional.ofNullable( - aaiUserPassword).orElse(aaiHttpClientConfiguration.aaiUserPassword())) - .build(); + public AAIClientConfiguration getAAIClientConfiguration() { + return new ImmutableAAIClientConfiguration.Builder() + .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiClientConfiguration.aaiHost())) + .aaiHostPortNumber( + Optional.ofNullable(aaiHostPortNumber).orElse(aaiClientConfiguration.aaiHostPortNumber())) + .aaiIgnoreSSLCertificateErrors( + Optional.ofNullable(aaiIgnoreSSLCertificateErrors) + .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors())) + .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiClientConfiguration.aaiProtocol())) + .aaiUserName( + Optional.ofNullable(aaiUserName).orElse(aaiClientConfiguration.aaiUserName())) + .aaiUserPassword(Optional.ofNullable( + aaiUserPassword).orElse(aaiClientConfiguration.aaiUserPassword())) + .build(); } @Override public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { return new ImmutableDmaapPublisherConfiguration.Builder() - .dmaapContentType( - Optional.ofNullable(producerDmmapContentType).orElse(dmaapPublisherConfiguration.dmaapContentType())) - .dmaapHostName( - Optional.ofNullable(producerDmmapHostName).orElse(dmaapPublisherConfiguration.dmaapHostName())) - .dmaapPortNumber( - Optional.ofNullable(producerDmmapPortNumber).orElse(dmaapPublisherConfiguration.dmaapPortNumber())) - .dmaapProtocol( - Optional.ofNullable(producerDmmapProtocol).orElse(dmaapPublisherConfiguration.dmaapProtocol())) - .dmaapTopicName( - Optional.ofNullable(producerDmmapTopicName).orElse(dmaapPublisherConfiguration.dmaapTopicName())) - .dmaapUserName( - Optional.ofNullable(producerDmmapUserName).orElse(dmaapPublisherConfiguration.dmaapUserName())) - .dmaapUserPassword( - Optional.ofNullable(producerDmmapUserPassword).orElse(dmaapPublisherConfiguration.dmaapUserPassword())) - .build(); + .dmaapContentType( + Optional.ofNullable(producerDmaapContentType).orElse(dmaapPublisherConfiguration.dmaapContentType())) + .dmaapHostName( + Optional.ofNullable(producerDmaapHostName).orElse(dmaapPublisherConfiguration.dmaapHostName())) + .dmaapPortNumber( + Optional.ofNullable(producerDmaapPortNumber).orElse(dmaapPublisherConfiguration.dmaapPortNumber())) + .dmaapProtocol( + Optional.ofNullable(producerDmaapProtocol).orElse(dmaapPublisherConfiguration.dmaapProtocol())) + .dmaapTopicName( + Optional.ofNullable(producerDmaapTopicName).orElse(dmaapPublisherConfiguration.dmaapTopicName())) + .dmaapUserName( + Optional.ofNullable(producerDmaapUserName).orElse(dmaapPublisherConfiguration.dmaapUserName())) + .dmaapUserPassword( + Optional.ofNullable(producerDmaapUserPassword).orElse(dmaapPublisherConfiguration.dmaapUserPassword())) + .build(); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java index 8dd2bf3b..605a1bd7 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java @@ -19,7 +19,7 @@ */ package org.onap.dcaegen2.services.prh.configuration; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; @@ -30,7 +30,7 @@ public interface Config { DmaapConsumerConfiguration getDmaapConsumerConfiguration(); - AAIHttpClientConfiguration getAAIHttpClientConfiguration(); + AAIClientConfiguration getAAIClientConfiguration(); 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 8720cf47..0473c1aa 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 @@ -19,24 +19,8 @@ */ package org.onap.dcaegen2.services.prh.configuration; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; -import com.google.gson.TypeAdapterFactory; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ServiceLoader; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; +import com.google.gson.*; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; import org.slf4j.Logger; @@ -45,6 +29,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.*; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ServiceLoader; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 */ @@ -63,7 +54,7 @@ public abstract class PrhAppConfig implements Config { private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - AAIHttpClientConfiguration aaiHttpClientConfiguration; + AAIClientConfiguration aaiClientConfiguration; DmaapConsumerConfiguration dmaapConsumerConfiguration; @@ -79,8 +70,8 @@ public abstract class PrhAppConfig implements Config { } @Override - public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { - return aaiHttpClientConfiguration; + public AAIClientConfiguration getAAIClientConfiguration() { + return aaiClientConfiguration; } @Override @@ -99,41 +90,41 @@ public abstract class PrhAppConfig implements Config { JsonElement rootElement = parser.parse(new InputStreamReader(inputStream)); if (rootElement.isJsonObject()) { jsonObject = rootElement.getAsJsonObject(); - aaiHttpClientConfiguration = deserializeType(gsonBuilder, - jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG), - AAIHttpClientConfiguration.class); + aaiClientConfiguration = deserializeType(gsonBuilder, + jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG), + AAIClientConfiguration.class); dmaapConsumerConfiguration = deserializeType(gsonBuilder, - jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER), - DmaapConsumerConfiguration.class); + jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER), + DmaapConsumerConfiguration.class); dmaapPublisherConfiguration = deserializeType(gsonBuilder, - jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER), - DmaapPublisherConfiguration.class); + jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER), + DmaapPublisherConfiguration.class); } } catch (FileNotFoundException e) { logger - .error( - "Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}", - dateTimeFormatter.format( - LocalDateTime.now()), e); + .error( + "Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}", + dateTimeFormatter.format( + LocalDateTime.now()), e); } catch (IOException e) { logger - .error( - "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}", - dateTimeFormatter.format( - LocalDateTime.now()), e); + .error( + "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}", + dateTimeFormatter.format( + LocalDateTime.now()), e); } catch (JsonSyntaxException e) { logger - .error( - "Configuration PrhAppConfig initFileStreamReader()::JsonSyntaxException :: Execution Time - {}:{}", - dateTimeFormatter.format( - LocalDateTime.now()), e); + .error( + "Configuration PrhAppConfig initFileStreamReader()::JsonSyntaxException :: Execution Time - {}:{}", + dateTimeFormatter.format( + LocalDateTime.now()), e); } } private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject, - @NotNull Class<T> type) { + @NotNull Class<T> type) { return gsonBuilder.create().fromJson(jsonObject, type); } 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 95b360e1..b91b56c5 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 @@ -21,6 +21,7 @@ package org.onap.dcaegen2.services.prh.controllers; 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 6f08dd8a..733b7dfc 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 @@ -24,6 +24,7 @@ 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/tasks/AAIConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java new file mode 100644 index 00000000..5a3afd86 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.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.tasks; + +import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; + +public abstract class AAIConsumerTask<T> extends Task { + + protected abstract void consume() throws AAINotFoundException; + + protected abstract T resolveConfiguration(); +} 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 new file mode 100644 index 00000000..64ccad5c --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java @@ -0,0 +1,89 @@ +/*- + * ============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.tasks; + +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> { + + private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + private final Config prhAppConfig; + private final HttpRequestDetails requestDetails; + private AAIProducerClient producerClient; + public Optional<String> response; + + @Autowired + public AAIConsumerTaskImpl(AppConfig prhAppConfig, HttpRequestDetails requestDetails) { + this.prhAppConfig = prhAppConfig; + this.requestDetails = requestDetails; + } + + @Override + protected void consume() throws AAINotFoundException { + logger.debug("Start task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + + producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration()); + + response = producerClient.getHttpResponse(requestDetails); + + logger.debug("End task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + } + + @Override + public ResponseEntity execute(Object object) throws AAINotFoundException { + logger.debug("Start task AAIProducerTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + consume(); + logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + return null; + } + + @Override + void initConfigs() { + } + + @Override + protected AAIClientConfiguration resolveConfiguration() { + return prhAppConfig.getAAIClientConfiguration(); + } +} 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/AAIProducerTask.java index 8ea4ac8f..787e614d 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/AAIProducerTask.java @@ -24,7 +24,7 @@ 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<T> extends Task { +public abstract class AAIProducerTask<T> extends Task { protected abstract void publish() throws AAINotFoundException; 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/AAIProducerTaskImpl.java index aa452047..a5d173ba 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/AAIProducerTaskImpl.java @@ -19,48 +19,61 @@ */ 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.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; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @Component -public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfiguration> { +public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration> { private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); private final Config prhAppConfig; + private AAIProducerClient producerClient; + private HttpRequestDetails requestDetails; + private String jsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}"; + private String pnfName = "example-pnf-name-val-40510"; // pnf name received from dmaap required for URI + public Optional<String> response; @Autowired - public AAIPublisherTaskImpl(AppConfig prhAppConfig) { + public AAIProducerTaskImpl(AppConfig prhAppConfig, HttpRequestDetails requestDetails) { this.prhAppConfig = prhAppConfig; - + this.requestDetails = requestDetails; } @Override protected void publish() throws AAINotFoundException { - logger.debug("Start task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + logger.debug("Start task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); - prhAppConfig.getAAIHttpClientConfiguration(); - logger.debug("End task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + + producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration()); + + response = producerClient.getHttpResponse(requestDetails); + + logger.debug("End task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); } @Override public ResponseEntity execute(Object object) throws AAINotFoundException { - logger.debug("Start task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( + logger.debug("Start task AAIProducerTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( LocalDateTime.now())); publish(); logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( @@ -73,8 +86,8 @@ public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfigur } @Override - protected AAIHttpClientConfiguration resolveConfiguration() { - return prhAppConfig.getAAIHttpClientConfiguration(); + protected AAIClientConfiguration resolveConfiguration() { + return prhAppConfig.getAAIClientConfiguration(); } } 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 0db49f7c..eb66361d 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,8 +19,6 @@ */ 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.onap.dcaegen2.services.prh.configuration.Config; @@ -30,6 +28,9 @@ 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; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ 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 072f9c7d..ff5f5893 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,8 +19,6 @@ */ 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.onap.dcaegen2.services.prh.configuration.Config; @@ -30,6 +28,9 @@ 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; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ 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 c051afbc..2922da1a 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 @@ -39,14 +39,16 @@ public class ScheduledTasks { private final Task dmaapConsumerTask; private final Task dmaapProducerTask; - private final Task aaiPublisherTask; + private final Task aaiProducerTask; + private final Task aaiConsumerTask; @Autowired public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask, - AAIPublisherTask aaiPublisherTask) { + AAIProducerTask aaiPublisherTask, AAIConsumerTask aaiConsumerTask) { this.dmaapConsumerTask = dmaapConsumerTask; this.dmaapProducerTask = dmaapPublisherTask; - this.aaiPublisherTask = aaiPublisherTask; + this.aaiProducerTask = aaiPublisherTask; + this.aaiConsumerTask = aaiConsumerTask; } public void scheduleMainPrhEventTask() { @@ -65,8 +67,10 @@ public class ScheduledTasks { } private void setTaskExecutionFlow() { - dmaapConsumerTask.setNext(aaiPublisherTask); - aaiPublisherTask.setNext(dmaapProducerTask); + dmaapConsumerTask.setNext(aaiProducerTask); + aaiProducerTask.setNext(dmaapProducerTask); + aaiConsumerTask.setNext(aaiConsumerTask); + dmaapProducerTask.setNext(dmaapConsumerTask); } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java index faecec4d..8094c993 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java @@ -23,19 +23,15 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; -import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; +import org.onap.dcaegen2.services.utils.HttpRequestDetails; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -77,6 +73,11 @@ class ServiceMockProvider { public PrhAppConfig getPrhAppConfig() { return mock(PrhAppConfig.class); } + + @Bean + public HttpRequestDetails getRequestDetails() { + return mock(HttpRequestDetails.class); + } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java index 764bafec..e7d55419 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java @@ -88,13 +88,13 @@ class PrhAppConfigTest { prhAppConfig.initFileStreamReader(); appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration(); appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration(); - appConfig.aaiHttpClientConfiguration = prhAppConfig.getAAIHttpClientConfiguration(); + appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration(); // // Then // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(prhAppConfig.getAAIHttpClientConfiguration()); + Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration()); Assertions @@ -102,7 +102,7 @@ class PrhAppConfigTest { Assertions .assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration()); Assertions - .assertEquals(appConfig.getAAIHttpClientConfiguration(), prhAppConfig.getAAIHttpClientConfiguration()); + .assertEquals(appConfig.getAAIClientConfiguration(), prhAppConfig.getAAIClientConfiguration()); } @@ -122,7 +122,7 @@ class PrhAppConfigTest { // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNull(prhAppConfig.getAAIHttpClientConfiguration()); + Assertions.assertNull(prhAppConfig.getAAIClientConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); @@ -147,7 +147,7 @@ class PrhAppConfigTest { // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(prhAppConfig.getAAIHttpClientConfiguration()); + Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java new file mode 100644 index 00000000..57c3ce21 --- /dev/null +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * 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.tasks; + +import org.onap.dcaegen2.services.config.AAIClientConfiguration; + +import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.utils.HttpRequestDetails; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import static org.mockito.Mockito.*; + + +@Configuration +public class AAIConsumerTaskSpy { + + @Bean + @Primary + public AAIConsumerTask registerSimpleAAIPublisherTask() { + AppConfig appConfig = mock(AppConfig.class); + HttpRequestDetails requestDetails = mock(HttpRequestDetails.class); + when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class)); + return spy(new AAIConsumerTaskImpl(appConfig, requestDetails)); + } +}
\ No newline at end of file diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java index c27c8813..8da7f85d 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java @@ -19,16 +19,15 @@ */ package org.onap.dcaegen2.services.prh.tasks; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.utils.HttpRequestDetails; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import static org.mockito.Mockito.*; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @@ -37,9 +36,10 @@ public class AAIPublisherTaskSpy { @Bean @Primary - public AAIPublisherTask registerSimpleAAIPublisherTask() { + public AAIProducerTask registerSimpleAAIPublisherTask() { AppConfig appConfig = mock(AppConfig.class); - when(appConfig.getAAIHttpClientConfiguration()).thenReturn(mock(AAIHttpClientConfiguration.class)); - return spy(new AAIPublisherTaskImpl(appConfig)); + HttpRequestDetails requestDetails = mock(HttpRequestDetails.class); + when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class)); + return spy(new AAIProducerTaskImpl(appConfig, requestDetails)); } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java index 2d599b23..606b0cb8 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java @@ -40,11 +40,14 @@ public class ScheduleControllerSpy { private DmaapPublisherTask dmaapPublisherTaskImplSpy; @Autowired - private AAIPublisherTask aaiPublisherTaskImplSpy; + private AAIProducerTask aaiPublisherTaskImplSpy; + + @Autowired + private AAIConsumerTask aaiConsumerTaskImplSpy; @Bean @Primary public ScheduledTasks registerSimpleScheduledTask() { - return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy)); + return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy, aaiConsumerTaskImplSpy)); } } |