Skip to content

Commit

Permalink
[Remove] AliasesExistAction (#3149) (#3158)
Browse files Browse the repository at this point in the history
With the removal of Transport Client AliasesExistAction is no longer needed and
is removed.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
(cherry picked from commit 5f531b3)
  • Loading branch information
opensearch-trigger-bot[bot] authored May 3, 2022
1 parent e0b3410 commit 4e7cd2a
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.action.admin.indices.alias;

import org.opensearch.action.RequestValidators;
import org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse;
import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.opensearch.cluster.metadata.AliasMetadata;
Expand Down Expand Up @@ -143,8 +142,6 @@ public void testSomeAllowed() {
final Exception e = expectThrows(IllegalStateException.class, () -> client().admin().indices().aliases(request).actionGet());
final String index = "foo_allowed".equals(origin) ? "bar" : "foo";
assertThat(e, hasToString(containsString("origin [" + origin + "] not allowed for index [" + index + "]")));
final AliasesExistResponse response = client().admin().indices().aliasesExist(new GetAliasesRequest("alias")).actionGet();
assertFalse(response.exists());
assertTrue(client().admin().indices().getAliases(new GetAliasesRequest("alias")).actionGet().getAliases().isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.opensearch.action.admin.indices.alias.Alias;
import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse;
import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.opensearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.opensearch.action.delete.DeleteResponse;
Expand Down Expand Up @@ -684,8 +683,9 @@ public void testDeleteAliases() throws Exception {

assertAliasesVersionIncreases(indices, () -> admin().indices().prepareAliases().removeAlias(indices, aliases).get());

AliasesExistResponse response = admin().indices().prepareAliasesExist(aliases).get();
assertThat(response.exists(), equalTo(false));
for (String alias : aliases) {
assertTrue(admin().indices().prepareGetAliases(alias).get().getAliases().isEmpty());
}

logger.info("--> creating index [foo_foo] and [bar_bar]");
assertAcked(prepareCreate("foo_foo"));
Expand All @@ -701,9 +701,9 @@ public void testDeleteAliases() throws Exception {
() -> assertAcked(admin().indices().prepareAliases().addAliasAction(AliasActions.remove().index("foo*").alias("foo")))
);

assertTrue(admin().indices().prepareAliasesExist("foo").get().exists());
assertFalse(admin().indices().prepareAliasesExist("foo").setIndices("foo_foo").get().exists());
assertTrue(admin().indices().prepareAliasesExist("foo").setIndices("bar_bar").get().exists());
assertFalse(admin().indices().prepareGetAliases("foo").get().getAliases().isEmpty());
assertTrue(admin().indices().prepareGetAliases("foo").setIndices("foo_foo").get().getAliases().isEmpty());
assertFalse(admin().indices().prepareGetAliases("foo").setIndices("bar_bar").get().getAliases().isEmpty());
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> admin().indices().prepareAliases().addAliasAction(AliasActions.remove().index("foo").alias("foo")).execute().actionGet()
Expand Down Expand Up @@ -880,8 +880,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("alias1").get().getAliases().isEmpty());

logger.info("--> getting all aliases that start with alias*");
getResponse = admin().indices().prepareGetAliases("alias*").get();
Expand All @@ -898,8 +897,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("alias*").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("alias*").get().getAliases().isEmpty());

logger.info("--> creating aliases [bar, baz, foo]");
assertAliasesVersionIncreases(
Expand Down Expand Up @@ -937,8 +935,10 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("bar", "bac").addIndices("bazbar").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("bar").get().getAliases().isEmpty());
assertFalse(admin().indices().prepareGetAliases("bac").get().getAliases().isEmpty());
assertFalse(admin().indices().prepareGetAliases("bar").addIndices("bazbar").get().getAliases().isEmpty());
assertFalse(admin().indices().prepareGetAliases("bac").addIndices("bazbar").get().getAliases().isEmpty());

logger.info("--> getting *b* for index baz*");
getResponse = admin().indices().prepareGetAliases("*b*").addIndices("baz*").get();
Expand All @@ -957,8 +957,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("*b*").addIndices("baz*").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("*b*").addIndices("baz*").get().getAliases().isEmpty());

logger.info("--> getting *b* for index *bar");
getResponse = admin().indices().prepareGetAliases("b*").addIndices("*bar").get();
Expand All @@ -982,8 +981,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla"));
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla"));
existsResponse = admin().indices().prepareAliasesExist("b*").addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("b*").addIndices("*bar").get().getAliases().isEmpty());

logger.info("--> getting f* for index *bar");
getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").get();
Expand All @@ -994,8 +992,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("f*").addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("f*").addIndices("*bar").get().getAliases().isEmpty());

