public static DateTime floor(DateTime dateTime, int sec) { long modValue = dateTime.getMillis() % (1000 * sec); return dateTime.minus(modValue); }
@Override public boolean appliesTo(Interval theInterval, DateTime referenceTimestamp) { final DateTime periodAgo = referenceTimestamp.minus(period); return theInterval.getEndMillis() <= periodAgo.getMillis(); } }
public static DateTime ceil(DateTime dateTime, int sec) { long modValue = dateTime.getMillis() % (1000 * sec); return dateTime.minus(modValue).plusSeconds(sec); } }
@Override public boolean test(Sidecar sidecar) { final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(timeoutPeriod); return sidecar.lastSeen().isAfter(threshold); } }
private boolean isAbandoned(T query) { DateTime oldestAllowedHeartbeat = DateTime.now().minus(clientTimeout.toMillis()); DateTime lastHeartbeat = query.getLastHeartbeat(); return lastHeartbeat != null && lastHeartbeat.isBefore(oldestAllowedHeartbeat); }
Bucket(Interval interval, ArrayList<DataSegment> sortedSegments, double[] leftSum, double[] rightSum) { this.interval = Preconditions.checkNotNull(interval, "interval"); this.sortedSegments = Preconditions.checkNotNull(sortedSegments, "sortedSegments"); this.leftSum = Preconditions.checkNotNull(leftSum, "leftSum"); this.rightSum = Preconditions.checkNotNull(rightSum, "rightSum"); Preconditions.checkArgument(sortedSegments.size() == leftSum.length && sortedSegments.size() == rightSum.length); Preconditions.checkArgument(SEGMENT_ORDERING.isOrdered(sortedSegments)); this.calculationInterval = new Interval( interval.getStart().minus(LIFE_THRESHOLD), interval.getEnd().plus(LIFE_THRESHOLD) ); }
@Override public List<TaskInfo<Task, TaskStatus>> getRecentlyCreatedAlreadyFinishedTaskInfo( @Nullable Integer maxTaskStatuses, @Nullable Duration durationBeforeNow, @Nullable String datasource ) { return ImmutableList.copyOf( handler.getCompletedTaskInfo( DateTimes.nowUtc().minus(durationBeforeNow == null ? config.getRecentlyFinishedThreshold() : durationBeforeNow), maxTaskStatuses, datasource ) ); }
public void removeOldTasks() { DateTime oldestAllowedTask = DateTime.now().minus(infoCacheTime.toMillis()); for (TaskInfo taskInfo : filter(transform(tasks.asMap().values(), SqlTask::getTaskInfo), notNull())) { TaskId taskId = taskInfo.getTaskStatus().getTaskId(); try { DateTime endTime = taskInfo.getStats().getEndTime(); if (endTime != null && endTime.isBefore(oldestAllowedTask)) { tasks.asMap().remove(taskId); } } catch (RuntimeException e) { log.warn(e, "Error while inspecting age of complete task %s", taskId); } } }
public int destroyExpired(Period period) { final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(period); int count; try (final Stream<Sidecar> collectorStream = streamAll()) { count = collectorStream .mapToInt(collector -> { if (collector.lastSeen().isBefore(threshold)) { return delete(collector.id()); } return 0; }) .sum(); } return count; }
@Override @JsonIgnore public DateTime getFrom() { // TODO this should be computed once if (range() > 0) { return Tools.nowUTC().minus(Seconds.seconds(range())); } return new DateTime(0, DateTimeZone.UTC); }
@VisibleForTesting Interval findIntervalForKillTask(String dataSource, int limit) { List<Interval> unusedSegmentIntervals = segmentManager.getUnusedSegmentIntervals( dataSource, new Interval(DateTimes.EPOCH, DateTimes.nowUtc().minus(retainDuration)), limit ); if (unusedSegmentIntervals != null && unusedSegmentIntervals.size() > 0) { return JodaUtils.umbrellaInterval(unusedSegmentIntervals); } else { return null; } } }
private Interval getIntervalOrDefault(Interval interval) { final Interval theInterval; if (interval == null) { DateTime now = DateTimes.nowUtc(); theInterval = new Interval(now.minus(config.getAuditHistoryMillis()), now); } else { theInterval = interval; } return theInterval; }
protected org.graylog2.plugin.indexer.searches.timeranges.TimeRange restrictTimeRange(final org.graylog2.plugin.indexer.searches.timeranges.TimeRange timeRange) { final DateTime originalFrom = timeRange.getFrom(); final DateTime to = timeRange.getTo(); final DateTime from; final SearchesClusterConfig config = clusterConfigService.get(SearchesClusterConfig.class); if (config == null || Period.ZERO.equals(config.queryTimeRangeLimit())) { from = originalFrom; } else { final DateTime limitedFrom = to.minus(config.queryTimeRangeLimit()); from = limitedFrom.isAfter(originalFrom) ? limitedFrom : originalFrom; } return AbsoluteRange.create(from, to); }
@Test public void testAccept() { Period period = new Period("PT10M"); RejectionPolicy rejectionPolicy = new ServerTimeRejectionPolicyFactory().create(period); DateTime now = DateTimes.nowUtc(); DateTime past = now.minus(period).minus(100); DateTime future = now.plus(period).plus(100); Assert.assertTrue(rejectionPolicy.accept(now.getMillis())); Assert.assertFalse(rejectionPolicy.accept(past.getMillis())); Assert.assertFalse(rejectionPolicy.accept(future.getMillis())); } }
@Test public void testAccept() { Period period = new Period("PT10M"); RejectionPolicy rejectionPolicy = new MessageTimeRejectionPolicyFactory().create(period); DateTime now = DateTimes.nowUtc(); DateTime past = now.minus(period).minus(1); DateTime future = now.plus(period).plus(1); Assert.assertTrue(rejectionPolicy.accept(now.getMillis())); Assert.assertFalse(rejectionPolicy.accept(past.getMillis())); Assert.assertTrue(rejectionPolicy.accept(future.getMillis())); Assert.assertFalse(rejectionPolicy.accept(now.getMillis())); } }
@Override public Interval getDataInterval() { return new Interval(DateTimes.nowUtc().minus(Days.days(1)), DateTimes.nowUtc()); }
@Test public void testUnUsedOverlapLow() throws IOException { coordinator.announceHistoricalSegments(SEGMENTS); unUseSegment(); Assert.assertTrue( coordinator.getUnusedSegmentsForInterval( defaultSegment.getDataSource(), new Interval( defaultSegment.getInterval().getStart().minus(1), defaultSegment.getInterval().getStart().plus(1) ) ).isEmpty() ); }
@Test public void testUnUsedOverlapHigh() throws IOException { coordinator.announceHistoricalSegments(SEGMENTS); unUseSegment(); Assert.assertTrue( coordinator.getUnusedSegmentsForInterval( defaultSegment.getDataSource(), defaultSegment.getInterval().withStart(defaultSegment.getInterval().getEnd().minus(1)) ).isEmpty() ); }
@Test public void testUsedOutOfBoundsLow() throws IOException { coordinator.announceHistoricalSegments(SEGMENTS); Assert.assertTrue( coordinator.getUsedSegmentsForInterval( defaultSegment.getDataSource(), new Interval(defaultSegment.getInterval().getStart().minus(1), defaultSegment.getInterval().getStart()) ).isEmpty() ); }
@Test public void testUnUsedUnderlapHigh() throws IOException { coordinator.announceHistoricalSegments(SEGMENTS); unUseSegment(); Assert.assertTrue( coordinator.getUnusedSegmentsForInterval( defaultSegment.getDataSource(), new Interval(defaultSegment.getInterval().getStart(), defaultSegment.getInterval().getEnd().minus(1)) ).isEmpty() ); }