Search in sources :

Example 16 with EnrichmentConverter

use of org.apache.metron.enrichment.converter.EnrichmentConverter 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)

Example 17 with EnrichmentConverter

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

the class TaxiiIntegrationTest method getIndicators.

private static Set<String> getIndicators(String indicatorType, Iterable<Put> puts, String cf) throws IOException {
    EnrichmentConverter converter = new EnrichmentConverter();
    Set<String> ret = new HashSet<>();
    for (Put p : puts) {
        LookupKV<EnrichmentKey, EnrichmentValue> kv = converter.fromPut(p, cf);
        if (kv.getKey().type.equals(indicatorType)) {
            ret.add(kv.getKey().indicator);
        }
    }
    return ret;
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) Put(org.apache.hadoop.hbase.client.Put) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) HashSet(java.util.HashSet)

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