use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserConfigServiceImplTest method missingParserClassShouldThrowRestException.
@Test
public void missingParserClassShouldThrowRestException() throws Exception {
exception.expect(RestException.class);
final SensorParserConfig sensorParserConfig = new SensorParserConfig();
sensorParserConfig.setSensorTopic("squid");
ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
parseMessageRequest.setSensorParserConfig(sensorParserConfig);
sensorParserConfigService.parseMessage(parseMessageRequest);
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class ConfiguredParserBoltTest method test.
@Test
public void test() throws Exception {
ParserConfigurations sampleConfigurations = new ParserConfigurations();
UnitTestHelper.setLog4jLevel(ConfiguredBolt.class, Level.FATAL);
try {
StandAloneConfiguredParserBolt configuredBolt = new StandAloneConfiguredParserBolt(null);
configuredBolt.prepare(new HashMap(), topologyContext, outputCollector);
Assert.fail("A valid zookeeper url must be supplied");
} catch (RuntimeException e) {
}
UnitTestHelper.setLog4jLevel(ConfiguredBolt.class, Level.ERROR);
configsUpdated = new HashSet<>();
sampleConfigurations.updateGlobalConfig(ConfigurationsUtils.readGlobalConfigFromFile(TestConstants.SAMPLE_CONFIG_PATH));
Map<String, byte[]> sensorParserConfigs = ConfigurationsUtils.readSensorParserConfigsFromFile(TestConstants.PARSER_CONFIGS_PATH);
for (String sensorType : sensorParserConfigs.keySet()) {
sampleConfigurations.updateSensorParserConfig(sensorType, sensorParserConfigs.get(sensorType));
}
StandAloneConfiguredParserBolt configuredBolt = new StandAloneConfiguredParserBolt(zookeeperUrl);
configuredBolt.prepare(new HashMap(), topologyContext, outputCollector);
waitForConfigUpdate(parserConfigurationTypes);
Assert.assertEquals(sampleConfigurations, configuredBolt.getConfigurations());
configsUpdated = new HashSet<>();
Map<String, Object> sampleGlobalConfig = sampleConfigurations.getGlobalConfig();
sampleGlobalConfig.put("newGlobalField", "newGlobalValue");
ConfigurationsUtils.writeGlobalConfigToZookeeper(sampleGlobalConfig, zookeeperUrl);
waitForConfigUpdate(ConfigurationType.GLOBAL.getTypeName());
Assert.assertEquals("Add global config field", sampleConfigurations.getGlobalConfig(), configuredBolt.getConfigurations().getGlobalConfig());
configsUpdated = new HashSet<>();
sampleGlobalConfig.remove("newGlobalField");
ConfigurationsUtils.writeGlobalConfigToZookeeper(sampleGlobalConfig, zookeeperUrl);
waitForConfigUpdate(ConfigurationType.GLOBAL.getTypeName());
Assert.assertEquals("Remove global config field", sampleConfigurations, configuredBolt.getConfigurations());
configsUpdated = new HashSet<>();
String sensorType = "testSensorConfig";
SensorParserConfig testSensorConfig = new SensorParserConfig();
testSensorConfig.setParserClassName("className");
testSensorConfig.setSensorTopic("sensorTopic");
testSensorConfig.setParserConfig(new HashMap<String, Object>() {
{
put("configName", "configObject");
}
});
sampleConfigurations.updateSensorParserConfig(sensorType, testSensorConfig);
ConfigurationsUtils.writeSensorParserConfigToZookeeper(sensorType, testSensorConfig, zookeeperUrl);
waitForConfigUpdate(sensorType);
Assert.assertEquals("Add new sensor config", sampleConfigurations, configuredBolt.getConfigurations());
configuredBolt.cleanup();
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class FieldTransformationTest method testSimpleMapping.
@Test
public void testSimpleMapping() throws IOException {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(config));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
Assert.assertNotNull(handler);
Assert.assertEquals(ImmutableMap.of("protocol", "TCP"), handler.transform(new JSONObject(ImmutableMap.of("protocol", 6)), Context.EMPTY_CONTEXT(), c.getParserConfig()));
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class FieldTransformationTest method testValidSerde_simple.
@Test
public void testValidSerde_simple() throws IOException {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(config));
Assert.assertEquals(1, c.getFieldTransformations().size());
Assert.assertEquals(IPProtocolTransformation.class, c.getFieldTransformations().get(0).getFieldTransformation().getClass());
Assert.assertEquals(ImmutableList.of("protocol"), c.getFieldTransformations().get(0).getInput());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SelectTransformationTest method testSingleFieldReturned.
@Test
public void testSingleFieldReturned() throws Exception {
SensorParserConfig sensorConfig = SensorParserConfig.fromBytes(Bytes.toBytes(selectSingleFieldConfig));
FieldTransformer handler = Iterables.getFirst(sensorConfig.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
put("field2", "bar");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
Assert.assertTrue(input.containsKey("field1"));
Assert.assertFalse(input.containsKey("field2"));
Assert.assertEquals(1, input.size());
}
Aggregations