From 92f9c348d3e51f4032e858c6ae443b70a74e8699 Mon Sep 17 00:00:00 2001 From: wasala Date: Fri, 13 Apr 2018 14:03:26 +0200 Subject: Extracted high abstraction for tasks *First of all, all tasks were defined as implementation. *All tasks class have been injected into spring container. Change-Id: I00337b49ed1de3f1b8cadf64f774f19377ae349e Issue-ID: DCAEGEN2-443 Signed-off-by: wasala --- .../services/prh/configuration/PrhAppConfig.java | 2 +- .../prh/controllers/ScheduleController.java | 8 +-- .../prh/exceptions/AAINotFoundException.java | 2 +- .../prh/exceptions/DmaapNotFoundException.java | 30 ++++++++++ .../services/prh/exceptions/PrhTaskException.java | 30 ++++++++++ .../services/prh/tasks/AAIPublisherTask.java | 30 ++++++++++ .../services/prh/tasks/AAIPublisherTaskImpl.java | 60 ++++++++++++++++++++ .../services/prh/tasks/DmaapConsumerTask.java | 36 +++--------- .../services/prh/tasks/DmaapConsumerTaskImpl.java | 61 ++++++++++++++++++++ .../services/prh/tasks/DmaapPublisherTask.java | 31 ++++++++++ .../services/prh/tasks/DmaapPublisherTaskImpl.java | 59 +++++++++++++++++++ .../dcaegen2/services/prh/tasks/DmaapTask.java | 32 ----------- .../dcaegen2/services/prh/tasks/ScheduledTask.java | 59 ------------------- .../services/prh/tasks/ScheduledTasks.java | 66 ++++++++++++++++++++++ .../org/onap/dcaegen2/services/prh/tasks/Task.java | 32 +++++++++++ 15 files changed, 412 insertions(+), 126 deletions(-) create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java delete mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java delete mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java create mode 100644 prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java (limited to 'prh-app-server/src/main/java/org') 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 57335eff..19fcb8b8 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ 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 a0739637..99516c46 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 @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.prh.controllers; import java.util.concurrent.ScheduledFuture; -import org.onap.dcaegen2.services.prh.tasks.ScheduledTask; +import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,12 +40,12 @@ public class ScheduleController { private static final int SCHEDULING_DELAY = 20000; private final TaskScheduler taskScheduler; - private final ScheduledTask scheduledTask; + private final ScheduledTasks scheduledTask; private ScheduledFuture scheduledFuture; @Autowired - public ScheduleController(TaskScheduler taskScheduler, ScheduledTask scheduledTask) { + public ScheduleController(TaskScheduler taskScheduler, ScheduledTasks scheduledTask) { this.taskScheduler = taskScheduler; this.scheduledTask = scheduledTask; } @@ -54,7 +54,7 @@ public class ScheduleController { @RequestMapping(value = "preferences", method = RequestMethod.PUT) public ResponseEntity startTask() { scheduledFuture = taskScheduler - .scheduleWithFixedDelay(scheduledTask::scheduledTaskAskingDMaaPOfConsumeEvent, SCHEDULING_DELAY); + .scheduleWithFixedDelay(scheduledTask::scheduleMainPrhEventTask, SCHEDULING_DELAY); return new ResponseEntity<>(HttpStatus.OK); } 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 index e54d158e..a01abc56 100644 --- 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 @@ -22,7 +22,7 @@ package org.onap.dcaegen2.services.prh.exceptions; /** * @author Przemysław Wąsala on 3/23/18 */ -public class AAINotFoundException extends Exception { +public class AAINotFoundException extends PrhTaskException { public AAINotFoundException(String message) { super(message); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java new file mode 100644 index 00000000..af22284f --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.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 Przemysław Wąsala on 4/13/18 + */ +public class DmaapNotFoundException extends PrhTaskException { + + public DmaapNotFoundException(String message) { + super(message); + } +} 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 new file mode 100644 index 00000000..646ca7e7 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.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 Przemysław Wąsala on 4/13/18 + */ +public class PrhTaskException extends Exception { + + public PrhTaskException(String message) { + super(message); + } +} 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/AAIPublisherTask.java new file mode 100644 index 00000000..87a70810 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.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; + +/** + * @author Przemysław Wąsala on 4/13/18 + */ +public abstract class AAIPublisherTask implements 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/AAIPublisherTaskImpl.java new file mode 100644 index 00000000..d4efea4f --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java @@ -0,0 +1,60 @@ +/* + * ============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 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; + +/** + * @author Przemysław Wąsala on 4/13/18 + */ +@Component +public class AAIPublisherTaskImpl extends AAIPublisherTask { + + private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + @Autowired + public AppConfig prhAppConfig; + + @Override + protected void publish() { + logger.debug("Start task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + logger.debug("End task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + } + + @Override + public void execute() { + logger.debug("Start task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + } +} 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 2dc9b730..41031664 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 @@ -1,6 +1,6 @@ -/*- +/* * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER + * PROJECT * ================================================================================ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. * ================================================================================ @@ -19,34 +19,12 @@ */ 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; +import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; /** - * @author Przemysław Wąsala on 3/23/18 + * @author Przemysław Wąsala on 4/13/18 */ -@Component -public class DmaapConsumerTask implements DmaapTask { +public abstract class DmaapConsumerTask implements Task { - - 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())); - } -} \ No newline at end of file + protected abstract void consume() throws DmaapNotFoundException; +} 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 new file mode 100644 index 00000000..57f97778 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -0,0 +1,61 @@ +/*- + * ============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 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; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +@Component +public class DmaapConsumerTaskImpl extends DmaapConsumerTask { + + + private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.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())); + } + + @Override + protected void consume() { + logger.debug("Start task DmaapConsumerTask::consume() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + logger.debug("End task DmaapConsumerTask::consume() :: 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/DmaapPublisherTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java new file mode 100644 index 00000000..d203c8c5 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java @@ -0,0 +1,31 @@ +/*- + * ============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.DmaapNotFoundException; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +public abstract class DmaapPublisherTask implements Task { + + protected abstract void publish() throws DmaapNotFoundException; + +} 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 new file mode 100644 index 00000000..92eb875c --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java @@ -0,0 +1,59 @@ +/* + * ============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.configuration.AppConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Przemysław Wąsala on 4/13/18 + */ +@Component +public class DmaapPublisherTaskImpl extends DmaapPublisherTask { + + private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + @Autowired + public AppConfig prhAppConfig; + + @Override + public void execute() { + logger.debug("Start task DmaapPublisherTask::consume() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + logger.debug("End task DmaapPublisherTask::consume() :: Execution Time - {}", + dateTimeFormatter.format(LocalDateTime.now())); + } + + @Override + protected void publish() { + logger.debug("Start task DmaapPublisherTask::publish() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + + logger.debug("End task DmaapPublisherTask::publish() :: Execution Time - {}", + dateTimeFormatter.format(LocalDateTime.now())); + } +} 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 deleted file mode 100644 index 0032a3e1..00000000 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapTask.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============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; - -/** - * @author Przemysław Wąsala on 3/23/18 - */ -@FunctionalInterface -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 deleted file mode 100644 index b0466421..00000000 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTask.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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 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.stereotype.Component; - -/** - * @author Przemysław Wąsala on 3/23/18 - */ -@Component -public class ScheduledTask { - - 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(DmaapTask dmaapConsumerTask) { - this.dmaapConsumerTask = dmaapConsumerTask; - } - - public void scheduledTaskAskingDMaaPOfConsumeEvent() { - logger.debug("Task scheduledTaskAskingDMaaPOfConsumeEvent() :: Execution Time - {}", dateTimeFormatter.format( - LocalDateTime.now())); - try { - dmaapConsumerTask.execute(); - } catch (AAINotFoundException e) { - logger - .error("Task scheduledTaskAskingDMaaPOfConsumeEvent()::AAINotFoundException :: Execution Time - {}:{}", - dateTimeFormatter.format( - LocalDateTime.now()), e); - } - } - -} 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 new file mode 100644 index 00000000..713f5d48 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java @@ -0,0 +1,66 @@ +/*- + * ============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 java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Przemysław Wąsala on 3/23/18 + */ +@Component +public class ScheduledTasks { + + private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + + private final DmaapConsumerTask dmaapConsumerTask; + private final DmaapPublisherTask dmaapPublisherTask; + private final AAIPublisherTask aaiPublisherTask; + + @Autowired + public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask, + AAIPublisherTask aaiPublisherTask) { + this.dmaapConsumerTask = dmaapConsumerTask; + this.dmaapPublisherTask = dmaapPublisherTask; + this.aaiPublisherTask = aaiPublisherTask; + } + + public void scheduleMainPrhEventTask() { + logger.debug("Task scheduledTaskAskingDMaaPOfConsumeEvent() :: Execution Time - {}", dateTimeFormatter.format( + LocalDateTime.now())); + try { + dmaapConsumerTask.execute(); + dmaapPublisherTask.execute(); + aaiPublisherTask.execute(); + } catch (PrhTaskException e) { + logger + .error("Task scheduledTaskAskingDMaaPOfConsumeEvent()::PrhTaskException :: Execution Time - {}:{}", + dateTimeFormatter.format( + LocalDateTime.now()), e); + } + } + +} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java new file mode 100644 index 00000000..1bf8f6d3 --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/Task.java @@ -0,0 +1,32 @@ +/* + * ============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.PrhTaskException; + +/** + * @author Przemysław Wąsala on 4/13/18 + */ + +@FunctionalInterface +public interface Task { + + void execute() throws PrhTaskException; +} -- cgit 1.2.3-korg