use of org.graylog2.indexer.messages.Indexable in project graylog2-server by Graylog2.
the class MessagesAdapterES6 method indexingErrorsFrom.
private List<Messages.IndexingError> indexingErrorsFrom(List<BulkResult.BulkResultItem> failedItems, List<IndexingRequest> messageList) {
if (failedItems.isEmpty()) {
return Collections.emptyList();
}
final Map<String, Indexable> messageMap = messageList.stream().map(IndexingRequest::message).distinct().collect(Collectors.toMap(Indexable::getId, Function.identity()));
final List<Messages.IndexingError> indexFailures = new ArrayList<>(failedItems.size());
for (BulkResult.BulkResultItem item : failedItems) {
LOG.warn("Failed to index message: index=<{}> id=<{}> error=<{}>", item.index, item.id, item.error);
final Indexable messageEntry = messageMap.get(item.id);
final Messages.IndexingError indexFailure = indexingErrorFromResultItem(item, messageEntry);
indexFailures.add(indexFailure);
}
return indexFailures;
}
use of org.graylog2.indexer.messages.Indexable in project graylog2-server by Graylog2.
the class DefaultFailureHandlerTest method handle_allFailuresHandedOverToIndexFailureService.
@Test
public void handle_allFailuresHandedOverToIndexFailureService() {
// given
final DateTime ts = DateTime.now(DateTimeZone.UTC);
final Indexable indexable1 = mock(Indexable.class);
when(indexable1.getId()).thenReturn("msg-1");
when(indexable1.getTimestamp()).thenReturn(ts);
final Indexable indexable2 = mock(Indexable.class);
when(indexable2.getId()).thenReturn("msg-2");
when(indexable2.getTimestamp()).thenReturn(ts);
final IndexingFailure indexingFailure1 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage1", "indexingFailureDetails1", Tools.nowUTC(), indexable1, "index1");
final IndexingFailure indexingFailure2 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage2", "indexingFailureDetails2", Tools.nowUTC(), indexable2, "index2");
final FailureBatch indexingFailureBatch = FailureBatch.indexingFailureBatch(ImmutableList.of(indexingFailure1, indexingFailure2));
// when
underTest.handle(indexingFailureBatch);
// then
verify(indexFailureService, times(2)).saveWithoutValidation(any());
verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-1") && arg.asMap().get("index").equals("index1") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails1") && arg.asMap().get("timestamp") != null));
verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-2") && arg.asMap().get("index").equals("index2") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails2") && arg.asMap().get("timestamp") != null));
}
use of org.graylog2.indexer.messages.Indexable in project graylog2-server by Graylog2.
the class MessagesAdapterES6 method bulkIndexChunk.
private BulkResult bulkIndexChunk(List<IndexingRequest> chunk) throws IOException {
final Bulk.Builder bulk = new Bulk.Builder();
for (IndexingRequest entry : chunk) {
final Indexable message = entry.message();
bulk.addAction(new Index.Builder(message.toElasticSearchObject(objectMapper, invalidTimestampMeter)).index(entry.indexSet().getWriteIndexAlias()).type(IndexMapping.TYPE_MESSAGE).id(message.getId()).build());
}
return runBulkRequest(bulk.build(), chunk.size());
}
Aggregations