Search in sources :

Example 81 with ClusterHealthResponse

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"));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 82 with ClusterHealthResponse

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));
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Index(org.elasticsearch.index.Index)

Example 83 with ClusterHealthResponse

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");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index)

Example 84 with ClusterHealthResponse

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());
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 85 with ClusterHealthResponse

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");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client)

Aggregations

ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)123 Settings (org.elasticsearch.common.settings.Settings)29 Client (org.elasticsearch.client.Client)24 ClusterState (org.elasticsearch.cluster.ClusterState)16 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)15 Test (org.junit.Test)15 IOException (java.io.IOException)13 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)12 SearchResponse (org.elasticsearch.action.search.SearchResponse)11 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)10 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)7 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)7 Index (org.elasticsearch.index.Index)7 MockTransportService (org.elasticsearch.test.transport.MockTransportService)6 TransportService (org.elasticsearch.transport.TransportService)6 Path (java.nio.file.Path)5