本文整理了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder
类的一些代码示例,展示了ClusterHealthRequestBuilder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClusterHealthRequestBuilder
类的具体详情如下:
包路径:org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder
类名称:ClusterHealthRequestBuilder
暂无
代码示例来源: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: yacy/yacy_grid_mcp
public boolean clusterReady() {
if (clusterReadyCache) return true;
ClusterHealthResponse chr = elasticsearchClient.admin().cluster().prepareHealth().get();
clusterReadyCache = chr.getStatus() != ClusterHealthStatus.RED;
return clusterReadyCache;
}
代码示例来源:origin: Netflix/conductor
@Override
public void setup() throws Exception {
elasticSearchClient.admin()
.cluster()
.prepareHealth()
.setWaitForGreenStatus()
.execute()
.get();
try {
initIndex();
updateLogIndexName();
Executors.newScheduledThreadPool(1)
.scheduleAtFixedRate(() -> updateLogIndexName(), 0, 1, TimeUnit.HOURS);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
//1. Create the required index
addIndex(indexName);
//2. Add Mappings for the workflow document type
addMappingToIndex(indexName, WORKFLOW_DOC_TYPE, "/mappings_docType_workflow.json");
//3. Add Mappings for task document type
addMappingToIndex(indexName, TASK_DOC_TYPE, "/mappings_docType_task.json");
}
代码示例来源:origin: SonarSource/sonarqube
public void waitForStatus(ClusterHealthStatus status) {
prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForStatus(status).get();
}
代码示例来源:origin: loklak/loklak_server
public boolean wait_ready(long maxtimemillis, ClusterHealthStatus status) {
// wait for yellow status
long start = System.currentTimeMillis();
boolean is_ready;
do {
// wait for yellow status
ClusterHealthResponse health = elasticsearchClient.admin().cluster().prepareHealth().setWaitForStatus(status).execute().actionGet();
is_ready = !health.isTimedOut();
if (!is_ready && System.currentTimeMillis() - start > maxtimemillis) return false;
} while (!is_ready);
return is_ready;
}
代码示例来源:origin: SonarSource/sonarqube
private void waitForIndexYellow(String index) {
Client nativeClient = esClient.nativeClient();
ClusterHealthAction.INSTANCE.newRequestBuilder(nativeClient).setIndices(index).setWaitForYellowStatus().get(TimeValue.timeValueMinutes(10));
}
代码示例来源:origin: org.neolumin.vertexium/vertexium-elasticsearch-base
@SuppressWarnings("unused")
protected void createIndex(String indexName, boolean storeSourceData) throws IOException {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet();
LOGGER.debug(createResponse.toString());
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName)
.setWaitForGreenStatus()
.execute().actionGet();
LOGGER.debug("Index status: " + health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for green index status, for index: " + indexName);
}
}
代码示例来源:origin: codelibs/elasticsearch-taste
.admin()
.cluster()
.prepareHealth(index)
.setWaitForYellowStatus()
.setTimeout(
params.param("timeout",
DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
.actionGet();
if (healthResponse.isTimedOut()) {
listener.onError(new OperationFailedException(
"Failed to create index: " + index + "/" + type));
final PutMappingResponse mappingResponse = client.admin().indices()
.preparePutMapping(index).setType(type).setSource(builder)
.execute().actionGet();
if (mappingResponse.isAcknowledged()) {
fork(() -> execute(params, listener, requestMap, paramMap,
代码示例来源: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.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: lbroudoux/es-amazon-s3-river
client.admin().cluster().prepareHealth("_river").setWaitForYellowStatus().get();
logger.debug("Yellow or green status received");
if (!client.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) {
client.admin().indices().prepareCreate(indexName).execute().actionGet();
代码示例来源:origin: awslabs/amazon-kinesis-connectors
private void printClusterStatus() {
ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth();
ClusterHealthResponse response = healthRequestBuilder.execute().actionGet();
if (response.getStatus().equals(ClusterHealthStatus.RED)) {
LOG.error("Cluster health is RED. Indexing ability will be limited");
} else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) {
LOG.warn("Cluster health is YELLOW.");
} else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) {
LOG.info("Cluster health is GREEN.");
}
}
}
代码示例来源:origin: floragunncom/search-guard
try {
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()) {
throw new IOException("cluster state is " + healthResponse.getStatus().name() + " with "
+ healthResponse.getNumberOfNodes() + " nodes");
} else {
log.debug("... cluster state ok " + healthResponse.getStatus().name() + " with "
org.junit.Assert.assertEquals(expectedNodeCount, healthResponse.getNumberOfNodes());
final NodesInfoResponse res = client.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();
代码示例来源:origin: SonarSource/sonarqube
CreateIndexResponse indexResponse = SHARED_NODE.client().admin().indices()
.prepareCreate(index.getName())
.setSettings(settings)
throw new IllegalStateException("Failed to create index " + index.getName());
SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get();
PutMappingResponse mappingResponse = SHARED_NODE.client().admin().indices().preparePutMapping(index.getName())
.setType(entry.getKey())
.setSource(entry.getValue().getAttributes())
SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get();
result.add(index);
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-sail-elasticsearch
boolean exists = client.admin().indices().prepareExists(indexName).execute().actionGet().isExists();
if (!exists) {
createIndex();
ClusterHealthRequestBuilder healthReqBuilder = client.admin().cluster().prepareHealth(indexName);
String waitForStatus = parameters.getProperty(WAIT_FOR_STATUS_KEY);
if ("green".equals(waitForStatus)) {
healthReqBuilder.setWaitForGreenStatus();
healthReqBuilder.setWaitForYellowStatus();
healthReqBuilder.setWaitForNodes(waitForNodes);
healthReqBuilder.setWaitForActiveShards(Integer.parseInt(waitForActiveShards));
healthReqBuilder.setWaitForNoRelocatingShards(Boolean.parseBoolean(waitForNoRelocatingShards));
ClusterHealthResponse healthResponse = healthReqBuilder.execute().actionGet();
logger.info("Cluster health: {}", healthResponse.getStatus());
logger.info("Cluster nodes: {} (data {})", healthResponse.getNumberOfNodes(),
healthResponse.getNumberOfDataNodes());
ClusterIndexHealth indexHealth = healthResponse.getIndices().get(indexName);
logger.info("Index health: {}", indexHealth.getStatus());
代码示例来源:origin: com.netflix.raigad/raigad
ClusterHealthStatus clusterHealthStatus = esTransportClient.admin().cluster().prepareHealth().setTimeout(MASTER_NODE_TIMEOUT).execute().get().getStatus();
ClusterHealthResponse clusterHealthResponse = esTransportClient.admin().cluster().prepareHealth().execute().actionGet(MASTER_NODE_TIMEOUT);
healthBean.nodematch = (clusterHealthResponse.getNumberOfNodes() == instanceManager.getAllInstances().size()) ? 0 : 1;
else
healthBean.nodematch = (clusterHealthResponse.getNumberOfNodes() == config.getDesiredNumberOfNodesInCluster()) ? 0 : 1;
代码示例来源:origin: pinterest/soundwave
@Override
public String checkStatus() throws Exception {
final ClusterHealthResponse healthResponse = esClient
.admin().cluster().prepareHealth().execute().actionGet();
if (healthResponse.isTimedOut()) {
return EsStatus.TIMEOUT.toString();
} else if (ClusterHealthStatus.RED.equals(healthResponse.getStatus())) {
logger.warn("Elastic search health status is reported RED");
return EsStatus.ERROR.toString();
} else if (ClusterHealthStatus.GREEN.equals(healthResponse.getStatus())) {
return EsStatus.SUCCESS.toString();
} else {
logger.warn("Elastic search health status is unknown");
return EsStatus.UNKNOWN.toString();
}
}
代码示例来源:origin: ncolomer/elasticsearch-osmosis-plugin
protected void checkConnection(Client client) {
ClusterHealthResponse health = client.admin().cluster()
.prepareHealth().execute().actionGet();
if (health.getNumberOfDataNodes() == 0) throw new RuntimeException("Unable to connect to elasticsearch");
LOG.info(String.format("Connected to %d data node(s) with cluster status %s",
health.getNumberOfDataNodes(), health.getStatus().name()));
}
代码示例来源:origin: stagemonitor/stagemonitor
node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
adminClient = client.admin();
adminClient.cluster().prepareHealth()
.setWaitForYellowStatus().execute().actionGet();
代码示例来源:origin: com.scireum/sirius-search
@Routed("/system/index")
public void index(WebContext ctx) {
ClusterHealthResponse clusterHealthResponse = index.getClient().admin().cluster().prepareHealth().get();
ClusterStatsResponse clusterStatsResponse = index.getClient().admin().cluster().prepareClusterStats().get();
NodesInfoResponse nodesInfoResponse = index.getClient().admin().cluster().prepareNodesInfo().get();
NodesStatsResponse nodesStatsResponse = index.getClient().admin().cluster().prepareNodesStats().get();
ClusterStateResponse clusterStateResponse = index.getClient().admin().cluster().prepareState().get();
内容来源于网络,如有侵权,请联系作者删除!