Search in sources :

Example 31 with LookupKV

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

the class SimpleEnrichmentFlatFileLoaderIntegrationTest method testLocalLineByLine_zip.

@Test
public void testLocalLineByLine_zip() throws Exception {
    String[] argv = { "-c cf", "-t enrichment", "-e " + lineByLineExtractorConfigFile.getPath(), "-i " + multilineZipFile.getPath(), "-p 2", "-b 128", "-q" };
    SimpleEnrichmentFlatFileLoader.main(config, argv);
    EnrichmentConverter converter = new EnrichmentConverter();
    ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
    List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
    for (Result r : scanner) {
        results.add(converter.fromResult(r, cf));
        testTable.delete(new Delete(r.getRow()));
    }
    Assert.assertEquals(NUM_LINES, results.size());
    Assert.assertTrue(results.get(0).getKey().indicator.startsWith("google"));
    Assert.assertEquals(results.get(0).getKey().type, "enrichment");
    Assert.assertEquals(results.get(0).getValue().getMetadata().size(), 2);
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 32 with LookupKV

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

the class SimpleEnrichmentFlatFileLoaderIntegrationTest method testMRLineByLine.

@Test
public void testMRLineByLine() throws Exception {
    String[] argv = { "-c cf", "-t enrichment", "-e " + lineByLineExtractorConfigFile.getPath(), "-i " + multilineFile.getName(), "-m MR", "-p 2", "-b 128", "-q" };
    FileSystem fs = FileSystem.get(config);
    HBaseUtil.INSTANCE.writeFile(new String(Files.readAllBytes(multilineFile.toPath())), new Path(multilineFile.getName()), fs);
    SimpleEnrichmentFlatFileLoader.main(config, argv);
    EnrichmentConverter converter = new EnrichmentConverter();
    ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
    List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
    for (Result r : scanner) {
        results.add(converter.fromResult(r, cf));
        testTable.delete(new Delete(r.getRow()));
    }
    Assert.assertEquals(NUM_LINES, results.size());
    Assert.assertTrue(results.get(0).getKey().indicator.startsWith("google"));
    Assert.assertEquals(results.get(0).getKey().type, "enrichment");
    Assert.assertEquals(results.get(0).getValue().getMetadata().size(), 2);
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
Also used : Path(org.apache.hadoop.fs.Path) Delete(org.apache.hadoop.hbase.client.Delete) EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) FileSystem(org.apache.hadoop.fs.FileSystem) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 33 with LookupKV

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

the class SimpleEnrichmentFlatFileLoaderIntegrationTest method testLocalLineByLine_gz.

@Test
public void testLocalLineByLine_gz() throws Exception {
    String[] argv = { "-c cf", "-t enrichment", "-e " + lineByLineExtractorConfigFile.getPath(), "-i " + multilineGzFile.getPath(), "-p 2", "-b 128", "-q" };
    SimpleEnrichmentFlatFileLoader.main(config, argv);
    EnrichmentConverter converter = new EnrichmentConverter();
    ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
    List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
    for (Result r : scanner) {
        results.add(converter.fromResult(r, cf));
        testTable.delete(new Delete(r.getRow()));
    }
    Assert.assertEquals(NUM_LINES, results.size());
    Assert.assertTrue(results.get(0).getKey().indicator.startsWith("google"));
    Assert.assertEquals(results.get(0).getKey().type, "enrichment");
    Assert.assertEquals(results.get(0).getValue().getMetadata().size(), 2);
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
    Assert.assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result) 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