public void updateSensorEnrichmentConfig(String sensorType, byte[] data) throws IOException { updateSensorEnrichmentConfig(sensorType, new ByteArrayInputStream(data)); }
@Override public void update(String name, byte[] data) throws IOException { getConfigurations().updateSensorEnrichmentConfig(name, data); }
public void updateSensorEnrichmentConfig(String sensorType, InputStream io) throws IOException { SensorEnrichmentConfig sensorEnrichmentConfig = JSONUtils.INSTANCE.load(io, SensorEnrichmentConfig.class); updateSensorEnrichmentConfig(sensorType, sensorEnrichmentConfig); }
public static void updateEnrichmentConfigsFromZookeeper(EnrichmentConfigurations configurations, CuratorFramework client) throws Exception { updateConfigsFromZookeeper( configurations , ENRICHMENT , sensorType -> configurations.updateSensorEnrichmentConfig(sensorType, readSensorEnrichmentConfigBytesFromZookeeper(sensorType, client)) , client ); }
public static EnrichmentConfigurations getSampleEnrichmentConfigs() throws IOException { EnrichmentConfigurations configurations = new EnrichmentConfigurations(); configurations.updateGlobalConfig(ConfigurationsUtils.readGlobalConfigFromFile(TestConstants.SAMPLE_CONFIG_PATH)); Map<String, byte[]> sensorEnrichmentConfigs = ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.SAMPLE_CONFIG_PATH); for(String sensorType: sensorEnrichmentConfigs.keySet()) { configurations.updateSensorEnrichmentConfig(sensorType, sensorEnrichmentConfigs.get(sensorType)); } return configurations; }
@Test public void test() throws IOException { EnrichmentJoinBolt enrichmentJoinBolt = new EnrichmentJoinBolt("zookeeperUrl"); enrichmentJoinBolt.setCuratorFramework(client); enrichmentJoinBolt.setZKCache(cache); enrichmentJoinBolt.getConfigurations().updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath)); enrichmentJoinBolt.withMaxCacheSize(100); enrichmentJoinBolt.withMaxTimeRetain(10000); enrichmentJoinBolt.prepare(new HashMap<>(), topologyContext, outputCollector); Set<String> actualStreamIds = enrichmentJoinBolt.getStreamIds(sampleMessage); Assert.assertEquals(joinStreamIds, actualStreamIds); Map<String, Tuple> streamMessageMap = new HashMap<>(); MessageGetStrategy messageGetStrategy = mock(MessageGetStrategy.class); Tuple sampleTuple = mock(Tuple.class); when(messageGetStrategy.get(sampleTuple)).thenReturn(sampleMessage); Tuple enrichedTuple = mock(Tuple.class); when(messageGetStrategy.get(enrichedTuple)).thenReturn(enrichedMessage); streamMessageMap.put("message", sampleTuple); streamMessageMap.put("enriched", enrichedTuple); JSONObject joinedMessage = enrichmentJoinBolt.joinMessages(streamMessageMap, messageGetStrategy); removeTimingFields(joinedMessage); Assert.assertEquals(expectedJoinedMessage, joinedMessage); } }
@Test public void test() throws IOException { String threatIntelType = "hbaseThreatIntel"; ThreatIntelSplitterBolt threatIntelSplitterBolt = new ThreatIntelSplitterBolt("zookeeperUrl"); threatIntelSplitterBolt.setCuratorFramework(client); threatIntelSplitterBolt.setZKCache(cache); threatIntelSplitterBolt.getConfigurations().updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath)); threatIntelSplitterBolt.prepare(new HashMap<>(), topologyContext, outputCollector); Map<String, Object> fieldMap = threatIntelSplitterBolt.getFieldMap(sensorType); Assert.assertTrue(fieldMap.containsKey(threatIntelType)); String fieldName = threatIntelSplitterBolt.getKeyName(threatIntelType, "field"); Assert.assertEquals("threatintels.hbaseThreatIntel.field", fieldName); } }
threatIntelJoinBolt.getConfigurations().updateSensorEnrichmentConfig(sensorType, enrichmentConfig); HashMap<String, Object> globalConfig = new HashMap<>(); String baseDir = UnitTestHelper.findDir("GeoLite");
genericEnrichmentBolt.setCuratorFramework(client); genericEnrichmentBolt.setZKCache(cache); genericEnrichmentBolt.getConfigurations().updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath));
enrichmentSplitterBolt.setCuratorFramework(client); enrichmentSplitterBolt.setZKCache(cache); enrichmentSplitterBolt.getConfigurations().updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath)); enrichmentSplitterBolt.prepare(new HashMap<>(), topologyContext, outputCollector);
Map<String, byte[]> sensorEnrichmentConfigs = ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.ENRICHMENTS_CONFIGS_PATH); for (String sensorType : sensorEnrichmentConfigs.keySet()) { sampleConfigurations.updateSensorEnrichmentConfig(sensorType, sensorEnrichmentConfigs.get(sensorType)); }}); testSensorConfig.getThreatIntel().setFieldMap(threatIntelFieldMap); sampleConfigurations.updateSensorEnrichmentConfig(sensorType, testSensorConfig); ConfigurationsUtils.writeSensorEnrichmentConfigToZookeeper(sensorType, testSensorConfig, zookeeperUrl); waitForConfigUpdate(sensorType);