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);
}
}
}
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");
}
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();
}
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");
}
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");
}
Aggregations