本文整理了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder.setTimeout()
方法的一些代码示例,展示了ClusterHealthRequestBuilder.setTimeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClusterHealthRequestBuilder.setTimeout()
方法的具体详情如下:
包路径:org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder
类名称:ClusterHealthRequestBuilder
方法名:setTimeout
暂无
代码示例来源:origin: thinkaurelius/titan
public ElasticSearchIndex(Configuration config) {
indexName = config.get(INDEX_NAME);
useDeprecatedIgnoreUnmapped = config.get(USE_EDEPRECATED_IGNORE_UNMAPPED_OPTION);
checkExpectedClientVersion();
final ElasticSearchSetup.Connection c;
if (!config.has(INTERFACE)) {
c = legacyConfiguration(config);
} else {
c = interfaceConfiguration(config);
}
node = c.getNode();
client = c.getClient();
maxResultsSize = config.get(INDEX_MAX_RESULT_SET_SIZE);
log.debug("Configured ES query result set max size to {}", maxResultsSize);
client.admin().cluster().prepareHealth().setTimeout(config.get(HEALTH_REQUEST_TIMEOUT))
.setWaitForYellowStatus().execute().actionGet();
checkForOrCreateIndex(config);
}
代码示例来源:origin: floragunncom/search-guard
log.debug("waiting for cluster state {} and {} nodes", status.name(), expectedNodeCount);
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth()
.setWaitForStatus(status).setTimeout(timeout).setMasterNodeTimeout(timeout).setWaitForNodes("" + expectedNodeCount).execute()
.actionGet();
if (healthResponse.isTimedOut()) {
代码示例来源:origin: javanna/elasticshell
protected boolean clusterKo(Client client) {
try {
client.admin().cluster().prepareHealth().setTimeout(TimeValue.timeValueSeconds(1)).execute().actionGet();
return false;
} catch(Exception e) {
return true;
}
}
代码示例来源:origin: com.github.tlrx/elasticsearch-test
@Override
public void open() {
// Wait for Yellow status
client().admin().cluster()
.prepareHealth()
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueMinutes(1))
.execute()
.actionGet();
}
代码示例来源:origin: tlrx/elasticsearch-test
@Override
public void open() {
// Wait for Yellow status
client().admin().cluster()
.prepareHealth()
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueMinutes(1))
.execute()
.actionGet();
}
代码示例来源:origin: salyh/elasticsearch-imap
private void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout) throws IOException {
try {
logger.debug("waiting for cluster state {}", status.name());
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
.setTimeout(timeout).execute().actionGet();
if (healthResponse.isTimedOut()) {
throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
+ ", cowardly refusing to continue with operations");
} else {
logger.debug("... cluster state ok");
}
} catch (final ElasticsearchTimeoutException e) {
throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
}
}
代码示例来源:origin: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core
@Override
public boolean waitForYellowStatus(String[] indexNames, int timeoutSecond) {
String timeout = timeoutSecond + "s";
log.debug("Waiting for cluster yellow health status, indexes: " + Arrays.toString(indexNames));
try {
ClusterHealthResponse response = client.admin()
.cluster()
.prepareHealth(indexNames)
.setTimeout(timeout)
.setWaitForYellowStatus()
.get();
if (response.isTimedOut()) {
throw new NuxeoException(
"Elasticsearch Cluster health status not Yellow after " + timeout + " give up: " + response);
}
if (response.getStatus() != ClusterHealthStatus.GREEN) {
log.warn("Elasticsearch Cluster ready but not GREEN: " + response);
return false;
}
log.info("Elasticsearch Cluster ready: " + response);
} catch (NoNodeAvailableException e) {
throw new NuxeoException(
"Failed to connect to elasticsearch, check addressList and clusterName: " + e.getMessage());
}
return true;
}
代码示例来源:origin: org.codehaus.sonar/sonar-search
@Override
public boolean isReady() {
return node != null && node.client().admin().cluster().prepareHealth()
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueSeconds(30L))
.get()
.getStatus() != ClusterHealthStatus.RED;
}
代码示例来源:origin: sirensolutions/siren-join
public void waitForGreen() {
client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
}
代码示例来源:origin: sirensolutions/siren-join
public void waitForGreen() {
client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
}
代码示例来源:origin: flaxsearch/BioSolr
@Override
public boolean isSearchEngineReady() {
ClusterHealthStatus status = new ClusterHealthRequestBuilder(client, ClusterHealthAction.INSTANCE)
.setIndices(configuration.getIndexName())
.setTimeout(new TimeValue(configuration.getTimeoutMillis(), TimeUnit.MILLISECONDS))
.request()
.waitForStatus();
return status != ClusterHealthStatus.RED;
}
代码示例来源:origin: com.github.tlrx/elasticsearch-test
@Override
public void open() {
if (node == null || node.isClosed()) {
// Build and start the node
node = NodeBuilder.nodeBuilder().settings(buildNodeSettings()).node();
// Get a client
client = node.client();
// Wait for Yellow status
client.admin().cluster()
.prepareHealth()
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueMinutes(1))
.execute()
.actionGet();
}
}
代码示例来源:origin: tlrx/elasticsearch-test
@Override
public void open() {
if (node == null || node.isClosed()) {
// Build and start the node
node = NodeBuilder.nodeBuilder().settings(buildNodeSettings()).node();
// Get a client
client = node.client();
// Wait for Yellow status
client.admin().cluster()
.prepareHealth()
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueMinutes(1))
.execute()
.actionGet();
}
}
代码示例来源:origin: org.hawkular.titan/titan-es
public ElasticSearchIndex(Configuration config) {
indexName = config.get(INDEX_NAME);
checkExpectedClientVersion();
final ElasticSearchSetup.Connection c;
if (!config.has(INTERFACE)) {
c = legacyConfiguration(config);
} else {
c = interfaceConfiguration(config);
}
node = c.getNode();
client = c.getClient();
maxResultsSize = config.get(INDEX_MAX_RESULT_SET_SIZE);
log.debug("Configured ES query result set max size to {}", maxResultsSize);
client.admin().cluster().prepareHealth().setTimeout(config.get(HEALTH_REQUEST_TIMEOUT))
.setWaitForYellowStatus().execute().actionGet();
checkForOrCreateIndex(config);
}
代码示例来源:origin: salyh/elasticsearch-imap
public static void waitForYellowCluster(Client client) throws IOException {
ClusterHealthStatus status = ClusterHealthStatus.YELLOW;
try {
logger.debug("waiting for cluster state {}", status.name());
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
.setTimeout(TimeValue.timeValueSeconds(30)).execute().actionGet();
if (healthResponse.isTimedOut()) {
logger.error("Timeout while waiting for cluster state: {}, current cluster state is: {}", status.name(), healthResponse.getStatus().name());
throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
+ ", cowardly refusing to continue with operations");
} else {
logger.debug("... cluster state ok");
}
} catch (final Exception e) {
logger.error("Exception while waiting for cluster state: {} due to ", e, status.name(), e.toString());
throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations", e);
}
}
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
/**
* 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();
}
代码示例来源:origin: com.github.cafdataprocessing/corepolicy-condition-engine
private boolean isClusterHealthy() throws UnknownHostException {
ClusterHealthResponse healthResponse = getElasticClient()
.admin()
.cluster()
.prepareHealth(policyIndexName)
.setWaitForYellowStatus()
.setTimeout(TimeValue.timeValueSeconds(elasticsearchProperties.getElasticsearchIndexStatusTimeout()))
.get();
if (healthResponse.isTimedOut()) {
logger.warn("Timed out while awaiting at least YELLOW status for Elasticsearch index {} ", policyIndexName);
return false;
}
if (!healthResponse.getStatus().equals(ClusterHealthStatus.YELLOW) && !healthResponse.getStatus().equals(ClusterHealthStatus.GREEN)) {
logger.warn("The Elasticsearch index {} is reporting status {}", policyIndexName, healthResponse.getStatus().name());
return false;
}
return true;
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
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();
}
代码示例来源:origin: meltwater/elasticsearch-batch-percolator
public void waitForYellowStatus(Client client) throws ExecutionException, InterruptedException {
client.admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(new TimeValue(10, TimeUnit.SECONDS)).execute().get();
}
}
代码示例来源:origin: floragunncom/search-guard-ssl
protected void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout, final Client client) throws IOException {
try {
log.debug("waiting for cluster state {}", status.name());
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
.setTimeout(timeout).setWaitForNodes("3").execute().actionGet();
if (healthResponse.isTimedOut()) {
throw new IOException("cluster state is " + healthResponse.getStatus().name() + " with "
+ healthResponse.getNumberOfNodes() + " nodes");
} else {
log.debug("... cluster state ok " + healthResponse.getStatus().name() + " with " + healthResponse.getNumberOfNodes()
+ " nodes");
}
final NodesInfoResponse res = esNode1.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();
final List<NodeInfo> nodes = res.getNodes();
for (NodeInfo nodeInfo: nodes) {
if (nodeInfo.getHttp() != null && nodeInfo.getHttp().address() != null) {
final TransportAddress is = nodeInfo.getHttp().address().publishAddress();
httpPort = is.getPort();
httpHost = is.getAddress();
}
final TransportAddress is = nodeInfo.getTransport().getAddress().publishAddress();
nodePort = is.getPort();
nodeHost = is.getAddress();
}
} catch (final ElasticsearchTimeoutException e) {
throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
}
}
内容来源于网络,如有侵权,请联系作者删除!