Search in sources :

Example 1 with BulkWriterComponent

use of org.apache.metron.writer.BulkWriterComponent 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)

Aggregations

WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)1 AckTuplesPolicy (org.apache.metron.writer.AckTuplesPolicy)1 BulkWriterComponent (org.apache.metron.writer.BulkWriterComponent)1 WriterToBulkWriter (org.apache.metron.writer.WriterToBulkWriter)1 HdfsWriter (org.apache.metron.writer.hdfs.HdfsWriter)1 JSONObject (org.json.simple.JSONObject)1