Search in sources :

Example 6 with LookupKV

use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.

the class BulkLoadMapper method map.

@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    for (LookupKV results : extractor.extract(value.toString())) {
        if (results != null) {
            Put put = converter.toPut(columnFamily, results.getKey(), results.getValue());
            write(new ImmutableBytesWritable(results.getKey().toBytes()), put, context);
        }
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) Put(org.apache.hadoop.hbase.client.Put)

Example 7 with LookupKV

use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.

the class LocalImporter method toPut.

public List<Put> toPut(String line, Extractor extractor, String cf, HbaseConverter converter) throws IOException {
    List<Put> ret = new ArrayList<>();
    Iterable<LookupKV> kvs = extractor.extract(line);
    for (LookupKV kv : kvs) {
        Put put = converter.toPut(cf, kv.getKey(), kv.getValue());
        ret.add(put);
    }
    return ret;
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) Put(org.apache.hadoop.hbase.client.Put)

Example 8 with LookupKV

use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.

the class ExtractorTest method testDummyExtractor.

@Test
public void testDummyExtractor() throws IllegalAccessException, InstantiationException, ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException {
    Extractor extractor = Extractors.create(DummyExtractor.class.getName());
    LookupKV results = Iterables.getFirst(extractor.extract(null), null);
    EnrichmentKey key = (EnrichmentKey) results.getKey();
    EnrichmentValue value = (EnrichmentValue) results.getValue();
    Assert.assertEquals("dummy", key.indicator);
    Assert.assertEquals("type", key.type);
    Assert.assertEquals("dummy", value.getMetadata().get("indicator"));
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Example 9 with LookupKV

use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.

the class ExtractorTest method testExtractionLoading.

@Test
public void testExtractionLoading() throws Exception {
    /**
     *         config:
     *         {
     *            "config" : {}
     *            ,"extractor" : "org.apache.metron.dataloads.extractor.ExtractorTest$DummyExtractor"
     *         }
     */
    String config = "{\n" + "            \"config\" : {}\n" + "            ,\"extractor\" : \"org.apache.metron.dataloads.extractor.ExtractorTest$DummyExtractor\"\n" + "         }";
    ExtractorHandler handler = ExtractorHandler.load(config);
    LookupKV results = Iterables.getFirst(handler.getExtractor().extract(null), null);
    EnrichmentKey key = (EnrichmentKey) results.getKey();
    EnrichmentValue value = (EnrichmentValue) results.getValue();
    Assert.assertEquals("dummy", key.indicator);
    Assert.assertEquals("type", key.type);
    Assert.assertEquals("dummy", value.getMetadata().get("indicator"));
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Example 10 with LookupKV

use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.

the class TransformFilterExtractorDecoratorTest method transforms_values_and_indicators.

@Test
public void transforms_values_and_indicators() throws IOException {
    final String indicatorVal = "val2";
    EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", indicatorVal);
    EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {

        {
            put("foo", "val1");
            put("bar", indicatorVal);
            put("baz", "val3");
        }
    });
    LookupKV lkv = new LookupKV<>(lookupKey, lookupValue);
    List<LookupKV> extractedLkvs = new ArrayList<>();
    extractedLkvs.add(lkv);
    Mockito.when(extractor.extract("val1,val2,val3")).thenReturn(extractedLkvs);
    Iterable<LookupKV> extracted = decorator.extract("val1,val2,val3");
    EnrichmentKey expectedLookupKey = new EnrichmentKey("testenrichment", "VAL2");
    EnrichmentValue expectedLookupValue = new EnrichmentValue(new HashMap<String, Object>() {

        {
            put("foo", "VAL1");
            put("bar", "val2");
            put("baz", "val3");
            put("newvar", "VAL1");
            put("lowernewvar", "val1");
        }
    });
    LookupKV expectedLkv = new LookupKV<>(expectedLookupKey, expectedLookupValue);
    List<LookupKV> expectedLkvs = new ArrayList<>();
    expectedLkvs.add(expectedLkv);
    Assert.assertThat(extracted, CoreMatchers.equalTo(expectedLkvs));
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Aggregations

LookupKV (org.apache.metron.enrichment.lookup.LookupKV)33 Test (org.junit.Test)19 EnrichmentKey (org.apache.metron.enrichment.converter.EnrichmentKey)16 EnrichmentValue (org.apache.metron.enrichment.converter.EnrichmentValue)14 ArrayList (java.util.ArrayList)12 EnrichmentConverter (org.apache.metron.enrichment.converter.EnrichmentConverter)10 Result (org.apache.hadoop.hbase.client.Result)9 Delete (org.apache.hadoop.hbase.client.Delete)7 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)7 MockHTable (org.apache.metron.hbase.mock.MockHTable)6 HashMap (java.util.HashMap)5 Put (org.apache.hadoop.hbase.client.Put)3 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)3 SimpleHbaseEnrichmentWriter (org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter)3 JSONObject (org.json.simple.JSONObject)3 Before (org.junit.Before)3 File (java.io.File)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 ConfigUploadComponent (org.apache.metron.enrichment.integration.components.ConfigUploadComponent)2 EnrichmentLookup (org.apache.metron.enrichment.lookup.EnrichmentLookup)2