Search in sources :

Example 16 with WriterConfiguration

use of org.apache.metron.common.configuration.writer.WriterConfiguration 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 17 with WriterConfiguration

use of org.apache.metron.common.configuration.writer.WriterConfiguration 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 18 with WriterConfiguration

use of org.apache.metron.common.configuration.writer.WriterConfiguration 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 19 with WriterConfiguration

use of org.apache.metron.common.configuration.writer.WriterConfiguration 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)

Example 20 with WriterConfiguration

use of org.apache.metron.common.configuration.writer.WriterConfiguration in project metron by apache.

the class HdfsWriterTest method testGetHdfsPathFormatVariable.

@Test
@SuppressWarnings("unchecked")
public void testGetHdfsPathFormatVariable() {
    IndexingConfigurations indexingConfig = new IndexingConfigurations();
    WriterConfiguration config = new IndexingWriterConfiguration(WRITER_NAME, indexingConfig);
    HdfsWriter writer = new HdfsWriter().withFileNameFormat(testFormat);
    writer.init(new HashMap<String, String>(), createTopologyContext(), config);
    JSONObject message = new JSONObject();
    message.put("test.key", "test.value");
    message.put("test.key.2", "test.value.2");
    message.put("test.key.3", "test.value.3");
    Object result = writer.getHdfsPathExtension(SENSOR_NAME, "FORMAT('%s/%s/%s', test.key, test.key.2, test.key.3)", message);
    writer.close();
    Assert.assertEquals("test.value/test.value.2/test.value.3", result);
}
Also used : JSONObject(org.json.simple.JSONObject) IndexingWriterConfiguration(org.apache.metron.common.configuration.writer.IndexingWriterConfiguration) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) IndexingWriterConfiguration(org.apache.metron.common.configuration.writer.IndexingWriterConfiguration) JSONObject(org.json.simple.JSONObject) IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) Test(org.junit.Test)

Aggregations

WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)32 Test (org.junit.Test)29 JSONObject (org.json.simple.JSONObject)26 IndexingWriterConfiguration (org.apache.metron.common.configuration.writer.IndexingWriterConfiguration)21 IndexingConfigurations (org.apache.metron.common.configuration.IndexingConfigurations)13 SimpleHbaseEnrichmentWriter (org.apache.metron.enrichment.writer.SimpleHbaseEnrichmentWriter)9 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Tuple (org.apache.storm.tuple.Tuple)6 DefaultFileNameFormat (org.apache.storm.hdfs.bolt.format.DefaultFileNameFormat)4 FileNameFormat (org.apache.storm.hdfs.bolt.format.FileNameFormat)4 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)3 WriterToBulkWriter (org.apache.metron.writer.WriterToBulkWriter)3 ParserWriterConfiguration (org.apache.metron.common.configuration.writer.ParserWriterConfiguration)2 CountSyncPolicy (org.apache.storm.hdfs.bolt.sync.CountSyncPolicy)2