aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2018-04-12 21:43:29 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-12 21:43:29 +0000
commitfe084656d61212a7e4a5f6cc6f60b3eb6a146302 (patch)
tree94b7077f4a2ad0a0e4e469f39ffbbeb3cd220e21 /prh-app-server/src/main
parented8fc543198ec2a878f7e4e2966fa66a6c4986a9 (diff)
parent3c2e8c9c4c32ad59be75a7500e628344c6dab5bf (diff)
Merge "Already added loading config for AAI and DMAAP"
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java1
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java37
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java147
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java6
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java2
5 files changed, 191 insertions, 2 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
index 9a1fec28..2671669a 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
@@ -41,7 +41,6 @@ public class MainApp {
SpringApplication.run(MainApp.class, args);
}
-
@Bean
TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
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
new file mode 100644
index 00000000..59cf40da
--- /dev/null
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
@@ -0,0 +1,37 @@
+/*
+ * ============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.configuration;
+
+import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.config.DmaapProducerConfiguration;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ */
+public interface AppConfig {
+
+ DmaapConsumerConfiguration getDmaapConsumerConfiguration() throws Exception;
+
+ AAIHttpClientConfiguration getAAIHttpClientConfiguration() throws Exception;
+
+ DmaapProducerConfiguration getDmaapProducerConfiguration() throws Exception;
+
+}
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
new file mode 100644
index 00000000..57335eff
--- /dev/null
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
@@ -0,0 +1,147 @@
+/*-
+ * ============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.configuration;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.NullNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Optional;
+import javax.validation.constraints.NotEmpty;
+import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.config.DmaapProducerConfiguration;
+import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.config.ImmutableDmaapProducerConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ */
+@Configuration
+@EnableConfigurationProperties
+@ConfigurationProperties("app")
+public class PrhAppConfig implements AppConfig {
+
+ private static final String CONFIG = "configs";
+ private static final String AAI = "aai";
+ private static final String DMAAP = "dmaap";
+ private static final String AAI_CONFIG = "aaiHttpClientConfiguration";
+ private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
+ private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
+
+ private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class);
+ private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+
+ private ImmutableAAIHttpClientConfiguration immutableAAIHttpClientConfiguration;
+
+ private ImmutableDmaapConsumerConfiguration immutableDmaapConsumerConfiguration;
+
+ private ImmutableDmaapProducerConfiguration immutableDmaapProducerConfiguration;
+
+ @NotEmpty
+ private String filepath;
+
+ public void initFileStreamReader() {
+
+ ObjectMapper jsonObjectMapper = new ObjectMapper().registerModule(new Jdk8Module());
+ JsonNode jsonNode;
+ try (InputStream inputStream = getInputStream(filepath)) {
+ ObjectNode root = (ObjectNode) jsonObjectMapper.readTree(inputStream);
+ jsonNode = Optional.ofNullable(root.get(CONFIG).get(AAI).get(AAI_CONFIG)).orElse(NullNode.getInstance());
+ immutableAAIHttpClientConfiguration = jsonObjectMapper
+ .treeToValue(jsonNode, ImmutableAAIHttpClientConfiguration.class);
+ jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_CONSUMER))
+ .orElse(NullNode.getInstance());
+ immutableDmaapConsumerConfiguration = jsonObjectMapper
+ .treeToValue(jsonNode, ImmutableDmaapConsumerConfiguration.class);
+ jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_PRODUCER))
+ .orElse(NullNode.getInstance());
+ immutableDmaapProducerConfiguration = jsonObjectMapper
+ .treeToValue(jsonNode, ImmutableDmaapProducerConfiguration.class);
+ } catch (FileNotFoundException e) {
+ logger
+ .error(
+ "Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}",
+ dateTimeFormatter.format(
+ LocalDateTime.now()), e);
+ } catch (JsonParseException e) {
+ logger
+ .error(
+ "Configuration PrhAppConfig initFileStreamReader()::JsonParseException :: Execution Time - {}:{}",
+ dateTimeFormatter.format(
+ LocalDateTime.now()), e);
+ } catch (JsonMappingException e) {
+ logger
+ .error(
+ "Configuration PrhAppConfig initFileStreamReader()::JsonMappingException :: Execution Time - {}:{}",
+ dateTimeFormatter.format(
+ LocalDateTime.now()), e);
+ } catch (IOException e) {
+ logger
+ .error(
+ "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}",
+ dateTimeFormatter.format(
+ LocalDateTime.now()), e);
+ }
+ }
+
+ InputStream getInputStream(String filepath) throws FileNotFoundException {
+ return new BufferedInputStream(new FileInputStream(filepath));
+ }
+
+ String getFilepath() {
+ return this.filepath;
+ }
+
+ public void setFilepath(String filepath) {
+ this.filepath = filepath;
+ }
+
+ @Override
+ public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
+ return immutableDmaapConsumerConfiguration;
+ }
+
+ @Override
+ public AAIHttpClientConfiguration getAAIHttpClientConfiguration() {
+ return immutableAAIHttpClientConfiguration;
+ }
+
+ @Override
+ public DmaapProducerConfiguration getDmaapProducerConfiguration() {
+ return immutableDmaapProducerConfiguration;
+ }
+} \ 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 812f920c..2dc9b730 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
@@ -21,8 +21,10 @@ package org.onap.dcaegen2.services.prh.tasks;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -35,11 +37,15 @@ public class DmaapConsumerTask implements DmaapTask {
private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTask.class);
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+ @Autowired
+ public AppConfig prhAppConfig;
+
@Override
public void execute() {
logger.debug("Start task DmaapConsumerTask::execute() :: Execution Time - {}", dateTimeFormatter.format(
LocalDateTime.now()));
+
logger.debug("End task DmaapConsumerTask::execute() :: Execution Time - {}",
dateTimeFormatter.format(LocalDateTime.now()));
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java
index a8a0f0be..09bd5d8e 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java
@@ -52,7 +52,7 @@ public class ScheduledTask {
dmaapConsumerTask.execute();
} catch (AAINotFoundException e) {
logger
- .warn("Task scheduledTaskAskingDMaaPOfConsumeEvent()::AAINotFoundException :: Execution Time - {}:{}",
+ .error("Task scheduledTaskAskingDMaaPOfConsumeEvent()::AAINotFoundException :: Execution Time - {}:{}",
dateTimeFormatter.format(
LocalDateTime.now()), e);
}