use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.
the class SimpleHbaseEnrichmentWriter method configure.
@Override
public void configure(String sensorName, WriterConfiguration configuration) {
validateEnrichmentType(sensorName, configuration);
validateKeyColumns(sensorName, configuration);
String hbaseProviderImpl = Configurations.HBASE_PROVIDER.getAndConvert(configuration.getSensorConfig(sensorName), String.class);
if (hbaseProviderImpl != null) {
provider = ReflectionUtils.createInstance(hbaseProviderImpl);
}
if (converter == null) {
converter = new EnrichmentConverter();
}
LOG.debug("Sensor: '{}': {Provider: '{}', Converter: '{}'}", sensorName, getClassName(provider), getClassName(converter));
}
use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.
the class HBaseEnrichmentConverterTest method testResult.
@Test
public void testResult() throws IOException {
HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
Result r = converter.toResult("cf", key, value);
LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromResult(r, "cf");
Assert.assertEquals(results, converted);
}
use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.
the class HBaseEnrichmentConverterTest method testGet.
@Test
public void testGet() throws Exception {
HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
Get get = converter.toGet("cf", key);
Assert.assertArrayEquals(key.toBytes(), get.getRow());
}
use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.
the class HBaseEnrichmentConverterTest method testPut.
@Test
public void testPut() throws IOException {
HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
Put put = converter.toPut("cf", key, value);
LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromPut(put, "cf");
Assert.assertEquals(results, converted);
}
use of org.apache.metron.enrichment.converter.EnrichmentConverter in project metron by apache.
the class BulkLoadMapperTest method testMapper.
@Test
public void testMapper() throws IOException, InterruptedException {
final Map<ImmutableBytesWritable, Put> puts = new HashMap<>();
BulkLoadMapper mapper = new BulkLoadMapper() {
@Override
protected void write(ImmutableBytesWritable key, Put value, Context context) throws IOException, InterruptedException {
puts.put(key, value);
}
};
mapper.initialize(new Configuration() {
{
set(BulkLoadMapper.COLUMN_FAMILY_KEY, "cf");
set(BulkLoadMapper.CONFIG_KEY, extractorConfig);
set(BulkLoadMapper.LAST_SEEN_KEY, "0");
set(BulkLoadMapper.CONVERTER_KEY, EnrichmentConverter.class.getName());
}
});
{
mapper.map(null, new Text("#google.com,1,foo"), null);
Assert.assertTrue(puts.size() == 0);
}
{
mapper.map(null, new Text("google.com,1,foo"), null);
Assert.assertTrue(puts.size() == 1);
EnrichmentKey expectedKey = new EnrichmentKey() {
{
indicator = "google.com";
type = "threat";
}
};
EnrichmentConverter converter = new EnrichmentConverter();
Put put = puts.get(new ImmutableBytesWritable(expectedKey.toBytes()));
Assert.assertNotNull(puts);
LookupKV<EnrichmentKey, EnrichmentValue> results = converter.fromPut(put, "cf");
Assert.assertEquals(results.getKey().indicator, "google.com");
Assert.assertEquals(results.getValue().getMetadata().size(), 2);
Assert.assertEquals(results.getValue().getMetadata().get("meta"), "foo");
Assert.assertEquals(results.getValue().getMetadata().get("host"), "google.com");
}
}
Aggregations