Skip to content

Commit

Permalink
Reuse method notFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Nov 9, 2022
1 parent 938d2c0 commit d1f11d4
Showing 1 changed file with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,6 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
return concreteIndices.toArray(Index.EMPTY_ARRAY);
}

private IndexNotFoundException notFoundException(String... indexExpressions) {
IndexNotFoundException infe;
if (indexExpressions.length == 1) {
if (indexExpressions[0].equals(Metadata.ALL)) {
infe = new IndexNotFoundException("no indices exist", indexExpressions[0]);
} else {
infe = new IndexNotFoundException(indexExpressions[0]);
}
infe.setResources("index_expression", indexExpressions[0]);
} else {
infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
}
return infe;
}

private void checkSystemIndexAccess(Context context, Set<Index> concreteIndices) {
final Metadata metadata = context.getState().metadata();
final Predicate<String> systemIndexAccessPredicate = context.getSystemIndexAccessPredicate().negate();
Expand Down Expand Up @@ -489,6 +473,22 @@ private void checkSystemIndexAccess(Context context, Set<Index> concreteIndices)
}
}

private static IndexNotFoundException notFoundException(String... indexExpressions) {
IndexNotFoundException infe;
if (indexExpressions != null && indexExpressions.length == 1) {
if (Metadata.ALL.equals(indexExpressions[0])) {
infe = new IndexNotFoundException("no indices exist", indexExpressions[0]);
} else {
infe = new IndexNotFoundException(indexExpressions[0]);
}
infe.setResources("index_or_alias", indexExpressions[0]);
} else {
infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
}
return infe;
}

private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, Index index) {
if (context.systemIndexAccessLevel == SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY
&& context.netNewSystemIndexPredicate.test(index.getName())) {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ private static Collection<String> innerResolve(Context context, List<String> exp
matchingOpenClosedNames.forEachOrdered(result::add);
}
if (emptyWildcardExpansion.get()) {
throw indexNotFoundException(expression);
throw notFoundException(expression);
}
} else {
if (isExclusion) {
Expand Down Expand Up @@ -1248,7 +1248,7 @@ private static Collection<String> innerResolve(Context context, List<String> exp

private static String validateAliasOrIndex(String expression) {
if (Strings.isEmpty(expression)) {
throw indexNotFoundException(expression);
throw notFoundException(expression);
}
// Expressions can not start with an underscore. This is reserved for APIs. If the check gets here, the API
// does not exist and the path is interpreted as an expression. If the expression begins with an underscore,
Expand All @@ -1265,23 +1265,17 @@ private static void ensureAliasOrIndexExists(Context context, String expression)
final IndicesOptions options = context.getOptions();
IndexAbstraction indexAbstraction = context.getState().getMetadata().getIndicesLookup().get(expression);
if (indexAbstraction == null) {
throw indexNotFoundException(expression);
throw notFoundException(expression);
}
// treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
if (indexAbstraction.getType() == Type.ALIAS && options.ignoreAliases()) {
throw aliasesNotSupportedException(expression);
}
if (indexAbstraction.isDataStreamRelated() && context.includeDataStreams() == false) {
throw indexNotFoundException(expression);
throw notFoundException(expression);
}
}

private static IndexNotFoundException indexNotFoundException(String expression) {
IndexNotFoundException infe = new IndexNotFoundException(expression);
infe.setResources("index_or_alias", expression);
return infe;
}

private static IndexMetadata.State excludeState(IndicesOptions options) {
final IndexMetadata.State excludeState;
if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) {
Expand Down

0 comments on commit d1f11d4

Please sign in to comment.