use of org.apache.metron.profiler.hbase.RowKeyBuilder 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.RowKeyBuilder 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);
}
use of org.apache.metron.profiler.hbase.RowKeyBuilder in project metron by apache.
the class VerboseProfile method apply.
@Override
public Object apply(List<Object> args, Context context) throws ParseException {
// required arguments
String profile = getArg(0, String.class, args);
String entity = getArg(1, String.class, args);
List<ProfilePeriod> periods = getArg(2, List.class, args);
// optional 'groups' argument
List<Object> groups = new ArrayList<>();
if (args.size() >= 4) {
groups = getArg(3, List.class, args);
}
// get globals from the context
Map<String, Object> globals = (Map<String, Object>) context.getCapability(GLOBAL_CONFIG).orElse(Collections.emptyMap());
// lazily create the profiler client, if needed
if (client == null) {
RowKeyBuilder rowKeyBuilder = getRowKeyBuilder(globals);
ColumnBuilder columnBuilder = getColumnBuilder(globals);
TableProvider provider = getTableProvider(globals);
long periodDuration = getPeriodDurationInMillis(globals);
client = new HBaseProfilerClient(provider, rowKeyBuilder, columnBuilder, periodDuration, getTableName(globals), HBaseConfiguration.create());
}
// is there a default value?
Optional<Object> defaultValue = Optional.empty();
if (globals != null) {
defaultValue = Optional.ofNullable(PROFILER_DEFAULT_VALUE.get(globals));
}
List<ProfileMeasurement> measurements = client.fetch(Object.class, profile, entity, groups, periods, defaultValue);
// render a view of each profile measurement
List<Object> results = new ArrayList<>();
for (ProfileMeasurement measurement : measurements) {
results.add(render(measurement));
}
return results;
}
use of org.apache.metron.profiler.hbase.RowKeyBuilder in project metron by apache.
the class ProfileHBaseMapperTest method setup.
@BeforeEach
public void setup() {
rowKeyBuilder = mock(RowKeyBuilder.class);
mapper = new ProfileHBaseMapper();
mapper.setRowKeyBuilder(rowKeyBuilder);
profile = new ProfileConfig("profile", "ip_src_addr", new ProfileResult("2 + 2"));
measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withProfileValue(22).withDefinition(profile);
// the tuple will contain the original message
tuple = mock(Tuple.class);
when(tuple.getValueByField(eq("measurement"))).thenReturn(measurement);
}
use of org.apache.metron.profiler.hbase.RowKeyBuilder in project metron by apache.
the class ProfileHBaseMapperTest method setup.
@Before
public void setup() {
rowKeyBuilder = mock(RowKeyBuilder.class);
mapper = new ProfileHBaseMapper();
mapper.setRowKeyBuilder(rowKeyBuilder);
profile = new ProfileConfig("profile", "ip_src_addr", new ProfileResult("2 + 2"));
measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withProfileValue(22).withDefinition(profile);
// the tuple will contain the original message
tuple = mock(Tuple.class);
when(tuple.getValueByField(eq("measurement"))).thenReturn(measurement);
}
Aggregations