@@ -49,7 +49,6 @@ public final class SourceDestValidator {
4949
5050 // messages
5151 public static final String SOURCE_INDEX_MISSING = "Source index [{0}] does not exist" ;
52- public static final String SOURCE_LOWERCASE = "Source index [{0}] must be lowercase" ;
5352 public static final String DEST_IN_SOURCE = "Destination index [{0}] is included in source expression [{1}]" ;
5453 public static final String DEST_LOWERCASE = "Destination index [{0}] must be lowercase" ;
5554 public static final String NEEDS_REMOTE_CLUSTER_SEARCH = "Source index is configured with a remote index pattern(s) [{0}]"
@@ -62,6 +61,7 @@ public final class SourceDestValidator {
6261 + "alias [{0}], at least a [{1}] license is required, found license [{2}]" ;
6362 public static final String REMOTE_CLUSTER_LICENSE_INACTIVE = "License check failed for remote cluster "
6463 + "alias [{0}], license is not active" ;
64+ public static final String REMOTE_SOURCE_INDICES_NOT_SUPPORTED = "remote source indices are not supported" ;
6565
6666 // workaround for 7.x: remoteClusterAliases does not throw
6767 private static final ClusterNameExpressionResolver clusterNameExpressionResolver = new ClusterNameExpressionResolver ();
@@ -222,7 +222,7 @@ private void resolveLocalAndRemoteSource() {
222222 }
223223 }
224224
225- interface SourceDestValidation {
225+ public interface SourceDestValidation {
226226 void validate (Context context , ActionListener <Context > listener );
227227 }
228228
@@ -234,18 +234,7 @@ interface SourceDestValidation {
234234 public static final SourceDestValidation REMOTE_SOURCE_VALIDATION = new RemoteSourceEnabledAndRemoteLicenseValidation ();
235235 public static final SourceDestValidation DESTINATION_IN_SOURCE_VALIDATION = new DestinationInSourceValidation ();
236236 public static final SourceDestValidation DESTINATION_SINGLE_INDEX_VALIDATION = new DestinationSingleIndexValidation ();
237-
238- // set of default validation collections, if you want to automatically benefit from new validators, use those
239- public static final List <SourceDestValidation > PREVIEW_VALIDATIONS = Arrays .asList (SOURCE_MISSING_VALIDATION , REMOTE_SOURCE_VALIDATION );
240-
241- public static final List <SourceDestValidation > ALL_VALIDATIONS = Arrays .asList (
242- SOURCE_MISSING_VALIDATION ,
243- REMOTE_SOURCE_VALIDATION ,
244- DESTINATION_IN_SOURCE_VALIDATION ,
245- DESTINATION_SINGLE_INDEX_VALIDATION
246- );
247-
248- public static final List <SourceDestValidation > NON_DEFERABLE_VALIDATIONS = Arrays .asList (DESTINATION_SINGLE_INDEX_VALIDATION );
237+ public static final SourceDestValidation REMOTE_SOURCE_NOT_SUPPORTED_VALIDATION = new RemoteSourceNotSupportedValidation ();
249238
250239 /**
251240 * Create a new Source Dest Validator
@@ -305,10 +294,11 @@ public void validate(
305294 }
306295 }, listener ::onFailure );
307296
297+ // We traverse the validations in reverse order as we chain the listeners from back to front
308298 for (int i = validations .size () - 1 ; i >= 0 ; i --) {
309- final SourceDestValidation validation = validations .get (i );
299+ SourceDestValidation validation = validations .get (i );
310300 final ActionListener <Context > previousValidationListener = validationListener ;
311- validationListener = ActionListener .wrap (c -> { validation .validate (c , previousValidationListener ); } , listener ::onFailure );
301+ validationListener = ActionListener .wrap (c -> validation .validate (c , previousValidationListener ), listener ::onFailure );
312302 }
313303
314304 validationListener .onResponse (context );
@@ -433,13 +423,13 @@ public void validate(Context context, ActionListener<Context> listener) {
433423 return ;
434424 }
435425
436- if (context .resolvedSource .contains (destIndex )) {
426+ if (context .resolveSource () .contains (destIndex )) {
437427 context .addValidationError (DEST_IN_SOURCE , destIndex , Strings .arrayToCommaDelimitedString (context .getSource ()));
438428 listener .onResponse (context );
439429 return ;
440430 }
441431
442- if (context .resolvedSource .contains (context .resolveDest ())) {
432+ if (context .resolveSource () .contains (context .resolveDest ())) {
443433 context .addValidationError (
444434 DEST_IN_SOURCE ,
445435 context .resolveDest (),
@@ -460,6 +450,17 @@ public void validate(Context context, ActionListener<Context> listener) {
460450 }
461451 }
462452
453+ static class RemoteSourceNotSupportedValidation implements SourceDestValidation {
454+
455+ @ Override
456+ public void validate (Context context , ActionListener <Context > listener ) {
457+ if (context .resolveRemoteSource ().isEmpty () == false ) {
458+ context .addValidationError (REMOTE_SOURCE_INDICES_NOT_SUPPORTED );
459+ }
460+ listener .onResponse (context );
461+ }
462+ }
463+
463464 private static String getMessage (String message , Object ... args ) {
464465 return new MessageFormat (message , Locale .ROOT ).format (args );
465466 }
0 commit comments