Search in sources :

Example 1 with SimpleFunctionResolver

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());
}
Also used : HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Before(org.junit.Before)

Example 2 with SimpleFunctionResolver

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);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ComponentRunner(org.apache.metron.integration.ComponentRunner) FunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) KafkaComponent(org.apache.metron.integration.components.KafkaComponent) ArrayList(java.util.ArrayList) List(java.util.List) BaseIntegrationTest(org.apache.metron.integration.BaseIntegrationTest) After(org.junit.After) Map(java.util.Map) ZKServerComponent(org.apache.metron.integration.components.ZKServerComponent) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) FunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)

Example 3 with SimpleFunctionResolver

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();
}
Also used : StringFunctions(org.apache.metron.stellar.dsl.functions.StringFunctions) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Properties(java.util.Properties) DefaultStellarShellExecutor(org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor) Before(org.junit.Before)

Example 4 with SimpleFunctionResolver

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());
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) HashMap(java.util.HashMap) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) ProfileWriter(org.apache.metron.profiler.client.ProfileWriter) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) GetProfile(org.apache.metron.profiler.client.stellar.GetProfile) Before(org.junit.Before)

Example 5 with SimpleFunctionResolver

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;
}
Also used : Context(org.apache.metron.stellar.dsl.Context) HashMap(java.util.HashMap) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) GetProfile(org.apache.metron.profiler.client.stellar.GetProfile)

Aggregations

SimpleFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)7 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)4 Properties (java.util.Properties)3 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)2 GetProfile (org.apache.metron.profiler.client.stellar.GetProfile)2 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)2 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)2 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)2 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)2 DefaultStellarShellExecutor (org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor)2 Context (org.apache.metron.stellar.dsl.Context)2 StringFunctions (org.apache.metron.stellar.dsl.functions.StringFunctions)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1