use of org.apache.metron.hbase.mock.MockHBaseTableProvider 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.hbase.mock.MockHBaseTableProvider in project metron by apache.
the class TestConfig method hBaseClient.
@Bean()
public HBaseClient hBaseClient() throws RestException, IOException {
final String cf = "t";
final String cq = "v";
Table table = MockHBaseTableProvider.addToCache("enrichment_list", cf);
List<String> enrichmentTypes = new ArrayList<String>() {
{
add("foo");
add("bar");
add("baz");
}
};
for (String type : enrichmentTypes) {
Put put = new Put(Bytes.toBytes(type));
put.addColumn(Bytes.toBytes(cf), Bytes.toBytes(cq), "{}".getBytes(StandardCharsets.UTF_8));
table.put(put);
}
return new HBaseClient(new MockHBaseTableProvider(), HBaseConfiguration.create(), "enrichment_list");
}
use of org.apache.metron.hbase.mock.MockHBaseTableProvider in project metron by apache.
the class TaxiiIntegrationTest method testTaxii.
@Test
public void testTaxii() throws Exception {
final MockHBaseTableProvider provider = new MockHBaseTableProvider();
final Configuration config = HBaseConfiguration.create();
Extractor extractor = new TransformFilterExtractorDecorator(new StixExtractor());
TaxiiHandler handler = new TaxiiHandler(TaxiiConnectionConfig.load(taxiiConnectionConfig), extractor, config) {
@Override
protected synchronized Table createHTable(String tableInfo) throws IOException {
return provider.addToCache("threat_intel", "cf");
}
};
// UnitTestHelper.verboseLogging();
handler.run();
Set<String> maliciousDomains;
{
MockHTable table = (MockHTable) provider.getTable(config, "threat_intel");
maliciousDomains = getIndicators("domainname:FQDN", table.getPutLog(), "cf");
}
assertTrue(maliciousDomains.contains("www.office-112.com"));
assertEquals(numStringsMatch(MockTaxiiService.pollMsg, "DomainNameObj:Value condition=\"Equals\""), maliciousDomains.size());
Set<String> maliciousAddresses;
{
MockHTable table = (MockHTable) provider.getTable(config, "threat_intel");
maliciousAddresses = getIndicators("address:IPV_4_ADDR", table.getPutLog(), "cf");
}
assertTrue(maliciousAddresses.contains("94.102.53.142"));
assertEquals(numStringsMatch(MockTaxiiService.pollMsg, "AddressObj:Address_Value condition=\"Equal\""), maliciousAddresses.size());
MockHBaseTableProvider.clear();
// Ensure that the handler can be run multiple times without connection issues.
handler.run();
}
use of org.apache.metron.hbase.mock.MockHBaseTableProvider in project metron by apache.
the class ElasticsearchUpdateIntegrationTest method setup.
@BeforeClass
public static void setup() throws Exception {
Configuration config = HBaseConfiguration.create();
MockHBaseTableProvider tableProvider = new MockHBaseTableProvider();
tableProvider.addToCache(TABLE_NAME, CF);
table = (MockHTable) tableProvider.getTable(config, TABLE_NAME);
// setup the client
es = new ElasticSearchComponent.Builder().withHttpPort(9211).withIndexDir(new File(indexDir)).build();
es.start();
hbaseDao = new HBaseDao();
AccessConfig accessConfig = new AccessConfig();
accessConfig.setTableProvider(tableProvider);
Map<String, Object> globalConfig = new HashMap<String, Object>() {
{
put("es.clustername", "metron");
put("es.port", "9300");
put("es.ip", "localhost");
put("es.date.format", dateFormat);
put(HBaseDao.HBASE_TABLE, TABLE_NAME);
put(HBaseDao.HBASE_CF, CF);
}
};
accessConfig.setGlobalConfigSupplier(() -> globalConfig);
esDao = new ElasticsearchDao();
dao = new MultiIndexDao(hbaseDao, esDao);
dao.init(accessConfig);
}
use of org.apache.metron.hbase.mock.MockHBaseTableProvider in project metron by apache.
the class ElasticsearchUpdateIntegrationTest method setupBeforeClass.
@BeforeAll
public static void setupBeforeClass() throws UnableToStartException, IOException {
Configuration config = HBaseConfiguration.create();
MockHBaseTableProvider tableProvider = new MockHBaseTableProvider();
MockHBaseTableProvider.addToCache(TABLE_NAME, CF);
table = (MockHTable) tableProvider.getTable(config, TABLE_NAME);
globalConfig = new HashMap<>();
globalConfig.put("es.clustername", "metron");
globalConfig.put("es.port", "9200");
globalConfig.put("es.ip", "localhost");
globalConfig.put("es.date.format", dateFormat);
globalConfig.put(HBaseDao.HBASE_TABLE, TABLE_NAME);
globalConfig.put(HBaseDao.HBASE_CF, CF);
accessConfig = new AccessConfig();
accessConfig.setTableProvider(tableProvider);
accessConfig.setGlobalConfigSupplier(() -> globalConfig);
es = new ElasticSearchComponent.Builder().withHttpPort(9211).withIndexDir(new File(indexDir)).withAccessConfig(accessConfig).build();
es.start();
installIndexTemplate();
}
Aggregations