use of org.apache.metron.profiler.ProfilePeriod in project metron by apache.
the class WindowLookback method apply.
@Override
public Object apply(List<Object> args, Context context) throws ParseException {
Optional<Map> configOverridesMap = Optional.empty();
long now = System.currentTimeMillis();
String windowSelector = Util.getArg(0, String.class, args);
if (args.size() > 1) {
Optional<Object> arg2 = Optional.ofNullable(args.get(1));
Optional<Object> mapArg = args.size() > 2 ? Optional.ofNullable(args.get(2)) : Optional.empty();
if (!mapArg.isPresent() && arg2.isPresent() && arg2.get() instanceof Map) {
mapArg = arg2;
}
if (arg2.isPresent() && arg2.get() instanceof Number) {
now = ConversionUtils.convert(arg2.get(), Long.class);
}
if (mapArg.isPresent()) {
Map rawMap = ConversionUtils.convert(mapArg.get(), Map.class);
configOverridesMap = rawMap == null || rawMap.isEmpty() ? Optional.empty() : Optional.of(rawMap);
}
}
Map<String, Object> effectiveConfigs = Util.getEffectiveConfig(context, configOverridesMap.orElse(null));
Long tickDuration = ProfilerClientConfig.PROFILER_PERIOD.get(effectiveConfigs, Long.class);
TimeUnit tickUnit = TimeUnit.valueOf(ProfilerClientConfig.PROFILER_PERIOD_UNITS.get(effectiveConfigs, String.class));
Window w = null;
try {
w = windowCache.get(windowSelector, () -> WindowProcessor.process(windowSelector));
} catch (ExecutionException e) {
throw new IllegalStateException("Unable to process " + windowSelector + ": " + e.getMessage(), e);
}
long end = w.getEndMillis(now);
long start = w.getStartMillis(now);
IntervalPredicate<ProfilePeriod> intervalSelector = new IntervalPredicate<>(period -> period.getStartTimeMillis(), w.toIntervals(now), ProfilePeriod.class);
return ProfilePeriod.visitPeriods(start, end, tickDuration, tickUnit, Optional.of(intervalSelector), period -> period);
}
Aggregations