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;
}
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;
}
Aggregations