private Set<String> getReopenedIndices(final Collection<String> indices) { final Version elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version.")); final String indexList = String.join(",", indices); final State request = new State.Builder().withMetadata().indices(indexList).build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for reopened indices " + indices); final JsonNode clusterStateJson = jestResult.getJsonObject(); 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(); }
private Set<String> getReopenedIndices(final Collection<String> indices) { final Version elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version.")); final String indexList = String.join(",", indices); final State request = new State.Builder().withMetadata().indices(indexList).build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for reopened indices " + indices); final JsonNode clusterStateJson = jestResult.getJsonObject(); 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(); }
public Map<String, Set<String>> getAllMessageFieldsForIndices(final String[] writeIndexWildcards) { final String indices = String.join(",", writeIndexWildcards); final State request = new State.Builder() .indices(indices) .withMetadata() .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for indices " + indices); final JsonNode indicesJson = getClusterStateIndicesMetadata(jestResult.getJsonObject()); final ImmutableMap.Builder<String, Set<String>> fields = ImmutableMap.builder(); final Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); final String indexName = entry.getKey(); final Set<String> fieldNames = ImmutableSet.copyOf( entry.getValue() .path("mappings") .path(IndexMapping.TYPE_MESSAGE) .path("properties").fieldNames() ); if (!fieldNames.isEmpty()) { fields.put(indexName, fieldNames); } } return fields.build(); }
public static void assertThatConnectionToElasticsearchIsPossible(Set<String> servers, int numRetries, int waitTime, TimeUnit waitUnit) { final JestClientFactory clientFactory = new JestClientFactory(); final JestClient jestClient = clientFactory.getObject(); try { jestClient.setServers(servers); for (int i = 0; i < numRetries; i++) { try { final State request = new State.Builder().build(); final JestResult result = jestClient.execute(request); if (result.isSucceeded()) { return; } } catch (Exception e) { Uninterruptibles.sleepUninterruptibly(waitTime, waitUnit); } } } finally { if (jestClient != null) { jestClient.shutdownClient(); } } throw new AssertionError("Couldn't connect to Elasticsearch at " + servers); } }
/** * Shows the metadata part of the response. */ public Builder withMetadata() { return addCleanApiParameter("metadata"); }
/** * Shows the elected master_node part of the response. */ public Builder withMasterNode() { return addCleanApiParameter("master_node"); }
/** * For debugging purposes, you can retrieve the cluster state local to a particular node. */ public Builder local() { return addCleanApiParameter("local"); }
/** * Shows the metadata part of the response. */ public Builder withMetadata() { return addCleanApiParameter("metadata"); }
/** * Shows the routing_table part of the response. */ public Builder withRoutingTable() { return addCleanApiParameter("routing_table"); }
/** * Shows the cluster state version. */ public Builder withVersion() { return addCleanApiParameter("version"); }
/** * When not filtering metadata, a comma separated list of indices to include in the response. */ public Builder indices(String value) { return setParameter("indices", value); }
/** * Shows the blocks part of the response */ public Builder withBlocks() { return addCleanApiParameter("blocks"); }
/** * Shows the cluster state version. */ public Builder withVersion() { return addCleanApiParameter("version"); }
/** * Shows the blocks part of the response */ public Builder withBlocks() { return addCleanApiParameter("blocks"); }
/** * Shows the elected master_node part of the response. */ public Builder withMasterNode() { return addCleanApiParameter("master_node"); }
/** * Shows the nodes part of the response */ public Builder withNodes() { return addCleanApiParameter("nodes"); }
/** * When not filtering metadata, a comma separated list of indices to include in the response. */ public Builder indices(String value) { return setParameter("indices", value); }
/** * For debugging purposes, you can retrieve the cluster state local to a particular node. */ public Builder local() { return addCleanApiParameter("local"); }
/** * Shows the nodes part of the response */ public Builder withNodes() { return addCleanApiParameter("nodes"); }
/** * Shows the routing_table part of the response. */ public Builder withRoutingTable() { return addCleanApiParameter("routing_table"); }