本文整理汇总了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse.isTimedOut方法的典型用法代码示例。如果您正苦于以下问题:Java ClusterHealthResponse.isTimedOut方法的具体用法?Java ClusterHealthResponse.isTimedOut怎么用?Java ClusterHealthResponse.isTimedOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse
的用法示例。
在下文中一共展示了ClusterHealthResponse.isTimedOut方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName)
.setSettings(Settings.builder()
.put("number_of_shards", getConfig().getNumberOfShards())
.put("number_of_replicas", getConfig().getNumberOfReplicas())
)
.execute().actionGet();
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName)
.setWaitForGreenStatus()
.execute().actionGet();
LOGGER.debug("Index status: %s", health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
}
}
示例2: waitForRelocation
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
* Waits for all relocating shards to become active and the cluster has reached the given health status
* using the cluster health API.
*/
public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) {
ClusterHealthRequest request = Requests.clusterHealthRequest().waitForNoRelocatingShards(true);
if (status != null) {
request.waitForStatus(status);
}
ClusterHealthResponse actionGet = client().admin().cluster()
.health(request).actionGet();
if (actionGet.isTimedOut()) {
logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status,
client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
}
if (status != null) {
assertThat(actionGet.getStatus(), equalTo(status));
}
return actionGet.getStatus();
}
示例3: ensureStableCluster
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
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();
}
示例4: getClient
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public Client getClient() {
if (!staticValue.isNeedEs()) {
LOG.info("已在配置文件中声明不需要ES,如需要ES,请在配置文件中进行配置");
return null;
}
if (client != null) return client;
try {
LOG.info("正在初始化ElasticSearch客户端," + staticValue.getEsHost());
Settings settings = Settings.builder()
.put("cluster.name", staticValue.getEsClusterName()).build();
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(staticValue.getEsHost()), 9300));
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth()
.setTimeout(TimeValue.timeValueMinutes(1)).execute().actionGet();
if (healthResponse.isTimedOut()) {
LOG.error("ES客户端初始化失败");
} else {
LOG.info("ES客户端初始化成功");
}
} catch (IOException e) {
LOG.fatal("构建ElasticSearch客户端失败!");
}
return client;
}
示例5: checkStatus
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@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();
}
}
示例6: getClient
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public Client getClient() {
if(!sValue.isNeedES()) {
LOG.info("配置文件已声明不需要ES, 如需要ES, 请更改配置文件");
return null;
}
if(client!=null)
return client;
LOG.info("正在初始化客户端, Host:{},Port:{}", sValue.getEsHost(), sValue.getEsPort());
Settings settings = Settings.builder()
.put("cluster.name", sValue.getEsClusterName()).build();
try {
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(sValue.getEsHost()), sValue.getEsPort()));
final ClusterHealthResponse healthResponse = client.admin().cluster()
.prepareHealth().setTimeout(TimeValue.timeValueMinutes(1)).get();
if(healthResponse.isTimedOut())
LOG.info("ES客户端初始化失败,响应超时");
else
LOG.info("ES客户端初始化成功");
} catch(IOException e) {
LOG.fatal("ES客户端构建失败,由于 " + e.getLocalizedMessage());
}
return client;
}
示例7: getClient
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public Client getClient() {
if (!staticValue.isNeedEs()) {
LOG.info("已在配置文件中声明不需要ES,如需要ES,请在配置文件中进行配置");
return null;
}
if (client != null) return client;
LOG.info("正在初始化ElasticSearch客户端," + staticValue.getEsHost());
Settings settings = Settings.builder()
.put("cluster.name", staticValue.getEsClusterName()).build();
try {
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(staticValue.getEsHost()), staticValue.getEsPort()));
final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth()
.setTimeout(TimeValue.timeValueMinutes(1)).execute().actionGet();
if (healthResponse.isTimedOut()) {
LOG.error("ES客户端初始化失败");
} else {
LOG.info("ES客户端初始化成功");
}
} catch (IOException e) {
LOG.fatal("构建ElasticSearch客户端失败!");
}
return client;
}
示例8: startNodes
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@Before
public void startNodes() {
try {
logger.info("starting");
setClusterName();
startNode("1");
findNodeAddress();
try {
ClusterHealthResponse healthResponse = client("1").execute(ClusterHealthAction.INSTANCE,
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN).timeout(TimeValue.timeValueSeconds(30))).actionGet();
if (healthResponse != null && healthResponse.isTimedOut()) {
throw new IOException("cluster state is " + healthResponse.getStatus().name()
+ ", from here on, everything will fail!");
}
} catch (ElasticsearchTimeoutException e) {
throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
}
} catch (Throwable t) {
logger.error("startNodes failed", t);
}
}
示例9: createIndex
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@SuppressWarnings("unused")
protected void createIndex(String indexName) {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName)
.setSettings(Settings.builder()
.put("number_of_shards", getConfig().getNumberOfShards())
.put("number_of_replicas", getConfig().getNumberOfReplicas())
.put("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit())
)
.execute().actionGet();
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName)
.setWaitForGreenStatus()
.execute().actionGet();
LOGGER.debug("Index status: %s", health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
}
}
示例10: ensureGreen
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
* 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(final TimeValue timeout, final String... indices) {
final ClusterHealthResponse actionGet = client()
.admin()
.cluster()
.health(Requests.clusterHealthRequest(indices).timeout(timeout).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));
logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices);
return actionGet.getStatus();
}
示例11: waitForRelocation
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
* Waits for all relocating shards to become active and the cluster has reached the given health status
* using the cluster health API.
*/
public ClusterHealthStatus waitForRelocation(final ClusterHealthStatus status) {
final ClusterHealthRequest request = Requests.clusterHealthRequest().waitForRelocatingShards(0);
if (status != null) {
request.waitForStatus(status);
}
final ClusterHealthResponse actionGet = client().admin().cluster().health(request).actionGet();
if (actionGet.isTimedOut()) {
logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status, client().admin().cluster()
.prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get()
.prettyPrint());
assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
}
if (status != null) {
assertThat(actionGet.getStatus(), equalTo(status));
}
return actionGet.getStatus();
}
示例12: waitForCluster
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public static void waitForCluster(Client client, ClusterHealthStatus statusThreshold,
String timeout) throws UnableToStartException {
try {
ClusterHealthResponse healthResponse = (ClusterHealthResponse) client
.execute(ClusterHealthAction.INSTANCE,
new ClusterHealthRequest().waitForStatus(statusThreshold).timeout(timeout))
.actionGet();
if (healthResponse != null && healthResponse.isTimedOut()) {
throw new UnableToStartException("cluster state is " + healthResponse.getStatus().name()
+ " and not " + statusThreshold.name()
+ ", from here on, everything will fail!");
}
} catch (ElasticsearchTimeoutException e) {
throw new UnableToStartException(
"timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
}
}
示例13: startCluster
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public void startCluster() {
try {
logger.info("settings cluster name");
setClusterName();
logger.info("starting nodes");
this.node = startNode();
this.client = node.client();
findNodeAddress();
ClusterHealthResponse healthResponse = client.execute(ClusterHealthAction.INSTANCE,
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.YELLOW)
.timeout(TimeValue.timeValueSeconds(30))).actionGet();
if (healthResponse != null && healthResponse.isTimedOut()) {
throw new IOException("cluster state is " + healthResponse.getStatus().name()
+ ", from here on, everything will fail!");
}
logger.info("nodes are started");
} catch (Throwable t) {
logger.error("start of nodes failed", t);
}
}
示例14: ensureGreen
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
* 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();
}
示例15: ensureYellow
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
* 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();
}