From b7af8524228891c305b8868ff7f748ec10cf724c Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 30 Mar 2020 08:10:07 +0200 Subject: [PATCH] Refactor AliasOrIndex abstraction. (#53982) In order to prepare the `AliasOrIndex` abstraction for the introduction of data streams, the abstraction needs to be made more flexible, because currently it really can be only an alias or an index. * Renamed `AliasOrIndex` to `IndexAbstraction`. * Introduced a `IndexAbstraction.Type` enum to indicate what a `IndexAbstraction` instance is. * Replaced the `isAlias()` method that returns a boolean with the `getType()` method that returns the new Type enum. * Moved `getWriteIndex()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface. * Moved `getAliasName()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface and renamed it to `getName()`. * Removed unnecessary casting to `IndexAbstraction.Alias` by just checking the `getType()` method. Relates to #53100 --- .../example/CustomAuthorizationEngine.java | 8 +- .../CustomAuthorizationEngineTests.java | 12 +-- .../rollover/MetaDataRolloverService.java | 20 ++-- .../action/bulk/TransportBulkAction.java | 16 ++-- ...liasOrIndex.java => IndexAbstraction.java} | 91 +++++++++++++++---- .../metadata/IndexNameExpressionResolver.java | 74 +++++++-------- .../cluster/metadata/MetaData.java | 65 ++++++------- .../MetaDataRolloverServiceTests.java | 7 +- .../elasticsearch/aliases/IndexAliasesIT.java | 6 +- ...xTests.java => IndexAbstractionTests.java} | 20 ++-- .../MetaDataIndexAliasesServiceTests.java | 38 ++++---- .../core/ilm/WaitForActiveShardsStep.java | 12 +-- .../core/ml/annotations/AnnotationIndex.java | 4 +- .../persistence/ElasticsearchMappings.java | 8 +- .../xpack/core/ml/utils/MlIndexAndAlias.java | 2 +- .../security/authz/AuthorizationEngine.java | 8 +- .../authz/permission/IndicesPermission.java | 10 +- .../authz/permission/LimitedRole.java | 4 +- .../core/security/authz/permission/Role.java | 4 +- .../slm/history/SnapshotHistoryStore.java | 12 +-- .../authz/permission/LimitedRoleTests.java | 16 ++-- .../authz/store/ReservedRolesStoreTests.java | 6 +- .../xpack/enrich/EnrichProcessorFactory.java | 12 +-- .../idp/saml/sp/SamlServiceProviderIndex.java | 10 +- .../xpack/ilm/history/ILMHistoryStore.java | 12 +-- .../ml/integration/MlConfigMigratorIT.java | 6 +- .../security/authz/AuthorizationService.java | 8 +- .../authz/IndicesAndAliasesResolver.java | 33 +++---- .../xpack/security/authz/RBACEngine.java | 14 +-- .../DeprecationRoleDescriptorConsumer.java | 12 +-- .../support/SecurityIndexManager.java | 10 +- .../test/SecurityIntegTestCase.java | 8 +- .../authz/AuthorizationServiceTests.java | 6 +- .../authz/AuthorizedIndicesTests.java | 14 +-- .../authz/IndicesAndAliasesResolverTests.java | 6 +- .../accesscontrol/IndicesPermissionTests.java | 14 +-- .../authz/store/CompositeRolesStoreTests.java | 2 +- .../support/SecurityIndexManagerTests.java | 2 +- .../TransformClusterStateListener.java | 4 +- .../xpack/watcher/watch/WatchStoreUtils.java | 10 +- .../watcher/WatcherIndexingListenerTests.java | 12 +-- 41 files changed, 346 insertions(+), 292 deletions(-) rename server/src/main/java/org/elasticsearch/cluster/metadata/{AliasOrIndex.java => IndexAbstraction.java} (73%) rename server/src/test/java/org/elasticsearch/cluster/metadata/{AliasOrIndexTests.java => IndexAbstractionTests.java} (86%) diff --git a/plugins/examples/security-authorization-engine/src/main/java/org/elasticsearch/example/CustomAuthorizationEngine.java b/plugins/examples/security-authorization-engine/src/main/java/org/elasticsearch/example/CustomAuthorizationEngine.java index 5595ec6a83899..3e2756c5ba80b 100644 --- a/plugins/examples/security-authorization-engine/src/main/java/org/elasticsearch/example/CustomAuthorizationEngine.java +++ b/plugins/examples/security-authorization-engine/src/main/java/org/elasticsearch/example/CustomAuthorizationEngine.java @@ -20,7 +20,7 @@ package org.elasticsearch.example; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesRequest; import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse; import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse.Indices; @@ -90,7 +90,7 @@ public void authorizeClusterAction(RequestInfo requestInfo, AuthorizationInfo au @Override public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, AsyncSupplier indicesAsyncSupplier, - Map aliasOrIndexLookup, + Map aliasOrIndexLookup, ActionListener listener) { if (isSuperuser(requestInfo.getAuthentication().getUser())) { indicesAsyncSupplier.getAsync(ActionListener.wrap(resolvedIndices -> { @@ -109,9 +109,9 @@ public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo auth @Override public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, - Map aliasOrIndexLookup, ActionListener> listener) { + Map indicesLookup, ActionListener> listener) { if (isSuperuser(requestInfo.getAuthentication().getUser())) { - listener.onResponse(new ArrayList<>(aliasOrIndexLookup.keySet())); + listener.onResponse(new ArrayList<>(indicesLookup.keySet())); } else { listener.onResponse(Collections.emptyList()); } diff --git a/plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java b/plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java index a4f3e90208695..b9d0495b24762 100644 --- a/plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java +++ b/plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java @@ -22,8 +22,8 @@ import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.cluster.metadata.AliasOrIndex; -import org.elasticsearch.cluster.metadata.AliasOrIndex.Index; +import org.elasticsearch.cluster.metadata.IndexAbstraction; +import org.elasticsearch.cluster.metadata.IndexAbstraction.Index; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; @@ -130,8 +130,8 @@ public void testAuthorizeClusterAction() { public void testAuthorizeIndexAction() { CustomAuthorizationEngine engine = new CustomAuthorizationEngine(); - Map aliasOrIndexMap = new HashMap<>(); - aliasOrIndexMap.put("index", new Index(IndexMetaData.builder("index") + Map indicesMap = new HashMap<>(); + indicesMap.put("index", new Index(IndexMetaData.builder("index") .settings(Settings.builder().put("index.version.created", Version.CURRENT)) .numberOfShards(1) .numberOfReplicas(0) @@ -148,7 +148,7 @@ public void testAuthorizeIndexAction() { PlainActionFuture resultFuture = new PlainActionFuture<>(); engine.authorizeIndexAction(requestInfo, authzInfo, listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), - aliasOrIndexMap, resultFuture); + indicesMap, resultFuture); IndexAuthorizationResult result = resultFuture.actionGet(); assertThat(result.isGranted(), is(true)); assertThat(result.isAuditable(), is(true)); @@ -169,7 +169,7 @@ public void testAuthorizeIndexAction() { PlainActionFuture resultFuture = new PlainActionFuture<>(); engine.authorizeIndexAction(requestInfo, authzInfo, listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), - aliasOrIndexMap, resultFuture); + indicesMap, resultFuture); IndexAuthorizationResult result = resultFuture.actionGet(); assertThat(result.isGranted(), is(false)); assertThat(result.isAuditable(), is(true)); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverService.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverService.java index 76428b8115bd4..3045f1f0e1842 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverService.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverService.java @@ -25,9 +25,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService; @@ -77,9 +77,9 @@ public RolloverResult rolloverClusterState(ClusterState currentState, String ali boolean silent) throws Exception { final MetaData metaData = currentState.metaData(); validate(metaData, aliasName); - final AliasOrIndex.Alias alias = (AliasOrIndex.Alias) metaData.getAliasAndIndexLookup().get(aliasName); + final IndexAbstraction alias = metaData.getIndicesLookup().get(aliasName); final IndexMetaData indexMetaData = alias.getWriteIndex(); - final AliasMetaData aliasMetaData = indexMetaData.getAliases().get(alias.getAliasName()); + final AliasMetaData aliasMetaData = indexMetaData.getAliases().get(alias.getName()); final String sourceProvidedName = indexMetaData.getSettings().get(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, indexMetaData.getIndex().getName()); final String sourceIndexName = indexMetaData.getIndex().getName(); @@ -174,16 +174,16 @@ static void checkNoDuplicatedAliasInIndexTemplate(MetaData metaData, String roll } static void validate(MetaData metaData, String aliasName) { - final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(aliasName); - if (aliasOrIndex == null) { + final IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(aliasName); + if (indexAbstraction == null) { throw new IllegalArgumentException("source alias does not exist"); } - if (aliasOrIndex.isAlias() == false) { - throw new IllegalArgumentException("source alias is a concrete index"); + if (indexAbstraction.getType() != IndexAbstraction.Type.ALIAS) { + throw new IllegalArgumentException("source alias is a [" + indexAbstraction.getType().getDisplayName() + + "], but an [" + IndexAbstraction.Type.ALIAS.getDisplayName() + "] was expected"); } - final AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex; - if (alias.getWriteIndex() == null) { - throw new IllegalArgumentException("source alias [" + alias.getAliasName() + "] does not point to a write index"); + if (indexAbstraction.getWriteIndex() == null) { + throw new IllegalArgumentException("source alias [" + indexAbstraction.getName() + "] does not point to a write index"); } } } diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index acc063e85fb82..fc6b34d1681f2 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -48,7 +48,7 @@ import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; @@ -281,18 +281,16 @@ static boolean resolvePipelines(final DocWriteRequest originalRequest, final IndexMetaData indexMetaData = metaData.indices().get(originalRequest.index()); // check the alias for the index request (this is how normal index requests are modeled) if (indexMetaData == null && indexRequest.index() != null) { - AliasOrIndex indexOrAlias = metaData.getAliasAndIndexLookup().get(indexRequest.index()); - if (indexOrAlias != null && indexOrAlias.isAlias()) { - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) indexOrAlias; - indexMetaData = alias.getWriteIndex(); + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(indexRequest.index()); + if (indexAbstraction != null) { + indexMetaData = indexAbstraction.getWriteIndex(); } } // check the alias for the action request (this is how upserts are modeled) if (indexMetaData == null && originalRequest.index() != null) { - AliasOrIndex indexOrAlias = metaData.getAliasAndIndexLookup().get(originalRequest.index()); - if (indexOrAlias != null && indexOrAlias.isAlias()) { - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) indexOrAlias; - indexMetaData = alias.getWriteIndex(); + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(originalRequest.index()); + if (indexAbstraction != null) { + indexMetaData = indexAbstraction.getWriteIndex(); } } if (indexMetaData != null) { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasOrIndex.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java similarity index 73% rename from server/src/main/java/org/elasticsearch/cluster/metadata/AliasOrIndex.java rename to server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java index 9d458663c2f62..3dc055fa1581d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasOrIndex.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.elasticsearch.cluster.metadata; import org.apache.lucene.util.SetOnce; @@ -25,7 +24,6 @@ import org.elasticsearch.common.collect.Tuple; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -35,30 +33,77 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_HIDDEN_SETTING; /** - * Encapsulates the {@link IndexMetaData} instances of a concrete index or indices an alias is pointing to. + * An index abstraction is a reference to one or more concrete indices. + * An index abstraction has a unique name and encapsulates all the {@link IndexMetaData} instances it is pointing to. + * Also depending on type it may refer to a single or many concrete indices and may or may not have a write index. */ -public interface AliasOrIndex { +public interface IndexAbstraction { + + /** + * @return the type of the index abstraction + */ + Type getType(); /** - * @return whether this an alias or concrete index + * @return the name of the index abstraction */ - boolean isAlias(); + String getName(); /** - * @return All {@link IndexMetaData} of all concrete indices this alias is referring to - * or if this is a concrete index its {@link IndexMetaData} + * @return All {@link IndexMetaData} of all concrete indices this index abstraction is referring to. */ List getIndices(); /** - * @return whether this alias/index is hidden or not + * A write index is a dedicated concrete index, that accepts all the new documents that belong to an index abstraction. + * + * A write index may also be a regular concrete index of a index abstraction and may therefore also be returned + * by {@link #getIndices()}. An index abstraction may also not have a dedicated write index. + * + * @return the write index of this index abstraction or + * null if this index abstraction doesn't have a write index. + */ + @Nullable + IndexMetaData getWriteIndex(); + + /** + * @return whether this index abstraction is hidden or not */ boolean isHidden(); + /** + * An index abstraction type. + */ + enum Type { + + /** + * An index abstraction that refers to a single concrete index. + * This concrete index is also the write index. + */ + CONCRETE_INDEX("concrete index"), + + /** + * An index abstraction that refers to an alias. + * An alias typically refers to many concrete indices and + * may have a write index. + */ + ALIAS("alias"); + + private final String displayName; + + Type(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + } + /** * Represents an concrete index and encapsulates its {@link IndexMetaData} */ - class Index implements AliasOrIndex { + class Index implements IndexAbstraction { private final IndexMetaData concreteIndex; @@ -67,13 +112,23 @@ public Index(IndexMetaData indexMetaData) { } @Override - public boolean isAlias() { - return false; + public String getName() { + return concreteIndex.getIndex().getName(); + } + + @Override + public Type getType() { + return Type.CONCRETE_INDEX; } @Override public List getIndices() { - return Collections.singletonList(concreteIndex); + return List.of(concreteIndex); + } + + @Override + public IndexMetaData getWriteIndex() { + return concreteIndex; } @Override @@ -85,7 +140,7 @@ public boolean isHidden() { /** * Represents an alias and groups all {@link IndexMetaData} instances sharing the same alias name together. */ - class Alias implements AliasOrIndex { + class Alias implements IndexAbstraction { private final String aliasName; private final List referenceIndexMetaDatas; @@ -100,11 +155,11 @@ public Alias(AliasMetaData aliasMetaData, IndexMetaData indexMetaData) { } @Override - public boolean isAlias() { - return true; + public Type getType() { + return Type.ALIAS; } - public String getAliasName() { + public String getName() { return aliasName; } @@ -131,7 +186,7 @@ public boolean isHidden() { * and filters) */ public Iterable> getConcreteIndexAndAliasMetaDatas() { - return () -> new Iterator>() { + return () -> new Iterator<>() { int index = 0; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index 1339e8a0edeea..a917e9cdbef7f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -180,8 +180,8 @@ Index[] concreteIndices(Context context, String... indexExpressions) { final Set concreteIndices = new HashSet<>(expressions.size()); for (String expression : expressions) { - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); - if (aliasOrIndex == null ) { + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(expression); + if (indexAbstraction == null ) { if (failNoIndices) { IndexNotFoundException infe; if (expression.equals(MetaData.ALL)) { @@ -194,7 +194,7 @@ Index[] concreteIndices(Context context, String... indexExpressions) { } else { continue; } - } else if (aliasOrIndex.isAlias() && context.getOptions().ignoreAliases()) { + } else if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS && context.getOptions().ignoreAliases()) { if (failNoIndices) { throw aliasesNotSupportedException(expression); } else { @@ -202,11 +202,10 @@ Index[] concreteIndices(Context context, String... indexExpressions) { } } - if (aliasOrIndex.isAlias() && context.isResolveToWriteIndex()) { - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex; - IndexMetaData writeIndex = alias.getWriteIndex(); + if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS && context.isResolveToWriteIndex()) { + IndexMetaData writeIndex = indexAbstraction.getWriteIndex(); if (writeIndex == null) { - throw new IllegalArgumentException("no write index is defined for alias [" + alias.getAliasName() + "]." + + throw new IllegalArgumentException("no write index is defined for alias [" + indexAbstraction.getName() + "]." + " The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" + " indices without one being designated as a write index"); } @@ -214,17 +213,17 @@ Index[] concreteIndices(Context context, String... indexExpressions) { concreteIndices.add(writeIndex.getIndex()); } } else { - if (aliasOrIndex.getIndices().size() > 1 && !options.allowAliasesToMultipleIndices()) { - String[] indexNames = new String[aliasOrIndex.getIndices().size()]; + if (indexAbstraction.getIndices().size() > 1 && !options.allowAliasesToMultipleIndices()) { + String[] indexNames = new String[indexAbstraction.getIndices().size()]; int i = 0; - for (IndexMetaData indexMetaData : aliasOrIndex.getIndices()) { + for (IndexMetaData indexMetaData : indexAbstraction.getIndices()) { indexNames[i++] = indexMetaData.getIndex().getName(); } throw new IllegalArgumentException("Alias [" + expression + "] has more than one indices associated with it [" + Arrays.toString(indexNames) + "], can't execute a single index op"); } - for (IndexMetaData index : aliasOrIndex.getIndices()) { + for (IndexMetaData index : indexAbstraction.getIndices()) { if (index.getState() == IndexMetaData.State.CLOSE) { if (failClosed) { throw new IndexClosedException(index.getIndex()); @@ -328,7 +327,7 @@ public Index concreteWriteIndex(ClusterState state, IndicesOptions options, Stri public boolean hasIndexOrAlias(String aliasOrIndex, ClusterState state) { Context context = new Context(state, IndicesOptions.lenientExpandOpen()); String resolvedAliasOrIndex = dateMathExpressionResolver.resolveExpression(aliasOrIndex, context); - return state.metaData().getAliasAndIndexLookup().containsKey(resolvedAliasOrIndex); + return state.metaData().getIndicesLookup().containsKey(resolvedAliasOrIndex); } /** @@ -457,9 +456,9 @@ public Map> resolveSearchRouting(ClusterState state, @Nullab } for (String expression : resolvedExpressions) { - AliasOrIndex aliasOrIndex = state.metaData().getAliasAndIndexLookup().get(expression); - if (aliasOrIndex != null && aliasOrIndex.isAlias()) { - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex; + IndexAbstraction indexAbstraction = state.metaData().getIndicesLookup().get(expression); + if (indexAbstraction != null && indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) { + IndexAbstraction.Alias alias = (IndexAbstraction.Alias) indexAbstraction; for (Tuple item : alias.getConcreteIndexAndAliasMetaDatas()) { String concreteIndex = item.v1(); AliasMetaData aliasMetaData = item.v2(); @@ -722,10 +721,10 @@ private Set innerResolve(Context context, List expressions, Indi if (Regex.isSimpleMatchPattern(expression) == false) { //TODO why does wildcard resolver throw exceptions regarding non wildcarded expressions? This should not be done here. if (options.ignoreUnavailable() == false) { - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); - if (aliasOrIndex == null) { + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(expression); + if (indexAbstraction == null) { throw indexNotFoundException(expression); - } else if (aliasOrIndex.isAlias() && options.ignoreAliases()) { + } else if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS && options.ignoreAliases()) { throw aliasesNotSupportedException(expression); } } @@ -738,7 +737,7 @@ private Set innerResolve(Context context, List expressions, Indi } final IndexMetaData.State excludeState = excludeState(options); - final Map matches = matches(context, metaData, expression); + final Map matches = matches(context, metaData, expression); Set expand = expand(context, excludeState, matches, expression, options.expandWildcardsHidden()); if (add) { result.addAll(expand); @@ -766,9 +765,10 @@ private static void validateAliasOrIndex(String expression) { } private static boolean aliasOrIndexExists(IndicesOptions options, MetaData metaData, String expression) { - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(expression); //treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api) - return aliasOrIndex != null && (options.ignoreAliases() == false || aliasOrIndex.isAlias() == false); + return indexAbstraction != null && (options.ignoreAliases() == false || + indexAbstraction.getType() != IndexAbstraction.Type.ALIAS); } private static IndexNotFoundException indexNotFoundException(String expression) { @@ -792,15 +792,15 @@ private static IndexMetaData.State excludeState(IndicesOptions options) { return excludeState; } - public static Map matches(Context context, MetaData metaData, String expression) { + public static Map matches(Context context, MetaData metaData, String expression) { if (Regex.isMatchAllPattern(expression)) { // Can only happen if the expressions was initially: '-*' if (context.getOptions().ignoreAliases()) { - return metaData.getAliasAndIndexLookup().entrySet().stream() - .filter(e -> e.getValue().isAlias() == false) + return metaData.getIndicesLookup().entrySet().stream() + .filter(e -> e.getValue().getType() != IndexAbstraction.Type.ALIAS) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } else { - return metaData.getAliasAndIndexLookup(); + return metaData.getIndicesLookup(); } } else if (expression.indexOf("*") == expression.length() - 1) { return suffixWildcard(context, metaData, expression); @@ -809,43 +809,43 @@ public static Map matches(Context context, MetaData metaDa } } - private static Map suffixWildcard(Context context, MetaData metaData, String expression) { + private static Map suffixWildcard(Context context, MetaData metaData, String expression) { assert expression.length() >= 2 : "expression [" + expression + "] should have at least a length of 2"; String fromPrefix = expression.substring(0, expression.length() - 1); char[] toPrefixCharArr = fromPrefix.toCharArray(); toPrefixCharArr[toPrefixCharArr.length - 1]++; String toPrefix = new String(toPrefixCharArr); - SortedMap subMap = metaData.getAliasAndIndexLookup().subMap(fromPrefix, toPrefix); + SortedMap subMap = metaData.getIndicesLookup().subMap(fromPrefix, toPrefix); if (context.getOptions().ignoreAliases()) { return subMap.entrySet().stream() - .filter(entry -> entry.getValue().isAlias() == false) + .filter(entry -> entry.getValue().getType() != IndexAbstraction.Type.ALIAS) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } return subMap; } - private static Map otherWildcard(Context context, MetaData metaData, String expression) { + private static Map otherWildcard(Context context, MetaData metaData, String expression) { final String pattern = expression; - return metaData.getAliasAndIndexLookup() + return metaData.getIndicesLookup() .entrySet() .stream() - .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().isAlias() == false) + .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().getType() != IndexAbstraction.Type.ALIAS) .filter(e -> Regex.simpleMatch(pattern, e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private static Set expand(Context context, IndexMetaData.State excludeState, Map matches, + private static Set expand(Context context, IndexMetaData.State excludeState, Map matches, String expression, boolean includeHidden) { Set expand = new HashSet<>(); - for (Map.Entry entry : matches.entrySet()) { + for (Map.Entry entry : matches.entrySet()) { String aliasOrIndexName = entry.getKey(); - AliasOrIndex aliasOrIndex = entry.getValue(); + IndexAbstraction indexAbstraction = entry.getValue(); - if (aliasOrIndex.isHidden() == false || includeHidden || implicitHiddenMatch(aliasOrIndexName, expression)) { - if (context.isPreserveAliases() && aliasOrIndex.isAlias()) { + if (indexAbstraction.isHidden() == false || includeHidden || implicitHiddenMatch(aliasOrIndexName, expression)) { + if (context.isPreserveAliases() && indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) { expand.add(aliasOrIndexName); } else { - for (IndexMetaData meta : aliasOrIndex.getIndices()) { + for (IndexMetaData meta : indexAbstraction.getIndices()) { if (excludeState == null || meta.getState() != excludeState) { expand.add(meta.getIndex().getName()); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 2e32ad47cfdd8..49c861d367fe5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -184,14 +184,14 @@ public interface Custom extends NamedDiffable, ToXContentFragment { private final String[] allClosedIndices; private final String[] visibleClosedIndices; - private final SortedMap aliasAndIndexLookup; + private final SortedMap indicesLookup; MetaData(String clusterUUID, boolean clusterUUIDCommitted, long version, CoordinationMetaData coordinationMetaData, Settings transientSettings, Settings persistentSettings, DiffableStringMap hashesOfConsistentSettings, ImmutableOpenMap indices, ImmutableOpenMap templates, ImmutableOpenMap customs, String[] allIndices, String[] visibleIndices, String[] allOpenIndices, String[] visibleOpenIndices, String[] allClosedIndices, String[] visibleClosedIndices, - SortedMap aliasAndIndexLookup) { + SortedMap indicesLookup) { this.clusterUUID = clusterUUID; this.clusterUUIDCommitted = clusterUUIDCommitted; this.version = version; @@ -220,7 +220,7 @@ public interface Custom extends NamedDiffable, ToXContentFragment { this.visibleOpenIndices = visibleOpenIndices; this.allClosedIndices = allClosedIndices; this.visibleClosedIndices = visibleClosedIndices; - this.aliasAndIndexLookup = aliasAndIndexLookup; + this.indicesLookup = indicesLookup; } public long version() { @@ -263,9 +263,9 @@ public CoordinationMetaData coordinationMetaData() { } public boolean hasAlias(String alias) { - AliasOrIndex aliasOrIndex = getAliasAndIndexLookup().get(alias); - if (aliasOrIndex != null) { - return aliasOrIndex.isAlias(); + IndexAbstraction indexAbstraction = getIndicesLookup().get(alias); + if (indexAbstraction != null) { + return indexAbstraction.getType() == IndexAbstraction.Type.ALIAS; } else { return false; } @@ -286,8 +286,8 @@ public boolean equalsAliases(MetaData other) { return true; } - public SortedMap getAliasAndIndexLookup() { - return aliasAndIndexLookup; + public SortedMap getIndicesLookup() { + return indicesLookup; } /** @@ -531,16 +531,15 @@ public String resolveWriteIndexRouting(@Nullable String routing, String aliasOrI return routing; } - AliasOrIndex result = getAliasAndIndexLookup().get(aliasOrIndex); - if (result == null || result.isAlias() == false) { + IndexAbstraction result = getIndicesLookup().get(aliasOrIndex); + if (result == null || result.getType() != IndexAbstraction.Type.ALIAS) { return routing; } - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) result; - IndexMetaData writeIndex = alias.getWriteIndex(); + IndexMetaData writeIndex = result.getWriteIndex(); if (writeIndex == null) { throw new IllegalArgumentException("alias [" + aliasOrIndex + "] does not have a write index"); } - AliasMetaData aliasMd = writeIndex.getAliases().get(alias.getAliasName()); + AliasMetaData aliasMd = writeIndex.getAliases().get(result.getName()); if (aliasMd.indexRouting() != null) { if (aliasMd.indexRouting().indexOf(',') != -1) { throw new IllegalArgumentException("index/alias [" + aliasOrIndex + "] provided with routing value [" @@ -568,11 +567,11 @@ public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex) return routing; } - AliasOrIndex result = getAliasAndIndexLookup().get(aliasOrIndex); - if (result == null || result.isAlias() == false) { + IndexAbstraction result = getIndicesLookup().get(aliasOrIndex); + if (result == null || result.getType() != IndexAbstraction.Type.ALIAS) { return routing; } - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) result; + IndexAbstraction.Alias alias = (IndexAbstraction.Alias) result; if (result.getIndices().size() > 1) { rejectSingleIndexOperation(aliasOrIndex, result); } @@ -594,7 +593,7 @@ public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex) return routing; } - private void rejectSingleIndexOperation(String aliasOrIndex, AliasOrIndex result) { + private void rejectSingleIndexOperation(String aliasOrIndex, IndexAbstraction result) { String[] indexNames = new String[result.getIndices().size()]; int i = 0; for (IndexMetaData indexMetaData : result.getIndices()) { @@ -609,7 +608,7 @@ public boolean hasIndex(String index) { } public boolean hasConcreteIndex(String index) { - return getAliasAndIndexLookup().containsKey(index); + return getIndicesLookup().containsKey(index); } public IndexMetaData index(String index) { @@ -1327,9 +1326,9 @@ public MetaData build() { } - SortedMap aliasAndIndexLookup = Collections.unmodifiableSortedMap(buildAliasAndIndexLookup()); + SortedMap indicesLookup = Collections.unmodifiableSortedMap(buildIndicesLookup()); - validateDataStreams(aliasAndIndexLookup); + validateDataStreams(indicesLookup); // build all concrete indices arrays: // TODO: I think we can remove these arrays. it isn't worth the effort, for operations on all indices. @@ -1344,43 +1343,45 @@ public MetaData build() { return new MetaData(clusterUUID, clusterUUIDCommitted, version, coordinationMetaData, transientSettings, persistentSettings, hashesOfConsistentSettings, indices.build(), templates.build(), customs.build(), allIndicesArray, visibleIndicesArray, - allOpenIndicesArray, visibleOpenIndicesArray, allClosedIndicesArray, visibleClosedIndicesArray, aliasAndIndexLookup); + allOpenIndicesArray, visibleOpenIndicesArray, allClosedIndicesArray, visibleClosedIndicesArray, indicesLookup); } - private SortedMap buildAliasAndIndexLookup() { - SortedMap aliasAndIndexLookup = new TreeMap<>(); + private SortedMap buildIndicesLookup() { + SortedMap aliasAndIndexLookup = new TreeMap<>(); for (ObjectCursor cursor : indices.values()) { IndexMetaData indexMetaData = cursor.value; - AliasOrIndex existing = aliasAndIndexLookup.put(indexMetaData.getIndex().getName(), new AliasOrIndex.Index(indexMetaData)); + IndexAbstraction existing = + aliasAndIndexLookup.put(indexMetaData.getIndex().getName(), new IndexAbstraction.Index(indexMetaData)); assert existing == null : "duplicate for " + indexMetaData.getIndex(); for (ObjectObjectCursor aliasCursor : indexMetaData.getAliases()) { AliasMetaData aliasMetaData = aliasCursor.value; aliasAndIndexLookup.compute(aliasMetaData.getAlias(), (aliasName, alias) -> { if (alias == null) { - return new AliasOrIndex.Alias(aliasMetaData, indexMetaData); + return new IndexAbstraction.Alias(aliasMetaData, indexMetaData); } else { - assert alias instanceof AliasOrIndex.Alias : alias.getClass().getName(); - ((AliasOrIndex.Alias) alias).addIndex(indexMetaData); + assert alias.getType() == IndexAbstraction.Type.ALIAS : alias.getClass().getName(); + ((IndexAbstraction.Alias) alias).addIndex(indexMetaData); return alias; } }); } } - aliasAndIndexLookup.values().stream().filter(AliasOrIndex::isAlias) - .forEach(alias -> ((AliasOrIndex.Alias) alias).computeAndValidateAliasProperties()); + aliasAndIndexLookup.values().stream() + .filter(aliasOrIndex -> aliasOrIndex.getType() == IndexAbstraction.Type.ALIAS) + .forEach(alias -> ((IndexAbstraction.Alias) alias).computeAndValidateAliasProperties()); return aliasAndIndexLookup; } - private void validateDataStreams(SortedMap aliasAndIndexLookup) { + private void validateDataStreams(SortedMap indicesLookup) { DataStreamMetadata dsMetadata = (DataStreamMetadata) customs.get(DataStreamMetadata.TYPE); if (dsMetadata != null) { for (DataStream ds : dsMetadata.dataStreams().values()) { - if (aliasAndIndexLookup.containsKey(ds.getName())) { + if (indicesLookup.containsKey(ds.getName())) { throw new IllegalStateException("data stream [" + ds.getName() + "] conflicts with existing index or alias"); } - SortedMap map = aliasAndIndexLookup.subMap(ds.getName() + "-", ds.getName() + "."); // '.' is the char after '-' + SortedMap map = indicesLookup.subMap(ds.getName() + "-", ds.getName() + "."); // '.' is the char after '-' if (map.size() != 0) { throw new IllegalStateException("data stream [" + ds.getName() + "] could create backing indices that conflict with " + map.size() + " existing index(s) or alias(s)" + diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverServiceTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverServiceTests.java index 6a4d7563ad4b0..86315196845cc 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverServiceTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetaDataRolloverServiceTests.java @@ -27,10 +27,10 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; import org.elasticsearch.cluster.metadata.AliasValidator; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService; @@ -212,7 +212,7 @@ public void testValidation() { assertThat(exception.getMessage(), equalTo("source alias [" + aliasWithNoWriteIndex + "] does not point to a write index")); exception = expectThrows(IllegalArgumentException.class, () -> MetaDataRolloverService.validate(metaData, randomFrom(index1, index2))); - assertThat(exception.getMessage(), equalTo("source alias is a concrete index")); + assertThat(exception.getMessage(), equalTo("source alias is a [concrete index], but an [alias] was expected")); exception = expectThrows(IllegalArgumentException.class, () -> MetaDataRolloverService.validate(metaData, randomAlphaOfLength(5)) ); @@ -341,7 +341,8 @@ public void testRolloverClusterState() throws Exception { IndexMetaData rolloverIndexMetaData = rolloverMetaData.index(newIndexName); assertThat(rolloverIndexMetaData.getNumberOfShards(), equalTo(numberOfShards)); - AliasOrIndex.Alias alias = (AliasOrIndex.Alias) rolloverMetaData.getAliasAndIndexLookup().get(aliasName); + IndexAbstraction alias = rolloverMetaData.getIndicesLookup().get(aliasName); + assertThat(alias.getType(), equalTo(IndexAbstraction.Type.ALIAS)); assertThat(alias.getIndices(), hasSize(2)); assertThat(alias.getIndices(), hasItem(rolloverMetaData.index(sourceIndexName))); assertThat(alias.getIndices(), hasItem(rolloverIndexMetaData)); diff --git a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java index fa8b4d0a45140..24512e0510010 100644 --- a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java +++ b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.StopWatch; import org.elasticsearch.common.settings.Settings; @@ -676,8 +676,8 @@ public void testSameAlias() { assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); logger.info("--> verify that filter was updated"); - AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster() - .clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData(); + AliasMetaData aliasMetaData = ((IndexAbstraction.Alias) internalCluster() + .clusterService().state().metaData().getIndicesLookup().get("alias1")).getFirstAliasMetaData(); assertThat(aliasMetaData.getFilter().toString(), equalTo("{\"term\":{\"name\":{\"value\":\"bar\",\"boost\":1.0}}}")); logger.info("--> deleting alias1"); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/AliasOrIndexTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionTests.java similarity index 86% rename from server/src/test/java/org/elasticsearch/cluster/metadata/AliasOrIndexTests.java rename to server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionTests.java index 355c1cce42df7..ca99db1b061f9 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/AliasOrIndexTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionTests.java @@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; -public class AliasOrIndexTests extends ESTestCase { +public class IndexAbstractionTests extends ESTestCase { public void testHiddenAliasValidation() { final String hiddenAliasName = "hidden_alias"; @@ -44,19 +44,19 @@ public void testHiddenAliasValidation() { IndexMetaData indexWithUnspecifiedAlias = buildIndexWithAlias("nonhidden2", hiddenAliasName, null); { - AliasOrIndex.Alias allHidden = new AliasOrIndex.Alias(hiddenAliasMetadata, hidden1); + IndexAbstraction.Alias allHidden = new IndexAbstraction.Alias(hiddenAliasMetadata, hidden1); allHidden.addIndex(hidden2); allHidden.addIndex(hidden3); allHidden.computeAndValidateAliasProperties(); // Should be ok } { - AliasOrIndex.Alias allVisible; + IndexAbstraction.Alias allVisible; if (randomBoolean()) { - allVisible = new AliasOrIndex.Alias(hiddenAliasMetadata, indexWithNonHiddenAlias); + allVisible = new IndexAbstraction.Alias(hiddenAliasMetadata, indexWithNonHiddenAlias); allVisible.addIndex(indexWithUnspecifiedAlias); } else { - allVisible = new AliasOrIndex.Alias(hiddenAliasMetadata, indexWithUnspecifiedAlias); + allVisible = new IndexAbstraction.Alias(hiddenAliasMetadata, indexWithUnspecifiedAlias); allVisible.addIndex(indexWithNonHiddenAlias); } @@ -64,7 +64,7 @@ public void testHiddenAliasValidation() { } { - AliasOrIndex.Alias oneNonHidden = new AliasOrIndex.Alias(hiddenAliasMetadata, hidden1); + IndexAbstraction.Alias oneNonHidden = new IndexAbstraction.Alias(hiddenAliasMetadata, hidden1); oneNonHidden.addIndex(hidden2); oneNonHidden.addIndex(hidden3); oneNonHidden.addIndex(indexWithNonHiddenAlias); @@ -80,7 +80,7 @@ public void testHiddenAliasValidation() { } { - AliasOrIndex.Alias oneUnspecified = new AliasOrIndex.Alias(hiddenAliasMetadata, hidden1); + IndexAbstraction.Alias oneUnspecified = new IndexAbstraction.Alias(hiddenAliasMetadata, hidden1); oneUnspecified.addIndex(hidden2); oneUnspecified.addIndex(hidden3); oneUnspecified.addIndex(indexWithUnspecifiedAlias); @@ -96,12 +96,12 @@ public void testHiddenAliasValidation() { } { - AliasOrIndex.Alias mostlyVisibleOneHidden; + IndexAbstraction.Alias mostlyVisibleOneHidden; if (randomBoolean()) { - mostlyVisibleOneHidden = new AliasOrIndex.Alias(hiddenAliasMetadata, indexWithNonHiddenAlias); + mostlyVisibleOneHidden = new IndexAbstraction.Alias(hiddenAliasMetadata, indexWithNonHiddenAlias); mostlyVisibleOneHidden.addIndex(indexWithUnspecifiedAlias); } else { - mostlyVisibleOneHidden = new AliasOrIndex.Alias(hiddenAliasMetadata, indexWithUnspecifiedAlias); + mostlyVisibleOneHidden = new IndexAbstraction.Alias(hiddenAliasMetadata, indexWithUnspecifiedAlias); mostlyVisibleOneHidden.addIndex(indexWithNonHiddenAlias); } final IndexMetaData hiddenIndex = randomFrom(hidden1, hidden2, hidden3); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesServiceTests.java index c010927bf5c83..d95d6eb973560 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesServiceTests.java @@ -75,9 +75,9 @@ public void testAddAndRemove() { // Add an alias to it ClusterState after = service.applyAliasActions(before, singletonList(new AliasAction.Add(index, "test", null, null, null, null, null))); - AliasOrIndex alias = after.metaData().getAliasAndIndexLookup().get("test"); + IndexAbstraction alias = after.metaData().getIndicesLookup().get("test"); assertNotNull(alias); - assertTrue(alias.isAlias()); + assertThat(alias.getType(), equalTo(IndexAbstraction.Type.ALIAS)); assertThat(alias.getIndices(), contains(after.metaData().index(index))); assertAliasesVersionIncreased(index, before, after); @@ -86,18 +86,18 @@ public void testAddAndRemove() { after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Remove(index, "test"), new AliasAction.Add(index, "test_2", null, null, null, null, null))); - assertNull(after.metaData().getAliasAndIndexLookup().get("test")); - alias = after.metaData().getAliasAndIndexLookup().get("test_2"); + assertNull(after.metaData().getIndicesLookup().get("test")); + alias = after.metaData().getIndicesLookup().get("test_2"); assertNotNull(alias); - assertTrue(alias.isAlias()); + assertThat(alias.getType(), equalTo(IndexAbstraction.Type.ALIAS)); assertThat(alias.getIndices(), contains(after.metaData().index(index))); assertAliasesVersionIncreased(index, before, after); // Now just remove on its own before = after; after = service.applyAliasActions(before, singletonList(new AliasAction.Remove(index, "test_2"))); - assertNull(after.metaData().getAliasAndIndexLookup().get("test")); - assertNull(after.metaData().getAliasAndIndexLookup().get("test_2")); + assertNull(after.metaData().getIndicesLookup().get("test")); + assertNull(after.metaData().getIndicesLookup().get("test_2")); assertAliasesVersionIncreased(index, before, after); } @@ -199,9 +199,9 @@ public void testSwapIndexWithAlias() { ClusterState after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test_2", "test", null, null, null, null, null), new AliasAction.RemoveIndex("test"))); - AliasOrIndex alias = after.metaData().getAliasAndIndexLookup().get("test"); + IndexAbstraction alias = after.metaData().getIndicesLookup().get("test"); assertNotNull(alias); - assertTrue(alias.isAlias()); + assertThat(alias.getType(), equalTo(IndexAbstraction.Type.ALIAS)); assertThat(alias.getIndices(), contains(after.metaData().index("test_2"))); assertAliasesVersionIncreased("test_2", before, after); } @@ -225,7 +225,7 @@ public void testRemoveIndexTwice() { ClusterState after = service.applyAliasActions(before, Arrays.asList( new AliasAction.RemoveIndex("test"), new AliasAction.RemoveIndex("test"))); - assertNull(after.metaData().getAliasAndIndexLookup().get("test")); + assertNull(after.metaData().getIndicesLookup().get("test")); } public void testAddWriteOnlyWithNoExistingAliases() { @@ -234,20 +234,20 @@ public void testAddWriteOnlyWithNoExistingAliases() { ClusterState after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test", "alias", null, null, null, false, null))); assertFalse(after.metaData().index("test").getAliases().get("alias").writeIndex()); - assertNull(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex()); + assertNull(after.metaData().getIndicesLookup().get("alias").getWriteIndex()); assertAliasesVersionIncreased("test", before, after); after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test", "alias", null, null, null, null, null))); assertNull(after.metaData().index("test").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test"))); assertAliasesVersionIncreased("test", before, after); after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test", "alias", null, null, null, true, null))); assertTrue(after.metaData().index("test").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test"))); assertAliasesVersionIncreased("test", before, after); } @@ -264,7 +264,7 @@ public void testAddWriteOnlyWithExistingWriteIndex() { ClusterState after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test", "alias", null, null, null, null, null))); assertNull(after.metaData().index("test").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test2"))); assertAliasesVersionIncreased("test", before, after); assertAliasesVersionUnchanged("test2", before, after); @@ -292,7 +292,7 @@ public void testSwapWriteOnlyIndex() { ClusterState after = service.applyAliasActions(before, swapActions); assertThat(after.metaData().index("test").getAliases().get("alias").writeIndex(), equalTo(unsetValue)); assertTrue(after.metaData().index("test2").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test2"))); assertAliasesVersionIncreased("test", before, after); assertAliasesVersionIncreased("test2", before, after); @@ -310,12 +310,12 @@ public void testAddWriteOnlyWithExistingNonWriteIndices() { ClusterState before = ClusterState.builder(ClusterName.DEFAULT) .metaData(MetaData.builder().put(indexMetaData).put(indexMetaData2).put(indexMetaData3)).build(); - assertNull(((AliasOrIndex.Alias) before.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex()); + assertNull(before.metaData().getIndicesLookup().get("alias").getWriteIndex()); ClusterState after = service.applyAliasActions(before, Arrays.asList( new AliasAction.Add("test3", "alias", null, null, null, true, null))); assertTrue(after.metaData().index("test3").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test3"))); assertAliasesVersionUnchanged("test", before, after); assertAliasesVersionUnchanged("test2", before, after); @@ -334,11 +334,11 @@ public void testAddWriteOnlyWithIndexRemoved() { assertNull(before.metaData().index("test").getAliases().get("alias").writeIndex()); assertNull(before.metaData().index("test2").getAliases().get("alias").writeIndex()); - assertNull(((AliasOrIndex.Alias) before.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex()); + assertNull(before.metaData().getIndicesLookup().get("alias").getWriteIndex()); ClusterState after = service.applyAliasActions(before, Collections.singletonList(new AliasAction.RemoveIndex("test"))); assertNull(after.metaData().index("test2").getAliases().get("alias").writeIndex()); - assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(), + assertThat(after.metaData().getIndicesLookup().get("alias").getWriteIndex(), equalTo(after.metaData().index("test2"))); assertAliasesVersionUnchanged("test2", before, after); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsStep.java index ff480aeea9ed9..ab5e1ec7d4a1e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsStep.java @@ -10,8 +10,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; -import org.elasticsearch.cluster.metadata.AliasOrIndex.Alias; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -71,18 +70,17 @@ public Result isConditionMet(Index index, ClusterState clusterState) { + "] is not set on index [" + originalIndexMeta.getIndex().getName() + "]"); } - AliasOrIndex aliasOrIndex = clusterState.metaData().getAliasAndIndexLookup().get(rolloverAlias); - assert aliasOrIndex.isAlias() : rolloverAlias + " must be an alias but it is an index"; + IndexAbstraction indexAbstraction = clusterState.metaData().getIndicesLookup().get(rolloverAlias); + assert indexAbstraction.getType() == IndexAbstraction.Type.ALIAS : rolloverAlias + " must be an alias but it is not"; - Alias alias = (Alias) aliasOrIndex; - IndexMetaData aliasWriteIndex = alias.getWriteIndex(); + IndexMetaData aliasWriteIndex = indexAbstraction.getWriteIndex(); final String rolledIndexName; final String waitForActiveShardsSettingValue; if (aliasWriteIndex != null) { rolledIndexName = aliasWriteIndex.getIndex().getName(); waitForActiveShardsSettingValue = aliasWriteIndex.getSettings().get("index.write.wait_for_active_shards"); } else { - List indices = alias.getIndices(); + List indices = indexAbstraction.getIndices(); int maxIndexCounter = -1; IndexMetaData rolledIndexMeta = null; for (IndexMetaData indexMetaData : indices) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java index 131a1053519a7..05c083836b43b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; @@ -55,7 +55,7 @@ public static void createAnnotationsIndexIfNecessary(Settings settings, Client c }, finalListener::onFailure); // Only create the index or aliases if some other ML index exists - saves clutter if ML is never used. - SortedMap mlLookup = state.getMetaData().getAliasAndIndexLookup().tailMap(".ml"); + SortedMap mlLookup = state.getMetaData().getIndicesLookup().tailMap(".ml"); if (mlLookup.isEmpty() == false && mlLookup.firstKey().startsWith(".ml")) { // Create the annotations index if it doesn't exist already. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java index bbbc883960aa8..762b2c86af4c1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java @@ -15,7 +15,7 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.CheckedSupplier; @@ -147,13 +147,13 @@ static String[] mappingRequiresUpdate(ClusterState state, String[] concreteIndic public static void addDocMappingIfMissing(String alias, CheckedSupplier mappingSupplier, Client client, ClusterState state, ActionListener listener) { - AliasOrIndex aliasOrIndex = state.metaData().getAliasAndIndexLookup().get(alias); - if (aliasOrIndex == null) { + IndexAbstraction indexAbstraction = state.metaData().getIndicesLookup().get(alias); + if (indexAbstraction == null) { // The index has never been created yet listener.onResponse(true); return; } - String[] concreteIndices = aliasOrIndex.getIndices().stream().map(IndexMetaData::getIndex).map(Index::getName) + String[] concreteIndices = indexAbstraction.getIndices().stream().map(IndexMetaData::getIndex).map(Index::getName) .toArray(String[]::new); String[] indicesThatRequireAnUpdate; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java index 9a246183cfa18..a6e601c3aa79d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java @@ -84,7 +84,7 @@ public static void createIndexAndAliasIfNecessary(Client client, String[] concreteIndexNames = resolver.concreteIndexNames(clusterState, IndicesOptions.lenientExpandOpen(), indexPattern); Optional indexPointedByCurrentWriteAlias = clusterState.getMetaData().hasAlias(alias) - ? clusterState.getMetaData().getAliasAndIndexLookup().get(alias).getIndices().stream().findFirst() + ? clusterState.getMetaData().getIndicesLookup().get(alias).getIndices().stream().findFirst() : Optional.empty(); if (concreteIndexNames.length == 0) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java index fd5e6fba9c55e..8b2ae8ec14d7a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.core.security.authz; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesRequest; import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse; @@ -128,7 +128,7 @@ public interface AuthorizationEngine { * @param listener the listener to be notified of the authorization result */ void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, - AsyncSupplier indicesAsyncSupplier, Map aliasOrIndexLookup, + AsyncSupplier indicesAsyncSupplier, Map aliasOrIndexLookup, ActionListener listener); /** @@ -139,12 +139,12 @@ void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizati * and associated user(s) * @param authorizationInfo information needed from authorization that was previously retrieved * from {@link #resolveAuthorizationInfo(RequestInfo, ActionListener)} - * @param aliasOrIndexLookup a map of a string name to the cluster metadata specific to that + * @param indicesLookup a map of a string name to the cluster metadata specific to that * alias or index * @param listener the listener to be notified of the authorization result */ void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, - Map aliasOrIndexLookup, ActionListener> listener); + Map indicesLookup, ActionListener> listener); /** diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java index b68b9dd79204a..6be5fcf012713 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java @@ -10,7 +10,7 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.TooComplexToDeterminizeException; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -194,7 +194,7 @@ public Automaton allowedActionsMatcher(String index) { * Authorizes the provided action against the provided indices, given the current cluster metadata */ public Map authorize(String action, Set requestedIndicesOrAliases, - Map allAliasesAndIndices, + Map allAliasesAndIndices, FieldPermissionsCache fieldPermissionsCache) { // now... every index that is associated with the request, must be granted // by at least one indices permission group @@ -205,9 +205,9 @@ public Map authorize(String act for (String indexOrAlias : requestedIndicesOrAliases) { boolean granted = false; Set concreteIndices = new HashSet<>(); - AliasOrIndex aliasOrIndex = allAliasesAndIndices.get(indexOrAlias); - if (aliasOrIndex != null) { - for (IndexMetaData indexMetaData : aliasOrIndex.getIndices()) { + IndexAbstraction indexAbstraction = allAliasesAndIndices.get(indexOrAlias); + if (indexAbstraction != null) { + for (IndexMetaData indexMetaData : indexAbstraction.getIndices()) { concreteIndices.add(indexMetaData.getIndex().getName()); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRole.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRole.java index 871be8cbc6569..9114984787909 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRole.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRole.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.core.security.authz.permission; import org.apache.lucene.util.automaton.Automaton; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.core.security.authc.Authentication; import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl; @@ -62,7 +62,7 @@ public RunAsPermission runAs() { @Override public IndicesAccessControl authorize(String action, Set requestedIndicesOrAliases, - Map aliasAndIndexLookup, + Map aliasAndIndexLookup, FieldPermissionsCache fieldPermissionsCache) { IndicesAccessControl indicesAccessControl = super.authorize(action, requestedIndicesOrAliases, aliasAndIndexLookup, fieldPermissionsCache); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java index 94d583f616787..fe84f4fbe1c48 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.core.security.authz.permission; import org.apache.lucene.util.automaton.Automaton; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; @@ -168,7 +168,7 @@ public ResourcePrivilegesMap checkApplicationResourcePrivileges(final String app * is configured for any group also the allowed fields and role queries are resolved. */ public IndicesAccessControl authorize(String action, Set requestedIndicesOrAliases, - Map aliasAndIndexLookup, + Map aliasAndIndexLookup, FieldPermissionsCache fieldPermissionsCache) { Map indexPermissions = indices.authorize( action, requestedIndicesOrAliases, aliasAndIndexLookup, fieldPermissionsCache diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java index 7327aa3fa81c4..65ad3791d4943 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java @@ -16,7 +16,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; @@ -90,8 +90,8 @@ public void putAsync(SnapshotHistoryItem item) { */ static void ensureHistoryIndex(Client client, ClusterState state, ActionListener andThen) { final String initialHistoryIndexName = SLM_HISTORY_INDEX_PREFIX + "000001"; - final AliasOrIndex slmHistory = state.metaData().getAliasAndIndexLookup().get(SLM_HISTORY_ALIAS); - final AliasOrIndex initialHistoryIndex = state.metaData().getAliasAndIndexLookup().get(initialHistoryIndexName); + final IndexAbstraction slmHistory = state.metaData().getIndicesLookup().get(SLM_HISTORY_ALIAS); + final IndexAbstraction initialHistoryIndex = state.metaData().getIndicesLookup().get(initialHistoryIndexName); if (slmHistory == null && initialHistoryIndex == null) { // No alias or index exists with the expected names, so create the index with appropriate alias @@ -122,15 +122,15 @@ public void onFailure(Exception e) { // alias does not exist but initial index does, something is broken andThen.onFailure(new IllegalStateException("SLM history index [" + initialHistoryIndexName + "] already exists but does not have alias [" + SLM_HISTORY_ALIAS + "]")); - } else if (slmHistory.isAlias() && slmHistory instanceof AliasOrIndex.Alias) { - if (((AliasOrIndex.Alias) slmHistory).getWriteIndex() != null) { + } else if (slmHistory.getType() == IndexAbstraction.Type.ALIAS) { + if (slmHistory.getWriteIndex() != null) { // The alias exists and has a write index, so we're good andThen.onResponse(false); } else { // The alias does not have a write index, so we can't index into it andThen.onFailure(new IllegalStateException("SLM history alias [" + SLM_HISTORY_ALIAS + "does not have a write index")); } - } else if (slmHistory.isAlias() == false) { + } else if (slmHistory.getType() != IndexAbstraction.Type.ALIAS) { // This is not an alias, error out andThen.onFailure(new IllegalStateException("SLM history alias [" + SLM_HISTORY_ALIAS + "] already exists as concrete index")); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java index 74e06d1cbce25..f73c7b0e6367f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java @@ -69,13 +69,13 @@ public void testAuthorize() { Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList()) .add(IndexPrivilege.ALL, "_index").add(IndexPrivilege.CREATE_INDEX, "_index1").build(); - IndicesAccessControl iac = fromRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + IndicesAccessControl iac = fromRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(true)); assertThat(iac.getIndexPermissions("_index1"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); - iac = fromRole.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_index1"), md.getAliasAndIndexLookup(), + iac = fromRole.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_index1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(true)); @@ -86,19 +86,19 @@ public void testAuthorize() { Role limitedByRole = Role.builder("limited-role") .cluster(Collections.singleton("all"), Collections.emptyList()).add(IndexPrivilege.READ, "_index") .add(IndexPrivilege.NONE, "_index1").build(); - iac = limitedByRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + iac = limitedByRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(true)); assertThat(iac.getIndexPermissions("_index1"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); - iac = limitedByRole.authorize(DeleteIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + iac = limitedByRole.authorize(DeleteIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(false)); assertThat(iac.getIndexPermissions("_index1"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); - iac = limitedByRole.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + iac = limitedByRole.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(false)); @@ -106,19 +106,19 @@ public void testAuthorize() { assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole); - iac = role.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + iac = role.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(true)); assertThat(iac.getIndexPermissions("_index1"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); - iac = role.authorize(DeleteIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), + iac = role.authorize(DeleteIndexAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(false)); assertThat(iac.getIndexPermissions("_index1"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index1").isGranted(), is(false)); - iac = role.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_index1"), md.getAliasAndIndexLookup(), + iac = role.authorize(CreateIndexAction.NAME, Sets.newHashSet("_index", "_index1"), md.getIndicesLookup(), fieldPermissionsCache); assertThat(iac.getIndexPermissions("_index"), is(notNullValue())); assertThat(iac.getIndexPermissions("_index").isGranted(), is(false)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java index dc9be3beaf732..bb8b378b80143 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java @@ -42,7 +42,7 @@ import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.update.UpdateAction; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.settings.Settings; @@ -764,7 +764,7 @@ private void assertMonitoringOnRestrictedIndices(Role role) { String asyncSearchIndex = RestrictedIndicesNames.ASYNC_SEARCH_PREFIX + randomAlphaOfLengthBetween(0, 2); final Map authzMap = role.indices().authorize(indexMonitoringActionName, Sets.newHashSet(internalSecurityIndex, RestrictedIndicesNames.SECURITY_MAIN_ALIAS, asyncSearchIndex), - metaData.getAliasAndIndexLookup(), fieldPermissionsCache); + metaData.getIndicesLookup(), fieldPermissionsCache); assertThat(authzMap.get(internalSecurityIndex).isGranted(), is(true)); assertThat(authzMap.get(RestrictedIndicesNames.SECURITY_MAIN_ALIAS).isGranted(), is(true)); assertThat(authzMap.get(asyncSearchIndex).isGranted(), is(true)); @@ -893,7 +893,7 @@ public void testSuperuserRole() { .build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - SortedMap lookup = metaData.getAliasAndIndexLookup(); + SortedMap lookup = metaData.getIndicesLookup(); Map authzMap = superuserRole.indices().authorize(SearchAction.NAME, Sets.newHashSet("a1", "ba"), lookup, fieldPermissionsCache); assertThat(authzMap.get("a1").isGranted(), is(true)); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java index 96d9efadde750..c31f453683899 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java @@ -7,7 +7,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.geo.ShapeRelation; @@ -38,13 +38,13 @@ final class EnrichProcessorFactory implements Processor.Factory, Consumer processorFactories, String tag, Map config) throws Exception { String policyName = ConfigurationUtils.readStringProperty(TYPE, tag, config, "policy_name"); String policyAlias = EnrichPolicy.getBaseName(policyName); - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(policyAlias); - if (aliasOrIndex == null) { + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(policyAlias); + if (indexAbstraction == null) { throw new IllegalArgumentException("no enrich index exists for policy with name [" + policyName + "]"); } - assert aliasOrIndex.isAlias(); - assert aliasOrIndex.getIndices().size() == 1; - IndexMetaData imd = aliasOrIndex.getIndices().get(0); + assert indexAbstraction.getType() == IndexAbstraction.Type.ALIAS; + assert indexAbstraction.getIndices().size() == 1; + IndexMetaData imd = indexAbstraction.getIndices().get(0); Map mappingAsMap = imd.mapping().sourceAsMap(); String policyType = (String) XContentMapValues.extractValue( diff --git a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndex.java b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndex.java index e509654520d22..6027d39458c24 100644 --- a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndex.java +++ b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndex.java @@ -27,7 +27,7 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.ValidationException; @@ -173,7 +173,7 @@ private void installTemplateIfRequired(ClusterState state) { } private void checkForAliasStateChange(ClusterState state) { - final AliasOrIndex aliasInfo = state.getMetaData().getAliasAndIndexLookup().get(ALIAS_NAME); + final IndexAbstraction aliasInfo = state.getMetaData().getIndicesLookup().get(ALIAS_NAME); final boolean previousState = aliasExists; this.aliasExists = aliasInfo != null; if (aliasExists != previousState) { @@ -187,11 +187,11 @@ public void close() { clusterService.removeListener(clusterStateListener); } - private void logChangedAliasState(AliasOrIndex aliasInfo) { + private void logChangedAliasState(IndexAbstraction aliasInfo) { if (aliasInfo == null) { logger.warn("service provider index/alias [{}] no longer exists", ALIAS_NAME); - } else if (aliasInfo.isAlias() == false) { - logger.warn("service provider index [{}] exists as a concrete index, but it should be an alias", ALIAS_NAME); + } else if (aliasInfo.getType() != IndexAbstraction.Type.ALIAS) { + logger.warn("service provider index [{}] does not exist as an alias, but it should be", ALIAS_NAME); } else if (aliasInfo.getIndices().size() != 1) { logger.warn("service provider alias [{}] refers to multiple indices [{}] - this is unexpected and is likely to cause problems", ALIAS_NAME, Strings.collectionToCommaDelimitedString(aliasInfo.getIndices())); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStore.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStore.java index a2bb00ea5c73d..d310aef36d098 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStore.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStore.java @@ -23,7 +23,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.OriginSettingClient; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; @@ -182,8 +182,8 @@ public void putAsync(ILMHistoryItem item) { @SuppressWarnings("unchecked") static void ensureHistoryIndex(Client client, ClusterState state, ActionListener listener) { final String initialHistoryIndexName = ILM_HISTORY_INDEX_PREFIX + "000001"; - final AliasOrIndex ilmHistory = state.metaData().getAliasAndIndexLookup().get(ILM_HISTORY_ALIAS); - final AliasOrIndex initialHistoryIndex = state.metaData().getAliasAndIndexLookup().get(initialHistoryIndexName); + final IndexAbstraction ilmHistory = state.metaData().getIndicesLookup().get(ILM_HISTORY_ALIAS); + final IndexAbstraction initialHistoryIndex = state.metaData().getIndicesLookup().get(initialHistoryIndexName); if (ilmHistory == null && initialHistoryIndex == null) { // No alias or index exists with the expected names, so create the index with appropriate alias @@ -222,15 +222,15 @@ public void onFailure(Exception e) { // alias does not exist but initial index does, something is broken listener.onFailure(new IllegalStateException("ILM history index [" + initialHistoryIndexName + "] already exists but does not have alias [" + ILM_HISTORY_ALIAS + "]")); - } else if (ilmHistory.isAlias() && ilmHistory instanceof AliasOrIndex.Alias) { - if (((AliasOrIndex.Alias) ilmHistory).getWriteIndex() != null) { + } else if (ilmHistory.getType() == IndexAbstraction.Type.ALIAS) { + if (ilmHistory.getWriteIndex() != null) { // The alias exists and has a write index, so we're good listener.onResponse(false); } else { // The alias does not have a write index, so we can't index into it listener.onFailure(new IllegalStateException("ILM history alias [" + ILM_HISTORY_ALIAS + "does not have a write index")); } - } else if (ilmHistory.isAlias() == false) { + } else if (ilmHistory.getType() != IndexAbstraction.Type.ALIAS) { // This is not an alias, error out listener.onFailure(new IllegalStateException("ILM history alias [" + ILM_HISTORY_ALIAS + "] already exists as concrete index")); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java index 08f344e030852..a45574331b6cd 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java @@ -16,7 +16,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; @@ -83,8 +83,8 @@ public void setUpTests() { ClusterSettings clusterSettings = new ClusterSettings(nodeSettings(), new HashSet<>(Collections.singletonList( MlConfigMigrationEligibilityCheck.ENABLE_CONFIG_MIGRATION))); MetaData metaData = mock(MetaData.class); - SortedMap aliasOrIndexSortedMap = new TreeMap<>(); - when(metaData.getAliasAndIndexLookup()).thenReturn(aliasOrIndexSortedMap); + SortedMap indicesMap = new TreeMap<>(); + when(metaData.getIndicesLookup()).thenReturn(indicesMap); ClusterState clusterState = mock(ClusterState.class); when(clusterState.getMetaData()).thenReturn(metaData); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java index 783f31f8ce855..452f323e776ff 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java @@ -250,7 +250,7 @@ private void authorizeAction(final RequestInfo requestInfo, final String request } else if (IndexPrivilege.ACTION_MATCHER.test(action)) { final MetaData metaData = clusterService.state().metaData(); final AsyncSupplier> authorizedIndicesSupplier = new CachingAsyncSupplier<>(authzIndicesListener -> - authzEngine.loadAuthorizedIndices(requestInfo, authzInfo, metaData.getAliasAndIndexLookup(), + authzEngine.loadAuthorizedIndices(requestInfo, authzInfo, metaData.getIndicesLookup(), authzIndicesListener)); final AsyncSupplier resolvedIndicesAsyncSupplier = new CachingAsyncSupplier<>((resolvedIndicesListener) -> { authorizedIndicesSupplier.getAsync(ActionListener.wrap(authorizedIndices -> { @@ -265,7 +265,7 @@ private void authorizeAction(final RequestInfo requestInfo, final String request })); }); authzEngine.authorizeIndexAction(requestInfo, authzInfo, resolvedIndicesAsyncSupplier, - metaData.getAliasAndIndexLookup(), wrapPreservingContext(new AuthorizationResultListener<>(result -> + metaData.getIndicesLookup(), wrapPreservingContext(new AuthorizationResultListener<>(result -> handleIndexActionAuthorizationResult(result, requestInfo, requestId, authzInfo, authzEngine, authorizedIndicesSupplier, resolvedIndicesAsyncSupplier, metaData, listener), listener::onFailure, requestInfo, requestId, authzInfo), threadContext)); @@ -309,7 +309,7 @@ private void handleIndexActionAuthorizationResult(final IndexAuthorizationResult ril.onResponse(withAliases); }, ril::onFailure)); }, - metaData.getAliasAndIndexLookup(), + metaData.getIndicesLookup(), wrapPreservingContext(new AuthorizationResultListener<>( authorizationResult -> runRequestInterceptors(requestInfo, authzInfo, authorizationEngine, listener), listener::onFailure, aliasesRequestInfo, requestId, authzInfo), threadContext)); @@ -530,7 +530,7 @@ private void authorizeBulkItems(RequestInfo requestInfo, AuthorizationInfo authz new RequestInfo(requestInfo.getAuthentication(), requestInfo.getRequest(), bulkItemAction); authzEngine.authorizeIndexAction(bulkItemInfo, authzInfo, ril -> ril.onResponse(new ResolvedIndices(new ArrayList<>(indices), Collections.emptyList())), - metaData.getAliasAndIndexLookup(), ActionListener.wrap(indexAuthorizationResult -> + metaData.getIndicesLookup(), ActionListener.wrap(indexAuthorizationResult -> groupedActionListener.onResponse(new Tuple<>(bulkItemAction, indexAuthorizationResult)), groupedActionListener::onFailure)); }); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java index 2a974e6469758..c92bed06da07b 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData.State; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; @@ -228,12 +228,13 @@ static String getPutMappingIndexOrAlias(PutMappingRequest request, List final String concreteIndexName = request.getConcreteIndex().getName(); // validate that the concrete index exists, otherwise there is no remapping that we could do - final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(concreteIndexName); + final IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(concreteIndexName); final String resolvedAliasOrIndex; - if (aliasOrIndex == null) { + if (indexAbstraction == null) { resolvedAliasOrIndex = concreteIndexName; - } else if (aliasOrIndex.isAlias()) { - throw new IllegalStateException("concrete index [" + concreteIndexName + "] is an alias but should not be"); + } else if (indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX) { + throw new IllegalStateException("concrete index [" + concreteIndexName + "] is a [" + + indexAbstraction.getType().getDisplayName() + "], but a concrete index is expected"); } else if (authorizedIndicesList.contains(concreteIndexName)) { // user is authorized to put mappings for this index resolvedAliasOrIndex = concreteIndexName; @@ -247,13 +248,13 @@ static String getPutMappingIndexOrAlias(PutMappingRequest request, List .map(AliasMetaData::alias) .filter(authorizedIndicesList::contains) .filter(aliasName -> { - AliasOrIndex alias = metaData.getAliasAndIndexLookup().get(aliasName); + IndexAbstraction alias = metaData.getIndicesLookup().get(aliasName); List indexMetadata = alias.getIndices(); if (indexMetadata.size() == 1) { return true; } else { - assert alias instanceof AliasOrIndex.Alias; - IndexMetaData idxMeta = ((AliasOrIndex.Alias) alias).getWriteIndex(); + assert alias.getType() == IndexAbstraction.Type.ALIAS; + IndexMetaData idxMeta = alias.getWriteIndex(); return idxMeta != null && idxMeta.getIndex().getName().equals(concreteIndexName); } }) @@ -274,10 +275,10 @@ static boolean allowsRemoteIndices(IndicesRequest request) { private List loadAuthorizedAliases(List authorizedIndices, MetaData metaData) { List authorizedAliases = new ArrayList<>(); - SortedMap existingAliases = metaData.getAliasAndIndexLookup(); + SortedMap existingAliases = metaData.getIndicesLookup(); for (String authorizedIndex : authorizedIndices) { - AliasOrIndex aliasOrIndex = existingAliases.get(authorizedIndex); - if (aliasOrIndex != null && aliasOrIndex.isAlias()) { + IndexAbstraction indexAbstraction = existingAliases.get(authorizedIndex); + if (indexAbstraction != null && indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) { authorizedAliases.add(authorizedIndex); } } @@ -416,9 +417,9 @@ private static boolean isIndexVisible(String expression, String index, IndicesOp private static boolean isIndexVisible(String expression, String index, IndicesOptions indicesOptions, MetaData metaData, boolean dateMathExpression) { - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(index); - final boolean isHidden = aliasOrIndex.isHidden(); - if (aliasOrIndex.isAlias()) { + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(index); + final boolean isHidden = indexAbstraction.isHidden(); + if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) { //it's an alias, ignore expandWildcardsOpen and expandWildcardsClosed. //complicated to support those options with aliases pointing to multiple indices... //TODO investigate supporting expandWildcards option for aliases too, like es core does. @@ -430,8 +431,8 @@ private static boolean isIndexVisible(String expression, String index, IndicesOp return false; } } - assert aliasOrIndex.getIndices().size() == 1 : "concrete index must point to a single index"; - IndexMetaData indexMetaData = aliasOrIndex.getIndices().get(0); + assert indexAbstraction.getIndices().size() == 1 : "concrete index must point to a single index"; + IndexMetaData indexMetaData = indexAbstraction.getIndices().get(0); if (isHidden && indicesOptions.expandWildcardsHidden() == false && isVisibleDueToImplicitHidden(expression, index) == false) { return false; } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java index 38091ffe94fc6..81b35e4dfb163 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java @@ -25,7 +25,7 @@ import org.elasticsearch.action.search.SearchScrollAction; import org.elasticsearch.action.search.SearchTransportService; import org.elasticsearch.action.termvectors.MultiTermVectorsAction; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -233,7 +233,7 @@ private static boolean shouldAuthorizeIndexActionNameOnly(String action, Transpo @Override public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, AsyncSupplier indicesAsyncSupplier, - Map aliasOrIndexLookup, + Map aliasOrIndexLookup, ActionListener listener) { final String action = requestInfo.getAction(); final TransportRequest request = requestInfo.getRequest(); @@ -339,10 +339,10 @@ private void authorizeIndexActionName(String action, AuthorizationInfo authoriza @Override public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, - Map aliasOrIndexLookup, ActionListener> listener) { + Map indicesLookup, ActionListener> listener) { if (authorizationInfo instanceof RBACAuthorizationInfo) { final Role role = ((RBACAuthorizationInfo) authorizationInfo).getRole(); - listener.onResponse(resolveAuthorizedIndicesFromRole(role, requestInfo.getAction(), aliasOrIndexLookup)); + listener.onResponse(resolveAuthorizedIndicesFromRole(role, requestInfo.getAction(), indicesLookup)); } else { listener.onFailure( new IllegalArgumentException("unsupported authorization info:" + authorizationInfo.getClass().getSimpleName())); @@ -499,12 +499,12 @@ GetUserPrivilegesResponse buildUserPrivilegesResponseObject(Role userRole) { return new GetUserPrivilegesResponse(cluster, conditionalCluster, indices, application, runAs); } - static List resolveAuthorizedIndicesFromRole(Role role, String action, Map aliasAndIndexLookup) { + static List resolveAuthorizedIndicesFromRole(Role role, String action, Map aliasAndIndexLookup) { Predicate predicate = role.allowedIndicesMatcher(action); List indicesAndAliases = new ArrayList<>(); // TODO: can this be done smarter? I think there are usually more indices/aliases in the cluster then indices defined a roles? - for (Map.Entry entry : aliasAndIndexLookup.entrySet()) { + for (Map.Entry entry : aliasAndIndexLookup.entrySet()) { String aliasOrIndex = entry.getKey(); if (predicate.test(aliasOrIndex)) { indicesAndAliases.add(aliasOrIndex); @@ -515,7 +515,7 @@ static List resolveAuthorizedIndicesFromRole(Role role, String action, M private void buildIndicesAccessControl(Authentication authentication, String action, AuthorizationInfo authorizationInfo, Set indices, - Map aliasAndIndexLookup, + Map aliasAndIndexLookup, ActionListener listener) { if (authorizationInfo instanceof RBACAuthorizationInfo) { final Role role = ((RBACAuthorizationInfo) authorizationInfo).getRole(); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java index e3be8e0972927..34fd7ff3fd7fa 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java @@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.util.automaton.Operations; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.logging.DeprecationLogger; @@ -157,23 +157,23 @@ protected void doRun() throws Exception { } private void logDeprecatedPermission(RoleDescriptor roleDescriptor) { - final SortedMap aliasOrIndexMap = clusterService.state().metaData().getAliasAndIndexLookup(); + final SortedMap aliasOrIndexMap = clusterService.state().metaData().getIndicesLookup(); final Map> privilegesByAliasMap = new HashMap<>(); // sort answer by alias for tests final SortedMap> privilegesByIndexMap = new TreeMap<>(); // collate privileges by index and by alias separately for (final IndicesPrivileges indexPrivilege : roleDescriptor.getIndicesPrivileges()) { final Predicate namePatternPredicate = IndicesPermission.indexMatcher(Arrays.asList(indexPrivilege.getIndices())); - for (final Map.Entry aliasOrIndex : aliasOrIndexMap.entrySet()) { + for (final Map.Entry aliasOrIndex : aliasOrIndexMap.entrySet()) { final String aliasOrIndexName = aliasOrIndex.getKey(); if (namePatternPredicate.test(aliasOrIndexName)) { - if (aliasOrIndex.getValue().isAlias()) { + if (aliasOrIndex.getValue().getType() == IndexAbstraction.Type.ALIAS) { final Set privilegesByAlias = privilegesByAliasMap.computeIfAbsent(aliasOrIndexName, - k -> new HashSet()); + k -> new HashSet<>()); privilegesByAlias.addAll(Arrays.asList(indexPrivilege.getPrivileges())); } else { final Set privilegesByIndex = privilegesByIndexMap.computeIfAbsent(aliasOrIndexName, - k -> new HashSet()); + k -> new HashSet<>()); privilegesByIndex.addAll(Arrays.asList(indexPrivilege.getPrivileges())); } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java index e4eacd62e40ff..f1008fdbc66a7 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java @@ -29,7 +29,7 @@ import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.health.ClusterIndexHealth; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -289,10 +289,10 @@ private static Set loadIndexMappingVersions(String aliasName, ClusterSt * that if supplied with an alias, the alias resolves to at most one concrete index. */ private static IndexMetaData resolveConcreteIndex(final String indexOrAliasName, final MetaData metaData) { - final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(indexOrAliasName); - if (aliasOrIndex != null) { - final List indices = aliasOrIndex.getIndices(); - if (aliasOrIndex.isAlias() && indices.size() > 1) { + final IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(indexOrAliasName); + if (indexAbstraction != null) { + final List indices = indexAbstraction.getIndices(); + if (indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX && indices.size() > 1) { throw new IllegalStateException("Alias [" + indexOrAliasName + "] points to more than one index: " + indices.stream().map(imd -> imd.getIndex().getName()).collect(Collectors.toList())); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java index a474027ce5044..fccd98a67c063 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java @@ -21,7 +21,7 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.common.Strings; @@ -439,9 +439,9 @@ protected void deleteSecurityIndex() { } private static Index resolveSecurityIndex(MetaData metaData) { - final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(SECURITY_MAIN_ALIAS); - if (aliasOrIndex != null) { - return aliasOrIndex.getIndices().get(0).getIndex(); + final IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(SECURITY_MAIN_ALIAS); + if (indexAbstraction != null) { + return indexAbstraction.getIndices().get(0).getIndex(); } return null; } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java index 7bed19e4aab87..cefc7b8d6ebc2 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java @@ -70,7 +70,7 @@ import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; @@ -1417,14 +1417,14 @@ public void authorizeClusterAction(RequestInfo requestInfo, AuthorizationInfo au @Override public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, AsyncSupplier indicesAsyncSupplier, - Map aliasOrIndexLookup, + Map aliasOrIndexLookup, ActionListener listener) { throw new UnsupportedOperationException("not implemented"); } @Override public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo, - Map aliasOrIndexLookup, ActionListener> listener) { + Map indicesLookup, ActionListener> listener) { throw new UnsupportedOperationException("not implemented"); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java index d099a6719f9e7..383077f9ea3b9 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java @@ -35,7 +35,7 @@ public class AuthorizedIndicesTests extends ESTestCase { public void testAuthorizedIndicesUserWithoutRoles() { List authorizedIndices = - RBACEngine.resolveAuthorizedIndicesFromRole(Role.EMPTY, "", MetaData.EMPTY_META_DATA.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(Role.EMPTY, "", MetaData.EMPTY_META_DATA.getIndicesLookup()); assertTrue(authorizedIndices.isEmpty()); } @@ -71,7 +71,7 @@ public void testAuthorizedIndicesUserWithSomeRoles() { CompositeRolesStore.buildRoleFromDescriptors(descriptors, new FieldPermissionsCache(Settings.EMPTY), null, future); Role roles = future.actionGet(); List list = - RBACEngine.resolveAuthorizedIndicesFromRole(roles, SearchAction.NAME, metaData.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(roles, SearchAction.NAME, metaData.getIndicesLookup()); assertThat(list, containsInAnyOrder("a1", "a2", "aaaaaa", "b", "ab")); assertFalse(list.contains("bbbbb")); assertFalse(list.contains("ba")); @@ -82,14 +82,14 @@ public void testAuthorizedIndicesUserWithSomeRoles() { public void testAuthorizedIndicesUserWithSomeRolesEmptyMetaData() { Role role = Role.builder("role").add(IndexPrivilege.ALL, "*").build(); List authorizedIndices = - RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getIndicesLookup()); assertTrue(authorizedIndices.isEmpty()); } public void testSecurityIndicesAreRemovedFromRegularUser() { Role role = Role.builder("user_role").add(IndexPrivilege.ALL, "*").cluster(Set.of("all"), Set.of()).build(); List authorizedIndices = - RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getIndicesLookup()); assertTrue(authorizedIndices.isEmpty()); } @@ -114,7 +114,7 @@ public void testSecurityIndicesAreRestrictedForDefaultRole() { .build(); List authorizedIndices = - RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getIndicesLookup()); assertThat(authorizedIndices, containsInAnyOrder("an-index", "another-index")); assertThat(authorizedIndices, not(contains(internalSecurityIndex))); assertThat(authorizedIndices, not(contains(RestrictedIndicesNames.SECURITY_MAIN_ALIAS))); @@ -140,12 +140,12 @@ public void testSecurityIndicesAreNotRemovedFromUnrestrictedRole() { .build(); List authorizedIndices = - RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getIndicesLookup()); assertThat(authorizedIndices, containsInAnyOrder( "an-index", "another-index", RestrictedIndicesNames.SECURITY_MAIN_ALIAS, internalSecurityIndex)); List authorizedIndicesSuperUser = - RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getAliasAndIndexLookup()); + RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, metaData.getIndicesLookup()); assertThat(authorizedIndicesSuperUser, containsInAnyOrder( "an-index", "another-index", RestrictedIndicesNames.SECURITY_MAIN_ALIAS, internalSecurityIndex)); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java index a41ec5184cfe4..a61583ea4a9ed 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java @@ -1383,7 +1383,7 @@ public void testWhenAliasToMultipleIndicesAndUserIsAuthorizedUsingAliasReturnsAl String index = "logs-00003"; // write index PutMappingRequest request = new PutMappingRequest(Strings.EMPTY_ARRAY).setConcreteIndex(new Index(index, UUIDs.base64UUID())); List authorizedIndices = Collections.singletonList("logs-alias"); - assert metaData.getAliasAndIndexLookup().get("logs-alias").getIndices().size() == 3; + assert metaData.getIndicesLookup().get("logs-alias").getIndices().size() == 3; String putMappingIndexOrAlias = IndicesAndAliasesResolver.getPutMappingIndexOrAlias(request, authorizedIndices, metaData); String message = "user is authorized to access `logs-alias` and the put mapping request is for a write index" + "so this should have returned the alias name"; @@ -1394,7 +1394,7 @@ public void testWhenAliasToMultipleIndicesAndUserIsAuthorizedUsingAliasReturnsIn String index = "logs-00002"; // read index PutMappingRequest request = new PutMappingRequest(Strings.EMPTY_ARRAY).setConcreteIndex(new Index(index, UUIDs.base64UUID())); List authorizedIndices = Collections.singletonList("logs-alias"); - assert metaData.getAliasAndIndexLookup().get("logs-alias").getIndices().size() == 3; + assert metaData.getIndicesLookup().get("logs-alias").getIndices().size() == 3; String putMappingIndexOrAlias = IndicesAndAliasesResolver.getPutMappingIndexOrAlias(request, authorizedIndices, metaData); String message = "user is authorized to access `logs-alias` and the put mapping request is for a read index" + "so this should have returned the concrete index as fallback"; @@ -1504,7 +1504,7 @@ private List buildAuthorizedIndices(User user, String action) { final Authentication authentication = new Authentication(user, new RealmRef("test", "indices-aliases-resolver-tests", "node"), null); rolesStore.getRoles(user, authentication, rolesListener); - return RBACEngine.resolveAuthorizedIndicesFromRole(rolesListener.actionGet(), action, metaData.getAliasAndIndexLookup()); + return RBACEngine.resolveAuthorizedIndicesFromRole(rolesListener.actionGet(), action, metaData.getIndicesLookup()); } public static IndexMetaData.Builder indexBuilder(String index) { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/IndicesPermissionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/IndicesPermissionTests.java index ee10a29083ad3..0d23e6c06021a 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/IndicesPermissionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/IndicesPermissionTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; @@ -56,7 +56,7 @@ public void testAuthorize() { .putAlias(AliasMetaData.builder("_alias")); MetaData md = MetaData.builder().put(imbBuilder).build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - SortedMap lookup = md.getAliasAndIndexLookup(); + SortedMap lookup = md.getIndicesLookup(); // basics: Set query = Collections.singleton(new BytesArray("{}")); @@ -138,7 +138,7 @@ public void testAuthorize() { ) .putAlias(AliasMetaData.builder("_alias")); md = MetaData.builder(md).put(imbBuilder1).build(); - lookup = md.getAliasAndIndexLookup(); + lookup = md.getIndicesLookup(); // match all fields with more than one permission Set fooQuery = Collections.singleton(new BytesArray("{foo}")); @@ -180,7 +180,7 @@ public void testAuthorizeMultipleGroupsMixedDls() { .putAlias(AliasMetaData.builder("_alias")); MetaData md = MetaData.builder().put(imbBuilder).build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - SortedMap lookup = md.getAliasAndIndexLookup(); + SortedMap lookup = md.getIndicesLookup(); Set query = Collections.singleton(new BytesArray("{}")); String[] fields = new String[]{"_field"}; @@ -235,7 +235,7 @@ public void testCorePermissionAuthorize() { .put(new IndexMetaData.Builder("a1").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) .put(new IndexMetaData.Builder("a2").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) .build(); - SortedMap lookup = metaData.getAliasAndIndexLookup(); + SortedMap lookup = metaData.getIndicesLookup(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); IndicesPermission.Group group1 = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, randomBoolean(), @@ -303,7 +303,7 @@ public void testSecurityIndicesPermissions() { .build(), true) .build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - SortedMap lookup = metaData.getAliasAndIndexLookup(); + SortedMap lookup = metaData.getIndicesLookup(); // allow_restricted_indices: false IndicesPermission.Group group = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, false, "*"); @@ -333,7 +333,7 @@ public void testAsyncSearchIndicesPermissions() { .build(), true) .build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - SortedMap lookup = metaData.getAliasAndIndexLookup(); + SortedMap lookup = metaData.getIndicesLookup(); // allow_restricted_indices: false IndicesPermission.Group group = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, false, "*"); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java index d4008c71c2047..2b6b10730c2ad 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java @@ -537,7 +537,7 @@ public void testMergingRolesWithFls() { .numberOfShards(1).numberOfReplicas(0).build(), true) .build(); Map acls = role.indices().authorize("indices:data/read/search", - Collections.singleton("test"), metaData.getAliasAndIndexLookup(), cache); + Collections.singleton("test"), metaData.getIndicesLookup(), cache); assertFalse(acls.isEmpty()); assertTrue(acls.get("test").getFieldPermissions().grantsAccessTo("L1.foo")); assertFalse(acls.get("test").getFieldPermissions().grantsAccessTo("L2.foo")); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java index 4194096333745..c0a127e50c8a6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java @@ -508,7 +508,7 @@ private ClusterState.Builder createClusterStateWithTemplate(String securityTempl private ClusterState.Builder createClusterStateWithMapping(String securityTemplateString) throws IOException { final ClusterState clusterState = createClusterStateWithIndex(securityTemplateString).build(); - final String indexName = clusterState.metaData().getAliasAndIndexLookup() + final String indexName = clusterState.metaData().getIndicesLookup() .get(RestrictedIndicesNames.SECURITY_MAIN_ALIAS).getIndices().get(0).getIndex().getName(); return ClusterState.builder(clusterState).routingTable(SecurityTestUtils.buildIndexRoutingTable(indexName)); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java index 30ad79b974381..3b2df203c6d4b 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java @@ -66,12 +66,12 @@ public void clusterChanged(ClusterChangedEvent event) { private static void createAuditAliasForDataFrameBWC(ClusterState state, Client client, final ActionListener finalListener) { // check if old audit index exists, no need to create the alias if it does not - if (state.getMetaData().getAliasAndIndexLookup().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) == false) { + if (state.getMetaData().getIndicesLookup().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) == false) { finalListener.onResponse(false); return; } - if (state.getMetaData().getAliasAndIndexLookup().get(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED).getIndices().stream() + if (state.getMetaData().getIndicesLookup().get(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED).getIndices().stream() .anyMatch(metaData -> metaData.getAliases().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS))) { finalListener.onResponse(false); return; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchStoreUtils.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchStoreUtils.java index 151d3c59b6ffa..51d009c3bb6bf 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchStoreUtils.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchStoreUtils.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.xpack.watcher.watch; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.index.IndexNotFoundException; @@ -22,16 +22,16 @@ public class WatchStoreUtils { * @throws IndexNotFoundException If no index exists */ public static IndexMetaData getConcreteIndex(String name, MetaData metaData) { - AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(name); - if (aliasOrIndex == null) { + IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(name); + if (indexAbstraction == null) { return null; } - if (aliasOrIndex.isAlias() && aliasOrIndex.getIndices().size() > 1) { + if (indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX && indexAbstraction.getIndices().size() > 1) { throw new IllegalStateException("Alias [" + name + "] points to more than one index"); } - return aliasOrIndex.getIndices().get(0); + return indexAbstraction.getIndices().get(0); } } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java index 0d8af470df056..45d390520acfa 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherIndexingListenerTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.coordination.NoMasterBlockService; import org.elasticsearch.cluster.metadata.AliasMetaData; -import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -683,22 +683,22 @@ public void testThatIndexingListenerBecomesInactiveOnClusterBlock() { private ClusterState mockClusterState(String watchIndex) { MetaData metaData = mock(MetaData.class); if (watchIndex == null) { - when(metaData.getAliasAndIndexLookup()).thenReturn(Collections.emptySortedMap()); + when(metaData.getIndicesLookup()).thenReturn(Collections.emptySortedMap()); } else { - SortedMap indices = new TreeMap<>(); + SortedMap indices = new TreeMap<>(); IndexMetaData indexMetaData = mock(IndexMetaData.class); when(indexMetaData.getIndex()).thenReturn(new Index(watchIndex, randomAlphaOfLength(10))); - indices.put(watchIndex, new AliasOrIndex.Index(indexMetaData)); + indices.put(watchIndex, new IndexAbstraction.Index(indexMetaData)); // now point the alias, if the watch index is not .watches if (watchIndex.equals(Watch.INDEX) == false) { AliasMetaData aliasMetaData = mock(AliasMetaData.class); when(aliasMetaData.alias()).thenReturn(watchIndex); - indices.put(Watch.INDEX, new AliasOrIndex.Alias(aliasMetaData, indexMetaData)); + indices.put(Watch.INDEX, new IndexAbstraction.Alias(aliasMetaData, indexMetaData)); } - when(metaData.getAliasAndIndexLookup()).thenReturn(indices); + when(metaData.getIndicesLookup()).thenReturn(indices); } ClusterState clusterState = mock(ClusterState.class);