use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.
the class OpenCloseIndexIT method testOpenOneMissingIndexIgnoreMissing.
public void testOpenOneMissingIndexIgnoreMissing() {
Client client = client();
createIndex("test1");
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(healthResponse.isTimedOut(), equalTo(false));
OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1", "test2").setIndicesOptions(IndicesOptions.lenientExpandOpen()).execute().actionGet();
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
assertIndexIsOpened("test1");
}
use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.
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));
AcknowledgedResponse 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));
assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
assertIndexIsOpened("test1", "test2", "a");
}
use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.
the class OpenCloseIndexIT method testCloseOpenAliasMultipleIndices.
public void testCloseOpenAliasMultipleIndices() {
Client client = client();
createIndex("test1", "test2");
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(healthResponse.isTimedOut(), equalTo(false));
AcknowledgedResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
AcknowledgedResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));
AcknowledgedResponse closeIndexResponse = client.admin().indices().prepareClose("test-alias").execute().actionGet();
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
assertIndexIsClosed("test1", "test2");
OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test-alias").execute().actionGet();
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
assertIndexIsOpened("test1", "test2");
}
use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.
the class IndicesClientIT method testOpenExistingIndex.
public void testOpenExistingIndex() throws IOException {
String index = "index";
createIndex(index, Settings.EMPTY);
closeIndex(index);
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(index), equalTo(true));
OpenIndexRequest openIndexRequest = new OpenIndexRequest(index);
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync);
assertTrue(openIndexResponse.isAcknowledged());
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}
use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.
the class IndicesClientIT method testOpenNonExistentIndex.
public void testOpenNonExistentIndex() throws IOException {
String nonExistentIndex = "non_existent_index";
assertFalse(indexExists(nonExistentIndex));
OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex);
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync);
assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true));
OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen());
OpenSearchException strictException = expectThrows(OpenSearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
assertEquals(RestStatus.NOT_FOUND, strictException.status());
}
Aggregations