Search in sources :

Example 1 with MockHBaseTableProvider

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);
}
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 2 with MockHBaseTableProvider

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");
}
Also used : Table(org.apache.hadoop.hbase.client.Table) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) HBaseClient(org.apache.metron.hbase.client.HBaseClient) Put(org.apache.hadoop.hbase.client.Put) Bean(org.springframework.context.annotation.Bean)

Example 3 with MockHBaseTableProvider

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();
}
Also used : TransformFilterExtractorDecorator(org.apache.metron.dataloads.extractor.TransformFilterExtractorDecorator) StixExtractor(org.apache.metron.dataloads.extractor.stix.StixExtractor) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) StixExtractor(org.apache.metron.dataloads.extractor.stix.StixExtractor) Extractor(org.apache.metron.dataloads.extractor.Extractor) MockHTable(org.apache.metron.hbase.mock.MockHTable) Test(org.junit.jupiter.api.Test)

Example 4 with MockHBaseTableProvider

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);
}
Also used : ElasticsearchDao(org.apache.metron.elasticsearch.dao.ElasticsearchDao) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 5 with MockHBaseTableProvider

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();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) ElasticSearchComponent(org.apache.metron.elasticsearch.integration.components.ElasticSearchComponent) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)8 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 Table (org.apache.hadoop.hbase.client.Table)3 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)3 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)3 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)3 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)3 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)3 File (java.io.File)2 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)2 ProfileWriter (org.apache.metron.profiler.client.ProfileWriter)2 SimpleFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)2 Put (org.apache.hadoop.hbase.client.Put)1 Extractor (org.apache.metron.dataloads.extractor.Extractor)1 TransformFilterExtractorDecorator (org.apache.metron.dataloads.extractor.TransformFilterExtractorDecorator)1 StixExtractor (org.apache.metron.dataloads.extractor.stix.StixExtractor)1 ElasticsearchDao (org.apache.metron.elasticsearch.dao.ElasticsearchDao)1 ElasticSearchComponent (org.apache.metron.elasticsearch.integration.components.ElasticSearchComponent)1