Search in sources :

Example 1 with ParserWriterConfiguration

use of org.apache.metron.common.configuration.writer.ParserWriterConfiguration in project metron by apache.

the class ParserWriterConfigurationTest method testDefaultIndex.

@Test
public void testDefaultIndex() {
    ParserWriterConfiguration config = new ParserWriterConfiguration(new ParserConfigurations());
    Assert.assertEquals("foo", config.getIndex("foo"));
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) ParserWriterConfiguration(org.apache.metron.common.configuration.writer.ParserWriterConfiguration) Test(org.junit.Test)

Example 2 with ParserWriterConfiguration

use of org.apache.metron.common.configuration.writer.ParserWriterConfiguration in project metron by apache.

the class ParserTopologyBuilder method createErrorBolt.

/**
 * Create a bolt that handles error messages.
 *
 * @param zookeeperUrl    Kafka zookeeper URL
 * @param brokerUrl    Kafka Broker URL
 * @param sensorType   Type of sensor that is being consumed.
 * @param securityProtocol   Security protocol used (if any)
 * @param configs
 * @param parserConfig
 * @return A Storm bolt that handles error messages.
 */
private static WriterBolt createErrorBolt(String zookeeperUrl, Optional<String> brokerUrl, String sensorType, Optional<String> securityProtocol, ParserConfigurations configs, SensorParserConfig parserConfig) {
    // create writer - if not configured uses a sensible default
    AbstractWriter writer = parserConfig.getErrorWriterClassName() == null ? createKafkaWriter(brokerUrl, zookeeperUrl, securityProtocol).withTopic((String) configs.getGlobalConfig().get("parser.error.topic")).withConfigPrefix("error") : ReflectionUtils.createInstance(parserConfig.getWriterClassName());
    writer.configure(sensorType, new ParserWriterConfiguration(configs));
    // create a writer handler
    WriterHandler writerHandler = createWriterHandler(writer);
    return new WriterBolt(writerHandler, configs, sensorType).withErrorType(Constants.ErrorType.PARSER_ERROR);
}
Also used : WriterBolt(org.apache.metron.parsers.bolt.WriterBolt) WriterHandler(org.apache.metron.parsers.bolt.WriterHandler) ParserWriterConfiguration(org.apache.metron.common.configuration.writer.ParserWriterConfiguration) AbstractWriter(org.apache.metron.writer.AbstractWriter)

Example 3 with ParserWriterConfiguration

use of org.apache.metron.common.configuration.writer.ParserWriterConfiguration in project metron by apache.

the class ParserWriterConfigurationTest method testDefaultBatchSize.

@Test
public void testDefaultBatchSize() {
    ParserWriterConfiguration config = new ParserWriterConfiguration(new ParserConfigurations());
    Assert.assertEquals(1, config.getBatchSize("foo"));
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) ParserWriterConfiguration(org.apache.metron.common.configuration.writer.ParserWriterConfiguration) Test(org.junit.Test)

Example 4 with ParserWriterConfiguration

use of org.apache.metron.common.configuration.writer.ParserWriterConfiguration in project metron by apache.

the class KafkaWriterTest method createConfiguration.

public WriterConfiguration createConfiguration(final Map<String, Object> parserConfig) {
    ParserConfigurations configurations = new ParserConfigurations();
    configurations.updateSensorParserConfig(SENSOR_TYPE, new SensorParserConfig() {

        {
            setParserConfig(parserConfig);
        }
    });
    return new ParserWriterConfiguration(configurations);
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) ParserWriterConfiguration(org.apache.metron.common.configuration.writer.ParserWriterConfiguration) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig)

Example 5 with ParserWriterConfiguration

use of org.apache.metron.common.configuration.writer.ParserWriterConfiguration in project metron by apache.

the class ParserTopologyBuilder method createParserBolt.

/**
 * Create a bolt that parses input from a sensor.
 *
 * @param zookeeperUrl Zookeeper URL
 * @param brokerUrl    Kafka Broker URL
 * @param sensorType   Type of sensor that is being consumed.
 * @param configs
 * @param parserConfig
 * @return A Storm bolt that parses input from a sensor
 */
private static ParserBolt createParserBolt(String zookeeperUrl, Optional<String> brokerUrl, String sensorType, Optional<String> securityProtocol, ParserConfigurations configs, SensorParserConfig parserConfig, Optional<String> outputTopic) {
    // create message parser
    MessageParser<JSONObject> parser = ReflectionUtils.createInstance(parserConfig.getParserClassName());
    parser.configure(parserConfig.getParserConfig());
    // create writer - if not configured uses a sensible default
    AbstractWriter writer = parserConfig.getWriterClassName() == null ? createKafkaWriter(brokerUrl, zookeeperUrl, securityProtocol).withTopic(outputTopic.orElse(Constants.ENRICHMENT_TOPIC)) : ReflectionUtils.createInstance(parserConfig.getWriterClassName());
    writer.configure(sensorType, new ParserWriterConfiguration(configs));
    // create a writer handler
    WriterHandler writerHandler = createWriterHandler(writer);
    return new ParserBolt(zookeeperUrl, sensorType, parser, writerHandler);
}
Also used : JSONObject(org.json.simple.JSONObject) WriterHandler(org.apache.metron.parsers.bolt.WriterHandler) ParserBolt(org.apache.metron.parsers.bolt.ParserBolt) ParserWriterConfiguration(org.apache.metron.common.configuration.writer.ParserWriterConfiguration) AbstractWriter(org.apache.metron.writer.AbstractWriter)

Aggregations

ParserWriterConfiguration (org.apache.metron.common.configuration.writer.ParserWriterConfiguration)5 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)3 WriterHandler (org.apache.metron.parsers.bolt.WriterHandler)2 AbstractWriter (org.apache.metron.writer.AbstractWriter)2 Test (org.junit.Test)2 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)1 ParserBolt (org.apache.metron.parsers.bolt.ParserBolt)1 WriterBolt (org.apache.metron.parsers.bolt.WriterBolt)1 JSONObject (org.json.simple.JSONObject)1