use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse in project metron by apache.
the class ElasticsearchWriterTest method testMultipleSuccesses.
@Test
public void testMultipleSuccesses() throws Exception {
Tuple tuple1 = mock(Tuple.class);
Tuple tuple2 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(false);
BulkWriterResponse expected = new BulkWriterResponse();
expected.addSuccess(tuple1);
expected.addSuccess(tuple2);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
assertEquals("Response should have no errors and two successes", expected, actual);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse in project metron by apache.
the class ElasticsearchWriterTest method testTwoSameFailure.
@Test
public void testTwoSameFailure() throws Exception {
Tuple tuple1 = mock(Tuple.class);
Tuple tuple2 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(true);
Exception e = new IllegalStateException();
BulkItemResponse itemResponse = buildBulkItemFailure(e);
BulkItemResponse itemResponse2 = buildBulkItemFailure(e);
when(response.iterator()).thenReturn(ImmutableList.of(itemResponse, itemResponse2).iterator());
BulkWriterResponse expected = new BulkWriterResponse();
expected.addError(e, tuple1);
expected.addError(e, tuple2);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
assertEquals("Response should have two errors and no successes", expected, actual);
// Ensure the errors actually get collapsed together
Map<Throwable, Collection<Tuple>> actualErrors = actual.getErrors();
HashMap<Throwable, Collection<Tuple>> expectedErrors = new HashMap<>();
expectedErrors.put(e, ImmutableList.of(tuple1, tuple2));
assertEquals("Errors should have collapsed together", expectedErrors, actualErrors);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse in project metron by apache.
the class ElasticsearchWriterTest method testTwoDifferentFailure.
@Test
public void testTwoDifferentFailure() throws Exception {
Tuple tuple1 = mock(Tuple.class);
Tuple tuple2 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(true);
Exception e = new IllegalStateException("Cause");
Exception e2 = new IllegalStateException("Different Cause");
BulkItemResponse itemResponse = buildBulkItemFailure(e);
BulkItemResponse itemResponse2 = buildBulkItemFailure(e2);
when(response.iterator()).thenReturn(ImmutableList.of(itemResponse, itemResponse2).iterator());
BulkWriterResponse expected = new BulkWriterResponse();
expected.addError(e, tuple1);
expected.addError(e2, tuple2);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
assertEquals("Response should have two errors and no successes", expected, actual);
// Ensure the errors did not get collapsed together
Map<Throwable, Collection<Tuple>> actualErrors = actual.getErrors();
HashMap<Throwable, Collection<Tuple>> expectedErrors = new HashMap<>();
expectedErrors.put(e, ImmutableList.of(tuple1));
expectedErrors.put(e2, ImmutableList.of(tuple2));
assertEquals("Errors should not have collapsed together", expectedErrors, actualErrors);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse in project ecs-dashboard by carone1.
the class ElasticBucketOwnerDAO method insert.
@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
if (bucketOwners != null && !bucketOwners.isEmpty()) {
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for (BucketOwner bucketOwner : bucketOwners) {
XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName).setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch" + "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse in project ecs-dashboard by carone1.
the class ElasticS3ObjectDAO method insert.
/**
* {@inheritDoc}
*/
@Override
public void insert(QueryObjectsResult queryObjectsResult, String namespace, String bucketName, Date collectionTime) {
if (queryObjectsResult == null || queryObjectsResult.getObjects() == null || queryObjectsResult.getObjects().isEmpty()) {
// nothing to insert
return;
}
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for (QueryObject queryObject : queryObjectsResult.getObjects()) {
XContentBuilder s3ObjectBuilder = toJsonFormat(queryObject, namespace, bucketName, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(s3ObjectIndexDayName).setType(S3_OBJECT_INDEX_TYPE).setSource(s3ObjectBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in Elasticsearch " + "index: " + s3ObjectIndexDayName + " index type: " + S3_OBJECT_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failure(s) occured while items in Elasticsearch " + "index: " + s3ObjectIndexDayName + " index type: " + S3_OBJECT_INDEX_TYPE);
}
}
Aggregations