use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse in project samza by apache.
the class ElasticsearchSystemProducerTest method getRespWithFailedDocument.
private BulkResponse getRespWithFailedDocument(RestStatus status) {
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(true);
BulkItemResponse itemResp = mock(BulkItemResponse.class);
when(itemResp.isFailed()).thenReturn(true);
BulkItemResponse.Failure failure = mock(BulkItemResponse.Failure.class);
when(failure.getStatus()).thenReturn(status);
when(itemResp.getFailure()).thenReturn(failure);
BulkItemResponse[] itemResponses = new BulkItemResponse[] { itemResp };
when(response.getItems()).thenReturn(itemResponses);
return response;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse in project flink by apache.
the class ElasticsearchWriter method extractFailures.
private void extractFailures(BulkRequest request, BulkResponse response) {
if (!response.hasFailures()) {
pendingActions -= request.numberOfActions();
return;
}
Throwable chainedFailures = null;
for (int i = 0; i < response.getItems().length; i++) {
final BulkItemResponse itemResponse = response.getItems()[i];
if (!itemResponse.isFailed()) {
continue;
}
final Throwable failure = itemResponse.getFailure().getCause();
if (failure == null) {
continue;
}
final RestStatus restStatus = itemResponse.getFailure().getStatus();
final DocWriteRequest<?> actionRequest = request.requests().get(i);
chainedFailures = firstOrSuppressed(wrapException(restStatus, failure, actionRequest), chainedFailures);
}
if (chainedFailures == null) {
return;
}
throw new FlinkRuntimeException(chainedFailures);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse in project metron by apache.
the class ElasticsearchBulkDocumentWriter method write.
@Override
public BulkDocumentWriterResults<D> write() {
BulkDocumentWriterResults<D> results = new BulkDocumentWriterResults<>();
try {
// create an index request for each document
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.setRefreshPolicy(refreshPolicy);
for (Indexable doc : documents) {
DocWriteRequest request = createRequest(doc.document, doc.index);
bulkRequest.add(request);
}
// submit the request and handle the response
BulkResponse bulkResponse = client.getHighLevelClient().bulk(bulkRequest);
handleBulkResponse(bulkResponse, documents, results);
if (LOG.isDebugEnabled()) {
String shards = Arrays.stream(bulkResponse.getItems()).map(bulkItemResponse -> bulkItemResponse.getResponse().getShardId().toString()).collect(Collectors.joining(","));
LOG.debug("{} results written to shards {} in {} ms; batchSize={}, success={}, failed={}", bulkResponse.getItems().length, shards, bulkResponse.getTookInMillis(), documents.size(), results.getSuccesses().size(), results.getFailures().size());
}
} catch (IOException e) {
// assume all documents have failed
for (Indexable indexable : documents) {
D failed = indexable.document;
results.addFailure(failed, e, ExceptionUtils.getRootCauseMessage(e));
}
LOG.error("Failed to submit bulk request; all documents failed", e);
} finally {
// flush all documents no matter which ones succeeded or failed
documents.clear();
}
return results;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse in project metron by apache.
the class ElasticsearchBulkDocumentWriterTest method setupElasticsearchToSucceed.
private void setupElasticsearchToSucceed() throws IOException {
final String documentId = UUID.randomUUID().toString();
final boolean isFailed = false;
final int itemID = 0;
// the write response will contain what is used as the document ID
DocWriteResponse writeResponse = mock(DocWriteResponse.class);
when(writeResponse.getId()).thenReturn(documentId);
// define the item level response
BulkItemResponse itemResponse = mock(BulkItemResponse.class);
when(itemResponse.isFailed()).thenReturn(isFailed);
when(itemResponse.getItemId()).thenReturn(itemID);
when(itemResponse.getResponse()).thenReturn(writeResponse);
List<BulkItemResponse> itemsResponses = Collections.singletonList(itemResponse);
// define the bulk response to indicate success
BulkResponse response = mock(BulkResponse.class);
when(response.iterator()).thenReturn(itemsResponses.iterator());
when(response.hasFailures()).thenReturn(isFailed);
// have the client return the mock response
when(highLevelClient.bulk(any(BulkRequest.class))).thenReturn(response);
}
Aggregations