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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations