Search in sources :

Example 1 with OpenIndexResponse

use of org.elasticsearch.action.admin.indices.open.OpenIndexResponse 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 OpenIndexResponse

use of org.elasticsearch.action.admin.indices.open.OpenIndexResponse 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 OpenIndexResponse

use of org.elasticsearch.action.admin.indices.open.OpenIndexResponse 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 OpenIndexResponse

use of org.elasticsearch.action.admin.indices.open.OpenIndexResponse 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 OpenIndexResponse

use of org.elasticsearch.action.admin.indices.open.OpenIndexResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testOpenAlreadyOpenedIndex.

public void testOpenAlreadyOpenedIndex() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    //no problem if we try to open an index that's already in open state
    OpenIndexResponse openIndexResponse1 = client.admin().indices().prepareOpen("test1").execute().actionGet();
    assertThat(openIndexResponse1.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client)

Aggregations

OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)13 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)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 IOException (java.io.IOException)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 OpenIndexRequest (org.elasticsearch.action.admin.indices.open.OpenIndexRequest)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexClosedException (org.elasticsearch.indices.IndexClosedException)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1