Search in sources :

Example 6 with SimpleHbaseEnrichmentWriter

use of org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter in project metron by apache.

the class SimpleHBaseEnrichmentWriterTest method testConfigValidation_missing_key_columns.

@Test(expected = IllegalArgumentException.class)
public void testConfigValidation_missing_key_columns() {
    final String sensorType = "dummy";
    SimpleHbaseEnrichmentWriter writer = new SimpleHbaseEnrichmentWriter();
    WriterConfiguration configuration = createConfig(1, new HashMap<String, Object>() {

        {
            put(SimpleHbaseEnrichmentWriter.Configurations.ENRICHMENT_TYPE.getKey(), ENRICHMENT_TYPE);
        }
    });
    try {
        writer.configure(sensorType, configuration);
    } catch (IllegalArgumentException ex) {
        Assert.assertEquals(String.format("%s must be provided", SimpleHbaseEnrichmentWriter.Configurations.KEY_COLUMNS.getKey()), ex.getMessage());
        throw ex;
    }
}
Also used : SimpleHbaseEnrichmentWriter(org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Example 7 with SimpleHbaseEnrichmentWriter

use of org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter in project metron by apache.

the class SimpleHBaseEnrichmentWriterTest method testBatchOneNormalPath.

@Test
public void testBatchOneNormalPath() throws Exception {
    final String sensorType = "dummy";
    SimpleHbaseEnrichmentWriter writer = new SimpleHbaseEnrichmentWriter();
    WriterConfiguration configuration = createConfig(1, new HashMap<String, Object>(BASE_WRITER_CONFIG) {

        {
            put(SimpleHbaseEnrichmentWriter.Configurations.KEY_COLUMNS.getKey(), "ip");
        }
    });
    writer.configure(sensorType, configuration);
    writer.write(SENSOR_TYPE, configuration, null, new ArrayList<JSONObject>() {

        {
            add(new JSONObject(ImmutableMap.of("ip", "localhost", "user", "cstella", "foo", "bar")));
        }
    });
    List<LookupKV<EnrichmentKey, EnrichmentValue>> values = getValues();
    Assert.assertEquals(1, values.size());
    Assert.assertEquals("localhost", values.get(0).getKey().indicator);
    Assert.assertEquals("cstella", values.get(0).getValue().getMetadata().get("user"));
    Assert.assertEquals("bar", values.get(0).getValue().getMetadata().get("foo"));
    Assert.assertEquals(2, values.get(0).getValue().getMetadata().size());
}
Also used : JSONObject(org.json.simple.JSONObject) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) SimpleHbaseEnrichmentWriter(org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Example 8 with SimpleHbaseEnrichmentWriter

use of org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter in project metron by apache.

the class SimpleHBaseEnrichmentWriterTest method testFilteredKey.

@Test
public void testFilteredKey() throws Exception {
    final String sensorType = "dummy";
    SimpleHbaseEnrichmentWriter writer = new SimpleHbaseEnrichmentWriter();
    WriterConfiguration configuration = createConfig(1, new HashMap<String, Object>(BASE_WRITER_CONFIG) {

        {
            put(SimpleHbaseEnrichmentWriter.Configurations.KEY_COLUMNS.getKey(), "ip");
            put(SimpleHbaseEnrichmentWriter.Configurations.VALUE_COLUMNS.getKey(), "user");
        }
    });
    writer.configure(sensorType, configuration);
    writer.write(SENSOR_TYPE, configuration, null, new ArrayList<JSONObject>() {

        {
            add(new JSONObject(ImmutableMap.of("ip", "localhost", "user", "cstella", "foo", "bar")));
        }
    });
    List<LookupKV<EnrichmentKey, EnrichmentValue>> values = getValues();
    Assert.assertEquals(1, values.size());
    Assert.assertEquals("localhost", values.get(0).getKey().indicator);
    Assert.assertEquals("cstella", values.get(0).getValue().getMetadata().get("user"));
    Assert.assertNull(values.get(0).getValue().getMetadata().get("foo"));
    Assert.assertEquals(1, values.get(0).getValue().getMetadata().size());
}
Also used : JSONObject(org.json.simple.JSONObject) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) SimpleHbaseEnrichmentWriter(org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Example 9 with SimpleHbaseEnrichmentWriter

use of org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter in project metron by apache.

the class SimpleHBaseEnrichmentWriterTest method testConfigValidation_missing_enrichment_type.

@Test(expected = IllegalArgumentException.class)
public void testConfigValidation_missing_enrichment_type() {
    final String sensorType = "dummy";
    SimpleHbaseEnrichmentWriter writer = new SimpleHbaseEnrichmentWriter();
    WriterConfiguration configuration = createConfig(1, new HashMap<String, Object>() {

        {
            put(SimpleHbaseEnrichmentWriter.Configurations.KEY_COLUMNS.getKey(), "ip");
        }
    });
    try {
        writer.configure(sensorType, configuration);
    } catch (IllegalArgumentException ex) {
        Assert.assertEquals(String.format("%s must be provided", SimpleHbaseEnrichmentWriter.Configurations.ENRICHMENT_TYPE.getKey()), ex.getMessage());
        throw ex;
    }
}
Also used : SimpleHbaseEnrichmentWriter(org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Aggregations

WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)9 SimpleHbaseEnrichmentWriter (org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter)9 JSONObject (org.json.simple.JSONObject)9 Test (org.junit.Test)9 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)3