use of org.graylog2.storage.SearchVersion 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.storage.SearchVersion in project graylog2-server by Graylog2.
the class NodeAdapterES7 method version.
@Override
public Optional<SearchVersion> version() {
final Request request = new Request("GET", "/");
final Optional<JsonNode> resp = Optional.of(jsonApi.perform(request, "Unable to retrieve cluster information"));
final Optional<String> version = resp.map(r -> r.path("version")).map(r -> r.path("number")).map(JsonNode::textValue);
final SearchVersion.Distribution distribution = resp.map(r -> r.path("version")).map(r -> r.path("distribution")).map(JsonNode::textValue).map(d -> d.toUpperCase(Locale.ROOT)).map(SearchVersion.Distribution::valueOf).orElse(SearchVersion.Distribution.ELASTICSEARCH);
return version.map(this::parseVersion).map(v -> SearchVersion.create(distribution, v));
}
use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.
the class CmdLineTool method annotateInjectorExceptions.
protected void annotateInjectorExceptions(Collection<Message> messages) {
for (Message message : messages) {
// noinspection ThrowableResultOfMethodCallIgnored
final Throwable rootCause = ExceptionUtils.getRootCause(message.getCause());
if (rootCause instanceof NodeIdPersistenceException) {
LOG.error(UI.wallString("Unable to read or persist your NodeId file. This means your node id file (" + configuration.getNodeIdFile() + ") is not readable or writable by the current user. The following exception might give more information: " + message));
System.exit(-1);
} else if (rootCause instanceof AccessDeniedException) {
LOG.error(UI.wallString("Unable to access file " + rootCause.getMessage()));
System.exit(-2);
} else if (rootCause instanceof UnsupportedSearchException) {
final SearchVersion search = ((UnsupportedSearchException) rootCause).getSearchMajorVersion();
LOG.error(UI.wallString("Unsupported search version: " + search, DocsHelper.PAGE_ES_VERSIONS.toString()));
System.exit(-3);
} else if (rootCause instanceof ElasticsearchProbeException) {
LOG.error(UI.wallString(rootCause.getMessage(), DocsHelper.PAGE_ES_CONFIGURATION.toString()));
System.exit(-4);
} else {
// other guice error, still print the raw messages
// TODO this could potentially print duplicate messages depending on what a subclass does...
LOG.error("Guice error (more detail on log level debug): {}", message.getMessage());
if (rootCause != null) {
LOG.debug("Stacktrace:", rootCause);
}
}
}
}
use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.
the class SearchDbPreflightCheck method runCheck.
@Override
public void runCheck() throws PreflightCheckException {
try {
final SearchVersion searchVersion = elasticVersionProbe.probe(elasticsearchHosts).orElseThrow(() -> new PreflightCheckException("Could not get Elasticsearch version"));
if (SUPPORTED_ES_VERSIONS.stream().noneMatch(searchVersion::satisfies)) {
throw new PreflightCheckException(StringUtils.f("Unsupported (Elastic/Open)Search version <%s>. Supported versions: <%s>", searchVersion, SUPPORTED_ES_VERSIONS));
}
LOG.info("Connected to (Elastic/Open)Search version <{}>", searchVersion);
} catch (ElasticsearchProbeException e) {
throw new PreflightCheckException(e);
}
}
use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.
the class VersionProbe method probeSingleHost.
private Optional<SearchVersion> probeSingleHost(URI host) {
final Retrofit retrofit;
try {
retrofit = new Retrofit.Builder().baseUrl(host.toURL()).addConverterFactory(JacksonConverterFactory.create(objectMapper)).client(addAuthenticationIfPresent(host, okHttpClient)).build();
} catch (MalformedURLException e) {
LOG.error("Elasticsearch node URL is invalid: " + host.toString(), e);
return Optional.empty();
}
final RootRoute root = retrofit.create(RootRoute.class);
final Converter<ResponseBody, ErrorResponse> errorResponseConverter = retrofit.responseBodyConverter(ErrorResponse.class, new Annotation[0]);
final Consumer<ResponseBody> errorLogger = (responseBody) -> {
try {
final ErrorResponse errorResponse = errorResponseConverter.convert(responseBody);
LOG.error("Unable to retrieve version from Elasticsearch node {}:{}: {}", host.getHost(), host.getPort(), errorResponse);
} catch (IOException e) {
LOG.error("Unable to retrieve version from Elasticsearch node {}:{}: unknown error - an exception occurred while deserializing error response: {}", host.getHost(), host.getPort(), e);
}
};
return rootResponse(root, errorLogger).map(RootResponse::version).flatMap(this::parseVersion);
}
Aggregations