Browse Source

Turn AliasValidator into a Utility Class (#82859)

Just a random thing I found going through name resolution code.
All methods in this class could be made `static` and hence there's no
need to have an instance of it anywhere.
Armin Braun 3 years ago
parent
commit
4be4ae480d

+ 0 - 6
server/src/main/java/org/elasticsearch/action/admin/indices/template/post/TransportSimulateIndexTemplateAction.java

@@ -16,7 +16,6 @@ import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.block.ClusterBlockException;
 import org.elasticsearch.cluster.block.ClusterBlockLevel;
 import org.elasticsearch.cluster.metadata.AliasMetadata;
-import org.elasticsearch.cluster.metadata.AliasValidator;
 import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -61,7 +60,6 @@ public class TransportSimulateIndexTemplateAction extends TransportMasterNodeRea
     private final MetadataIndexTemplateService indexTemplateService;
     private final NamedXContentRegistry xContentRegistry;
     private final IndicesService indicesService;
-    private final AliasValidator aliasValidator;
     private final SystemIndices systemIndices;
     private final Set<IndexSettingProvider> indexSettingProviders;
 
@@ -92,7 +90,6 @@ public class TransportSimulateIndexTemplateAction extends TransportMasterNodeRea
         this.indexTemplateService = indexTemplateService;
         this.xContentRegistry = xContentRegistry;
         this.indicesService = indicesService;
-        this.aliasValidator = new AliasValidator();
         this.systemIndices = systemIndices;
         this.indexSettingProviders = indexSettingProviders.getIndexSettingProviders();
     }
@@ -140,7 +137,6 @@ public class TransportSimulateIndexTemplateAction extends TransportMasterNodeRea
             stateWithTemplate,
             xContentRegistry,
             indicesService,
-            aliasValidator,
             systemIndices,
             indexSettingProviders
         );
@@ -193,7 +189,6 @@ public class TransportSimulateIndexTemplateAction extends TransportMasterNodeRea
         final ClusterState simulatedState,
         final NamedXContentRegistry xContentRegistry,
         final IndicesService indicesService,
-        final AliasValidator aliasValidator,
         final SystemIndices systemIndices,
         Set<IndexSettingProvider> indexSettingProviders
     ) throws Exception {
@@ -241,7 +236,6 @@ public class TransportSimulateIndexTemplateAction extends TransportMasterNodeRea
                 Set.of(),
                 resolvedAliases,
                 tempClusterState.metadata(),
-                aliasValidator,
                 xContentRegistry,
                 // the context is only used for validation so it's fine to pass fake values for the
                 // shard id and the current timestamp

+ 0 - 4
server/src/main/java/org/elasticsearch/action/admin/indices/template/post/TransportSimulateTemplateAction.java

@@ -14,7 +14,6 @@ import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
 import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.block.ClusterBlockException;
 import org.elasticsearch.cluster.block.ClusterBlockLevel;
-import org.elasticsearch.cluster.metadata.AliasValidator;
 import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
 import org.elasticsearch.cluster.metadata.MetadataIndexTemplateService;
@@ -51,7 +50,6 @@ public class TransportSimulateTemplateAction extends TransportMasterNodeReadActi
     private final MetadataIndexTemplateService indexTemplateService;
     private final NamedXContentRegistry xContentRegistry;
     private final IndicesService indicesService;
-    private final AliasValidator aliasValidator;
     private final SystemIndices systemIndices;
     private final Set<IndexSettingProvider> indexSettingProviders;
 
@@ -82,7 +80,6 @@ public class TransportSimulateTemplateAction extends TransportMasterNodeReadActi
         this.indexTemplateService = indexTemplateService;
         this.xContentRegistry = xContentRegistry;
         this.indicesService = indicesService;
-        this.aliasValidator = new AliasValidator();
         this.systemIndices = systemIndices;
         this.indexSettingProviders = indexSettingProviders.getIndexSettingProviders();
     }
@@ -162,7 +159,6 @@ public class TransportSimulateTemplateAction extends TransportMasterNodeReadActi
             stateWithTemplate,
             xContentRegistry,
             indicesService,
