Search in sources :

Example 26 with MessageId

use of org.apache.metron.common.writer.MessageId in project metron by apache.

the class SolrWriter method write.

@Override
public BulkWriterResponse write(String sourceType, WriterConfiguration configurations, List<BulkMessage<JSONObject>> messages) throws Exception {
    String collection = getCollection(sourceType, configurations);
    BulkWriterResponse bulkResponse = new BulkWriterResponse();
    Collection<SolrInputDocument> docs = toDocs(messages);
    Set<MessageId> ids = messages.stream().map(BulkMessage::getId).collect(Collectors.toSet());
    try {
        Optional<SolrException> exceptionOptional = fromUpdateResponse(solr.add(collection, docs));
        // Solr commits the entire batch or throws an exception for it.  There's no way to get partial failures.
        if (exceptionOptional.isPresent()) {
            bulkResponse.addAllErrors(exceptionOptional.get(), ids);
        } else {
            if (shouldCommit) {
                exceptionOptional = fromUpdateResponse(solr.commit(collection, waitFlush, waitSearcher, softCommit));
                if (exceptionOptional.isPresent()) {
                    bulkResponse.addAllErrors(exceptionOptional.get(), ids);
                }
            }
            if (!exceptionOptional.isPresent()) {
                bulkResponse.addAllSuccesses(ids);
            }
        }
    } catch (HttpSolrClient.RemoteSolrException sse) {
        bulkResponse.addAllErrors(sse, ids);
    }
    return bulkResponse;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) SolrException(org.apache.solr.common.SolrException) MessageId(org.apache.metron.common.writer.MessageId)

Example 27 with MessageId

use of org.apache.metron.common.writer.MessageId in project metron by apache.

the class WriterToBulkWriter method write.

@Override
public BulkWriterResponse write(String sensorType, WriterConfiguration configurations, List<BulkMessage<MESSAGE_T>> messages) throws Exception {
    Set<MessageId> ids = messages.stream().map(BulkMessage::getId).collect(Collectors.toSet());
    BulkWriterResponse response = new BulkWriterResponse();
    if (messages.size() > 1) {
        response.addAllErrors(new IllegalStateException("WriterToBulkWriter expects a batch of exactly 1"), ids);
        return response;
    }
    try {
        messageWriter.write(sensorType, configurations, Iterables.getFirst(messages, null));
    } catch (Exception e) {
        response.addAllErrors(e, ids);
        return response;
    }
    response.addAllSuccesses(ids);
    return response;
}
Also used : BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) MessageId(org.apache.metron.common.writer.MessageId)

Aggregations

MessageId (org.apache.metron.common.writer.MessageId)27 BulkWriterResponse (org.apache.metron.common.writer.BulkWriterResponse)25 Test (org.junit.jupiter.api.Test)18 JSONObject (org.json.simple.JSONObject)14 BulkMessage (org.apache.metron.common.writer.BulkMessage)11 BulkDocumentWriterResults (org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults)8 Tuple (org.apache.storm.tuple.Tuple)5 Future (java.util.concurrent.Future)3 InterruptException (org.apache.kafka.common.errors.InterruptException)3 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)3 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MetronError (org.apache.metron.common.error.MetronError)2 MetronErrorJSONMatcher (org.apache.metron.test.error.MetronErrorJSONMatcher)2 Values (org.apache.storm.tuple.Values)2 SimpleDateFormat (java.text.SimpleDateFormat)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1