Search in sources :

Example 1 with SaltyRowKeyBuilder

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

the class ProfilerIntegrationTest method generateExpectedRowKey.

/**
 * Generates the expected row key.
 *
 * @param profileName The name of the profile.
 * @param entity The entity.
 * @param whenMillis A timestamp in epoch milliseconds.
 * @return A row key.
 */
private byte[] generateExpectedRowKey(String profileName, String entity, long whenMillis) {
    // only the profile name, entity, and period are used to generate the row key
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName(profileName).withEntity(entity).withPeriod(whenMillis, periodDurationMillis, TimeUnit.MILLISECONDS);
    // build the row key
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDurationMillis, TimeUnit.MILLISECONDS);
    return rowKeyBuilder.rowKey(measurement);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement)

Example 2 with SaltyRowKeyBuilder

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

the class HBaseProfilerClientTest method setup.

@Before
public void setup() throws Exception {
    table = new MockHTable(tableName, columnFamily);
    executor = new DefaultStellarStatefulExecutor();
    // used to write values to be read during testing
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
    profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
    // what we're actually testing
    client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) 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) MockHTable(org.apache.metron.hbase.mock.MockHTable) Before(org.junit.Before)

Example 3 with SaltyRowKeyBuilder

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

the class SaltyRowKeyBuilderTest method setup.

@Before
public void setup() throws Exception {
    // a profile measurement
    measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(AUG2016, periodDuration, periodUnits);
    // the tuple will contain the original message
    tuple = mock(Tuple.class);
    when(tuple.getValueByField(eq("measurement"))).thenReturn(measurement);
    rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) Before(org.junit.Before)

Example 4 with SaltyRowKeyBuilder

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

the class GetProfile method getRowKeyBuilder.

/**
 * Creates the ColumnBuilder to use in accessing the profile data.
 * @param global The global configuration.
 */
private RowKeyBuilder getRowKeyBuilder(Map<String, Object> global) {
    // how long is the profile period?
    long duration = PROFILER_PERIOD.get(global, Long.class);
    LOG.debug("profiler client: {}={}", PROFILER_PERIOD, duration);
    // which units are used to define the profile period?
    String configuredUnits = PROFILER_PERIOD_UNITS.get(global, String.class);
    TimeUnit units = TimeUnit.valueOf(configuredUnits);
    LOG.debug("profiler client: {}={}", PROFILER_PERIOD_UNITS, units);
    // what is the salt divisor?
    Integer saltDivisor = PROFILER_SALT_DIVISOR.get(global, Integer.class);
    LOG.debug("profiler client: {}={}", PROFILER_SALT_DIVISOR, saltDivisor);
    return new SaltyRowKeyBuilder(saltDivisor, duration, units);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) TimeUnit(java.util.concurrent.TimeUnit)

Example 5 with SaltyRowKeyBuilder

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

the class ProfileWriter method main.

public static void main(String[] args) throws Exception {
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder();
    Configuration config = HBaseConfiguration.create();
    config.set("hbase.master.hostname", "node1");
    config.set("hbase.regionserver.hostname", "node1");
    config.set("hbase.zookeeper.quorum", "node1");
    HTableProvider provider = new HTableProvider();
    HTableInterface table = provider.getTable(config, "profiler");
    long when = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
    ProfileMeasurement measure = new ProfileMeasurement().withProfileName("profile1").withEntity("192.168.66.121").withPeriod(when, 15, TimeUnit.MINUTES);
    ProfileWriter writer = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
    writer.write(measure, 2 * 24 * 4, Collections.emptyList(), val -> new Random().nextInt(10));
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) HTableProvider(org.apache.metron.hbase.HTableProvider) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Random(java.util.Random) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) 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) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface)

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