-            aliasValidator,
             systemIndices,
             indexSettingProviders
         );

+ 12 - 7
server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java

@@ -34,12 +34,17 @@ import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQuery
  * and make sure the alias is valid
  */
 public class AliasValidator {
+
+    private AliasValidator() {
+        // utility class
+    }
+
     /**
      * Allows to validate an {@link org.elasticsearch.action.admin.indices.alias.Alias} and make sure
      * it's valid before it gets added to the index metadata. Doesn't validate the alias filter.
      * @throws IllegalArgumentException if the alias is not valid
      */
-    public void validateAlias(Alias alias, String index, Metadata metadata) {
+    public static void validateAlias(Alias alias, String index, Metadata metadata) {
         validateAlias(alias.name(), index, alias.indexRouting(), lookup(metadata));
     }
 
@@ -48,7 +53,7 @@ public class AliasValidator {
      * it's valid before it gets added to the index metadata. Doesn't validate the alias filter.
      * @throws IllegalArgumentException if the alias is not valid
      */
-    public void validateAliasMetadata(AliasMetadata aliasMetadata, String index, Metadata metadata) {
+    public static void validateAliasMetadata(AliasMetadata aliasMetadata, String index, Metadata metadata) {
         validateAlias(aliasMetadata.alias(), index, aliasMetadata.indexRouting(), lookup(metadata));
     }
 
@@ -59,7 +64,7 @@ public class AliasValidator {
      * without validating it as a filter though.
      * @throws IllegalArgumentException if the alias is not valid
      */
-    public void validateAliasStandalone(Alias alias) {
+    public static void validateAliasStandalone(Alias alias) {
         validateAliasStandalone(alias.name(), alias.indexRouting());
         if (Strings.hasLength(alias.filter())) {
             try {
@@ -73,7 +78,7 @@ public class AliasValidator {
     /**
      * Validate a proposed alias.
      */
-    public void validateAlias(String alias, String index, @Nullable String indexRouting, Function<String, String> lookup) {
+    public static void validateAlias(String alias, String index, @Nullable String indexRouting, Function<String, String> lookup) {
         validateAliasStandalone(alias, indexRouting);
 
         if (Strings.hasText(index) == false) {
@@ -86,7 +91,7 @@ public class AliasValidator {
         }
     }
 
-    void validateAliasStandalone(String alias, String indexRouting) {
+    static void validateAliasStandalone(String alias, String indexRouting) {
         if (Strings.hasText(alias) == false) {
             throw new IllegalArgumentException("alias name is required");
         }
@@ -101,7 +106,7 @@ public class AliasValidator {
      * provided {@link SearchExecutionContext}
      * @throws IllegalArgumentException if the filter is not valid
      */
-    public void validateAliasFilter(
+    public static void validateAliasFilter(
         String alias,
         String filter,
         SearchExecutionContext searchExecutionContext,
@@ -123,7 +128,7 @@ public class AliasValidator {
      * provided {@link SearchExecutionContext}
      * @throws IllegalArgumentException if the filter is not valid
      */
-    public void validateAliasFilter(
+    public static void validateAliasFilter(
         String alias,
         BytesReference filter,
         SearchExecutionContext searchExecutionContext,

+ 6 - 21
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

@@ -12,7 +12,6 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.elasticsearch.ElasticsearchException;
 import org.elasticsearch.ResourceAlreadyExistsException;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.ActionListener;
@@ -72,7 +71,7 @@ import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.xcontent.NamedXContentRegistry;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.time.Instant;
 import java.util.ArrayList;
@@ -121,7 +120,6 @@ public class MetadataCreateIndexService {
     private final ClusterService clusterService;
     private final IndicesService indicesService;
     private final AllocationService allocationService;
-    private final AliasValidator aliasValidator;
     private final Environment env;
     private final IndexScopedSettings indexScopedSettings;
     private final ActiveShardsObserver activeShardsObserver;
@@ -136,7 +134,6 @@ public class MetadataCreateIndexService {
         final ClusterService clusterService,
         final IndicesService indicesService,
         final AllocationService allocationService,
-        final AliasValidator aliasValidator,
         final ShardLimitValidator shardLimitValidator,
         final Environment env,
         final IndexScopedSettings indexScopedSettings,
@@ -150,7 +147,6 @@ public class MetadataCreateIndexService {
         this.clusterService = clusterService;
         this.indicesService = indicesService;
         this.allocationService = allocationService;
-        this.aliasValidator = aliasValidator;
         this.env = env;
         this.indexScopedSettings = indexScopedSettings;
         this.activeShardsObserver = new ActiveShardsObserver(clusterService, threadPool);
@@ -230,13 +226,7 @@ public class MetadataCreateIndexService {
         if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
             throw exceptionCtor.apply(index, "must not start with '_', '-', or '+'");
         }
-        int byteCount = 0;
-        try {
-            byteCount = index.getBytes("UTF-8").length;
-        } catch (UnsupportedEncodingException e) {
-            // UTF-8 should always be supported, but rethrow this if it is not for some reason
-            throw new ElasticsearchException("Unable to determine length of index name", e);
-        }
+        int byteCount = index.getBytes(StandardCharsets.UTF_8).length;
         if (byteCount > MAX_INDEX_NAME_BYTES) {
             throw exceptionCtor.apply(index, "index name is too long, (" + byteCount + " > " + MAX_INDEX_NAME_BYTES + ")");
         }
@@ -558,7 +548,6 @@ public class MetadataCreateIndexService {
                 request.aliases(),
                 MetadataIndexTemplateService.resolveAliases(templates),
                 currentState.metadata(),
-                aliasValidator,
                 // the context is only used for validation so it's fine to pass fake values for the
                 // shard id and the current timestamp
                 xContentRegistry,
@@ -626,7 +615,6 @@ public class MetadataCreateIndexService {
                 isDataStream ? Set.of() : request.aliases(),
                 isDataStream ? List.of() : MetadataIndexTemplateService.resolveAliases(currentState.metadata(), templateName),
                 currentState.metadata(),
-                aliasValidator,
                 xContentRegistry,
                 // the context is used ony for validation so it's fine to pass fake values for the shard id and the current timestamp
                 indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
@@ -684,7 +672,6 @@ public class MetadataCreateIndexService {
                 currentState.metadata(),
                 // the context is only used for validation so it's fine to pass fake values for the
                 // shard id and the current timestamp
-                aliasValidator,
                 xContentRegistry,
                 indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
                 indexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
@@ -777,7 +764,6 @@ public class MetadataCreateIndexService {
                 request.aliases(),
                 Collections.emptyList(),
                 currentState.metadata(),
-                aliasValidator,
                 xContentRegistry,
                 // the context is only used for validation so it's fine to pass fake values for the
                 // shard id and the current timestamp
@@ -1030,7 +1016,6 @@ public class MetadataCreateIndexService {
         Set<Alias> aliases,
         List<Map<String, AliasMetadata>> templateAliases,
         Metadata metadata,
-        AliasValidator aliasValidator,
         NamedXContentRegistry xContentRegistry,
         SearchExecutionContext searchExecutionContext,
         Function<String, String> indexNameExpressionResolver,
@@ -1043,9 +1028,9 @@ public class MetadataCreateIndexService {
         for (Alias alias : aliases) {
             final String resolvedExpression = indexNameExpressionResolver.apply(alias.name());
             alias = alias.name(resolvedExpression);
-            aliasValidator.validateAlias(alias, index, metadata);
+            AliasValidator.validateAlias(alias, index, metadata);
             if (Strings.hasLength(alias.filter())) {
-                aliasValidator.validateAliasFilter(alias.name(), alias.filter(), searchExecutionContext, xContentRegistry);
+                AliasValidator.validateAliasFilter(alias.name(), alias.filter(), searchExecutionContext, xContentRegistry);
             }
 
             AliasMetadata aliasMetadata = AliasMetadata.builder(alias.name())
@@ -1094,9 +1079,9 @@ public class MetadataCreateIndexService {
                         .build();
                 }
 
-                aliasValidator.validateAliasMetadata(aliasMetadata, index, metadata);
+                AliasValidator.validateAliasMetadata(aliasMetadata, index, metadata);
                 if (aliasMetadata.filter() != null) {
-                    aliasValidator.validateAliasFilter(
+                    AliasValidator.validateAliasFilter(
                         aliasMetadata.alias(),
                         aliasMetadata.filter().uncompressed(),
                         searchExecutionContext,

+ 3 - 7
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexAliasesService.java

@@ -50,8 +50,6 @@ public class MetadataIndexAliasesService {
 
     private final IndicesService indicesService;
 
-    private final AliasValidator aliasValidator;
-
     private final MetadataDeleteIndexService deleteIndexService;
 
     private final NamedXContentRegistry xContentRegistry;
@@ -60,13 +58,11 @@ public class MetadataIndexAliasesService {
     public MetadataIndexAliasesService(
         ClusterService clusterService,
         IndicesService indicesService,
-        AliasValidator aliasValidator,
         MetadataDeleteIndexService deleteIndexService,
         NamedXContentRegistry xContentRegistry
     ) {
         this.clusterService = clusterService;
         this.indicesService = indicesService;
-        this.aliasValidator = aliasValidator;
         this.deleteIndexService = deleteIndexService;
         this.xContentRegistry = xContentRegistry;
     }
@@ -134,7 +130,7 @@ public class MetadataIndexAliasesService {
                 DataStream dataStream = metadata.dataStream(action.getIndex());
                 if (dataStream != null) {
                     NewAliasValidator newAliasValidator = (alias, indexRouting, searchRouting, filter, writeIndex) -> {
-                        aliasValidator.validateAlias(alias, action.getIndex(), indexRouting, lookup);
+                        AliasValidator.validateAlias(alias, action.getIndex(), indexRouting, lookup);
                         if (Strings.hasLength(filter)) {
                             for (Index index : dataStream.getIndices()) {
                                 IndexMetadata imd = metadata.get(index.getName());
@@ -158,7 +154,7 @@ public class MetadataIndexAliasesService {
                 }
                 validateAliasTargetIsNotDSBackingIndex(currentState, action);
                 NewAliasValidator newAliasValidator = (alias, indexRouting, searchRouting, filter, writeIndex) -> {
-                    aliasValidator.validateAlias(alias, action.getIndex(), indexRouting, lookup);
+                    AliasValidator.validateAlias(alias, action.getIndex(), indexRouting, lookup);
                     IndexSettings.MODE.get(index.getSettings()).validateAlias(indexRouting, searchRouting);
                     if (Strings.hasLength(filter)) {
                         validateFilter(indicesToClose, indices, action, index, alias, filter);
@@ -221,7 +217,7 @@ public class MetadataIndexAliasesService {
         }
         // the context is only used for validation so it's fine to pass fake values for the shard id,
         // but the current timestamp should be set to real value as we may use `now` in a filtered alias
-        aliasValidator.validateAliasFilter(
+        AliasValidator.validateAliasFilter(
             alias,
             filter,
             indexService.newSearchExecutionContext(0, 0, null, System::currentTimeMillis, null, emptyMap()),

+ 1 - 5
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java

@@ -112,7 +112,6 @@ public class MetadataIndexTemplateService {
 
     private static final Logger logger = LogManager.getLogger(MetadataIndexTemplateService.class);
     private final ClusterService clusterService;
-    private final AliasValidator aliasValidator;
     private final IndicesService indicesService;
     private final MetadataCreateIndexService metadataCreateIndexService;
     private final IndexScopedSettings indexScopedSettings;
@@ -124,7 +123,6 @@ public class MetadataIndexTemplateService {
     public MetadataIndexTemplateService(
         ClusterService clusterService,
         MetadataCreateIndexService metadataCreateIndexService,
-        AliasValidator aliasValidator,
         IndicesService indicesService,
         IndexScopedSettings indexScopedSettings,
         NamedXContentRegistry xContentRegistry,
@@ -132,7 +130,6 @@ public class MetadataIndexTemplateService {
         IndexSettingProviders indexSettingProviders
     ) {
         this.clusterService = clusterService;
-        this.aliasValidator = aliasValidator;
         this.indicesService = indicesService;
         this.metadataCreateIndexService = metadataCreateIndexService;
         this.indexScopedSettings = indexScopedSettings;
@@ -1406,7 +1403,6 @@ public class MetadataIndexTemplateService {
                 Collections.emptySet(),
                 MetadataIndexTemplateService.resolveAliases(stateWithIndex.metadata(), templateName),
                 stateWithIndex.metadata(),
-                new AliasValidator(),
                 // the context is only used for validation so it's fine to pass fake values for the
                 // shard id and the current timestamp
                 xContentRegistry,
@@ -1589,7 +1585,7 @@ public class MetadataIndexTemplateService {
 
         for (Alias alias : aliases) {
             // we validate the alias only partially, as we don't know yet to which index it'll get applied to
-            aliasValidator.validateAliasStandalone(alias);
+            AliasValidator.validateAliasStandalone(alias);
             if (indexPatterns.contains(alias.name())) {
                 throw new IllegalArgumentException(
                     "alias [" + alias.name() + "] cannot be the same as any pattern in [" + String.join(", ", indexPatterns) + "]"

+ 0 - 4
server/src/main/java/org/elasticsearch/node/Node.java

@@ -40,7 +40,6 @@ import org.elasticsearch.cluster.InternalClusterInfoService;
 import org.elasticsearch.cluster.NodeConnectionsService;
 import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
 import org.elasticsearch.cluster.coordination.Coordinator;
-import org.elasticsearch.cluster.metadata.AliasValidator;
 import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
 import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
 import org.elasticsearch.cluster.metadata.Metadata;
@@ -630,7 +629,6 @@ public class Node implements Closeable {
                     .flatMap(p -> p.getAdditionalIndexSettingProviders().stream())
                     .collect(Collectors.toSet())
             );
-            final AliasValidator aliasValidator = new AliasValidator();
 
             final ShardLimitValidator shardLimitValidator = new ShardLimitValidator(settings, clusterService);
             final MetadataCreateIndexService metadataCreateIndexService = new MetadataCreateIndexService(
@@ -638,7 +636,6 @@ public class Node implements Closeable {
                 clusterService,
                 indicesService,
                 clusterModule.getAllocationService(),
-                aliasValidator,
                 shardLimitValidator,
                 environment,
                 settingsModule.getIndexScopedSettings(),
@@ -914,7 +911,6 @@ public class Node implements Closeable {
                 b.bind(MetaStateService.class).toInstance(metaStateService);
                 b.bind(PersistedClusterStateService.class).toInstance(persistedClusterStateService);
                 b.bind(IndicesService.class).toInstance(indicesService);
-                b.bind(AliasValidator.class).toInstance(aliasValidator);
                 b.bind(MetadataCreateIndexService.class).toInstance(metadataCreateIndexService);
                 b.bind(MetadataCreateDataStreamService.class).toInstance(metadataCreateDataStreamService);
                 b.bind(MetadataDataStreamsService.class).toInstance(metadataDataStreamsService);

+ 7 - 8
server/src/test/java/org/elasticsearch/cluster/metadata/AliasValidatorTests.java

@@ -15,21 +15,20 @@ import static org.hamcrest.Matchers.startsWith;
 
 public class AliasValidatorTests extends ESTestCase {
     public void testValidatesAliasNames() {
-        AliasValidator validator = new AliasValidator();
-        Exception e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone(".", null));
+        Exception e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone(".", null));
         assertEquals("Invalid alias name [.]: must not be '.' or '..'", e.getMessage());
-        e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone("..", null));
+        e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone("..", null));
         assertEquals("Invalid alias name [..]: must not be '.' or '..'", e.getMessage());
-        e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone("_cat", null));
+        e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone("_cat", null));
         assertEquals("Invalid alias name [_cat]: must not start with '_', '-', or '+'", e.getMessage());
-        e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone("-cat", null));
+        e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone("-cat", null));
         assertEquals("Invalid alias name [-cat]: must not start with '_', '-', or '+'", e.getMessage());
-        e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone("+cat", null));
+        e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone("+cat", null));
         assertEquals("Invalid alias name [+cat]: must not start with '_', '-', or '+'", e.getMessage());
-        e = expectThrows(InvalidAliasNameException.class, () -> validator.validateAliasStandalone("c*t", null));
+        e = expectThrows(InvalidAliasNameException.class, () -> AliasValidator.validateAliasStandalone("c*t", null));
         assertThat(e.getMessage(), startsWith("Invalid alias name [c*t]: must not contain the following characters "));
 
         // Doesn't throw an exception because we allow upper case alias names
-        validator.validateAliasStandalone("CAT", null);
+        AliasValidator.validateAliasStandalone("CAT", null);
     }
 }

+ 0 - 9
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java

@@ -107,7 +107,6 @@ import static org.hamcrest.Matchers.startsWith;
 
 public class MetadataCreateIndexServiceTests extends ESTestCase {
 
-    private AliasValidator aliasValidator;
     private CreateIndexClusterStateUpdateRequest request;
     private SearchExecutionContext searchExecutionContext;
     private IndexNameExpressionResolver indexNameExpressionResolver;
@@ -115,7 +114,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
     @Before
     public void setupCreateIndexRequestAndAliasValidator() {
         indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), EmptySystemIndices.INSTANCE);
-        aliasValidator = new AliasValidator();
         request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
         Settings indexSettings = Settings.builder()
             .put(SETTING_VERSION_CREATED, Version.CURRENT)
@@ -571,7 +569,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
                 clusterService,
                 null,
                 null,
-                null,
                 createTestShardLimitService(randomIntBetween(1, 1000), clusterService),
                 null,
                 null,
@@ -649,7 +646,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
                 clusterService,
                 null,
                 null,
-                null,
                 createTestShardLimitService(randomIntBetween(1, 1000), clusterService),
                 null,
                 null,
@@ -743,7 +739,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
                 request.aliases(),
                 List.of(),
                 Metadata.builder().build(),
-                aliasValidator,
                 xContentRegistry(),
                 searchExecutionContext,
                 indexNameExpressionResolver::resolveDateMathExpression,
@@ -762,7 +757,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
             request.aliases(),
             List.of(),
             Metadata.builder().build(),
-            aliasValidator,
             xContentRegistry(),
             searchExecutionContext,
             indexNameExpressionResolver::resolveDateMathExpression,
@@ -797,7 +791,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
             request.aliases(),
             MetadataIndexTemplateService.resolveAliases(List.of(templateMetadata)),
             Metadata.builder().build(),
-            aliasValidator,
             xContentRegistry(),
             searchExecutionContext,
             indexNameExpressionResolver::resolveDateMathExpression,
@@ -894,7 +887,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
             request.aliases(),
             MetadataIndexTemplateService.resolveAliases(templates),
             Metadata.builder().build(),
-            aliasValidator,
             xContentRegistry(),
             searchExecutionContext,
             indexNameExpressionResolver::resolveDateMathExpression,
@@ -936,7 +928,6 @@ public class MetadataCreateIndexServiceTests extends ESTestCase {
             request.aliases(),
             MetadataIndexTemplateService.resolveAliases(templates),
             Metadata.builder().build(),
-            aliasValidator,
             xContentRegistry(),
             searchExecutionContext,
             indexNameExpressionResolver::resolveDateMathExpression,

+ 1 - 8
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexAliasesServiceTests.java

@@ -44,15 +44,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class MetadataIndexAliasesServiceTests extends ESTestCase {
-    private final AliasValidator aliasValidator = new AliasValidator();
     private final MetadataDeleteIndexService deleteIndexService = mock(MetadataDeleteIndexService.class);
-    private final MetadataIndexAliasesService service = new MetadataIndexAliasesService(
-        null,
-        null,
-        aliasValidator,
-        deleteIndexService,
-        xContentRegistry()
-    );
+    private final MetadataIndexAliasesService service = new MetadataIndexAliasesService(null, null, deleteIndexService, xContentRegistry());
 
     public MetadataIndexAliasesServiceTests() {
         // Mock any deletes so we don't need to worry about how MetadataDeleteIndexService does its job

+ 0 - 4
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

@@ -1923,7 +1923,6 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
             clusterService,
             null,
             null,
-            null,
             createTestShardLimitService(randomIntBetween(1, 1000)),
             new Environment(builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build(), null),
             IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
@@ -1936,7 +1935,6 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
         MetadataIndexTemplateService service = new MetadataIndexTemplateService(
             null,
             createIndexService,
-            new AliasValidator(),
             null,
             new IndexScopedSettings(Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS),
             xContentRegistry,
@@ -1988,7 +1986,6 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
             clusterService,
             indicesService,
             null,
-            null,
             createTestShardLimitService(randomIntBetween(1, 1000)),
             new Environment(builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build(), null),
             IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
@@ -2001,7 +1998,6 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
         return new MetadataIndexTemplateService(
             clusterService,
             createIndexService,
-            new AliasValidator(),
             indicesService,
             new IndexScopedSettings(Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS),
             xContentRegistry(),

+ 0 - 5
server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java

@@ -8,8 +8,6 @@
 
 package org.elasticsearch.indices.cluster;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.ActionListener;
@@ -48,7 +46,6 @@ import org.elasticsearch.cluster.action.shard.ShardStateAction.StartedShardEntry
 import org.elasticsearch.cluster.block.ClusterBlock;
 import org.elasticsearch.cluster.coordination.JoinTaskExecutor;
 import org.elasticsearch.cluster.coordination.NodeRemovalClusterStateTaskExecutor;
-import org.elasticsearch.cluster.metadata.AliasValidator;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -117,7 +114,6 @@ import static org.mockito.Mockito.when;
 public class ClusterStateChanges {
     private static final Settings SETTINGS = Settings.builder().put(PATH_HOME_SETTING.getKey(), "dummy").build();
 
-    private static final Logger logger = LogManager.getLogger(ClusterStateChanges.class);
     private final AllocationService allocationService;
     private final ClusterService clusterService;
     private final ShardStateAction.ShardFailedClusterStateTaskExecutor shardFailedClusterStateTaskExecutor;
@@ -252,7 +248,6 @@ public class ClusterStateChanges {
             clusterService,
             indicesService,
             allocationService,
-            new AliasValidator(),
             shardLimitValidator,
             environment,
             IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,

+ 0 - 2
server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java

@@ -100,7 +100,6 @@ import org.elasticsearch.cluster.coordination.Coordinator;
 import org.elasticsearch.cluster.coordination.ElectionStrategy;
 import org.elasticsearch.cluster.coordination.InMemoryPersistedState;
 import org.elasticsearch.cluster.coordination.MockSinglePrioritizingExecutor;
-import org.elasticsearch.cluster.metadata.AliasValidator;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -1857,7 +1856,6 @@ public class SnapshotResiliencyTests extends ESTestCase {
                     clusterService,
                     indicesService,
                     allocationService,
-                    new AliasValidator(),
                     shardLimitValidator,
                     environment,
                     indexScopedSettings,

+ 1 - 8
test/framework/src/main/java/org/elasticsearch/cluster/metadata/DataStreamTestHelper.java

@@ -433,7 +433,6 @@ public final class DataStreamTestHelper {
             clusterService,
             indicesService,
             allocationService,
-            null,
             shardLimitValidator,
             env,
             IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
@@ -443,13 +442,7 @@ public final class DataStreamTestHelper {
             false,
             new IndexSettingProviders(providers)
         );
-        MetadataIndexAliasesService indexAliasesService = new MetadataIndexAliasesService(
-            clusterService,
-            indicesService,
-            new AliasValidator(),
-            null,
-            registry
-        );
+        MetadataIndexAliasesService indexAliasesService = new MetadataIndexAliasesService(clusterService, indicesService, null, registry);
         return new MetadataRolloverService(
             testThreadPool,
             createIndexService,