use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.
the class UpdateSettingsIT method testOpenCloseUpdateSettings.
public void testOpenCloseUpdateSettings() throws Exception {
createIndex("test");
try {
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
-1).put("index.fielddata.cache", // this one can't
"none")).execute().actionGet();
fail();
} catch (IllegalArgumentException e) {
// all is well
}
IndexMetaData indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.getSettings().get("index.refresh_interval"), nullValue());
assertThat(indexMetaData.getSettings().get("index.fielddata.cache"), nullValue());
// Now verify via dedicated get settings api:
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), nullValue());
assertThat(getSettingsResponse.getSetting("test", "index.fielddata.cache"), nullValue());
client().admin().indices().prepareUpdateSettings("test").setSettings(// this one can change
Settings.builder().put("index.refresh_interval", -1)).execute().actionGet();
indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.getSettings().get("index.refresh_interval"), equalTo("-1"));
// Now verify via dedicated get settings api:
getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), equalTo("-1"));
// now close the index, change the non dynamic setting, and see that it applies
// Wait for the index to turn green before attempting to close it
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setTimeout("30s").setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));
client().admin().indices().prepareClose("test").execute().actionGet();
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)).execute().actionGet();
indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.getNumberOfReplicas(), equalTo(1));
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
"1s").put("index.fielddata.cache", // this one can't
"none")).execute().actionGet();
indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.getSettings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetaData.getSettings().get("index.fielddata.cache"), equalTo("none"));
// Now verify via dedicated get settings api:
getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), equalTo("1s"));
assertThat(getSettingsResponse.getSetting("test", "index.fielddata.cache"), equalTo("none"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.
the class IndicesStoreIntegrationIT method testShardsCleanup.
public void testShardsCleanup() throws Exception {
final String node_1 = internalCluster().startNode();
final String node_2 = internalCluster().startNode();
logger.info("--> creating index [test] with one shard and on replica");
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)));
ensureGreen("test");
ClusterState state = client().admin().cluster().prepareState().get().getState();
Index index = state.metaData().index("test").getIndex();
logger.info("--> making sure that shard and its replica are allocated on node_1 and node_2");
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true));
assertThat(Files.exists(shardDirectory(node_2, index, 0)), equalTo(true));
logger.info("--> starting node server3");
String node_3 = internalCluster().startNode();
logger.info("--> running cluster_health");
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForNodes("3").setWaitForNoRelocatingShards(true).get();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
logger.info("--> making sure that shard is not allocated on server3");
assertThat(waitForShardDeletion(node_3, index, 0), equalTo(false));
Path server2Shard = shardDirectory(node_2, index, 0);
logger.info("--> stopping node {}", node_2);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node_2));
logger.info("--> running cluster_health");
clusterHealth = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).get();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
logger.info("--> done cluster_health, status {}", clusterHealth.getStatus());
assertThat(Files.exists(server2Shard), equalTo(true));
logger.info("--> making sure that shard and its replica exist on server1, server2 and server3");
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true));
assertThat(Files.exists(server2Shard), equalTo(true));
assertThat(Files.exists(shardDirectory(node_3, index, 0)), equalTo(true));
logger.info("--> starting node node_4");
final String node_4 = internalCluster().startNode();
logger.info("--> running cluster_health");
ensureGreen();
logger.info("--> making sure that shard and its replica are allocated on server1 and server3 but not on server2");
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true));
assertThat(Files.exists(shardDirectory(node_3, index, 0)), equalTo(true));
assertThat(waitForShardDeletion(node_4, index, 0), equalTo(false));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.
the class IndicesStoreIntegrationIT method testShardActiveElsewhereDoesNotDeleteAnother.
public void testShardActiveElsewhereDoesNotDeleteAnother() throws Exception {
final String masterNode = internalCluster().startMasterOnlyNode();
final List<String> nodes = internalCluster().startDataOnlyNodes(4);
final String node1 = nodes.get(0);
final String node2 = nodes.get(1);
final String node3 = nodes.get(2);
// we will use this later on, handy to start now to make sure it has a different data folder that node 1,2 &3
final String node4 = nodes.get(3);
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "_name", node4)));
assertFalse(client().admin().cluster().prepareHealth().setWaitForNoRelocatingShards(true).setWaitForGreenStatus().setWaitForNodes("5").get().isTimedOut());
// disable allocation to control the situation more easily
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")));
logger.debug("--> shutting down two random nodes");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node1, node2, node3));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node1, node2, node3));
logger.debug("--> verifying index is red");
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").get();
if (health.getStatus() != ClusterHealthStatus.RED) {
logClusterState();
fail("cluster didn't become red, despite of shutting 2 of 3 nodes");
}
logger.debug("--> allowing index to be assigned to node [{}]", node4);
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "_name", "NONE")));
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "all")));
logger.debug("--> waiting for shards to recover on [{}]", node4);
// we have to do this in two steps as we now do async shard fetching before assigning, so the change to the
// allocation filtering may not have immediate effect
// TODO: we should add an easier to do this. It's too much of a song and dance..
Index index = resolveIndex("test");
assertBusy(new Runnable() {
@Override
public void run() {
assertTrue(internalCluster().getInstance(IndicesService.class, node4).hasIndex(index));
}
});
// wait for 4 active shards - we should have lost one shard
assertFalse(client().admin().cluster().prepareHealth().setWaitForActiveShards(4).get().isTimedOut());
// disable allocation again to control concurrency a bit and allow shard active to kick in before allocation
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")));
logger.debug("--> starting the two old nodes back");
internalCluster().startDataOnlyNodes(2);
assertFalse(client().admin().cluster().prepareHealth().setWaitForNodes("5").get().isTimedOut());
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "all")));
logger.debug("--> waiting for the lost shard to be recovered");
ensureGreen("test");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.
the class SimpleGetMappingsIT method testSimpleGetMappings.
public void testSimpleGetMappings() throws Exception {
client().admin().indices().prepareCreate("indexa").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
client().admin().indices().prepareCreate("indexb").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
// Get all mappings
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(4));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all mappings, via wildcard support
response = client().admin().indices().prepareGetMappings("*").setTypes("*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(4));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all typeA mappings in all indices
response = client().admin().indices().prepareGetMappings("*").setTypes("typeA").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(1));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
// Get all mappings in indexa
response = client().admin().indices().prepareGetMappings("indexa").execute().actionGet();
assertThat(response.mappings().size(), equalTo(1));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
// Get all mappings beginning with A* in indexa
response = client().admin().indices().prepareGetMappings("indexa").setTypes("A*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(1));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
// Get all mappings beginning with B* in all indices
response = client().admin().indices().prepareGetMappings().setTypes("B*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(1));
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all mappings beginning with B* and A* in all indices
response = client().admin().indices().prepareGetMappings().setTypes("B*", "A*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(2));
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(2));
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.
the class OpenCloseIndexIT method testCloseOpenMultipleIndices.
public void testCloseOpenMultipleIndices() {
Client client = client();
createIndex("test1", "test2", "test3");
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(healthResponse.isTimedOut(), equalTo(false));
CloseIndexResponse closeIndexResponse1 = client.admin().indices().prepareClose("test1").execute().actionGet();
assertThat(closeIndexResponse1.isAcknowledged(), equalTo(true));
CloseIndexResponse closeIndexResponse2 = client.admin().indices().prepareClose("test2").execute().actionGet();
assertThat(closeIndexResponse2.isAcknowledged(), equalTo(true));
assertIndexIsClosed("test1", "test2");
assertIndexIsOpened("test3");
OpenIndexResponse openIndexResponse1 = client.admin().indices().prepareOpen("test1").execute().actionGet();
assertThat(openIndexResponse1.isAcknowledged(), equalTo(true));
OpenIndexResponse openIndexResponse2 = client.admin().indices().prepareOpen("test2").execute().actionGet();
assertThat(openIndexResponse2.isAcknowledged(), equalTo(true));
assertIndexIsOpened("test1", "test2", "test3");
}
Aggregations