use of org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver in project metron by apache.
the class ProfilerFunctionsTest method setup.
@Before
public void setup() {
state = new HashMap<>();
// global properties
Map<String, Object> global = new HashMap<String, Object>() {
{
put(PROFILER_PERIOD.getKey(), Long.toString(periodDuration));
put(PROFILER_PERIOD_UNITS.getKey(), periodUnits.toString());
}
};
// create the stellar execution environment
executor = new DefaultStellarStatefulExecutor(new SimpleFunctionResolver().withClass(ProfilerFunctions.ProfilerInit.class).withClass(ProfilerFunctions.ProfilerApply.class).withClass(ProfilerFunctions.ProfilerFlush.class), new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build());
}
use of org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver in project metron by apache.
the class KafkaFunctionsIntegrationTest method run.
/**
* Runs a Stellar expression.
* @param expr The expression to run.
*/
private Object run(String expr) {
// make the global properties available to the function
Context context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build();
FunctionResolver functionResolver = new SimpleFunctionResolver().withClass(KafkaFunctions.KafkaGet.class).withClass(KafkaFunctions.KafkaPut.class).withClass(KafkaFunctions.KafkaProps.class).withClass(KafkaFunctions.KafkaTail.class);
StellarProcessor processor = new StellarProcessor();
return processor.parse(expr, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), functionResolver, context);
}
use of org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver in project metron by apache.
the class MagicListFunctionsTest method setup.
@Before
public void setup() throws Exception {
// setup the %magic
magic = new MagicListFunctions();
// setup a function resolver - only 3 functions have been defined
SimpleFunctionResolver functionResolver = new SimpleFunctionResolver().withClass(StringFunctions.ToString.class).withClass(StringFunctions.ToLower.class).withClass(StringFunctions.ToUpper.class);
// setup the executor
Properties props = new Properties();
executor = new DefaultStellarShellExecutor(functionResolver, props, Optional.empty());
executor.init();
}
use of org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver in project metron by apache.
the class GetProfileTest method setup.
/**
* This method sets up the configuration context for both writing profile data
* (using profileWriter to mock the complex process of what the Profiler topology
* actually does), and then reading that profile data (thereby testing the PROFILE_GET
* Stellar client implemented in GetProfile).
*
* It runs at @Before time, and sets testclass global variables used by the writers and readers.
* The various writers and readers are in each test case, not here.
*
* @return void
*/
@Before
public void setup() {
state = new HashMap<>();
final HTableInterface table = MockHBaseTableProvider.addToCache(tableName, columnFamily);
// used to write values to be read during testing
RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
// global properties
Map<String, Object> global = new HashMap<String, Object>() {
{
put(PROFILER_HBASE_TABLE.getKey(), tableName);
put(PROFILER_COLUMN_FAMILY.getKey(), columnFamily);
put(PROFILER_HBASE_TABLE_PROVIDER.getKey(), MockHBaseTableProvider.class.getName());
put(PROFILER_PERIOD.getKey(), Long.toString(periodDuration));
put(PROFILER_PERIOD_UNITS.getKey(), periodUnits.toString());
put(PROFILER_SALT_DIVISOR.getKey(), Integer.toString(saltDivisor));
}
};
// create the stellar execution environment
executor = new DefaultStellarStatefulExecutor(new SimpleFunctionResolver().withClass(GetProfile.class).withClass(FixedLookback.class), new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build());
}
use of org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver in project metron by apache.
the class GetProfileTest method setup2.
/**
* This method is similar to setup(), in that it sets up profiler configuration context,
* but only for the client. Additionally, it uses periodDuration2, periodUnits2
* and saltDivisor2, instead of periodDuration, periodUnits and saltDivisor respectively.
*
* This is used in the unit tests that test the config_overrides feature of PROFILE_GET.
* In these tests, the context from @Before setup() is used to write the data, then the global
* context is changed to context2 (from this method). Each test validates that a default read
* using global context2 then gets no valid results (as expected), and that a read using
* original context values in the PROFILE_GET config_overrides argument gets all expected results.
*
* @return context2 - The profiler client configuration context created by this method.
* The context2 values are also set in the configuration of the StellarStatefulExecutor
* stored in the global variable 'executor'. However, there is no API for querying the
* context values from a StellarStatefulExecutor, so we output the context2 Context object itself,
* for validation purposes (so that its values can be validated as being significantly
* different from the setup() settings).
*/
private Context setup2() {
state = new HashMap<>();
// global properties
Map<String, Object> global = new HashMap<String, Object>() {
{
put(PROFILER_HBASE_TABLE.getKey(), tableName);
put(PROFILER_COLUMN_FAMILY.getKey(), columnFamily);
put(PROFILER_HBASE_TABLE_PROVIDER.getKey(), MockHBaseTableProvider.class.getName());
put(PROFILER_PERIOD.getKey(), Long.toString(periodDuration2));
put(PROFILER_PERIOD_UNITS.getKey(), periodUnits2.toString());
put(PROFILER_SALT_DIVISOR.getKey(), Integer.toString(saltDivisor2));
}
};
// create the modified context
Context context2 = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build();
// create the stellar execution environment
executor = new DefaultStellarStatefulExecutor(new SimpleFunctionResolver().withClass(GetProfile.class).withClass(FixedLookback.class), context2);
// because there is no executor.getContext() method
return context2;
}
Aggregations