Search in sources :

Example 1 with ScheduledLogging

use of org.onap.logging.filter.base.ScheduledLogging in project so by onap.

the class ScheduledDnsLookup method performDnsLookup.

@ScheduledLogging
@Scheduled(fixedRate = 15000)
public void performDnsLookup() throws ScheduledTaskException {
    String dnsUrl = System.getenv(DB_HOST);
    try {
        if (dnsUrl == null) {
            throw new ScheduledTaskException(ErrorCode.DataError, "Database DNS is not provided. Please verify the configuration");
        }
        InetAddress inetAddress = java.net.InetAddress.getByName(dnsUrl);
        String ipAddress = inetAddress.getHostAddress();
        String currentIpAddress = dnsIpAddress.getIpAddress();
        /* This is in initial state */
        if (currentIpAddress == null) {
            dnsIpAddress.setIpAddress(ipAddress);
            return;
        }
        if ((ipAddress != null) && (!ipAddress.equalsIgnoreCase(currentIpAddress))) {
            logger.debug("Switched Database IP Address from {} to {}", currentIpAddress, ipAddress);
            softEvictConnectionPool();
            dnsIpAddress.setIpAddress(ipAddress);
        }
    } catch (UnknownHostException e) {
        logger.warn("Database DNS %s is not resolvable to an IP Address", dnsUrl);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ScheduledTaskException(org.onap.logging.filter.base.ScheduledTaskException) InetAddress(java.net.InetAddress) Scheduled(org.springframework.scheduling.annotation.Scheduled) ScheduledLogging(org.onap.logging.filter.base.ScheduledLogging)

Example 2 with ScheduledLogging

use of org.onap.logging.filter.base.ScheduledLogging in project so by onap.

the class ArchiveInfraRequestsScheduler method infraRequestsScheduledTask.

/**
 * 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() throws ScheduledTaskException {
    logger.debug("Start of archiveInfraRequestsScheduler");
    Date currentDate = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);
    calendar.add(Calendar.DATE, -archivedPeriod);
    Date archivingDate = calendar.getTime();
    logger.debug("Date before 6 months: " + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE) + "-" + calendar.get(Calendar.YEAR));
    List<InfraActiveRequests> requestsByEndTime = new ArrayList<>();
    // Could use sorting here
    PageRequest pageRequest = PageRequest.of(0, 100);
    do {
        requestsByEndTime = infraActiveRepo.findByEndTimeLessThan(archivingDate, pageRequest);
        logger.debug("{} requests to be archived based on End Time", requestsByEndTime.size());
        archiveInfraRequests(requestsByEndTime);
    } while (!requestsByEndTime.isEmpty());
    List<InfraActiveRequests> requestsByStartTime = new ArrayList<>();
    do {
        requestsByStartTime = infraActiveRepo.findByStartTimeLessThanAndEndTime(archivingDate, null, pageRequest);
        logger.debug("{} requests to be archived based on Start Time", requestsByEndTime.size());
        archiveInfraRequests(requestsByStartTime);
    } while (!requestsByStartTime.isEmpty());
    logger.debug("End of archiveInfraRequestsScheduler");
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled) ScheduledLogging(org.onap.logging.filter.base.ScheduledLogging) SchedulerLock(net.javacrumbs.shedlock.core.SchedulerLock)

Example 3 with ScheduledLogging

use of org.onap.logging.filter.base.ScheduledLogging in project so by onap.

the class ASDCControllerSingleton method periodicControllerTask.

@ScheduledLogging
@Scheduled(fixedRate = 50000)
public void periodicControllerTask() throws ScheduledTaskException {
    try {
        final int randomNumber = new SecureRandom().nextInt(Integer.MAX_VALUE);
        asdcController.setControllerName("mso-controller" + randomNumber);
        if (asdcController.isStopped()) {
            logger.info("{} not running will try to initialize it, currrent status: {}", asdcController.getClass().getName(), asdcController.getControllerStatus());
            asdcController.initASDC();
        }
    } catch (final ASDCControllerException controllerException) {
        throw new ScheduledTaskException(ErrorCode.UnknownError, controllerException.getMessage(), controllerException);
    }
}
Also used : ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) SecureRandom(java.security.SecureRandom) ScheduledTaskException(org.onap.logging.filter.base.ScheduledTaskException) Scheduled(org.springframework.scheduling.annotation.Scheduled) ScheduledLogging(org.onap.logging.filter.base.ScheduledLogging)

Aggregations

ScheduledLogging (org.onap.logging.filter.base.ScheduledLogging)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)3 ScheduledTaskException (org.onap.logging.filter.base.ScheduledTaskException)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 SchedulerLock (net.javacrumbs.shedlock.core.SchedulerLock)1 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)1 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)1 PageRequest (org.springframework.data.domain.PageRequest)1