Search in sources :

Example 1 with RowKeyBuilder

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

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

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;
}
Also used : ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) ArrayList(java.util.ArrayList) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) TableProvider(org.apache.metron.hbase.TableProvider) HTableProvider(org.apache.metron.hbase.HTableProvider) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) HBaseProfilerClient(org.apache.metron.profiler.client.HBaseProfilerClient) ArrayList(java.util.ArrayList) List(java.util.List) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RowKeyBuilder

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);
}
Also used : ProfileResult(org.apache.metron.common.configuration.profiler.ProfileResult) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with RowKeyBuilder

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);
}
Also used : ProfileResult(org.apache.metron.common.configuration.profiler.ProfileResult) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Before(org.junit.Before)

Aggregations

RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)9 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)7 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)6 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)6 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)6 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)3 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Configuration (org.apache.hadoop.conf.Configuration)2 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 Table (org.apache.hadoop.hbase.client.Table)2 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)2 ProfileResult (org.apache.metron.common.configuration.profiler.ProfileResult)2 HTableProvider (org.apache.metron.hbase.HTableProvider)2 TableProvider (org.apache.metron.hbase.TableProvider)2 HBaseProfilerClient (org.apache.metron.profiler.client.HBaseProfilerClient)2