@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; EnrichmentValue that = (EnrichmentValue) o; return getMetadata() != null ? getMetadata().equals(that.getMetadata()) : that.getMetadata() == null; }
@Override public int hashCode() { return getMetadata() != null ? getMetadata().hashCode() : 0; }
try { LookupKV<EnrichmentKey, EnrichmentValue> kv = lookup.get(new EnrichmentKey(enrichmentType, indicator), hbaseContext, true); if (kv != null && kv.getValue() != null && kv.getValue().getMetadata() != null) { return kv.getValue().getMetadata();
if (kv != null && kv.getValue() != null && kv.getValue().getMetadata() != null) { for (Map.Entry<String, Object> values : kv.getValue().getMetadata().entrySet()) { enriched.put(kv.getKey().type + "." + values.getKey(), values.getValue());
kv.getValue().getMetadata().put("source_type", "taxii"); kv.getValue().getMetadata().put("taxii_url", endpoint.toString()); kv.getValue().getMetadata().put("taxii_collection", collection); Put p = converter.toPut(columnFamily, kv.getKey(), kv.getValue()); HTableInterface table = getTable(hbaseTable);
@Test public void testFilteredKeys() 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(), ImmutableList.of("user", "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("localhost", values.get(0).getValue().getMetadata().get("ip")); Assert.assertNull(values.get(0).getValue().getMetadata().get("foo")); Assert.assertEquals(2, values.get(0).getValue().getMetadata().size()); }
@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()); }
@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()); }
for (LookupKV<EnrichmentKey, EnrichmentValue> kv : result.getResult()) { Assert.assertTrue(validIndicators.contains(kv.getKey().indicator)); Assert.assertEquals(kv.getValue().getMetadata().get("source.type"), "dummy"); Assert.assertNotNull(kv.getValue().getMetadata().get("timestamp")); Assert.assertNotNull(kv.getValue().getMetadata().get("original_string")); Map<String, String> metadata = validMetadata.get(kv.getKey().indicator); for (Map.Entry<String, String> x : metadata.entrySet()) { Assert.assertEquals(kv.getValue().getMetadata().get(x.getKey()), x.getValue()); Assert.assertEquals(metadata.size() + 4, kv.getValue().getMetadata().size());