Search in sources :

Example 1 with WriterHandler

use of org.apache.metron.parsers.bolt.WriterHandler 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 2 with WriterHandler

use of org.apache.metron.parsers.bolt.WriterHandler 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)2 WriterHandler (org.apache.metron.parsers.bolt.WriterHandler)2 AbstractWriter (org.apache.metron.writer.AbstractWriter)2 ParserBolt (org.apache.metron.parsers.bolt.ParserBolt)1 WriterBolt (org.apache.metron.parsers.bolt.WriterBolt)1 JSONObject (org.json.simple.JSONObject)1