Search in sources :

Example 1 with ColumnBuilder

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

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

Example 3 with ColumnBuilder

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

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

the class GetProfile method apply.

/**
 * Apply the function.
 * @param args The function arguments.
 * @param context
 */
@Override
public Object apply(List<Object> args, Context context) throws ParseException {
    String profile = getArg(0, String.class, args);
    String entity = getArg(1, String.class, args);
    Optional<List<ProfilePeriod>> periods = Optional.ofNullable(getArg(2, List.class, args));
    // Optional arguments
    @SuppressWarnings("unchecked") List<Object> groups = null;
    Map configOverridesMap = null;
    if (args.size() < 4) {
        // no optional args, so default 'groups' and configOverridesMap remains null.
        groups = new ArrayList<>(0);
    } else if (args.get(3) instanceof List) {
        // correct extensible usage
        groups = getArg(3, List.class, args);
        if (args.size() >= 5) {
            configOverridesMap = getArg(4, Map.class, args);
            if (configOverridesMap.isEmpty())
                configOverridesMap = null;
        }
    } else {
        // Deprecated "varargs" style usage for groups_list
        // configOverridesMap cannot be specified so it remains null.
        groups = getGroupsArg(3, args);
    }
    Map<String, Object> effectiveConfig = getEffectiveConfig(context, configOverridesMap);
    Object defaultValue = null;
    // lazily create new profiler client if needed
    if (client == null || !cachedConfigMap.equals(effectiveConfig)) {
        RowKeyBuilder rowKeyBuilder = getRowKeyBuilder(effectiveConfig);
        ColumnBuilder columnBuilder = getColumnBuilder(effectiveConfig);
        HTableInterface table = getTable(effectiveConfig);
        client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder);
        cachedConfigMap = effectiveConfig;
    }
    if (cachedConfigMap != null) {
        defaultValue = ProfilerClientConfig.PROFILER_DEFAULT_VALUE.get(cachedConfigMap);
    }
    return client.fetch(Object.class, profile, entity, groups, periods.orElse(new ArrayList<>(0)), Optional.ofNullable(defaultValue));
}
Also used : ArrayList(java.util.ArrayList) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) 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 5 with ColumnBuilder

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

the class GetProfile method getColumnBuilder.

/**
 * Creates the ColumnBuilder to use in accessing the profile data.
 * @param global The global configuration.
 */
private ColumnBuilder getColumnBuilder(Map<String, Object> global) {
    ColumnBuilder columnBuilder;
    String columnFamily = PROFILER_COLUMN_FAMILY.get(global, String.class);
    columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
    return columnBuilder;
}
Also used : ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)

Aggregations

ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)5 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)5 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)4 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)4 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)3 HashMap (java.util.HashMap)2 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)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 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)1 HBaseProfilerClient (org.apache.metron.profiler.client.HBaseProfilerClient)1 ProfileWriter (org.apache.metron.profiler.client.ProfileWriter)1