use of org.apache.metron.profiler.client.HBaseProfilerClient in project metron by apache.
the class GetProfile method apply.
/**
* Apply the function.
* @param args The function arguments.
* @param context
*/
@Override
public Object apply(List<Object> args, Context context) throws ParseException {
String profile = getArg(0, String.class, args);
String entity = getArg(1, String.class, args);
Optional<List<ProfilePeriod>> periods = Optional.ofNullable(getArg(2, List.class, args));
// Optional arguments
@SuppressWarnings("unchecked") List<Object> groups = null;
Map configOverridesMap = null;
if (args.size() < 4) {
// no optional args, so default 'groups' and configOverridesMap remains null.
groups = new ArrayList<>(0);
} else if (args.get(3) instanceof List) {
// correct extensible usage
groups = getArg(3, List.class, args);
if (args.size() >= 5) {
configOverridesMap = getArg(4, Map.class, args);
if (configOverridesMap.isEmpty())
configOverridesMap = null;
}
} else {
// Deprecated "varargs" style usage for groups_list
// configOverridesMap cannot be specified so it remains null.
groups = getGroupsArg(3, args);
}
Map<String, Object> effectiveConfig = getEffectiveConfig(context, configOverridesMap);
Object defaultValue = null;
// lazily create new profiler client if needed
if (client == null || !cachedConfigMap.equals(effectiveConfig)) {
RowKeyBuilder rowKeyBuilder = getRowKeyBuilder(effectiveConfig);
ColumnBuilder columnBuilder = getColumnBuilder(effectiveConfig);
HTableInterface table = getTable(effectiveConfig);
client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
cachedConfigMap = effectiveConfig;
}
if (cachedConfigMap != null) {
defaultValue = ProfilerClientConfig.PROFILER_DEFAULT_VALUE.get(cachedConfigMap);
}
return client.fetch(Object.class, profile, entity, groups, periods.orElse(new ArrayList<>(0)), Optional.ofNullable(defaultValue));
}
Aggregations