Search in sources :

Example 1 with CloseIndexResponse

use of org.elasticsearch.action.admin.indices.close.CloseIndexResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testOpenCloseIndexWithBlocks.

public void testOpenCloseIndexWithBlocks() {
    createIndex("test");
    ensureGreen("test");
    int docs = between(10, 100);
    for (int i = 0; i < docs; i++) {
        client().prepareIndex("test", "type", "" + i).setSource("test", "init").execute().actionGet();
    }
    for (String blockSetting : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE)) {
        try {
            enableIndexBlock("test", blockSetting);
            // Closing an index is not blocked
            CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet();
            assertAcked(closeIndexResponse);
            assertIndexIsClosed("test");
            // Opening an index is not blocked
            OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").execute().actionGet();
            assertAcked(openIndexResponse);
            assertIndexIsOpened("test");
        } finally {
            disableIndexBlock("test", blockSetting);
        }
    }
    // Closing an index is blocked
    for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) {
        try {
            enableIndexBlock("test", blockSetting);
            assertBlocked(client().admin().indices().prepareClose("test"));
            assertIndexIsOpened("test");
        } finally {
            disableIndexBlock("test", blockSetting);
        }
    }
    CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet();
    assertAcked(closeIndexResponse);
    assertIndexIsClosed("test");
    // Opening an index is blocked
    for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) {
        try {
            enableIndexBlock("test", blockSetting);
            assertBlocked(client().admin().indices().prepareOpen("test"));
            assertIndexIsClosed("test");
        } finally {
            disableIndexBlock("test", blockSetting);
        }
    }
}
Also used : CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with CloseIndexResponse

use of org.elasticsearch.action.admin.indices.close.CloseIndexResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testCloseOpenWildcard.

public void testCloseOpenWildcard() {
    Client client = client();
    createIndex("test1", "test2", "a");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test*").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    assertIndexIsOpened("a");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test*").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2", "a");
}
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)

Example 3 with CloseIndexResponse

use of org.elasticsearch.action.admin.indices.close.CloseIndexResponse in project elasticsearch by elastic.

the class SimpleIndexStateIT method testSimpleOpenClose.

public void testSimpleOpenClose() {
    logger.info("--> creating test index");
    createIndex("test");
    logger.info("--> waiting for green status");
    ensureGreen();
    NumShards numShards = getNumShards("test");
    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
    assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN));
    assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries));
    assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), numShards.totalNumShards);
    logger.info("--> indexing a simple document");
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
    logger.info("--> closing test index...");
    CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").get();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    stateResponse = client().admin().cluster().prepareState().get();
    assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.CLOSE));
    assertThat(stateResponse.getState().routingTable().index("test"), nullValue());
    logger.info("--> trying to index into a closed index ...");
    try {
        client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
        fail();
    } catch (IndexClosedException e) {
    // all is well
    }
    logger.info("--> opening index...");
    OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").get();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    logger.info("--> waiting for green status");
    ensureGreen();
    stateResponse = client().admin().cluster().prepareState().get();
    assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN));
    assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries));
    assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), numShards.totalNumShards);
    logger.info("--> indexing a simple document");
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
}
Also used : CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) IndexClosedException(org.elasticsearch.indices.IndexClosedException) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse)

Example 4 with CloseIndexResponse

use of org.elasticsearch.action.admin.indices.close.CloseIndexResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testSimpleCloseOpen.

public void testSimpleCloseOpen() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
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)

Example 5 with CloseIndexResponse

use of org.elasticsearch.action.admin.indices.close.CloseIndexResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testCloseAlreadyClosedIndex.

public void testCloseAlreadyClosedIndex() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    //closing the index
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
    //no problem if we try to close an index that's already in close state
    closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) Client(org.elasticsearch.client.Client)

Aggregations

CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)13 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)10 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)9 Client (org.elasticsearch.client.Client)9 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)2 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 IndexClosedException (org.elasticsearch.indices.IndexClosedException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1