From 0d63836c2eaa7267d55a4757fd83ea1b4b1c8bb2 Mon Sep 17 00:00:00 2001 From: "Plummer, Brittany" Date: Wed, 4 Mar 2020 21:19:08 -0500 Subject: create custom spring aop annotation for logging Added annotation for setting up scheduled tasks logs Added new annotation to scheduledTasks Moved annotation setup to logging-library Issue-ID: SO-2713 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I7080c4bb289e454f14167631e2601c954389c0ef --- .../requestsdb/ArchiveInfraRequestsScheduler.java | 26 ++++++++-------------- .../requestsdb/MsoRequestsDbAdapterImpl.java | 2 +- .../exceptions/MsoRequestsDbException.java | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) (limited to 'adapters/mso-requests-db-adapter/src/main/java/org') diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java index 24dab2fc5b..a092099bfb 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java @@ -27,19 +27,15 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; -import org.onap.logging.filter.base.ONAPComponents; -import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.data.repository.ArchivedInfraRequestsRepository; import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; -import org.onap.so.logger.ErrorCode; -import org.onap.so.logger.LoggingAnchor; -import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.ScheduledTasksMDCSetup; +import org.onap.logging.filter.base.ErrorCode; +import org.onap.logging.filter.base.ScheduledLogging; +import org.onap.logging.filter.base.ScheduledTaskException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.PageRequest; @@ -56,8 +52,6 @@ public class ArchiveInfraRequestsScheduler { private InfraActiveRequestsRepository infraActiveRepo; @Autowired private ArchivedInfraRequestsRepository archivedInfraRepo; - @Autowired - private ScheduledTasksMDCSetup scheduledMDCSetup; @Value("${mso.infra-requests.archived.period}") @@ -65,11 +59,13 @@ public class ArchiveInfraRequestsScheduler { /** * Runs the scheduler nightly [Seconds] [Minutes] [Hours] [Day of month] [Month] [Day of week] [Year] + * + * @throws ScheduledTaskException */ + @ScheduledLogging @Scheduled(cron = "0 0 1 * * ?") @SchedulerLock(name = "archiveInfraRequestsScheduler") - public void infraRequestsScheduledTask() { - scheduledMDCSetup.mdcSetup(ONAPComponents.REQUEST_DB, "infraRequestsScheduledTask"); + public void infraRequestsScheduledTask() throws ScheduledTaskException { logger.debug("Start of archiveInfraRequestsScheduler"); Date currentDate = new Date(); @@ -97,10 +93,9 @@ public class ArchiveInfraRequestsScheduler { } while (!requestsByStartTime.isEmpty()); logger.debug("End of archiveInfraRequestsScheduler"); - scheduledMDCSetup.exitAndClearMDC(); } - protected void archiveInfraRequests(List requests) { + protected void archiveInfraRequests(List requests) throws ScheduledTaskException { List newArchivedReqs = new ArrayList<>(); List oldInfraReqs = new ArrayList<>(); @@ -151,10 +146,7 @@ public class ArchiveInfraRequestsScheduler { newArchivedReqs.add(archivedInfra); oldInfraReqs.add(iar); } catch (Exception e) { - scheduledMDCSetup.errorMDCSetup(ErrorCode.UnknownError, e.getMessage()); - MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString()); - logger.error(LoggingAnchor.TWO, MessageEnum.RA_GENERAL_EXCEPTION.toString(), - ErrorCode.UnknownError.getValue(), e); + throw new ScheduledTaskException(ErrorCode.UnknownError, e.getMessage(), e); } } diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java index 052a53bb1f..b262cb21cb 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java @@ -39,7 +39,7 @@ import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; import org.onap.so.db.request.data.repository.SiteStatusRepository; import org.onap.so.db.request.data.repository.InstanceNfvoMappingRepository; -import org.onap.so.logger.ErrorCode; +import org.onap.logging.filter.base.ErrorCode; import org.onap.so.requestsdb.RequestsDbConstant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java index 27580977b8..e1e629008d 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java @@ -24,7 +24,7 @@ package org.onap.so.adapters.requestsdb.exceptions; import javax.xml.ws.WebFault; import org.onap.so.exceptions.MSOException; -import org.onap.so.logger.ErrorCode; +import org.onap.logging.filter.base.ErrorCode; /** * This class simply extends Exception (without addition additional functionality) to provide an identifier for -- cgit 1.2.3-korg