Refactor AliasOrIndex abstraction. (#54394)

Backport of #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
This commit is contained in:
Martijn van Groningen 2020-03-30 10:12:16 +02:00 committed by GitHub
parent 00eaa0ebe5
commit 4b4fbc160d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 345 additions and 290 deletions

View File

@ -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 class CustomAuthorizationEngine implements AuthorizationEngine {
@Override
public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
Map<String, AliasOrIndex> aliasOrIndexLookup,
Map<String, IndexAbstraction> aliasOrIndexLookup,
ActionListener<IndexAuthorizationResult> listener) {
if (isSuperuser(requestInfo.getAuthentication().getUser())) {
indicesAsyncSupplier.getAsync(ActionListener.wrap(resolvedIndices -> {
@ -109,9 +109,9 @@ public class CustomAuthorizationEngine implements AuthorizationEngine {
@Override
public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
Map<String, AliasOrIndex> aliasOrIndexLookup, ActionListener<List<String>> listener) {
Map<String, IndexAbstraction> indicesLookup, ActionListener<List<String>> listener) {
if (isSuperuser(requestInfo.getAuthentication().getUser())) {
listener.onResponse(new ArrayList<>(aliasOrIndexLookup.keySet()));
listener.onResponse(new ArrayList<>(indicesLookup.keySet()));
} else {
listener.onResponse(Collections.emptyList());
}

View File

@ -22,8 +22,8 @@ package org.elasticsearch.example;
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 class CustomAuthorizationEngineTests extends ESTestCase {
public void testAuthorizeIndexAction() {
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
Map<String, AliasOrIndex> aliasOrIndexMap = new HashMap<>();
aliasOrIndexMap.put("index", new Index(IndexMetaData.builder("index")
Map<String, IndexAbstraction> 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 class CustomAuthorizationEngineTests extends ESTestCase {
PlainActionFuture<IndexAuthorizationResult> 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 class CustomAuthorizationEngineTests extends ESTestCase {
PlainActionFuture<IndexAuthorizationResult> 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));

View File

@ -25,9 +25,9 @@ import org.elasticsearch.action.support.ActiveShardCount;
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;
@ -79,9 +79,9 @@ public class MetaDataRolloverService {
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();
@ -176,16 +176,16 @@ public class MetaDataRolloverService {
}
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");
}
}
}

View File

@ -48,7 +48,7 @@ import org.elasticsearch.cluster.ClusterState;
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;
@ -285,18 +285,16 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
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) {

View File

@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.cluster.metadata;
import org.apache.lucene.util.SetOnce;
@ -35,30 +34,77 @@ import java.util.stream.Collectors;
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 whether this an alias or concrete index
* @return the type of the index abstraction
*/
boolean isAlias();
Type getType();
/**
* @return All {@link IndexMetaData} of all concrete indices this alias is referring to
* or if this is a concrete index its {@link IndexMetaData}
* @return the name of the index abstraction
*/
String getName();
/**
* @return All {@link IndexMetaData} of all concrete indices this index abstraction is referring to.
*/
List<IndexMetaData> 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
* <code>null</code> 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,8 +113,13 @@ public interface AliasOrIndex {
}
@Override
public boolean isAlias() {
return false;
public String getName() {
return concreteIndex.getIndex().getName();
}
@Override
public Type getType() {
return Type.CONCRETE_INDEX;
}
@Override
@ -76,6 +127,11 @@ public interface AliasOrIndex {
return Collections.singletonList(concreteIndex);
}
@Override
public IndexMetaData getWriteIndex() {
return concreteIndex;
}
@Override
public boolean isHidden() {
return INDEX_HIDDEN_SETTING.get(concreteIndex.getSettings());
@ -85,7 +141,7 @@ public interface AliasOrIndex {
/**
* 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<IndexMetaData> referenceIndexMetaDatas;
@ -100,11 +156,11 @@ public interface AliasOrIndex {
}
@Override
public boolean isAlias() {
return true;
public Type getType() {
return Type.ALIAS;
}
public String getAliasName() {
public String getName() {
return aliasName;
}
@ -131,7 +187,7 @@ public interface AliasOrIndex {
* and filters)
*/
public Iterable<Tuple<String, AliasMetaData>> getConcreteIndexAndAliasMetaDatas() {
return () -> new Iterator<Tuple<String,AliasMetaData>>() {
return () -> new Iterator<Tuple<String, AliasMetaData>>() {
int index = 0;

View File

@ -184,8 +184,8 @@ public class IndexNameExpressionResolver {
final Set<Index> 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)) {
@ -198,7 +198,7 @@ public class IndexNameExpressionResolver {
} 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 {
@ -206,11 +206,10 @@ public class IndexNameExpressionResolver {
}
}
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");
}
@ -218,17 +217,17 @@ public class IndexNameExpressionResolver {
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());
@ -332,7 +331,7 @@ public class IndexNameExpressionResolver {
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);
}
/**
@ -461,9 +460,9 @@ public class IndexNameExpressionResolver {
}
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<String, AliasMetaData> item : alias.getConcreteIndexAndAliasMetaDatas()) {
String concreteIndex = item.v1();
AliasMetaData aliasMetaData = item.v2();
@ -726,10 +725,10 @@ public class IndexNameExpressionResolver {
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);
}
}
@ -742,7 +741,7 @@ public class IndexNameExpressionResolver {
}
final IndexMetaData.State excludeState = excludeState(options);
final Map<String, AliasOrIndex> matches = matches(context, metaData, expression);
final Map<String, IndexAbstraction> matches = matches(context, metaData, expression);
Set<String> expand = expand(context, excludeState, matches, expression, options.expandWildcardsHidden());
if (add) {
result.addAll(expand);
@ -770,9 +769,10 @@ public class IndexNameExpressionResolver {
}
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) {
@ -796,15 +796,15 @@ public class IndexNameExpressionResolver {
return excludeState;
}
public static Map<String, AliasOrIndex> matches(Context context, MetaData metaData, String expression) {
public static Map<String, IndexAbstraction> 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);
@ -813,43 +813,43 @@ public class IndexNameExpressionResolver {
}
}
private static Map<String, AliasOrIndex> suffixWildcard(Context context, MetaData metaData, String expression) {
private static Map<String, IndexAbstraction> 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<String,AliasOrIndex> subMap = metaData.getAliasAndIndexLookup().subMap(fromPrefix, toPrefix);
SortedMap<String, IndexAbstraction> 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<String, AliasOrIndex> otherWildcard(Context context, MetaData metaData, String expression) {
private static Map<String, IndexAbstraction> 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<String> expand(Context context, IndexMetaData.State excludeState, Map<String, AliasOrIndex> matches,
private static Set<String> expand(Context context, IndexMetaData.State excludeState, Map<String, IndexAbstraction> matches,
String expression, boolean includeHidden) {
Set<String> expand = new HashSet<>();
for (Map.Entry<String, AliasOrIndex> entry : matches.entrySet()) {
for (Map.Entry<String, IndexAbstraction> 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());
}

View File

@ -186,14 +186,14 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
private final String[] allClosedIndices;
private final String[] visibleClosedIndices;
private final SortedMap<String, AliasOrIndex> aliasAndIndexLookup;
private final SortedMap<String, IndexAbstraction> indicesLookup;
MetaData(String clusterUUID, boolean clusterUUIDCommitted, long version, CoordinationMetaData coordinationMetaData,
Settings transientSettings, Settings persistentSettings, DiffableStringMap hashesOfConsistentSettings,
ImmutableOpenMap<String, IndexMetaData> indices, ImmutableOpenMap<String, IndexTemplateMetaData> templates,
ImmutableOpenMap<String, Custom> customs, String[] allIndices, String[] visibleIndices, String[] allOpenIndices,
String[] visibleOpenIndices, String[] allClosedIndices, String[] visibleClosedIndices,
SortedMap<String, AliasOrIndex> aliasAndIndexLookup) {
SortedMap<String, IndexAbstraction> indicesLookup) {
this.clusterUUID = clusterUUID;
this.clusterUUIDCommitted = clusterUUIDCommitted;
this.version = version;
@ -222,7 +222,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
this.visibleOpenIndices = visibleOpenIndices;
this.allClosedIndices = allClosedIndices;
this.visibleClosedIndices = visibleClosedIndices;
this.aliasAndIndexLookup = aliasAndIndexLookup;
this.indicesLookup = indicesLookup;
}
public long version() {
@ -265,9 +265,9 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
}
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;
}
@ -288,8 +288,8 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
return true;
}
public SortedMap<String, AliasOrIndex> getAliasAndIndexLookup() {
return aliasAndIndexLookup;
public SortedMap<String, IndexAbstraction> getIndicesLookup() {
return indicesLookup;
}
/**
@ -590,16 +590,15 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
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 ["
@ -627,11 +626,11 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
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);
}
@ -653,7 +652,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
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()) {
@ -668,7 +667,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
}
public boolean hasConcreteIndex(String index) {
return getAliasAndIndexLookup().containsKey(index);
return getIndicesLookup().containsKey(index);
}
public IndexMetaData index(String index) {
@ -1403,9 +1402,9 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
}
SortedMap<String, AliasOrIndex> aliasAndIndexLookup = Collections.unmodifiableSortedMap(buildAliasAndIndexLookup());
SortedMap<String, IndexAbstraction> 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.
@ -1420,43 +1419,45 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
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<String, AliasOrIndex> buildAliasAndIndexLookup() {
SortedMap<String, AliasOrIndex> aliasAndIndexLookup = new TreeMap<>();
private SortedMap<String, IndexAbstraction> buildIndicesLookup() {
SortedMap<String, IndexAbstraction> aliasAndIndexLookup = new TreeMap<>();
for (ObjectCursor<IndexMetaData> 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<String, AliasMetaData> 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<String, AliasOrIndex> aliasAndIndexLookup) {
private void validateDataStreams(SortedMap<String, IndexAbstraction> 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)" +

View File

@ -27,10 +27,10 @@ import org.elasticsearch.cluster.ClusterName;
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 class MetaDataRolloverServiceTests extends ESTestCase {
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 class MetaDataRolloverServiceTests extends ESTestCase {
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));

View File

@ -33,7 +33,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
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.cluster.metadata.MetaData;
import org.elasticsearch.common.StopWatch;
@ -679,8 +679,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
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");

View File

@ -30,7 +30,7 @@ import java.util.Objects;
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 class AliasOrIndexTests extends ESTestCase {
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 class AliasOrIndexTests extends ESTestCase {
}
{
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 class AliasOrIndexTests extends ESTestCase {
}
{
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 class AliasOrIndexTests extends ESTestCase {
}
{
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);

View File

@ -76,9 +76,9 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
// 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);
@ -87,18 +87,18 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
}
@ -200,9 +200,9 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
}
@ -226,7 +226,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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() {
@ -235,20 +235,20 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
}
@ -265,7 +265,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
@ -293,7 +293,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
@ -311,12 +311,12 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
@ -335,11 +335,11 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
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);
}

View File

@ -10,8 +10,7 @@ import org.apache.logging.log4j.LogManager;
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 class WaitForActiveShardsStep extends ClusterStateWaitStep {
+ "] 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<IndexMetaData> indices = alias.getIndices();
List<IndexMetaData> indices = indexAbstraction.getIndices();
int maxIndexCounter = -1;
IndexMetaData rolledIndexMeta = null;
for (IndexMetaData indexMetaData : indices) {

View File

@ -14,7 +14,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
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.common.xcontent.XContentType;
@ -69,7 +69,7 @@ public class AnnotationIndex {
}, finalListener::onFailure);
// Only create the index or aliases if some other ML index exists - saves clutter if ML is never used.
SortedMap<String, AliasOrIndex> mlLookup = state.getMetaData().getAliasAndIndexLookup().tailMap(".ml");
SortedMap<String, IndexAbstraction> mlLookup = state.getMetaData().getIndicesLookup().tailMap(".ml");
if (mlLookup.isEmpty() == false && mlLookup.firstKey().startsWith(".ml")) {
// Create the annotations index if it doesn't exist already.

View File

@ -15,7 +15,7 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
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.CheckedFunction;
@ -148,13 +148,13 @@ public class ElasticsearchMappings {
public static void addDocMappingIfMissing(String alias,
CheckedFunction<String, String, IOException> mappingSupplier,
Client client, ClusterState state, ActionListener<Boolean> 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;

View File

@ -88,7 +88,7 @@ public final class MlIndexAndAlias {
String[] concreteIndexNames =
resolver.concreteIndexNames(clusterState, IndicesOptions.lenientExpandOpen(), indexPattern);
Optional<IndexMetaData> 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) {

View File

@ -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<ResolvedIndices> indicesAsyncSupplier, Map<String, AliasOrIndex> aliasOrIndexLookup,
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier, Map<String, IndexAbstraction> aliasOrIndexLookup,
ActionListener<IndexAuthorizationResult> listener);
/**
@ -139,12 +139,12 @@ public interface AuthorizationEngine {
* 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<String, AliasOrIndex> aliasOrIndexLookup, ActionListener<List<String>> listener);
Map<String, IndexAbstraction> indicesLookup, ActionListener<List<String>> listener);
/**

View File

@ -10,7 +10,7 @@ import org.apache.lucene.util.automaton.Automaton;
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 final class IndicesPermission {
* Authorizes the provided action against the provided indices, given the current cluster metadata
*/
public Map<String, IndicesAccessControl.IndexAccessControl> authorize(String action, Set<String> requestedIndicesOrAliases,
Map<String, AliasOrIndex> allAliasesAndIndices,
Map<String, IndexAbstraction> 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 final class IndicesPermission {
for (String indexOrAlias : requestedIndicesOrAliases) {
boolean granted = false;
Set<String> 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());
}
}

View File

@ -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 final class LimitedRole extends Role {
@Override
public IndicesAccessControl authorize(String action, Set<String> requestedIndicesOrAliases,
Map<String, AliasOrIndex> aliasAndIndexLookup,
Map<String, IndexAbstraction> aliasAndIndexLookup,
FieldPermissionsCache fieldPermissionsCache) {
IndicesAccessControl indicesAccessControl =
super.authorize(action, requestedIndicesOrAliases, aliasAndIndexLookup, fieldPermissionsCache);

View File

@ -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 class Role {
* is configured for any group also the allowed fields and role queries are resolved.
*/
public IndicesAccessControl authorize(String action, Set<String> requestedIndicesOrAliases,
Map<String, AliasOrIndex> aliasAndIndexLookup,
Map<String, IndexAbstraction> aliasAndIndexLookup,
FieldPermissionsCache fieldPermissionsCache) {
Map<String, IndicesAccessControl.IndexAccessControl> indexPermissions = indices.authorize(
action, requestedIndicesOrAliases, aliasAndIndexLookup, fieldPermissionsCache

View File

@ -16,7 +16,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
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 class SnapshotHistoryStore {
*/
static void ensureHistoryIndex(Client client, ClusterState state, ActionListener<Boolean> 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 class SnapshotHistoryStore {
// 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"));

View File

@ -69,13 +69,13 @@ public class LimitedRoleTests extends ESTestCase {
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 class LimitedRoleTests extends ESTestCase {
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 class LimitedRoleTests extends ESTestCase {
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));

View File

@ -42,7 +42,7 @@ import org.elasticsearch.action.search.MultiSearchAction;
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 @@ public class ReservedRolesStoreTests extends ESTestCase {
String asyncSearchIndex = RestrictedIndicesNames.ASYNC_SEARCH_PREFIX + randomAlphaOfLengthBetween(0, 2);
final Map<String, IndexAccessControl> 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 class ReservedRolesStoreTests extends ESTestCase {
.build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
SortedMap<String, AliasOrIndex> lookup = metaData.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = metaData.getIndicesLookup();
Map<String, IndexAccessControl> authzMap =
superuserRole.indices().authorize(SearchAction.NAME, Sets.newHashSet("a1", "ba"), lookup, fieldPermissionsCache);
assertThat(authzMap.get("a1").isGranted(), is(true));

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.enrich;
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<Cluste
public Processor create(Map<String, Processor.Factory> processorFactories, String tag, Map<String, Object> 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<String, Object> mappingAsMap = imd.mapping().sourceAsMap();
String policyType = (String) XContentMapValues.extractValue(

View File

@ -27,7 +27,7 @@ import org.elasticsearch.client.OriginSettingClient;
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;
@ -174,7 +174,7 @@ public class SamlServiceProviderIndex implements Closeable {
}
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) {
@ -188,11 +188,11 @@ public class SamlServiceProviderIndex implements Closeable {
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()));

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.index.IndexRequest;
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;
@ -170,8 +170,8 @@ public class ILMHistoryStore implements Closeable {
@SuppressWarnings("unchecked")
static void ensureHistoryIndex(Client client, ClusterState state, ActionListener<Boolean> 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
@ -210,15 +210,15 @@ public class ILMHistoryStore implements Closeable {
// 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"));

View File

@ -16,7 +16,7 @@ import org.elasticsearch.action.support.WriteRequest;
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;
@ -82,8 +82,8 @@ public class MlConfigMigratorIT extends MlSingleNodeTestCase {
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings(), new HashSet<>(Collections.singletonList(
MlConfigMigrationEligibilityCheck.ENABLE_CONFIG_MIGRATION)));
MetaData metaData = mock(MetaData.class);
SortedMap<String, AliasOrIndex> aliasOrIndexSortedMap = new TreeMap<>();
when(metaData.getAliasAndIndexLookup()).thenReturn(aliasOrIndexSortedMap);
SortedMap<String, IndexAbstraction> indicesMap = new TreeMap<>();
when(metaData.getIndicesLookup()).thenReturn(indicesMap);
ClusterState clusterState = mock(ClusterState.class);
when(clusterState.getMetaData()).thenReturn(metaData);
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);

View File

@ -250,7 +250,7 @@ public class AuthorizationService {
} else if (IndexPrivilege.ACTION_MATCHER.test(action)) {
final MetaData metaData = clusterService.state().metaData();
final AsyncSupplier<List<String>> authorizedIndicesSupplier = new CachingAsyncSupplier<>(authzIndicesListener ->
authzEngine.loadAuthorizedIndices(requestInfo, authzInfo, metaData.getAliasAndIndexLookup(),
authzEngine.loadAuthorizedIndices(requestInfo, authzInfo, metaData.getIndicesLookup(),
authzIndicesListener));
final AsyncSupplier<ResolvedIndices> resolvedIndicesAsyncSupplier = new CachingAsyncSupplier<>((resolvedIndicesListener) -> {
authorizedIndicesSupplier.getAsync(ActionListener.wrap(authorizedIndices -> {
@ -265,7 +265,7 @@ public class AuthorizationService {
}));
});
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 @@ public class AuthorizationService {
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 @@ public class AuthorizationService {
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));
});

View File

@ -15,7 +15,7 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
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;
@ -235,12 +235,13 @@ class IndicesAndAliasesResolver {
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;
@ -254,13 +255,13 @@ class IndicesAndAliasesResolver {
.map(AliasMetaData::alias)
.filter(authorizedIndicesList::contains)
.filter(aliasName -> {
AliasOrIndex alias = metaData.getAliasAndIndexLookup().get(aliasName);
IndexAbstraction alias = metaData.getIndicesLookup().get(aliasName);
List<IndexMetaData> 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);
}
})
@ -281,10 +282,10 @@ class IndicesAndAliasesResolver {
private List<String> loadAuthorizedAliases(List<String> authorizedIndices, MetaData metaData) {
List<String> authorizedAliases = new ArrayList<>();
SortedMap<String, AliasOrIndex> existingAliases = metaData.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> 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);
}
}
@ -423,9 +424,9 @@ class IndicesAndAliasesResolver {
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.
@ -437,8 +438,8 @@ class IndicesAndAliasesResolver {
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;
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.action.search.MultiSearchAction;
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 @@ public class RBACEngine implements AuthorizationEngine {
@Override
public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
Map<String, AliasOrIndex> aliasOrIndexLookup,
Map<String, IndexAbstraction> aliasOrIndexLookup,
ActionListener<IndexAuthorizationResult> listener) {
final String action = requestInfo.getAction();
final TransportRequest request = requestInfo.getRequest();
@ -339,10 +339,10 @@ public class RBACEngine implements AuthorizationEngine {
@Override
public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
Map<String, AliasOrIndex> aliasOrIndexLookup, ActionListener<List<String>> listener) {
Map<String, IndexAbstraction> indicesLookup, ActionListener<List<String>> 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 @@ public class RBACEngine implements AuthorizationEngine {
return new GetUserPrivilegesResponse(cluster, conditionalCluster, indices, application, runAs);
}
static List<String> resolveAuthorizedIndicesFromRole(Role role, String action, Map<String, AliasOrIndex> aliasAndIndexLookup) {
static List<String> resolveAuthorizedIndicesFromRole(Role role, String action, Map<String, IndexAbstraction> aliasAndIndexLookup) {
Predicate<String> predicate = role.allowedIndicesMatcher(action);
List<String> 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<String, AliasOrIndex> entry : aliasAndIndexLookup.entrySet()) {
for (Map.Entry<String, IndexAbstraction> entry : aliasAndIndexLookup.entrySet()) {
String aliasOrIndex = entry.getKey();
if (predicate.test(aliasOrIndex)) {
indicesAndAliases.add(aliasOrIndex);
@ -515,7 +515,7 @@ public class RBACEngine implements AuthorizationEngine {
private void buildIndicesAccessControl(Authentication authentication, String action,
AuthorizationInfo authorizationInfo, Set<String> indices,
Map<String, AliasOrIndex> aliasAndIndexLookup,
Map<String, IndexAbstraction> aliasAndIndexLookup,
ActionListener<IndexAuthorizationResult> listener) {
if (authorizationInfo instanceof RBACAuthorizationInfo) {
final Role role = ((RBACAuthorizationInfo) authorizationInfo).getRole();

View File

@ -10,7 +10,7 @@ import org.apache.logging.log4j.LogManager;
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 @@ public final class DeprecationRoleDescriptorConsumer implements Consumer<Collect
}
private void logDeprecatedPermission(RoleDescriptor roleDescriptor) {
final SortedMap<String, AliasOrIndex> aliasOrIndexMap = clusterService.state().metaData().getAliasAndIndexLookup();
final SortedMap<String, IndexAbstraction> aliasOrIndexMap = clusterService.state().metaData().getIndicesLookup();
final Map<String, Set<String>> privilegesByAliasMap = new HashMap<>();
// sort answer by alias for tests
final SortedMap<String, Set<String>> privilegesByIndexMap = new TreeMap<>();
// collate privileges by index and by alias separately
for (final IndicesPrivileges indexPrivilege : roleDescriptor.getIndicesPrivileges()) {
final Predicate<String> namePatternPredicate = IndicesPermission.indexMatcher(Arrays.asList(indexPrivilege.getIndices()));
for (final Map.Entry<String, AliasOrIndex> aliasOrIndex : aliasOrIndexMap.entrySet()) {
for (final Map.Entry<String, IndexAbstraction> 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<String> privilegesByAlias = privilegesByAliasMap.computeIfAbsent(aliasOrIndexName,
k -> new HashSet<String>());
k -> new HashSet<>());
privilegesByAlias.addAll(Arrays.asList(indexPrivilege.getPrivileges()));
} else {
final Set<String> privilegesByIndex = privilegesByIndexMap.computeIfAbsent(aliasOrIndexName,
k -> new HashSet<String>());
k -> new HashSet<>());
privilegesByIndex.addAll(Arrays.asList(indexPrivilege.getPrivileges()));
}
}

View File

@ -29,7 +29,7 @@ import org.elasticsearch.cluster.ClusterState;
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;
@ -299,10 +299,10 @@ public class SecurityIndexManager implements ClusterStateListener {
* 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<IndexMetaData> indices = aliasOrIndex.getIndices();
if (aliasOrIndex.isAlias() && indices.size() > 1) {
final IndexAbstraction indexAbstraction = metaData.getIndicesLookup().get(indexOrAliasName);
if (indexAbstraction != null) {
final List<IndexMetaData> 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()));
}

View File

@ -22,7 +22,7 @@ import org.elasticsearch.client.RestHighLevelClient;
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;
@ -524,9 +524,9 @@ public abstract class SecurityIntegTestCase extends ESIntegTestCase {
}
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;
}

View File

@ -72,7 +72,7 @@ import org.elasticsearch.action.update.UpdateAction;
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;
@ -1420,14 +1420,14 @@ public class AuthorizationServiceTests extends ESTestCase {
@Override
public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
Map<String, AliasOrIndex> aliasOrIndexLookup,
Map<String, IndexAbstraction> aliasOrIndexLookup,
ActionListener<IndexAuthorizationResult> listener) {
throw new UnsupportedOperationException("not implemented");
}
@Override
public void loadAuthorizedIndices(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
Map<String, AliasOrIndex> aliasOrIndexLookup, ActionListener<List<String>> listener) {
Map<String, IndexAbstraction> indicesLookup, ActionListener<List<String>> listener) {
throw new UnsupportedOperationException("not implemented");
}

View File

@ -36,7 +36,7 @@ public class AuthorizedIndicesTests extends ESTestCase {
public void testAuthorizedIndicesUserWithoutRoles() {
List<String> authorizedIndices =
RBACEngine.resolveAuthorizedIndicesFromRole(Role.EMPTY, "", MetaData.EMPTY_META_DATA.getAliasAndIndexLookup());
RBACEngine.resolveAuthorizedIndicesFromRole(Role.EMPTY, "", MetaData.EMPTY_META_DATA.getIndicesLookup());
assertTrue(authorizedIndices.isEmpty());
}
@ -72,7 +72,7 @@ public class AuthorizedIndicesTests extends ESTestCase {
CompositeRolesStore.buildRoleFromDescriptors(descriptors, new FieldPermissionsCache(Settings.EMPTY), null, future);
Role roles = future.actionGet();
List<String> 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"));
@ -83,7 +83,7 @@ public class AuthorizedIndicesTests extends ESTestCase {
public void testAuthorizedIndicesUserWithSomeRolesEmptyMetaData() {
Role role = Role.builder("role").add(IndexPrivilege.ALL, "*").build();
List<String> authorizedIndices =
RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getAliasAndIndexLookup());
RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getIndicesLookup());
assertTrue(authorizedIndices.isEmpty());
}
@ -91,7 +91,7 @@ public class AuthorizedIndicesTests extends ESTestCase {
Role role = Role.builder("user_role").add(IndexPrivilege.ALL, "*").cluster(Collections.singleton("all"), Collections.emptySet())
.build();
List<String> authorizedIndices =
RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getAliasAndIndexLookup());
RBACEngine.resolveAuthorizedIndicesFromRole(role, SearchAction.NAME, MetaData.EMPTY_META_DATA.getIndicesLookup());
assertTrue(authorizedIndices.isEmpty());
}
@ -116,7 +116,7 @@ public class AuthorizedIndicesTests extends ESTestCase {
.build();
List<String> 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)));
@ -142,12 +142,12 @@ public class AuthorizedIndicesTests extends ESTestCase {
.build();
List<String> 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<String> 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));
}

View File

@ -1407,7 +1407,7 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
String index = "logs-00003"; // write index
PutMappingRequest request = new PutMappingRequest(Strings.EMPTY_ARRAY).setConcreteIndex(new Index(index, UUIDs.base64UUID()));
List<String> 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";
@ -1418,7 +1418,7 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
String index = "logs-00002"; // read index
PutMappingRequest request = new PutMappingRequest(Strings.EMPTY_ARRAY).setConcreteIndex(new Index(index, UUIDs.base64UUID()));
List<String> 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";
@ -1528,7 +1528,7 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
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) {

View File

@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchSecurityException;
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;
@ -57,7 +57,7 @@ public class IndicesPermissionTests extends ESTestCase {
.putAlias(AliasMetaData.builder("_alias"));
MetaData md = MetaData.builder().put(imbBuilder).build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
SortedMap<String, AliasOrIndex> lookup = md.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = md.getIndicesLookup();
// basics:
Set<BytesReference> query = Collections.singleton(new BytesArray("{}"));
@ -139,7 +139,7 @@ public class IndicesPermissionTests extends ESTestCase {
)
.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<BytesReference> fooQuery = Collections.singleton(new BytesArray("{foo}"));
@ -181,7 +181,7 @@ public class IndicesPermissionTests extends ESTestCase {
.putAlias(AliasMetaData.builder("_alias"));
MetaData md = MetaData.builder().put(imbBuilder).build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
SortedMap<String, AliasOrIndex> lookup = md.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = md.getIndicesLookup();
Set<BytesReference> query = Collections.singleton(new BytesArray("{}"));
String[] fields = new String[]{"_field"};
@ -236,7 +236,7 @@ public class IndicesPermissionTests extends ESTestCase {
.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<String, AliasOrIndex> lookup = metaData.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = metaData.getIndicesLookup();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
IndicesPermission.Group group1 = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, randomBoolean(),
@ -304,7 +304,7 @@ public class IndicesPermissionTests extends ESTestCase {
.build(), true)
.build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
SortedMap<String, AliasOrIndex> lookup = metaData.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = metaData.getIndicesLookup();
// allow_restricted_indices: false
IndicesPermission.Group group = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, false, "*");
@ -334,7 +334,7 @@ public class IndicesPermissionTests extends ESTestCase {
.build(), true)
.build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
SortedMap<String, AliasOrIndex> lookup = metaData.getAliasAndIndexLookup();
SortedMap<String, IndexAbstraction> lookup = metaData.getIndicesLookup();
// allow_restricted_indices: false
IndicesPermission.Group group = new IndicesPermission.Group(IndexPrivilege.ALL, new FieldPermissions(), null, false, "*");

View File

@ -537,7 +537,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
.numberOfShards(1).numberOfReplicas(0).build(), true)
.build();
Map<String, IndicesAccessControl.IndexAccessControl> 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"));

View File

@ -519,7 +519,7 @@ public class SecurityIndexManagerTests extends ESTestCase {
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));
}

View File

@ -67,12 +67,12 @@ class TransformClusterStateListener implements ClusterStateListener {
private static void createAuditAliasForDataFrameBWC(ClusterState state, Client client, final ActionListener<Boolean> 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;

View File

@ -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);
}
}

View File

@ -13,7 +13,7 @@ import org.elasticsearch.cluster.ClusterState;
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;
@ -684,22 +684,22 @@ public class WatcherIndexingListenerTests extends ESTestCase {
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<String, AliasOrIndex> indices = new TreeMap<>();
SortedMap<String, IndexAbstraction> 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);