use of org.graylog2.indexer.ElasticsearchException in project graylog2-server by Graylog2.
the class V20170607164210_MigrateReopenedIndicesToAliases method getReopenedIndices.
private Set<String> getReopenedIndices(final Collection<String> indices) {
final SearchVersion elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
final JsonNode clusterStateJson = clusterState.getForIndices(indices);
final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
if (indicesJson.isMissingNode()) {
LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
return Collections.emptySet();
}
for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
final Map.Entry<String, JsonNode> entry = it.next();
final String indexName = entry.getKey();
final JsonNode value = entry.getValue();
final JsonNode indexSettings = value.path("settings");
if (indexSettings.isMissingNode()) {
LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
LOG.debug("Index metadata was: {}", value.toString());
continue;
}
if (checkForReopened(indexSettings, elasticsearchVersion)) {
LOG.debug("Adding {} to list of indices to be migrated.", indexName);
reopenedIndices.add(indexName);
}
}
return reopenedIndices.build();
}
use of org.graylog2.indexer.ElasticsearchException in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithUnsuccessfulResponseAndErrorDetails.
@Test
public void executeWithUnsuccessfulResponseAndErrorDetails() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode rootCauseStub = objectMapper.createObjectNode();
rootCauseStub.set("reason", new TextNode("foobar"));
final ArrayNode rootCausesStub = objectMapper.createArrayNode();
rootCausesStub.add(rootCauseStub);
final ObjectNode errorStub = objectMapper.createObjectNode();
errorStub.set("root_cause", rootCausesStub);
final ObjectNode responseStub = objectMapper.createObjectNode();
responseStub.set("error", errorStub);
when(resultMock.getJsonObject()).thenReturn(responseStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("foobar").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("foobar");
}
}
use of org.graylog2.indexer.ElasticsearchException in project graylog2-server by Graylog2.
the class JestUtilsTest method executeFailsWithCustomMessage.
@Test
public void executeFailsWithCustomMessage() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode responseStub = objectMapper.createObjectNode();
final ObjectNode errorStub = objectMapper.createObjectNode();
responseStub.set("Message", new TextNode("Authorization header requires 'Credential' parameter."));
errorStub.set("error", responseStub);
when(resultMock.getJsonObject()).thenReturn(errorStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}");
}
}
use of org.graylog2.indexer.ElasticsearchException in project graylog2-server by Graylog2.
the class MessagesAdapterES7 method runBulkRequest.
private BulkResponse runBulkRequest(int indexedSuccessfully, List<IndexingRequest> chunk) throws ChunkedBulkIndexer.EntityTooLargeException {
final BulkRequest bulkRequest = createBulkRequest(chunk);
final BulkResponse result;
try {
result = this.client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
} catch (ElasticsearchException e) {
for (ElasticsearchException cause : e.guessRootCauses()) {
if (cause.status().equals(RestStatus.REQUEST_ENTITY_TOO_LARGE)) {
throw new ChunkedBulkIndexer.EntityTooLargeException(indexedSuccessfully, indexingErrorsFrom(chunk));
}
}
throw new org.graylog2.indexer.ElasticsearchException(e);
}
return result;
}
use of org.graylog2.indexer.ElasticsearchException in project graylog2-server by Graylog2.
the class ElasticsearchBackend method checkForFailedShards.
private Optional<ElasticsearchException> checkForFailedShards(MultiSearchResponse.Item multiSearchResponse) {
if (multiSearchResponse.isFailure()) {
return Optional.of(new ElasticsearchException(multiSearchResponse.getFailureMessage(), multiSearchResponse.getFailure()));
}
final SearchResponse searchResponse = multiSearchResponse.getResponse();
if (searchResponse != null && searchResponse.getFailedShards() > 0) {
final List<Throwable> shardFailures = Arrays.stream(searchResponse.getShardFailures()).map(ShardOperationFailedException::getCause).collect(Collectors.toList());
final List<String> nonNumericFieldErrors = shardFailures.stream().filter(shardFailure -> shardFailure.getMessage().contains("Expected numeric type on field")).map(Throwable::getMessage).distinct().collect(Collectors.toList());
if (!nonNumericFieldErrors.isEmpty()) {
return Optional.of(new FieldTypeException("Unable to perform search query: ", nonNumericFieldErrors));
}
final List<String> errors = shardFailures.stream().map(Throwable::getMessage).distinct().collect(Collectors.toList());
return Optional.of(new ElasticsearchException("Unable to perform search query: ", errors));
}
return Optional.empty();
}
Aggregations