@GET @ApiOperation(value = "Get the cluster traffic stats") public TrafficCounterService.TrafficHistogram get(@ApiParam(name = "days", value = "For how many days the traffic stats should be returned") @QueryParam("days") @DefaultValue("30") int days, @ApiParam(name = "daily", value = "Whether the traffic should be aggregate to daily values") @QueryParam("daily") @DefaultValue("false") boolean daily) { final TrafficCounterService.TrafficHistogram trafficHistogram = trafficCounterService.clusterTrafficOfLastDays(Duration.standardDays(days), daily ? TrafficCounterService.Interval.DAILY : TrafficCounterService.Interval.HOURLY); return trafficHistogram; } }
/** * Converts push frequency into duration. For invalid or less than 'hourly' push frequency, treats it as 'daily'. */ private Duration convertToDuration(String pushFrequency) { if ("hourly".equalsIgnoreCase(pushFrequency)) { return Duration.standardHours(1L); } if ("daily".equalsIgnoreCase(pushFrequency)) { return Duration.standardDays(1L); } if ("weekly".equalsIgnoreCase(pushFrequency)) { return Duration.standardDays(7L); } if ("monthly".equalsIgnoreCase(pushFrequency)) { return Duration.standardDays(30L); } return Duration.standardDays(1L); }
exec, initialDelay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>()
jan1st2nd3rd.add(jan2nd); jan1st2nd3rd.add(jan3rd); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan1st2nd3rd, Duration.standardDays(1)), 0); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan1st2nd3rd5th, Duration.standardDays(1)), 1); jan5th2nd1st.add(jan2nd); jan5th2nd1st.add(jan1st); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan5th2nd1st, Duration.standardDays(1)), 2); jan1st2nd4th5th.add(jan4th); jan1st2nd4th5th.add(jan5th); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan1st2nd4th5th, Duration.standardDays(1)), 1);
@Test public void testConfigsTakeOverrides() { final Duration funnyDuration = Duration.standardDays(100); final LookupCoordinatorManagerConfig config = new LookupCoordinatorManagerConfig(); config.setHostTimeout(funnyDuration); config.setAllHostTimeout(funnyDuration); config.setPeriod(funnyDuration.getMillis()); config.setThreadPoolSize(1200); Assert.assertEquals(funnyDuration, config.getHostTimeout()); Assert.assertEquals(funnyDuration, config.getAllHostTimeout()); Assert.assertEquals(funnyDuration.getMillis(), config.getPeriod()); Assert.assertEquals(1200, config.getThreadPoolSize()); }
@GET @ApiOperation(value = "Get the cluster traffic stats") public TrafficCounterService.TrafficHistogram get(@ApiParam(name = "days", value = "For how many days the traffic stats should be returned") @QueryParam("days") @DefaultValue("30") int days, @ApiParam(name = "daily", value = "Whether the traffic should be aggregate to daily values") @QueryParam("daily") @DefaultValue("false") boolean daily) { final TrafficCounterService.TrafficHistogram trafficHistogram = trafficCounterService.clusterTrafficOfLastDays(Duration.standardDays(days), daily ? TrafficCounterService.Interval.DAILY : TrafficCounterService.Interval.HOURLY); return trafficHistogram; } }
/** * Please instead use AerospikeTestOperations */ @Deprecated public void addDays(int days) { testOperations.addDuration(Duration.standardDays(days)); }
@Override public Optional<? extends RestxPrincipal> authenticate(String name, String passwordHash, ImmutableMap<String, ?> principalData) { boolean rememberMe = Boolean.valueOf((String) principalData.get("rememberMe")); Optional<? extends RestxPrincipal> u = users.findAndCheckCredentials(name, passwordHash); if (u.isPresent()) { RestxSession.current().expires(rememberMe ? Duration.standardDays(securitySettings.rememberMeDuration()) : Duration.ZERO); } return u; } }
@Override public Optional<? extends RestxPrincipal> authenticate(String name, String passwordHash, ImmutableMap<String, ?> principalData) { boolean rememberMe = Boolean.valueOf((String) principalData.get("rememberMe")); Optional<? extends RestxPrincipal> u = users.findAndCheckCredentials(name, passwordHash); if (u.isPresent()) { RestxSession.current().expires(rememberMe ? Duration.standardDays(securitySettings.rememberMeDuration()) : Duration.ZERO); } return u; } }
private int getTTL(MetricId<?> metricId) { Integer ttl = dataRetentions.get(new DataRetentionKey(metricId)); if (ttl == null) { ttl = dataRetentions.getOrDefault(new DataRetentionKey(metricId.getTenantId(), metricId.getType()), defaultTTL); } else { ttl = Duration.standardDays(ttl).toStandardSeconds().getSeconds(); } return ttl; }
private int getTTL(MetricId<?> metricId) { Integer ttl = dataRetentions.get(new DataRetentionKey(metricId)); if (ttl == null) { ttl = dataRetentions.getOrDefault(new DataRetentionKey(metricId.getTenantId(), metricId.getType()), defaultTTL); } else { ttl = Duration.standardDays(ttl).toStandardSeconds().getSeconds(); } return ttl; }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_properly_output_a_ResourceFile_with_ExpirationTime() throws Exception { final ResponseBuilder<?> builder = underTest.response().fromFile(resourceFile) .withExpirationTime(Duration.standardDays(7)); assertContents(builder, "ResourceFileOutputWithExpirationTime.txt"); }
@ProcessElement public void processElement(ProcessContext context, @TimerId(timerId) Timer timer) { // This aligned time will exceed the END_OF_GLOBAL_WINDOW timer.align(Duration.standardDays(1)).setRelative(); context.output(KV.of(3, context.timestamp())); }
@Override public PCollection<String> expand(PCollection<KV<String, Integer>> input) { return input .apply(Window.<KV<String, Integer>>into(FixedWindows.of(TWO_MINUTES)) .triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(1))) .withAllowedLateness(Duration.standardDays(1000)) .accumulatingFiredPanes()) .apply(Sum.integersPerKey()) .apply(ParDo.of(new FormatAsStrings())); }
@Override public PCollection<String> expand(PCollection<KV<String, Integer>> input) { return input .apply(Window.<KV<String, Integer>>into(FixedWindows.of(TWO_MINUTES)) .triggering(Repeatedly.forever(AfterProcessingTime .pastFirstElementInPane() .alignedTo(TWO_MINUTES, Utils.parseTime("12:05:00")))) .withAllowedLateness(Duration.standardDays(1000)) .accumulatingFiredPanes()) .apply(Sum.integersPerKey()) .apply(ParDo.of(new FormatAsStrings())); }
@Test public void testGetForeignSources() throws Exception { FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSources"); File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).pop(); File reqDir = bldr.dir("requisitions").file("test.xml").file("pending.xml").pop(); FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir); Set<ForeignSource> foreignSources = repo.getForeignSources(); assertEquals(1, foreignSources.size()); ForeignSource testFS = foreignSources.iterator().next(); assertEquals("test", testFS.getName()); assertEquals(Duration.standardDays(1), testFS.getScanInterval()); }
@Test public void testGlobalWindowErrorMessageShows() { PCollection<String> input = p.apply(Create.of(NO_LINES).withCoder(StringUtf8Coder.of())); PCollection<String> windowed = input.apply(Window.into(FixedWindows.of(Duration.standardDays(1)))); String expected = Count.combineFn().getIncompatibleGlobalWindowErrorMessage(); exceptionRule.expect(IllegalStateException.class); exceptionRule.expectMessage(expected); windowed.apply(Count.globally()); } }
@Test public void testMissingModeViaLateness() { FixedWindows fixed = FixedWindows.of(Duration.standardMinutes(10)); PCollection<String> input = pipeline .apply(Create.of("hello", "world").withCoder(StringUtf8Coder.of())) .apply("Window", Window.into(fixed)); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("allowed lateness"); thrown.expectMessage("accumulation mode be specified"); input.apply( "Lateness", Window.<String>configure().withAllowedLateness(Duration.standardDays(1))); }
@Test public void testTopEmptyWithIncompatibleWindows() { p.enableAbandonedNodeEnforcement(false); Window<String> windowingFn = Window.into(FixedWindows.of(Duration.standardDays(10L))); PCollection<String> input = p.apply(Create.empty(StringUtf8Coder.of())).apply(windowingFn); expectedEx.expect(IllegalStateException.class); expectedEx.expectMessage("Top"); expectedEx.expectMessage("GlobalWindows"); expectedEx.expectMessage("withoutDefaults"); expectedEx.expectMessage("asSingletonView"); input.apply(Top.of(1, new OrderByLength())); }
@Test public void testGetForeignSource() throws Exception { FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource"); File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop(); File reqDir = bldr.dir("requisitions").file("test.xml").file("pending.xml").pop(); FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir); ForeignSource testFS = repo.getForeignSource("test"); assertEquals("test", testFS.getName()); assertEquals(Duration.standardDays(1), testFS.getScanInterval()); }