Search in sources :

Example 6 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.

the class SimpleHbaseEnrichmentWriter method configure.

@Override
public void configure(String sensorName, WriterConfiguration configuration) {
    validateEnrichmentType(sensorName, configuration);
    validateKeyColumns(sensorName, configuration);
    String hbaseProviderImpl = Configurations.HBASE_PROVIDER.getAndConvert(configuration.getSensorConfig(sensorName), String.class);
    if (hbaseProviderImpl != null) {
        provider = ReflectionUtils.createInstance(hbaseProviderImpl);
    }
    if (converter == null) {
        converter = new EnrichmentConverter();
    }
    LOG.debug("Sensor: '{}': {Provider: '{}', Converter: '{}'}", sensorName, getClassName(provider), getClassName(converter));
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter)

Example 7 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.

the class HBaseEnrichmentConverterTest method testResult.

@Test
public void testResult() throws IOException {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Result r = converter.toResult("cf", key, value);
    LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromResult(r, "cf");
    Assert.assertEquals(results, converted);
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 8 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.

the class HBaseEnrichmentConverterTest method testGet.

@Test
public void testGet() throws Exception {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Get get = converter.toGet("cf", key);
    Assert.assertArrayEquals(key.toBytes(), get.getRow());
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) Get(org.apache.hadoop.hbase.client.Get) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Example 9 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.

the class HBaseEnrichmentConverterTest method testPut.

@Test
public void testPut() throws IOException {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Put put = converter.toPut("cf", key, value);
    LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromPut(put, "cf");
    Assert.assertEquals(results, converted);
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 10 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.

the class BulkLoadMapperTest method testMapper.

@Test
public void testMapper() throws IOException, InterruptedException {
    final Map<ImmutableBytesWritable, Put> puts = new HashMap<>();
    BulkLoadMapper mapper = new BulkLoadMapper() {

        @Override
        protected void write(ImmutableBytesWritable key, Put value, Context context) throws IOException, InterruptedException {
            puts.put(key, value);
        }
    };
    mapper.initialize(new Configuration() {

        {
            set(BulkLoadMapper.COLUMN_FAMILY_KEY, "cf");
            set(BulkLoadMapper.CONFIG_KEY, extractorConfig);
            set(BulkLoadMapper.LAST_SEEN_KEY, "0");
            set(BulkLoadMapper.CONVERTER_KEY, EnrichmentConverter.class.getName());
        }
    });
    {
        mapper.map(null, new Text("#google.com,1,foo"), null);
        Assert.assertTrue(puts.size() == 0);
    }
    {
        mapper.map(null, new Text("google.com,1,foo"), null);
        Assert.assertTrue(puts.size() == 1);
        EnrichmentKey expectedKey = new EnrichmentKey() {

            {
                indicator = "google.com";
                type = "threat";
            }
        };
        EnrichmentConverter converter = new EnrichmentConverter();
        Put put = puts.get(new ImmutableBytesWritable(expectedKey.toBytes()));
        Assert.assertNotNull(puts);
        LookupKV<EnrichmentKey, EnrichmentValue> results = converter.fromPut(put, "cf");
        Assert.assertEquals(results.getKey().indicator, "google.com");
        Assert.assertEquals(results.getValue().getMetadata().size(), 2);
        Assert.assertEquals(results.getValue().getMetadata().get("meta"), "foo");
        Assert.assertEquals(results.getValue().getMetadata().get("host"), "google.com");
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) Configuration(org.apache.hadoop.conf.Configuration) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) Put(org.apache.hadoop.hbase.client.Put) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) Test(org.junit.Test)

Aggregations

EnrichmentConverter (org.apache.metron.enrichment.converter.EnrichmentConverter)17 Test (org.junit.Test)12 Result (org.apache.hadoop.hbase.client.Result)10 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)10 ArrayList (java.util.ArrayList)8 Delete (org.apache.hadoop.hbase.client.Delete)7 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)7 EnrichmentKey (org.apache.metron.enrichment.converter.EnrichmentKey)7 EnrichmentValue (org.apache.metron.enrichment.converter.EnrichmentValue)6 Put (org.apache.hadoop.hbase.client.Put)3 HashMap (java.util.HashMap)2 MockHTable (org.apache.metron.hbase.mock.MockHTable)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Get (org.apache.hadoop.hbase.client.Get)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1