Search in sources :

Example 1 with AckTuplesPolicy

use of org.apache.metron.writer.AckTuplesPolicy in project metron by apache.

the class ParserBolt method prepare.

@SuppressWarnings("unchecked")
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    super.prepare(stormConf, context, collector);
    messageGetStrategy = MessageGetters.DEFAULT_BYTES_FROM_POSITION.get();
    this.collector = collector;
    this.parserRunner.init(this::getConfigurations, initializeStellar());
    ackTuplesPolicy = new AckTuplesPolicy(collector, messageGetStrategy);
    // Need to prep all sensors
    for (Map.Entry<String, WriterHandler> entry : sensorToWriterMap.entrySet()) {
        String sensor = entry.getKey();
        SensorParserConfig config = getSensorParserConfig(sensor);
        if (config != null) {
            config.init();
            topicToSensorMap.put(config.getSensorTopic(), sensor);
        } else {
            throw new IllegalStateException("Unable to retrieve a parser config for " + sensor);
        }
        WriterHandler writer = sensorToWriterMap.get(sensor);
        if (maxBatchTimeout == 0) {
            // This means getComponentConfiguration was never called to initialize maxBatchTimeout,
            // probably because we are in a unit test scenario.  So calculate it here.
            WriterConfiguration writerConfig = getConfigurationStrategy().createWriterConfig(writer.getBulkMessageWriter(), getConfigurations());
            BatchTimeoutHelper timeoutHelper = new BatchTimeoutHelper(writerConfig::getAllConfiguredTimeouts, batchTimeoutDivisor);
            maxBatchTimeout = timeoutHelper.getMaxBatchTimeout();
        }
        writer.init(stormConf, context, collector, getConfigurations(), ackTuplesPolicy, maxBatchTimeout);
    }
}
Also used : AckTuplesPolicy(org.apache.metron.writer.AckTuplesPolicy) BatchTimeoutHelper(org.apache.metron.writer.bolt.BatchTimeoutHelper) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AckTuplesPolicy

use of org.apache.metron.writer.AckTuplesPolicy in project metron by apache.

the class BulkMessageWriterBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    super.prepare(stormConf, context, collector);
    if (messageGetField != null) {
        messageGetStrategy = MessageGetters.valueOf(messageGetStrategyType).get(messageGetField);
    } else {
        messageGetStrategy = MessageGetters.valueOf(messageGetStrategyType).get();
    }
    if (bulkMessageWriter instanceof WriterToBulkWriter) {
        configurationTransformation = WriterToBulkWriter.TRANSFORMATION;
    } else {
        configurationTransformation = x -> x;
    }
    ackTuplesPolicy = new AckTuplesPolicy(collector, messageGetStrategy);
    try {
        WriterConfiguration writerconf = configurationTransformation.apply(getConfigurationStrategy().createWriterConfig(bulkMessageWriter, getConfigurations()));
        if (maxBatchTimeout == 0) {
            // This means getComponentConfiguration was never called to initialize maxBatchTimeout,
            // probably because we are in a unit test scenario.  So calculate it here.
            BatchTimeoutHelper timeoutHelper = new BatchTimeoutHelper(writerconf::getAllConfiguredTimeouts, batchTimeoutDivisor);
            maxBatchTimeout = timeoutHelper.getMaxBatchTimeout();
        }
        BulkWriterComponent<JSONObject> bulkWriterComponent = new BulkWriterComponent<>(maxBatchTimeout);
        bulkWriterComponent.addFlushPolicy(ackTuplesPolicy);
        setWriterComponent(bulkWriterComponent);
        bulkMessageWriter.init(stormConf, writerconf);
        if (bulkMessageWriter instanceof HdfsWriter) {
            ((HdfsWriter) bulkMessageWriter).initFileNameFormat(context);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WriterToBulkWriter(org.apache.metron.writer.WriterToBulkWriter) AckTuplesPolicy(org.apache.metron.writer.AckTuplesPolicy) JSONObject(org.json.simple.JSONObject) BulkWriterComponent(org.apache.metron.writer.BulkWriterComponent) HdfsWriter(org.apache.metron.writer.hdfs.HdfsWriter) WriterConfiguration(org.apache.metron.common.configuration.writer.WriterConfiguration)

Example 3 with AckTuplesPolicy

use of org.apache.metron.writer.AckTuplesPolicy in project metron by apache.

the class WriterBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    messageGetStrategy = MessageGetters.DEFAULT_JSON_FROM_FIELD.get();
    ackTuplesPolicy = new AckTuplesPolicy(collector, messageGetStrategy);
    handler.init(stormConf, context, collector, configuration, ackTuplesPolicy, UNINITIALIZED_MAX_BATCH_TIMEOUT);
}
Also used : AckTuplesPolicy(org.apache.metron.writer.AckTuplesPolicy)

Aggregations

AckTuplesPolicy (org.apache.metron.writer.AckTuplesPolicy)3 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)1 BulkWriterComponent (org.apache.metron.writer.BulkWriterComponent)1 WriterToBulkWriter (org.apache.metron.writer.WriterToBulkWriter)1 BatchTimeoutHelper (org.apache.metron.writer.bolt.BatchTimeoutHelper)1 HdfsWriter (org.apache.metron.writer.hdfs.HdfsWriter)1 JSONObject (org.json.simple.JSONObject)1