Search in sources :

Example 6 with SaltyRowKeyBuilder

use of org.apache.metron.profiler.hbase.SaltyRowKeyBuilder 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 7 with SaltyRowKeyBuilder

use of org.apache.metron.profiler.hbase.SaltyRowKeyBuilder in project metron by apache.

the class SaltyRowKeyBuilderTest method testRowKeys.

/**
 * `rowKeys` should return all of the row keys needed to retrieve the profile values over a given time horizon.
 */
@Test
public void testRowKeys() throws Exception {
    int hoursAgo = 1;
    // setup
    List<Object> groups = Collections.emptyList();
    rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits);
    // a dummy profile measurement
    long now = System.currentTimeMillis();
    long oldest = now - TimeUnit.HOURS.toMillis(hoursAgo);
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(oldest, periodDuration, periodUnits).withProfileValue(22);
    // generate a list of expected keys
    List<byte[]> expectedKeys = new ArrayList<>();
    for (int i = 0; i < (hoursAgo * 4) + 1; i++) {
        // generate the expected key
        byte[] rk = rowKeyBuilder.rowKey(m);
        expectedKeys.add(rk);
        // advance to the next period
        ProfilePeriod next = m.getPeriod().next();
        m = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(next.getStartTimeMillis(), periodDuration, periodUnits);
    }
    // execute
    List<byte[]> actualKeys = rowKeyBuilder.rowKeys(measurement.getProfileName(), measurement.getEntity(), groups, oldest, now);
    // validate - expectedKeys == actualKeys
    for (int i = 0; i < actualKeys.size(); i++) {
        byte[] actual = actualKeys.get(i);
        byte[] expected = expectedKeys.get(i);
        assertThat(actual, equalTo(expected));
    }
}
Also used : ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ArrayList(java.util.ArrayList) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Aggregations

SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)7 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)4 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)4 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)3 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)3 Before (org.junit.Before)3 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)2 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 TimeUnit (java.util.concurrent.TimeUnit)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 HTableProvider (org.apache.metron.hbase.HTableProvider)1 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)1 MockHTable (org.apache.metron.hbase.mock.MockHTable)1 ProfilePeriod (org.apache.metron.profiler.ProfilePeriod)1 ProfileWriter (org.apache.metron.profiler.client.ProfileWriter)1 GetProfile (org.apache.metron.profiler.client.stellar.GetProfile)1