use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteIndicesIgnoreIndicesAllMissing.
public void testConcreteIndicesIgnoreIndicesAllMissing() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("testXXX")).put(indexBuilder("kuku"));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false);
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy"));
assertThat(infe.getMessage(), is("no such index [testMo]"));
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testIndicesAliasesRequestIgnoresAliases.
public void testIndicesAliasesRequestIgnoresAliases() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias"))).put(indexBuilder("index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias2")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-alias");
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-a*");
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("test-a*", infe.getIndex().getName());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-index");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("test-*");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-alias");
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-a*");
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("test-a*", infe.getIndex().getName());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-index");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.remove().index("test-*");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-alias");
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-a*");
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions));
assertEquals("test-a*", infe.getIndex().getName());
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-index");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.removeIndex().index("test-*");
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions);
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testDeleteIndexIgnoresAliases.
public void testDeleteIndexIgnoresAliases() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias"))).put(indexBuilder("index").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias2")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("does_not_exist")));
assertEquals("does_not_exist", infe.getIndex().getName());
assertEquals("no such index [does_not_exist]", infe.getMessage());
}
{
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-alias")));
assertEquals("The provided expression [test-alias] matches an alias, " + "specify the corresponding concrete indices instead.", iae.getMessage());
}
{
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-alias");
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(true, true, true, true, false, false, true, false));
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest);
assertEquals(0, indices.length);
}
{
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-a*");
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, true, false, false, true, false));
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest));
assertEquals(infe.getIndex().getName(), "test-a*");
}
{
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-a*"));
assertEquals(0, indices.length);
}
{
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-index"));
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
{
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("test-*"));
assertEquals(1, indices.length);
assertEquals("test-index", indices[0]);
}
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testConcreteIndicesNoIndicesErrorMessage.
public void testConcreteIndicesNoIndicesErrorMessage() {
Metadata.Builder mdBuilder = Metadata.builder();
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(false, false, true, true), false);
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[] {}));
assertThat(infe.getMessage(), is("no such index [null] and no indices exist"));
}
use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.
the class IndexNameExpressionResolverTests method testIndexOptionsNoExpandWildcards.
public void testIndexOptionsNoExpandWildcards() {
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("foo").putAlias(AliasMetadata.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetadata.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetadata.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetadata.builder("barbaz")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
// ignore unavailable and allow no indices
{
IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false, randomBoolean());
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient, false);
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
assertEquals(0, results.length);
results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(0, results.length);
}
// ignore unavailable but don't allow no indices
{
IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false, randomBoolean());
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, false);
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*"));
assertThat(infe.getIndex().getName(), equalTo("baz*"));
}
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
{
// unavailable indices are ignored but no indices are disallowed
expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "bar", "baz"));
}
}
// error on unavailable but allow no indices
{
IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false, randomBoolean());
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, false);
{
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray());
}
{
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"));
assertThat(infe.getIndex().getName(), equalTo("baz*"));
}
{
// unavailable indices are not ignored, hence the error on the first unavailable indices encountered
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "bar", "baz"));
assertThat(infe.getIndex().getName(), equalTo("bar"));
}
{
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
}
}
// error on both unavailable and no indices
{
IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false, randomBoolean());
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict, false);
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*"));
assertThat(infe.getIndex().getName(), equalTo("baz*"));
IndexNotFoundException infe2 = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"));
assertThat(infe2.getIndex().getName(), equalTo("baz*"));
String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
}
}
Aggregations