protected void ensureNodeCount(InternalTestCluster cluster) { assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth() .setWaitForNodes(String.valueOf(cluster.size())) .setWaitForNoRelocatingShards(true) .get().isTimedOut()); }
protected void ensureNodeCount(InternalTestCluster cluster) { assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth() .setWaitForNodes(String.valueOf(cluster.size())) .setWaitForNoRelocatingShards(true) .get().isTimedOut()); } }
healthReqBuilder.setWaitForNoRelocatingShards(Boolean.parseBoolean(waitForNoRelocatingShards));
/** * 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. * * @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest} */ public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) { ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(indices); builder.setTimeout(timeout) .setWaitForGreenStatus() .setWaitForEvents(Priority.LANGUID) .setWaitForNoRelocatingShards(true); ClusterHealthResponse actionGet = builder.get(); if (actionGet.isTimedOut()) { logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get()); assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); } assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN)); logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices); return actionGet.getStatus(); }
protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) { if (viaNode == null) { viaNode = randomFrom(internalCluster().getNodeNames()); } logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue); ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth() .setWaitForEvents(Priority.LANGUID) .setWaitForNodes(Integer.toString(nodeCount)) .setTimeout(timeValue) .setLocal(local) .setWaitForNoRelocatingShards(true) .get(); if (clusterHealthResponse.isTimedOut()) { ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get(); fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n" + stateResponse.getState()); } assertThat(clusterHealthResponse.isTimedOut(), is(false)); ensureFullyConnectedCluster(); }
protected IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) { assertAcked(createIndexRequestBuilder.get()); // Wait for the index to be allocated so that cluster state updates don't override // changes that would have been done locally ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(index); builder.setWaitForYellowStatus() .setWaitForEvents(Priority.LANGUID) .setWaitForNoRelocatingShards(true); ClusterHealthResponse health = builder.get(); assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW)); assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1)); IndicesService instanceFromNode = getInstanceFromNode(IndicesService.class); return instanceFromNode.indexServiceSafe(resolveIndex(index)); }