public ClusterHealthRequestBuilder setWaitForEvents(Priority waitForEvents) { request.waitForEvents(waitForEvents); return this; } }
@Override public void onNoLongerMaster(String source) { logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents()); // TransportMasterNodeAction implements the retry logic, which is triggered by passing a NotMasterException listener.onFailure(new NotMasterException("no longer master. source: [" + source + "]")); }
@Override protected void masterOperation(Task task, final ClusterHealthRequest request, final ClusterState unusedState, final ActionListener<ClusterHealthResponse> listener) { if (request.waitForEvents() != null) { final long endTimeMS = TimeValue.nsecToMSec(System.nanoTime()) + request.timeout().millis(); if (request.local()) { clusterService.submitStateUpdateTask("cluster_health (wait_for_events [" + request.waitForEvents() + "])", new LocalClusterUpdateTask(request.waitForEvents()) { @Override public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) { clusterService.submitStateUpdateTask("cluster_health (wait_for_events [" + request.waitForEvents() + "])", new ClusterStateUpdateTask(request.waitForEvents()) { @Override public ClusterState execute(ClusterState currentState) {
public ClusterHealthRequestBuilder setWaitForEvents(Priority waitForEvents) { request.waitForEvents(waitForEvents); return this; } }
public ClusterHealthRequestBuilder setWaitForEvents(Priority waitForEvents) { request.waitForEvents(waitForEvents); return this; } }
public ClusterHealthRequestBuilder setWaitForEvents(Priority waitForEvents) { request.waitForEvents(waitForEvents); return this; } }
public ClusterHealthRequestBuilder setWaitForEvents(Priority waitForEvents) { request.waitForEvents(waitForEvents); return this; } }
@Override public void onNoLongerMaster(String source) { logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents()); doExecute(task, request, listener); }
@Override public void onNoLongerMaster(String source) { logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents()); doExecute(task, request, listener); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index"))); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout())); clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout())); String waitForStatus = request.param("wait_for_status"); if (waitForStatus != null) { clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT))); } clusterHealthRequest.waitForNoRelocatingShards( request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards())); clusterHealthRequest.waitForNoInitializingShards( request.paramAsBoolean("wait_for_no_initializing_shards", clusterHealthRequest.waitForNoRelocatingShards())); if (request.hasParam("wait_for_relocating_shards")) { // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " + "use wait_for_no_relocating_shards [true/false] instead"); } String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); } clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes())); if (request.param("wait_for_events") != null) { clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT))); } return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel)); }
@Override public void onNoLongerMaster(String source) { logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents()); // TransportMasterNodeAction implements the retry logic, which is triggered by passing a NotMasterException listener.onFailure(new NotMasterException("no longer master. source: [" + source + "]")); }
@Override public void onNoLongerMaster(String source) { logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents()); // TransportMasterNodeAction implements the retry logic, which is triggered by passing a NotMasterException listener.onFailure(new NotMasterException("no longer master. source: [" + source + "]")); }
/** * Wait for yellow state of a cluster. * * @param indices * @return */ public ClusterHealthStatus ensureYellow(final String... indices) { final ClusterHealthResponse actionGet = client().admin().cluster() .health(Requests.clusterHealthRequest(indices) .waitForNoRelocatingShards(true).waitForYellowStatus() .waitForEvents(Priority.LANGUID)) .actionGet(); if (actionGet.isTimedOut()) { onFailure("ensureYellow timed out, cluster state:\n" + "\n" + client().admin().cluster().prepareState().get().getState() + "\n" + client().admin().cluster() .preparePendingClusterTasks().get(), actionGet); } return actionGet.getStatus(); }
/** * Wait for green state of a cluster. * * @param indices * @return */ public ClusterHealthStatus ensureGreen(final String... indices) { final ClusterHealthResponse actionGet = client().admin().cluster() .health(Requests.clusterHealthRequest(indices) .waitForGreenStatus().waitForEvents(Priority.LANGUID) .waitForNoRelocatingShards(true)) .actionGet(); if (actionGet.isTimedOut()) { onFailure("ensureGreen timed out, cluster state:\n" + client().admin().cluster().prepareState().get().getState() + "\n" + client().admin().cluster() .preparePendingClusterTasks().get(), actionGet); } return actionGet.getStatus(); }
.timeout(timeout) .waitForStatus(clusterHealthStatus) .waitForEvents(Priority.LANGUID) .waitForNoRelocatingShards(true) .waitForNoInitializingShards(waitForNoInitializingShards)
/** * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations. * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating * are now allocated and started. */ public ClusterHealthStatus ensureGreen(Client client, String... indices) { ClusterHealthResponse actionGet = client.admin().cluster() .health(Requests.clusterHealthRequest(indices).waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); if (actionGet.isTimedOut()) { logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client.admin().cluster().prepareState().get().getState().prettyPrint(), client.admin().cluster().preparePendingClusterTasks().get().prettyPrint()); assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); } assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN)); return actionGet.getStatus(); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index"))); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout())); clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout())); String waitForStatus = request.param("wait_for_status"); if (waitForStatus != null) { clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT))); } clusterHealthRequest.waitForNoRelocatingShards( request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards())); if (request.hasParam("wait_for_relocating_shards")) { // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " + "use wait_for_no_relocating_shards [true/false] instead"); } String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); } clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes())); if (request.param("wait_for_events") != null) { clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT))); } return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel)); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index"))); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout())); clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout())); String waitForStatus = request.param("wait_for_status"); if (waitForStatus != null) { clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT))); } clusterHealthRequest.waitForNoRelocatingShards( request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards())); clusterHealthRequest.waitForNoInitializingShards( request.paramAsBoolean("wait_for_no_initializing_shards", clusterHealthRequest.waitForNoRelocatingShards())); if (request.hasParam("wait_for_relocating_shards")) { // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " + "use wait_for_no_relocating_shards [true/false] instead"); } String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); } clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes())); if (request.param("wait_for_events") != null) { clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT))); } return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel)); }
static Request clusterHealth(ClusterHealthRequest healthRequest) { String[] indices = healthRequest.indices() == null ? Strings.EMPTY_ARRAY : healthRequest.indices(); String endpoint = new RequestConverters.EndpointBuilder() .addPathPartAsIs("_cluster/health") .addCommaSeparatedPathParts(indices) .build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); new RequestConverters.Params(request) .withWaitForStatus(healthRequest.waitForStatus()) .withWaitForNoRelocatingShards(healthRequest.waitForNoRelocatingShards()) .withWaitForNoInitializingShards(healthRequest.waitForNoInitializingShards()) .withWaitForActiveShards(healthRequest.waitForActiveShards(), ActiveShardCount.NONE) .withWaitForNodes(healthRequest.waitForNodes()) .withWaitForEvents(healthRequest.waitForEvents()) .withTimeout(healthRequest.timeout()) .withMasterTimeout(healthRequest.masterNodeTimeout()) .withLocal(healthRequest.local()) .withLevel(healthRequest.level()); return request; } }
static Request clusterHealth(ClusterHealthRequest healthRequest) { String[] indices = healthRequest.indices() == null ? Strings.EMPTY_ARRAY : healthRequest.indices(); String endpoint = new RequestConverters.EndpointBuilder() .addPathPartAsIs("_cluster/health") .addCommaSeparatedPathParts(indices) .build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); new RequestConverters.Params(request) .withWaitForStatus(healthRequest.waitForStatus()) .withWaitForNoRelocatingShards(healthRequest.waitForNoRelocatingShards()) .withWaitForNoInitializingShards(healthRequest.waitForNoInitializingShards()) .withWaitForActiveShards(healthRequest.waitForActiveShards(), ActiveShardCount.NONE) .withWaitForNodes(healthRequest.waitForNodes()) .withWaitForEvents(healthRequest.waitForEvents()) .withTimeout(healthRequest.timeout()) .withMasterTimeout(healthRequest.masterNodeTimeout()) .withLocal(healthRequest.local()) .withLevel(healthRequest.level()); return request; } }