use of org.graylog2.indexer.MasterNotDiscoveredException in project graylog2-server by Graylog2.
the class JestUtils method specificException.
public static ElasticsearchException specificException(Supplier<String> errorMessage, JsonNode errorNode) {
final JsonNode rootCauses = errorNode.path("root_cause");
final List<String> reasons = new ArrayList<>(rootCauses.size());
for (JsonNode rootCause : rootCauses) {
final JsonNode reason = rootCause.path("reason");
if (reason.isTextual()) {
reasons.add(reason.asText());
}
final JsonNode type = rootCause.path("type");
if (!type.isTextual()) {
continue;
}
switch(type.asText()) {
case "master_not_discovered_exception":
return new MasterNotDiscoveredException();
case "cluster_block_exception":
if (reason.asText().contains("no master")) {
return new MasterNotDiscoveredException();
}
case "query_parsing_exception":
return buildQueryParsingException(errorMessage, rootCause, reasons);
case "index_not_found_exception":
final String indexName = rootCause.path("resource.id").asText();
return IndexNotFoundException.create(errorMessage.get(), indexName);
case "illegal_argument_exception":
final String reasonText = reason.asText();
if (reasonText.startsWith("Expected numeric type on field")) {
return buildFieldTypeException(errorMessage, reasonText);
}
if (reasonText.startsWith("no write index is defined for alias")) {
final Matcher matcher = invalidWriteTarget.matcher(reasonText);
if (matcher.find()) {
final String target = matcher.group("target");
return InvalidWriteTargetException.create(target);
}
}
break;
}
}
if (reasons.isEmpty()) {
return new ElasticsearchException(errorMessage.get(), Collections.singletonList(errorNode.toString()));
}
return new ElasticsearchException(errorMessage.get(), deduplicateErrors(reasons));
}
Aggregations