Search in sources :

Example 66 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class ParserTopologyCLITest method testSecurityProtocol_fromCLI.

@Test
public void testSecurityProtocol_fromCLI() throws Exception {
    testConfigOption(ParserTopologyCLI.ParserOptions.SECURITY_PROTOCOL, "PLAINTEXT", input -> input.getSecurityProtocol().equals("PLAINTEXT"), () -> {
        SensorParserConfig config = getBaseConfig();
        config.setSecurityProtocol("KERBEROS");
        return Collections.singletonList(config);
    }, input -> input.getSecurityProtocol().equals("KERBEROS"));
}
Also used : SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 67 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class ParserTopologyCLITest method testErrorNumTasks.

@Test
public void testErrorNumTasks() throws Exception {
    testConfigOption(ParserTopologyCLI.ParserOptions.ERROR_WRITER_NUM_TASKS, "10", input -> input.getErrorNumTasks().equals(10), () -> {
        SensorParserConfig config = getBaseConfig();
        config.setErrorWriterNumTasks(20);
        return Collections.singletonList(config);
    }, input -> input.getErrorNumTasks().equals(20));
}
Also used : SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 68 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class ParserTopologyCLITest method testSpoutConfig.

@Test
public void testSpoutConfig() throws Exception {
    File extraConfig = File.createTempFile("spoutConfig", "json");
    extraConfig.deleteOnExit();
    writeMap(extraConfig, new HashMap<String, Object>() {

        {
            put("extra_config", "from_file");
        }
    });
    EnumMap<ParserTopologyCLI.ParserOptions, String> cliOptions = new EnumMap<ParserTopologyCLI.ParserOptions, String>(ParserTopologyCLI.ParserOptions.class) {

        {
            put(ParserTopologyCLI.ParserOptions.SPOUT_CONFIG, extraConfig.getAbsolutePath());
        }
    };
    Predicate<ParserInput> cliOverrideExpected = input -> {
        return input.getSpoutConfig().get(0).get("extra_config").equals("from_file");
    };
    Predicate<ParserInput> configOverrideExpected = input -> {
        return input.getSpoutConfig().get(0).get("extra_config").equals("from_zk");
    };
    Supplier<List<SensorParserConfig>> configSupplier = () -> {
        SensorParserConfig config = getBaseConfig();
        config.setSpoutConfig(new HashMap<String, Object>() {

            {
                put("extra_config", "from_zk");
            }
        });
        return Collections.singletonList(config);
    };
    testConfigOption(cliOptions, cliOverrideExpected, configSupplier, configOverrideExpected);
}
Also used : java.util(java.util) Predicate(java.util.function.Predicate) ValueSupplier(org.apache.metron.parsers.topology.config.ValueSupplier) UnitTestHelper(org.apache.metron.test.utils.UnitTestHelper) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Parser(org.apache.commons.cli.Parser) Supplier(java.util.function.Supplier) File(java.io.File) Test(org.junit.jupiter.api.Test) ParseException(org.apache.commons.cli.ParseException) Multiline(org.adrianwalker.multilinestring.Multiline) Level(org.apache.log4j.Level) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Assertions(org.junit.jupiter.api.Assertions) CommandLine(org.apache.commons.cli.CommandLine) JSONUtils(org.apache.metron.common.utils.JSONUtils) Config(org.apache.storm.Config) PosixParser(org.apache.commons.cli.PosixParser) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 69 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);
    assertNotNull(handler);
    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.jupiter.api.Test)

Example 70 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));
    assertEquals(1, c.getFieldTransformations().size());
    assertEquals(IPProtocolTransformation.class, c.getFieldTransformations().get(0).getFieldTransformation().getClass());
    assertEquals(ImmutableList.of("protocol"), c.getFieldTransformations().get(0).getInput());
}
Also used : SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)97 Test (org.junit.jupiter.api.Test)74 JSONObject (org.json.simple.JSONObject)40 FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)20 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)19 HashMap (java.util.HashMap)15 Config (org.apache.storm.Config)7 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 File (java.io.File)5 Map (java.util.Map)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 WriterHandler (org.apache.metron.parsers.bolt.WriterHandler)5 IOException (java.io.IOException)4 SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)4 MetronError (org.apache.metron.common.error.MetronError)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 CommandLine (org.apache.commons.cli.CommandLine)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3