use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project elasticsearch by elastic.
the class ESIntegTestCase method ensureColor.
private ClusterHealthStatus ensureColor(ClusterHealthStatus clusterHealthStatus, TimeValue timeout, String... indices) {
String color = clusterHealthStatus.name().toLowerCase(Locale.ROOT);
String method = "ensure" + Strings.capitalize(color);
ClusterHealthRequest healthRequest = Requests.clusterHealthRequest(indices).timeout(timeout).waitForStatus(clusterHealthStatus).waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNodes(Integer.toString(cluster().size()));
ClusterHealthResponse actionGet = client().admin().cluster().health(healthRequest).actionGet();
if (actionGet.isTimedOut()) {
logger.info("{} timed out, cluster state:\n{}\n{}", method, client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
fail("timed out waiting for " + color + " state");
}
assertThat("Expected at least " + clusterHealthStatus + " but got " + actionGet.getStatus(), actionGet.getStatus().value(), lessThanOrEqualTo(clusterHealthStatus.value()));
logger.debug("indices {} are {}", indices.length == 0 ? "[_all]" : indices, color);
return actionGet.getStatus();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project elasticsearch by elastic.
the class ClusterStateHealthTests method testClusterHealthWaitsForClusterStateApplication.
public void testClusterHealthWaitsForClusterStateApplication() throws InterruptedException, ExecutionException {
final CountDownLatch applyLatch = new CountDownLatch(1);
final CountDownLatch listenerCalled = new CountDownLatch(1);
setState(clusterService, ClusterState.builder(clusterService.state()).nodes(DiscoveryNodes.builder(clusterService.state().nodes()).masterNodeId(null)).build());
clusterService.addStateApplier(event -> {
listenerCalled.countDown();
try {
applyLatch.await();
} catch (InterruptedException e) {
logger.debug("interrupted", e);
}
});
logger.info("--> submit task to restore master");
clusterService.submitStateUpdateTask("restore master", new LocalClusterUpdateTask() {
@Override
public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) throws Exception {
return newState(ClusterState.builder(currentState).nodes(DiscoveryNodes.builder(currentState.nodes()).masterNodeId(currentState.nodes().getLocalNodeId())).build());
}
@Override
public void onFailure(String source, Exception e) {
logger.warn("unexpected failure", e);
}
});
logger.info("--> waiting for listener to be called and cluster state being blocked");
listenerCalled.await();
TransportClusterHealthAction action = new TransportClusterHealthAction(Settings.EMPTY, transportService, clusterService, threadPool, new ActionFilters(new HashSet<>()), indexNameExpressionResolver, new TestGatewayAllocator());
PlainActionFuture<ClusterHealthResponse> listener = new PlainActionFuture<>();
action.execute(new ClusterHealthRequest().waitForGreenStatus(), listener);
assertFalse(listener.isDone());
logger.info("--> realising task to restore master");
applyLatch.countDown();
listener.get();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project graylog2-server by Graylog2.
the class IndexerSetupService method startUp.
@Override
protected void startUp() throws Exception {
Tools.silenceUncaughtExceptionsInThisThread();
LOG.debug("Starting indexer");
node.start();
final Client client = node.client();
try {
/* try to determine the cluster health. if this times out we could not connect and try to determine if there's
anything listening at all. if that happens this usually has these reasons:
1. cluster.name is different
2. network.publish_host is not reachable
3. wrong address configured
4. multicast in use but broken in this environment
we handle a red cluster state differently because if we can get that result it means the cluster itself
is reachable, which is a completely different problem from not being able to join at all.
*/
final ClusterHealthRequest atLeastRed = client.admin().cluster().prepareHealth().setWaitForStatus(ClusterHealthStatus.RED).request();
final ClusterHealthResponse health = client.admin().cluster().health(atLeastRed).actionGet(configuration.getClusterDiscoveryTimeout(), MILLISECONDS);
// we don't get here if we couldn't join the cluster. just check for red cluster state
if (ClusterHealthStatus.RED.equals(health.getStatus())) {
final Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.URGENT).addType(Notification.Type.ES_CLUSTER_RED);
notificationService.publishIfFirst(notification);
LOG.warn("The Elasticsearch cluster state is RED which means shards are unassigned.");
LOG.info("This usually indicates a crashed and corrupt cluster and needs to be investigated. Graylog will write into the local disk journal.");
LOG.info("See {} for details.", DocsHelper.PAGE_ES_CONFIGURATION);
}
if (ClusterHealthStatus.GREEN.equals(health.getStatus())) {
notificationService.fixed(Notification.Type.ES_CLUSTER_RED);
}
notificationService.fixed(Notification.Type.ES_UNAVAILABLE);
} catch (ElasticsearchTimeoutException e) {
final String hosts = node.settings().get("discovery.zen.ping.unicast.hosts");
if (!isNullOrEmpty(hosts)) {
final Iterable<String> hostList = Splitter.on(',').omitEmptyStrings().trimResults().split(hosts);
for (String host : hostList) {
final URI esUri = URI.create("http://" + HostAndPort.fromString(host).getHostText() + ":9200/");
LOG.info("Checking Elasticsearch HTTP API at {}", esUri);
// Try the HTTP API endpoint
final Request request = new Request.Builder().get().url(esUri.resolve("/_nodes").toString()).build();
try (final Response response = httpClient.newCall(request).execute()) {
if (response.isSuccessful()) {
final JsonNode resultTree = objectMapper.readTree(response.body().byteStream());
final JsonNode nodesList = resultTree.get("nodes");
if (!configuration.isDisableVersionCheck()) {
final Iterator<String> nodes = nodesList.fieldNames();
while (nodes.hasNext()) {
final String id = nodes.next();
final Version clusterVersion = Version.fromString(nodesList.get(id).get("version").textValue());
checkClusterVersion(clusterVersion);
}
}
final String clusterName = resultTree.get("cluster_name").textValue();
checkClusterName(clusterName);
} else {
LOG.error("Could not connect to Elasticsearch at " + esUri + ". Is it running?");
}
} catch (IOException ioException) {
LOG.error("Could not connect to Elasticsearch: {}", ioException.getMessage());
}
}
}
final Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.URGENT).addType(Notification.Type.ES_UNAVAILABLE);
notificationService.publishIfFirst(notification);
LOG.warn("Could not connect to Elasticsearch");
LOG.info("If you're using multicast, check that it is working in your network and that Elasticsearch is accessible. Also check that the cluster name setting is correct.");
LOG.info("See {} for details.", DocsHelper.PAGE_ES_CONFIGURATION);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project graylog2-server by Graylog2.
the class Indices method waitForStatus.
public ClusterHealthStatus waitForStatus(String index, ClusterHealthStatus clusterHealthStatus) {
final ClusterHealthRequest request = c.admin().cluster().prepareHealth(index).setWaitForStatus(clusterHealthStatus).request();
LOG.debug("Waiting until index health status of index {} is {}", index, clusterHealthStatus);
final ClusterHealthResponse response = c.admin().cluster().health(request).actionGet(5L, TimeUnit.MINUTES);
return response.getStatus();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project crate by crate.
the class DecommissioningService method clusterHealthGet.
private CompletableFuture<ClusterHealthResponse> clusterHealthGet() {
if (dataAvailability == DataAvailability.NONE) {
return CompletableFuture.completedFuture(null);
}
// NOTE: it waits for ALL relocating shards, not just those that involve THIS node.
ClusterHealthRequest request = new ClusterHealthRequest().waitForNoRelocatingShards(true).waitForEvents(Priority.LANGUID).timeout(gracefulStopTimeout);
if (dataAvailability == DataAvailability.FULL) {
request = request.waitForGreenStatus();
} else {
request = request.waitForYellowStatus();
}
FutureActionListener<ClusterHealthResponse, ClusterHealthResponse> listener = FutureActionListener.newInstance();
healthAction.execute(request, listener);
return listener;
}
Aggregations