本文整理汇总了Java中org.elasticsearch.cluster.health.ClusterHealthStatus类的典型用法代码示例。如果您正苦于以下问题:Java ClusterHealthStatus类的具体用法?Java ClusterHealthStatus怎么用?Java ClusterHealthStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClusterHealthStatus类属于org.elasticsearch.cluster.health包,在下文中一共展示了ClusterHealthStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testThatTransportClientCanConnect
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testThatTransportClientCanConnect() throws Exception {
Settings settings = Settings.builder()
.put("cluster.name", internalCluster().getClusterName())
.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
.build();
try (TransportClient transportClient = new MockTransportClient(settings, Netty4Plugin.class)) {
transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
}
}
示例2: waitForRelocation
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的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: clusterHealth
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
TimeValue pendingTaskTimeInQueue) {
if (logger.isTraceEnabled()) {
logger.trace("Calculating health based on state version [{}]", clusterState.version());
}
if (request.getHeader(LoginUserContext.TENANT_FILTER) != null) {
clusterState = AuthService.filterState(clusterState, clusterState.metaData(), (Long) request.getHeader(LoginUserContext.TENANT_FILTER));
}
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request);
} catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState,
numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
pendingTaskTimeInQueue);
response.setStatus(ClusterHealthStatus.RED);
return response;
}
return new ClusterHealthResponse(clusterName.value(), concreteIndices, clusterState, numberOfPendingTasks,
numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
示例4: readFrom
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
if (size == 0) {
indices = Strings.EMPTY_ARRAY;
} else {
indices = new String[size];
for (int i = 0; i < indices.length; i++) {
indices[i] = in.readString();
}
}
timeout = readTimeValue(in);
if (in.readBoolean()) {
waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
}
waitForRelocatingShards = in.readInt();
waitForActiveShards = in.readInt();
waitForNodes = in.readString();
if (in.readBoolean()) {
waitForEvents = Priority.readFrom(in);
}
}
示例5: clusterHealth
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
TimeValue pendingTaskTimeInQueue) {
if (logger.isTraceEnabled()) {
logger.trace("Calculating health based on state version [{}]", clusterState.version());
}
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
} catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, clusterState,
numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
pendingTaskTimeInQueue);
response.setStatus(ClusterHealthStatus.RED);
return response;
}
return new ClusterHealthResponse(clusterState.getClusterName().value(), concreteIndices, clusterState, numberOfPendingTasks,
numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
示例6: readFrom
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
if (size == 0) {
indices = Strings.EMPTY_ARRAY;
} else {
indices = new String[size];
for (int i = 0; i < indices.length; i++) {
indices[i] = in.readString();
}
}
timeout = new TimeValue(in);
if (in.readBoolean()) {
waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
}
waitForNoRelocatingShards = in.readBoolean();
waitForActiveShards = ActiveShardCount.readFrom(in);
waitForNodes = in.readString();
if (in.readBoolean()) {
waitForEvents = Priority.readFrom(in);
}
}
示例7: testSimpleMoreLikeThis
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testSimpleMoreLikeThis() throws Exception {
logger.info("Creating index test");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("text").field("type", "text").endObject()
.endObject().endObject().endObject()));
logger.info("Running Cluster Health");
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
logger.info("Indexing...");
client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())).actionGet();
client().index(indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject())).actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
logger.info("Running moreLikeThis");
SearchResponse response = client().prepareSearch().setQuery(
new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "type1", "1")}).minTermFreq(1).minDocFreq(1)).get();
assertHitCount(response, 1L);
}
示例8: testSimpleMoreLikeOnLongField
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testSimpleMoreLikeOnLongField() throws Exception {
logger.info("Creating index test");
assertAcked(prepareCreate("test").addMapping("type1", "some_long", "type=long"));
logger.info("Running Cluster Health");
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
logger.info("Indexing...");
client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580L).endObject())).actionGet();
client().index(indexRequest("test").type("type2").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet();
client().index(indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())).actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
logger.info("Running moreLikeThis");
SearchResponse response = client().prepareSearch().setQuery(
new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "type1", "1")}).minTermFreq(1).minDocFreq(1)).get();
assertHitCount(response, 0L);
}
示例9: testMoreLikeThisWithAliasesInLikeDocuments
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception {
String indexName = "foo";
String aliasName = "foo_name";
String typeName = "bar";
String mapping = XContentFactory.jsonBuilder().startObject().startObject("bar")
.startObject("properties")
.endObject()
.endObject().endObject().string();
client().admin().indices().prepareCreate(indexName).addMapping(typeName, mapping, XContentType.JSON).get();
client().admin().indices().prepareAliases().addAlias(indexName, aliasName).get();
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
client().index(indexRequest(indexName).type(typeName).id("1").source(jsonBuilder().startObject().field("text", "elasticsearch index").endObject())).actionGet();
client().index(indexRequest(indexName).type(typeName).id("2").source(jsonBuilder().startObject().field("text", "lucene index").endObject())).actionGet();
client().index(indexRequest(indexName).type(typeName).id("3").source(jsonBuilder().startObject().field("text", "elasticsearch index").endObject())).actionGet();
refresh(indexName);
SearchResponse response = client().prepareSearch().setQuery(
new MoreLikeThisQueryBuilder(null, new Item[] {new Item(aliasName, typeName, "1")}).minTermFreq(1).minDocFreq(1)).get();
assertHitCount(response, 2L);
assertThat(response.getHits().getAt(0).getId(), equalTo("3"));
}
示例10: testMoreLikeThisIssue2197
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testMoreLikeThisIssue2197() throws Exception {
Client client = client();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("bar")
.startObject("properties")
.endObject()
.endObject().endObject().string();
client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).execute().actionGet();
client().prepareIndex("foo", "bar", "1")
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("foo").execute().actionGet();
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
SearchResponse response = client().prepareSearch().setQuery(
new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1")})).get();
assertNoFailures(response);
assertThat(response, notNullValue());
response = client().prepareSearch().setQuery(
new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1")})).get();
assertNoFailures(response);
assertThat(response, notNullValue());
}
示例11: testSimpleMoreLikeThisIds
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testSimpleMoreLikeThisIds() throws Exception {
logger.info("Creating index test");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("text").field("type", "text").endObject()
.endObject().endObject().endObject()));
logger.info("Running Cluster Health");
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
logger.info("Indexing...");
List<IndexRequestBuilder> builders = new ArrayList<>();
builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene").setId("1"));
builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene release").setId("2"));
builders.add(client().prepareIndex("test", "type1").setSource("text", "apache lucene").setId("3"));
indexRandom(true, builders);
logger.info("Running MoreLikeThis");
MoreLikeThisQueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery(new String[] {"text"}, null, ids("1")).include(true).minTermFreq(1).minDocFreq(1);
SearchResponse mltResponse = client().prepareSearch().setTypes("type1").setQuery(queryBuilder).execute().actionGet();
assertHitCount(mltResponse, 3L);
}
示例12: setupSuiteScopeCluster
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("idx")
.addMapping("type", "ip", "type=ip", "ips", "type=ip"));
waitForRelocation(ClusterHealthStatus.GREEN);
indexRandom(true,
client().prepareIndex("idx", "type", "1").setSource(
"ip", "192.168.1.7",
"ips", Arrays.asList("192.168.0.13", "192.168.1.2")),
client().prepareIndex("idx", "type", "2").setSource(
"ip", "192.168.1.10",
"ips", Arrays.asList("192.168.1.25", "192.168.1.28")),
client().prepareIndex("idx", "type", "3").setSource(
"ip", "2001:db8::ff00:42:8329",
"ips", Arrays.asList("2001:db8::ff00:42:8329", "2001:db8::ff00:42:8380")));
assertAcked(prepareCreate("idx_unmapped"));
waitForRelocation(ClusterHealthStatus.GREEN);
refresh();
}
示例13: testPreferAllocatingPreviousPrimary
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
/**
* Tests that when there was a node that previously had the primary, it will be allocated to that same node again.
*/
public void testPreferAllocatingPreviousPrimary() {
String primaryAllocId = UUIDs.randomBase64UUID();
String replicaAllocId = UUIDs.randomBase64UUID();
RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(yesAllocationDeciders(),
randomFrom(CLUSTER_RECOVERED, INDEX_REOPENED), primaryAllocId, replicaAllocId);
boolean node1HasPrimaryShard = randomBoolean();
testAllocator.addData(node1, node1HasPrimaryShard ? primaryAllocId : replicaAllocId, node1HasPrimaryShard);
testAllocator.addData(node2, node1HasPrimaryShard ? replicaAllocId : primaryAllocId, !node1HasPrimaryShard);
testAllocator.allocateUnassigned(allocation);
assertThat(allocation.routingNodesChanged(), equalTo(true));
assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true));
assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
DiscoveryNode allocatedNode = node1HasPrimaryShard ? node1 : node2;
assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(allocatedNode.getId()));
assertClusterHealthStatus(allocation, ClusterHealthStatus.YELLOW);
}
示例14: update
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void update(ShardRouting shardRouting) {
if (shardRouting.active()) {
active++;
if (shardRouting.primary()) {
primaryActive++;
}
if (shardRouting.relocating()) {
relocating++;
}
return;
}
if (shardRouting.primary()) {
primaryInactive++;
if (inactivePrimaryCausesRed == false) {
inactivePrimaryCausesRed = getInactivePrimaryHealth(shardRouting) == ClusterHealthStatus.RED;
}
}
if (shardRouting.initializing()) {
initializing++;
} else {
unassigned++;
}
}
示例15: testPrimaryShardThrottleDecisionOnIndexCreation
import org.elasticsearch.cluster.health.ClusterHealthStatus; //导入依赖的package包/类
public void testPrimaryShardThrottleDecisionOnIndexCreation() throws IOException {
final String indexName = "test-idx";
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
.build();
AllocationDecider decider = new TestAllocateDecision(Decision.THROTTLE) {
// the only allocation decider that implements this is ShardsLimitAllocationDecider and it always
// returns only YES or NO, never THROTTLE
@Override
public Decision canAllocate(RoutingNode node, RoutingAllocation allocation) {
return randomBoolean() ? Decision.YES : Decision.NO;
}
};
// if deciders THROTTLE allocating a primary shard, stay in YELLOW state
runAllocationTest(
settings, indexName, Collections.singleton(decider), ClusterHealthStatus.YELLOW
);
}