Search in sources :

Example 1 with HTableProvider

use of org.apache.metron.hbase.HTableProvider in project metron by apache.

the class HBaseConfig method userSettingsClient.

@Bean()
public UserSettingsClient userSettingsClient() {
    UserSettingsClient userSettingsClient = new UserSettingsClient();
    userSettingsClient.init(() -> {
        try {
            return globalConfigService.get();
        } catch (RestException e) {
            throw new IllegalStateException("Unable to retrieve the global config.", e);
        }
    }, new HTableProvider());
    return userSettingsClient;
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) UserSettingsClient(org.apache.metron.hbase.client.UserSettingsClient) RestException(org.apache.metron.rest.RestException) Bean(org.springframework.context.annotation.Bean)

Example 2 with HTableProvider

use of org.apache.metron.hbase.HTableProvider in project metron by apache.

the class IndexConfig method indexDao.

@Bean
public IndexDao indexDao() {
    try {
        String hbaseProviderImpl = environment.getProperty(MetronRestConstants.INDEX_HBASE_TABLE_PROVIDER_IMPL, String.class, null);
        String indexDaoImpl = environment.getProperty(MetronRestConstants.INDEX_DAO_IMPL, String.class, null);
        int searchMaxResults = environment.getProperty(MetronRestConstants.SEARCH_MAX_RESULTS, Integer.class, 1000);
        int searchMaxGroups = environment.getProperty(MetronRestConstants.SEARCH_MAX_GROUPS, Integer.class, 1000);
        String metaDaoImpl = environment.getProperty(MetronRestConstants.META_DAO_IMPL, String.class, null);
        String metaDaoSort = environment.getProperty(MetronRestConstants.META_DAO_SORT, String.class, null);
        AccessConfig config = new AccessConfig();
        config.setMaxSearchResults(searchMaxResults);
        config.setMaxSearchGroups(searchMaxGroups);
        config.setGlobalConfigSupplier(() -> {
            try {
                return globalConfigService.get();
            } catch (RestException e) {
                throw new IllegalStateException("Unable to retrieve the global config.", e);
            }
        });
        config.setTableProvider(TableProvider.create(hbaseProviderImpl, () -> new HTableProvider()));
        if (indexDaoImpl == null) {
            throw new IllegalStateException("You must provide an index DAO implementation via the " + INDEX_DAO_IMPL + " config");
        }
        IndexDao indexDao = IndexDaoFactory.combine(IndexDaoFactory.create(indexDaoImpl, config));
        if (indexDao == null) {
            throw new IllegalStateException("IndexDao is unable to be created.");
        }
        if (metaDaoImpl == null) {
            // We're not using meta alerts.
            return indexDao;
        }
        // Create the meta alert dao and wrap it around the index dao.
        MetaAlertDao ret = (MetaAlertDao) IndexDaoFactory.create(metaDaoImpl, config).get(0);
        ret.init(indexDao, Optional.ofNullable(metaDaoSort));
        return ret;
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new IllegalStateException("Unable to create index DAO: " + e.getMessage(), e);
    }
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) RestException(org.apache.metron.rest.RestException) MetaAlertDao(org.apache.metron.indexing.dao.MetaAlertDao) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) IndexDao(org.apache.metron.indexing.dao.IndexDao) RestException(org.apache.metron.rest.RestException) Bean(org.springframework.context.annotation.Bean)

Example 3 with HTableProvider

use of org.apache.metron.hbase.HTableProvider in project metron by apache.

the class HBaseWriter method init.

@Override
public void init() {
    final Configuration config = HBaseConfiguration.create();
    try {
        provider = ReflectionUtils.createInstance(connectorImpl, new HTableProvider());
        table = provider.getTable(config, tableName);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException)

Example 4 with HTableProvider

use of org.apache.metron.hbase.HTableProvider in project metron by apache.

the class HBaseConfigTest method userSettingsTableShouldBeReturnedFromGlobalConfigByDefault.

@Test
public void userSettingsTableShouldBeReturnedFromGlobalConfigByDefault() throws Exception {
    when(globalConfigService.get()).thenReturn(new HashMap<String, Object>() {

        {
            put(USER_SETTINGS_HBASE_TABLE, "global_config_user_settings_table");
            put(USER_SETTINGS_HBASE_CF, "global_config_user_settings_cf");
        }
    });
    HTableProvider htableProvider = mock(HTableProvider.class);
    whenNew(HTableProvider.class).withNoArguments().thenReturn(htableProvider);
    Configuration configuration = mock(Configuration.class);
    when(HBaseConfiguration.create()).thenReturn(configuration);
    hBaseConfig.userSettingsClient();
    verify(htableProvider).getTable(configuration, "global_config_user_settings_table");
    verifyZeroInteractions(htableProvider);
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with HTableProvider

use of org.apache.metron.hbase.HTableProvider 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

HTableProvider (org.apache.metron.hbase.HTableProvider)7 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 IOException (java.io.IOException)2 RestException (org.apache.metron.rest.RestException)2 Test (org.junit.Test)2 Bean (org.springframework.context.annotation.Bean)2 Random (java.util.Random)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)1 TableProvider (org.apache.metron.hbase.TableProvider)1 UserSettingsClient (org.apache.metron.hbase.client.UserSettingsClient)1 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)1 IndexDao (org.apache.metron.indexing.dao.IndexDao)1 MetaAlertDao (org.apache.metron.indexing.dao.MetaAlertDao)1 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)1 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)1 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)1 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)1 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)1