Revert "Aliases: Throw exception if index is null when creating alias"

This reverts commit ee857bc073.
This commit is contained in:
Zachary Tong 2014-10-10 17:50:30 -04:00
parent ee857bc073
commit 7821387cca
2 changed files with 9 additions and 30 deletions

View File

@ -294,6 +294,10 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
+ "]: [alias] may not be empty string", validationException);
}
}
if (CollectionUtils.isEmpty(aliasAction.indices)) {
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
+ "]: indices may not be empty", validationException);
}
}
if (!CollectionUtils.isEmpty(aliasAction.indices)) {
for (String index : aliasAction.indices) {
@ -302,9 +306,6 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
+ "]: [index] may not be empty string", validationException);
}
}
} else {
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
+ "]: Property [index] was either missing or null", validationException);
}
}
return validationException;

View File

@ -754,31 +754,9 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(existsResponse.exists(), equalTo(false));
}
@Test
public void testAddAliasNullWithoutExistingIndices() {
try {
assertAcked(admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1")));
fail("create alias should have failed due to null index");
} catch (ElasticsearchIllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Validation Failed: 1: Alias action [add]: [index] may not be null;"));
}
}
@Test
public void testAddAliasNullWithExistingIndices() throws Exception {
logger.info("--> creating index [test]");
createIndex("test");
ensureGreen();
logger.info("--> aliasing index [null] with [empty-alias]");
try {
assertAcked(admin().indices().prepareAliases().addAlias((String) null, "empty-alias"));
fail("create alias should have failed due to null index");
} catch (ElasticsearchIllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Validation Failed: 1: Alias action [add]: [index] may not be null;"));
}
@Test(expected = IndexMissingException.class)
public void testAddAliasNullIndex() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1")).get();
}
@Test(expected = ActionRequestValidationException.class)
@ -803,7 +781,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2));
assertThat(e.validationErrors().size(), equalTo(1));
}
}
@ -960,7 +938,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
.addAlias("test", "a", FilterBuilders.matchAllFilter()) // <-- no fail, b/c no field mentioned
.get();
}
private void checkAliases() {
GetAliasesResponse getAliasesResponse = admin().indices().prepareGetAliases("alias1").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));