Search in sources :

Example 1 with DefaultStellarStatefulExecutor

use of org.apache.metron.stellar.common.DefaultStellarStatefulExecutor 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 DefaultStellarStatefulExecutor

use of org.apache.metron.stellar.common.DefaultStellarStatefulExecutor in project metron by apache.

the class HBaseProfilerClientTest method setup.

@BeforeEach
public void setup() {
    provider = new MockHBaseTableProvider();
    executor = new DefaultStellarStatefulExecutor();
    MockHBaseTableProvider.addToCache(tableName, columnFamily);
    // writes values to be read during testing
    long periodDurationMillis = periodUnits.toMillis(periodDuration);
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
    profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, provider, periodDurationMillis, tableName, null);
    client = new HBaseProfilerClient(provider, rowKeyBuilder, columnBuilder, periodDurationMillis, tableName, null);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with DefaultStellarStatefulExecutor

use of org.apache.metron.stellar.common.DefaultStellarStatefulExecutor in project metron by apache.

the class ProfilerFunctionsTest method setup.

@BeforeEach
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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with DefaultStellarStatefulExecutor

use of org.apache.metron.stellar.common.DefaultStellarStatefulExecutor in project metron by apache.

the class ProfilerFunctionsTest method testProfilerInitWithNoGlobalConfig.

@Test
public void testProfilerInitWithNoGlobalConfig() {
    state.put("config", helloWorldProfilerDef);
    String expression = "PROFILER_INIT(config)";
    // use an executor with no GLOBAL_CONFIG defined in the context
    StellarStatefulExecutor executor = new DefaultStellarStatefulExecutor(new SimpleFunctionResolver().withClass(ProfilerFunctions.ProfilerInit.class).withClass(ProfilerFunctions.ProfilerApply.class).withClass(ProfilerFunctions.ProfilerFlush.class), Context.EMPTY_CONTEXT());
    StandAloneProfiler profiler = executor.execute(expression, state, StandAloneProfiler.class);
    assertNotNull(profiler);
    assertEquals(1, profiler.getProfileCount());
    assertEquals(0, profiler.getMessageCount());
    assertEquals(0, profiler.getRouteCount());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) StellarStatefulExecutor(org.apache.metron.stellar.common.StellarStatefulExecutor) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Test(org.junit.Test)

Example 5 with DefaultStellarStatefulExecutor

use of org.apache.metron.stellar.common.DefaultStellarStatefulExecutor 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 @BeforeEach 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
 */
@BeforeEach
public void setup() {
    state = new HashMap<>();
    final Table table = MockHBaseTableProvider.addToCache(tableName, columnFamily);
    // used to write values to be read during testing
    long periodDurationMillis = TimeUnit.MINUTES.toMillis(15);
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
    profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, new MockHBaseTableProvider(), periodDurationMillis, tableName, null);
    // 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 : Table(org.apache.hadoop.hbase.client.Table) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) 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) 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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)11 SimpleFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)10 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)4 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)4 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)4 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)4 HashMap (java.util.HashMap)3 JSONObject (org.json.simple.JSONObject)3 Table (org.apache.hadoop.hbase.client.Table)2 ProfileWriter (org.apache.metron.profiler.client.ProfileWriter)2 FixedLookback (org.apache.metron.profiler.client.stellar.FixedLookback)2 StellarStatefulExecutor (org.apache.metron.stellar.common.StellarStatefulExecutor)2 Properties (java.util.Properties)1 GetDataBuilder (org.apache.curator.framework.api.GetDataBuilder)1 TableProvider (org.apache.metron.hbase.TableProvider)1 StandAloneProfiler (org.apache.metron.profiler.StandAloneProfiler)1 VerboseProfile (org.apache.metron.profiler.client.stellar.VerboseProfile)1 StellarStatisticsFunctions (org.apache.metron.statistics.StellarStatisticsFunctions)1