Search in sources :

Example 6 with ProfilePeriod

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);
}
Also used : Window(org.apache.metron.profiler.client.window.Window) ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) TimeUnit(java.util.concurrent.TimeUnit) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Aggregations

ProfilePeriod (org.apache.metron.profiler.ProfilePeriod)6 ArrayList (java.util.ArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)2 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Range (org.apache.commons.lang3.Range)1 Get (org.apache.hadoop.hbase.client.Get)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 Result (org.apache.hadoop.hbase.client.Result)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1 SerDeUtils (org.apache.metron.common.utils.SerDeUtils)1