Search in sources :

Example 26 with SensorParserConfig

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);
}
Also used : ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 27 with SensorParserConfig

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();
}
Also used : HashMap(java.util.HashMap) ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 28 with SensorParserConfig

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()));
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 29 with SensorParserConfig

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());
}
Also used : SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 30 with SensorParserConfig

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());
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Aggregations

SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)49 Test (org.junit.Test)39 JSONObject (org.json.simple.JSONObject)18 FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)17 HashMap (java.util.HashMap)9 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)5 Config (org.apache.storm.Config)5 File (java.io.File)4 IOException (java.io.IOException)3 JSONUtils (org.apache.metron.common.utils.JSONUtils)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Reference (java.lang.ref.Reference)2 java.util (java.util)2 List (java.util.List)2 Map (java.util.Map)2 Predicate (java.util.function.Predicate)2 Supplier (java.util.function.Supplier)2 Multiline (org.adrianwalker.multilinestring.Multiline)2 CommandLine (org.apache.commons.cli.CommandLine)2