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