Search in sources :

Example 21 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class RealtimePlumber method startPersistThread.

protected void startPersistThread() {
    final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity();
    final Period windowPeriod = config.getWindowPeriod();
    final DateTime truncatedNow = segmentGranularity.bucketStart(new DateTime());
    final long windowMillis = windowPeriod.toStandardDuration().getMillis();
    log.info("Expect to run at [%s]", new DateTime().plus(new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis)));
    ScheduledExecutors.scheduleAtFixedRate(scheduledExecutor, new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis), new Duration(truncatedNow, segmentGranularity.increment(truncatedNow)), new ThreadRenamingCallable<ScheduledExecutors.Signal>(String.format("%s-overseer-%d", schema.getDataSource(), config.getShardSpec().getPartitionNum())) {

        @Override
        public ScheduledExecutors.Signal doCall() {
            if (stopped) {
                log.info("Stopping merge-n-push overseer thread");
                return ScheduledExecutors.Signal.STOP;
            }
            mergeAndPush();
            if (stopped) {
                log.info("Stopping merge-n-push overseer thread");
                return ScheduledExecutors.Signal.STOP;
            } else {
                return ScheduledExecutors.Signal.REPEAT;
            }
        }
    });
}
Also used : Period(org.joda.time.Period) Duration(org.joda.time.Duration) Granularity(io.druid.java.util.common.granularity.Granularity) DateTime(org.joda.time.DateTime)

Example 22 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class FileRequestLogger method start.

@LifecycleStart
public void start() {
    try {
        baseDir.mkdirs();
        MutableDateTime mutableDateTime = new DateTime().toMutableDateTime();
        mutableDateTime.setMillisOfDay(0);
        synchronized (lock) {
            currentDay = mutableDateTime.toDateTime();
            fileWriter = getFileWriter();
        }
        long nextDay = currentDay.plusDays(1).getMillis();
        Duration delay = new Duration(nextDay - new DateTime().getMillis());
        ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() {

            @Override
            public ScheduledExecutors.Signal call() {
                try {
                    synchronized (lock) {
                        currentDay = currentDay.plusDays(1);
                        CloseQuietly.close(fileWriter);
                        fileWriter = getFileWriter();
                    }
                } catch (Exception e) {
                    Throwables.propagate(e);
                }
                return ScheduledExecutors.Signal.REPEAT;
            }
        });
    } catch (IOException e) {
        Throwables.propagate(e);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Duration(org.joda.time.Duration) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LifecycleStart(io.druid.java.util.common.lifecycle.LifecycleStart)

Example 23 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class CoordinatorRuleManager method start.

@LifecycleStart
public void start() {
    synchronized (lock) {
        if (started) {
            return;
        }
        this.exec = Execs.scheduledSingleThreaded("CoordinatorRuleManager-Exec--%d");
        ScheduledExecutors.scheduleWithFixedDelay(exec, new Duration(0), config.get().getPollPeriod().toStandardDuration(), new Runnable() {

            @Override
            public void run() {
                poll();
            }
        });
        started = true;
    }
}
Also used : Duration(org.joda.time.Duration) LifecycleStart(io.druid.java.util.common.lifecycle.LifecycleStart)

Example 24 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class RetryPolicy method getAndIncrementRetryDelay.

public Duration getAndIncrementRetryDelay() {
    if (hasExceededRetryThreshold()) {
        return null;
    }
    Duration retVal = currRetryDelay;
    currRetryDelay = new Duration(Math.min(currRetryDelay.getMillis() * 2, maxRetryDelay.getMillis()));
    ++retryCount;
    return retVal;
}
Also used : Duration(org.joda.time.Duration)

Example 25 with Duration

use of org.joda.time.Duration in project opennms by OpenNMS.

the class DefaultProvisionService method createScheduleForNode.

private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
    Assert.notNull(node, "Node may not be null");
    final String actualForeignSource = node.getForeignSource();
    if (actualForeignSource == null && !isDiscoveryEnabled()) {
        LOG.info("Not scheduling node {} to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond", node);
        return null;
    }
    final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource;
    try {
        final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);
        final Duration scanInterval = fs.getScanInterval();
        if (scanInterval.getMillis() <= 0) {
            LOG.debug("Node ({}/{}/{}) scan interval is zero, skipping schedule.", node.getId(), node.getForeignSource(), node.getForeignId());
            return null;
        }
        Duration initialDelay = Duration.ZERO;
        if (node.getLastCapsdPoll() != null && !force) {
            final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
            final DateTime now = new DateTime();
            if (nextPoll.isAfter(now)) {
                initialDelay = new Duration(now, nextPoll);
            }
        }
        return new NodeScanSchedule(node.getId(), actualForeignSource, node.getForeignId(), node.getLocation(), initialDelay, scanInterval);
    } catch (final ForeignSourceRepositoryException e) {
        LOG.warn("unable to get foreign source '{}' from repository", effectiveForeignSource, e);
        return null;
    }
}
Also used : ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9