From b80bcb81356fc9953e85196d8cbf6ada2ebbc143 Mon Sep 17 00:00:00 2001 From: wasala Date: Mon, 26 Mar 2018 15:48:46 +0200 Subject: Divide into module dependecy Add dependency build of dmaapClients and aaiClients. This modules are mandatory to prh application. Issue-ID: DCAEGEN2-407 Change-Id: I2150a15d76e81dd01503f44339ddb3c50f5b0348 Signed-off-by: wasala --- .../org/onap/dcaegen2/services/prh/MainApp.java | 40 ++++++++++++++ .../prh/exceptions/AAINotFoundException.java | 30 +++++++++++ .../services/prh/tasks/DmaapConsumerTask.java | 46 ++++++++++++++++ .../dcaegen2/services/prh/tasks/DmaapTask.java | 31 +++++++++++ .../dcaegen2/services/prh/tasks/ScheduledTask.java | 62 ++++++++++++++++++++++ prh-app-server/src/main/resources/application.yaml | 2 + .../dcaegen2/services/prh/ServerPrhAppTest.java | 31 +++++++++++ prh-app-server/src/test/resources/logback-test.xml | 33 ++++++++++++ 8 files changed, 275 insertions(+) create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java create mode 100644 prh-app-server/src/main/resources/application.yaml create mode 100644 prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/ServerPrhAppTest.java create mode 100644 prh-app-server/src/test/resources/logback-test.xml (limited to 'prh-app-server/src') 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 new file mode 100644 index 00000000..ebdf1bb4 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java @@ -0,0 +1,40 @@ +/*- + * ============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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +@SpringBootApplication +@Configuration +@ComponentScan +@EnableScheduling +public class MainApp { + + public static void main(String[] args) { + SpringApplication.run(MainApp.class, args); + } +} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java new file mode 100644 index 00000000..22dd24bd --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java @@ -0,0 +1,30 @@ +/*- + * ============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.exceptions; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +public class AAINotFoundException extends Exception { + + public AAINotFoundException(String message) { + super(message); + } +} 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 new file mode 100644 index 00000000..0d7ec225 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java @@ -0,0 +1,46 @@ +/*- + * ============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 java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +@Component +public class DmaapConsumerTask implements DmaapTask { + + private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTask.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + @Override + public void execute() { + logger.info("Start task DmaapConsumerTask::execute() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + //TODO: ADD implementation for executing request to consume topic from dmaap + + logger.info("End task DmaapConsumerTask::execute() :: Execution Time - {}", + dateTimeFormatter.format(LocalDateTime.now())); + } +} \ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java new file mode 100644 index 00000000..f5f8c284 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java @@ -0,0 +1,31 @@ +/*- + * ============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.prh.exceptions.AAINotFoundException; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +public interface DmaapTask { + + void execute() throws AAINotFoundException; + +} 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 new file mode 100644 index 00000000..006d44ea --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java @@ -0,0 +1,62 @@ +/*- + * ============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 java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +@Component +public class ScheduledTask { + + private static final int FIXED_DELAY = 1000; + private static final Logger logger = LoggerFactory.getLogger(ScheduledTask.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + private final DmaapTask dmaapConsumerTask; + + @Autowired + public ScheduledTask(DmaapConsumerTask dmaapConsumerTask) { + this.dmaapConsumerTask = dmaapConsumerTask; + } + + + @Scheduled(fixedDelay = FIXED_DELAY) + public void scheduledTaskAskingDMaaPOfConsumeEvent() { + logger.info("Task scheduledTaskAskingDMaaPOfConsumeEvent() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + try { + dmaapConsumerTask.execute(); + } catch (AAINotFoundException e) { + logger.warn("Task scheduledTaskAskingDMaaPOfConsumeEvent()::AAINotFoundException :: Execution Time - {}:{}", + dateTimeFormatter.format( + LocalDateTime.now()), e.getMessage()); + } + } + +} diff --git a/prh-app-server/src/main/resources/application.yaml b/prh-app-server/src/main/resources/application.yaml new file mode 100644 index 00000000..4d372c26 --- /dev/null +++ b/prh-app-server/src/main/resources/application.yaml @@ -0,0 +1,2 @@ +server: + port: 8100 \ No newline at end of file diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/ServerPrhAppTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/ServerPrhAppTest.java new file mode 100644 index 00000000..4373a50d --- /dev/null +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/ServerPrhAppTest.java @@ -0,0 +1,31 @@ +/*- + * ============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; + +import org.junit.jupiter.api.Test; + +class MainAppTest { + + @Test + void justAnExample() { + System.out.println("This test method should be run"); + } +} \ No newline at end of file diff --git a/prh-app-server/src/test/resources/logback-test.xml b/prh-app-server/src/test/resources/logback-test.xml new file mode 100644 index 00000000..0a53315a --- /dev/null +++ b/prh-app-server/src/test/resources/logback-test.xml @@ -0,0 +1,33 @@ + + + + + + + + %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n + + + + + + + + + -- cgit 1.2.3-korg