// alias at work
logger.info("--> getting f* for index *bac");
Expand All @@ -1008,8 +1005,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("foo").addIndices("*bac").get().getAliases().isEmpty());

logger.info("--> getting foo for index foobar");
getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
Expand All @@ -1020,8 +1016,7 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("foobar").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("foo").addIndices("foobar").get().getAliases().isEmpty());

for (String aliasName : new String[] { null, "_all", "*" }) {
logger.info("--> getting {} alias for index foobar", aliasName);
Expand All @@ -1044,17 +1039,15 @@ public void testIndicesGetAliases() throws Exception {
assertThat(getResponse.getAliases().size(), equalTo(2));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(4));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
existsResponse = admin().indices().prepareAliasesExist("*").addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("*").addIndices("*bac").get().getAliases().isEmpty());

assertAcked(admin().indices().prepareAliases().removeAlias("foobar", "foo"));

getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
for (final ObjectObjectCursor<String, List<AliasMetadata>> entry : getResponse.getAliases()) {
assertTrue(entry.value.isEmpty());
}
existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("foobar").get();
assertThat(existsResponse.exists(), equalTo(false));
assertTrue(admin().indices().prepareGetAliases("foo").addIndices("foobar").get().getAliases().isEmpty());
}

public void testGetAllAliasesWorks() {
Expand Down Expand Up @@ -1226,7 +1219,7 @@ public void testAliasesWithBlocks() {
);
assertAliasesVersionIncreases("test", () -> assertAcked(admin().indices().prepareAliases().removeAlias("test", "alias1")));
assertThat(admin().indices().prepareGetAliases("alias2").execute().actionGet().getAliases().get("test").size(), equalTo(1));
assertThat(admin().indices().prepareAliasesExist("alias2").get().exists(), equalTo(true));
assertFalse(admin().indices().prepareGetAliases("alias2").get().getAliases().isEmpty());
} finally {
disableIndexBlock("test", block);
}
Expand All @@ -1244,8 +1237,7 @@ public void testAliasesWithBlocks() {
() -> assertBlocked(admin().indices().prepareAliases().removeAlias("test", "alias2"), INDEX_READ_ONLY_BLOCK)
);
assertThat(admin().indices().prepareGetAliases("alias2").execute().actionGet().getAliases().get("test").size(), equalTo(1));
assertThat(admin().indices().prepareAliasesExist("alias2").get().exists(), equalTo(true));

assertFalse(admin().indices().prepareGetAliases("alias2").get().getAliases().isEmpty());
} finally {
disableIndexBlock("test", SETTING_READ_ONLY);
}
Expand All @@ -1262,8 +1254,7 @@ public void testAliasesWithBlocks() {
() -> assertBlocked(admin().indices().prepareAliases().removeAlias("test", "alias2"), INDEX_METADATA_BLOCK)
);
assertBlocked(admin().indices().prepareGetAliases("alias2"), INDEX_METADATA_BLOCK);
assertBlocked(admin().indices().prepareAliasesExist("alias2"), INDEX_METADATA_BLOCK);

assertBlocked(admin().indices().prepareGetAliases("alias2"), INDEX_METADATA_BLOCK);
} finally {
disableIndexBlock("test", SETTING_BLOCKS_METADATA);
}
Expand All @@ -1288,12 +1279,12 @@ public void testAliasActionRemoveIndex() throws InterruptedException, ExecutionE

assertAcked(client().admin().indices().prepareAliases().removeIndex("foo*"));
assertFalse(client().admin().indices().prepareExists("foo_foo").execute().actionGet().isExists());
assertTrue(admin().indices().prepareAliasesExist("foo").get().exists());
assertFalse(admin().indices().prepareGetAliases("foo").get().getAliases().isEmpty());
assertTrue(client().admin().indices().prepareExists("bar_bar").execute().actionGet().isExists());
assertTrue(admin().indices().prepareAliasesExist("foo").setIndices("bar_bar").get().exists());
assertFalse(admin().indices().prepareGetAliases("foo").setIndices("bar_bar").get().getAliases().isEmpty());

assertAcked(client().admin().indices().prepareAliases().removeIndex("bar_bar"));
assertFalse(admin().indices().prepareAliasesExist("foo").get().exists());
assertTrue(admin().indices().prepareGetAliases("foo").get().getAliases().isEmpty());
assertFalse(client().admin().indices().prepareExists("bar_bar").execute().actionGet().isExists());
}

Expand Down
Loading

0 comments on commit 4e7cd2a

Please sign in to comment.