@Override public ParserConfigurations defaultConfigurations() { return new ParserConfigurations(); }
public StellarParserRunner withParserConfiguration(String sensorType, SensorParserConfig config) { parserConfigurations = new ParserConfigurations(); parserConfigurations.updateSensorParserConfig(sensorType, config); return this; }
private ParserConfigurations create(byte[] sensorConfig) { try { ParserConfigurations result = new ParserConfigurations(); result.updateSensorParserConfig(sensorType, SensorParserConfig.fromBytes(sensorConfig)); return result; } catch(IOException e) { throw new IllegalArgumentException(e); } }
@Test public void testDefaultIndex() { ParserWriterConfiguration config = new ParserWriterConfiguration( new ParserConfigurations() ); Assert.assertEquals("foo", config.getIndex("foo")); }
@Test public void testDefaultBatchSize() { ParserWriterConfiguration config = new ParserWriterConfiguration( new ParserConfigurations() ); Assert.assertEquals(1, config.getBatchSize("foo")); }
public static ParserConfigurations getSampleParserConfigs() throws IOException { ParserConfigurations configurations = new ParserConfigurations(); configurations.updateGlobalConfig(ConfigurationsUtils.readGlobalConfigFromFile(TestConstants.SAMPLE_CONFIG_PATH)); Map<String, byte[]> sensorParserConfigs = ConfigurationsUtils.readSensorParserConfigsFromFile(TestConstants.PARSER_CONFIGS_PATH); for(String sensorType: sensorParserConfigs.keySet()) { configurations.updateSensorParserConfig(sensorType, sensorParserConfigs.get(sensorType)); } return configurations; }
@Override public ParserConfigurations getConfigurations() { ParserConfigurations configurations = new ParserConfigurations(); SensorParserConfig sensorParserConfig = new SensorParserConfig(); sensorParserConfig.setParserConfig(new HashMap<String, Object>() {{ put(IndexingConfigurations.BATCH_SIZE_CONF, 10); }}); configurations.updateSensorParserConfig("yaf", sensorParserConfig); return configurations; } };
ParserConfigurations configs = new ParserConfigurations(); Map<String, SensorParserConfig> sensorToParserConfigs = getSensorParserConfig(zookeeperUrl, sensorTypes, configs); Collection<SensorParserConfig> parserConfigs = sensorToParserConfigs.values();
@Test public void pulls_writer_configuration_from_parserConfig() throws IOException { ParserConfigurations parserConfigurations = new ParserConfigurations(); final String sensorName = "some-sensor"; parserConfigurations.updateSensorParserConfig("some-sensor", configJson.getBytes()); ParserWriterConfiguration writerConfiguration = new ParserWriterConfiguration( parserConfigurations); assertThat("batch size should match", writerConfiguration.getBatchSize(sensorName), equalTo(5)); assertThat("batch timeout should match", writerConfiguration.getBatchTimeout(sensorName), equalTo(10000)); assertThat("index should match", writerConfiguration.getIndex(sensorName), equalTo("modified-index")); assertThat("enabled should match", writerConfiguration.isEnabled(sensorName), equalTo(false)); }
@Before public void setup() throws IOException { parserConfigurations = new ParserConfigurations(); SensorParserConfig broConfig = SensorParserConfig.fromBytes(broConfigString.getBytes()); SensorParserConfig snortConfig = SensorParserConfig.fromBytes(snortConfigString.getBytes()); parserConfigurations.updateSensorParserConfig("bro", broConfig); parserConfigurations.updateSensorParserConfig("snort", snortConfig); parserConfigurations.updateGlobalConfig(JSONUtils.INSTANCE.load(globalConfigString, JSONUtils.MAP_SUPPLIER)); parserRunner = new ParserRunnerImpl(new HashSet<>(Arrays.asList("bro", "snort"))); broParser = mock(MessageParser.class); snortParser = mock(MessageParser.class); stellarFilter = mock(StellarFilter.class); mockStatic(ReflectionUtils.class); mockStatic(Filters.class); when(ReflectionUtils.createInstance("org.apache.metron.parsers.bro.BasicBroParser")).thenReturn(broParser); when(ReflectionUtils.createInstance("org.apache.metron.parsers.snort.BasicSnortParser")).thenReturn(snortParser); when(Filters.get("org.apache.metron.parsers.filters.StellarFilter", broConfig.getParserConfig())) .thenReturn(stellarFilter); }
public ParserDriver(String sensorType, String parserConfig, String globalConfig) throws IOException { SensorParserConfig sensorParserConfig = SensorParserConfig.fromBytes(parserConfig.getBytes()); this.sensorType = sensorType == null ? sensorParserConfig.getSensorTopic() : sensorType; config = new ParserConfigurations(); config.updateSensorParserConfig(this.sensorType, SensorParserConfig.fromBytes(parserConfig.getBytes())); config.updateGlobalConfig(JSONUtils.INSTANCE.load(globalConfig, JSONUtils.MAP_SUPPLIER)); parserRunner = new ParserRunnerImpl(new HashSet<String>() {{ add(sensorType); }}); }
@Test public void strategies_build_writer_configs() { assertThat(PARSERS.createWriterConfig(writer, new ParserConfigurations()), instanceOf(ParserWriterConfiguration.class)); assertThat(ENRICHMENT.createWriterConfig(writer, new EnrichmentConfigurations()), instanceOf(EnrichmentWriterConfiguration.class)); assertThat(INDEXING.createWriterConfig(writer, new IndexingConfigurations()), instanceOf(IndexingWriterConfiguration.class)); assertThat(PROFILER.createWriterConfig(writer, new ProfilerConfigurations()), instanceOf(ProfilerWriterConfiguration.class)); }
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic"); ParserConfigurations parserConfigurations = new ParserConfigurations(); parserConfigurations.updateSensorParserConfig("yaf", new SensorParserConfig()); doThrow(new IllegalStateException("parserRunner.execute failed")).when(parserRunner).execute(eq("yaf"), any(), eq(parserConfigurations));
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic"); MockParserRunner mockParserRunner = new MockParserRunner(new HashSet<String>() {{ add("yaf"); }}); ParserConfigurations parserConfigurations = new ParserConfigurations(); parserConfigurations.updateSensorParserConfig("yaf", new SensorParserConfig()); doThrow(new IllegalStateException("write failed")).when(writerHandler).write(any(), any(), any(), any(), any());
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic"); MockParserRunner mockParserRunner = new MockParserRunner(new HashSet<String>() {{ add("yaf"); }}); ParserConfigurations parserConfigurations = new ParserConfigurations(); parserConfigurations.updateSensorParserConfig("yaf", new SensorParserConfig());
}}); mockParserRunner.setInvalid(true); ParserConfigurations parserConfigurations = new ParserConfigurations(); parserConfigurations.updateSensorParserConfig("yaf", new SensorParserConfig());
@Test public void sensorParserConfig_properties_populated_by_JSON_configuration() throws IOException { ParserConfigurations parserConfigs = new ParserConfigurations(); parserConfigs.updateSensorParserConfig("test-sensor", parserConfig.getBytes()); SensorParserConfig actualSensorConfig = parserConfigs.getSensorParserConfig("test-sensor");
@Test public void test() throws Exception { ParserConfigurations sampleConfigurations = new ParserConfigurations(); UnitTestHelper.setLog4jLevel(ConfiguredBolt.class, Level.FATAL); try {