-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Reuse SourceDestValidator for data frame analytics #50841
Merged
dimitris-athanasiou
merged 3 commits into
elastic:master
from
dimitris-athanasiou:reuse-source-dest-validator-for-df-analytics
Jan 10, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ public final class SourceDestValidator { | |
|
||
// messages | ||
public static final String SOURCE_INDEX_MISSING = "Source index [{0}] does not exist"; | ||
public static final String SOURCE_LOWERCASE = "Source index [{0}] must be lowercase"; | ||
public static final String DEST_IN_SOURCE = "Destination index [{0}] is included in source expression [{1}]"; | ||
public static final String DEST_LOWERCASE = "Destination index [{0}] must be lowercase"; | ||
public static final String NEEDS_REMOTE_CLUSTER_SEARCH = "Source index is configured with a remote index pattern(s) [{0}]" | ||
|
@@ -59,6 +58,7 @@ public final class SourceDestValidator { | |
+ "alias [{0}], at least a [{1}] license is required, found license [{2}]"; | ||
public static final String REMOTE_CLUSTER_LICENSE_INACTIVE = "License check failed for remote cluster " | ||
+ "alias [{0}], license is not active"; | ||
public static final String REMOTE_SOURCE_INDICES_NOT_SUPPORTED = "remote source indices are not supported"; | ||
|
||
private final IndexNameExpressionResolver indexNameExpressionResolver; | ||
private final RemoteClusterService remoteClusterService; | ||
|
@@ -216,7 +216,7 @@ private void resolveLocalAndRemoteSource() { | |
} | ||
} | ||
|
||
interface SourceDestValidation { | ||
public interface SourceDestValidation { | ||
void validate(Context context, ActionListener<Context> listener); | ||
} | ||
|
||
|
@@ -228,18 +228,7 @@ interface SourceDestValidation { | |
public static final SourceDestValidation REMOTE_SOURCE_VALIDATION = new RemoteSourceEnabledAndRemoteLicenseValidation(); | ||
public static final SourceDestValidation DESTINATION_IN_SOURCE_VALIDATION = new DestinationInSourceValidation(); | ||
public static final SourceDestValidation DESTINATION_SINGLE_INDEX_VALIDATION = new DestinationSingleIndexValidation(); | ||
|
||
// set of default validation collections, if you want to automatically benefit from new validators, use those | ||
public static final List<SourceDestValidation> PREVIEW_VALIDATIONS = Arrays.asList(SOURCE_MISSING_VALIDATION, REMOTE_SOURCE_VALIDATION); | ||
|
||
public static final List<SourceDestValidation> ALL_VALIDATIONS = Arrays.asList( | ||
SOURCE_MISSING_VALIDATION, | ||
REMOTE_SOURCE_VALIDATION, | ||
DESTINATION_IN_SOURCE_VALIDATION, | ||
DESTINATION_SINGLE_INDEX_VALIDATION | ||
); | ||
|
||
public static final List<SourceDestValidation> NON_DEFERABLE_VALIDATIONS = Arrays.asList(DESTINATION_SINGLE_INDEX_VALIDATION); | ||
public static final SourceDestValidation REMOTE_SOURCE_NOT_SUPPORTED_VALIDATION = new RemoteSourceNotSupportedValidation(); | ||
|
||
/** | ||
* Create a new Source Dest Validator | ||
|
@@ -299,10 +288,11 @@ public void validate( | |
} | ||
}, listener::onFailure); | ||
|
||
// We traverse the validations in reverse order as we chain the listeners from back to front | ||
for (int i = validations.size() - 1; i >= 0; i--) { | ||
final SourceDestValidation validation = validations.get(i); | ||
SourceDestValidation validation = validations.get(i); | ||
final ActionListener<Context> previousValidationListener = validationListener; | ||
validationListener = ActionListener.wrap(c -> { validation.validate(c, previousValidationListener); }, listener::onFailure); | ||
validationListener = ActionListener.wrap(c -> validation.validate(c, previousValidationListener), listener::onFailure); | ||
} | ||
|
||
validationListener.onResponse(context); | ||
|
@@ -427,13 +417,13 @@ public void validate(Context context, ActionListener<Context> listener) { | |
return; | ||
} | ||
|
||
if (context.resolvedSource.contains(destIndex)) { | ||
if (context.resolveSource().contains(destIndex)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice spot! |
||
context.addValidationError(DEST_IN_SOURCE, destIndex, Strings.arrayToCommaDelimitedString(context.getSource())); | ||
listener.onResponse(context); | ||
return; | ||
} | ||
|
||
if (context.resolvedSource.contains(context.resolveDest())) { | ||
if (context.resolveSource().contains(context.resolveDest())) { | ||
context.addValidationError( | ||
DEST_IN_SOURCE, | ||
context.resolveDest(), | ||
|
@@ -454,6 +444,17 @@ public void validate(Context context, ActionListener<Context> listener) { | |
} | ||
} | ||
|
||
static class RemoteSourceNotSupportedValidation implements SourceDestValidation { | ||
|
||
@Override | ||
public void validate(Context context, ActionListener<Context> listener) { | ||
if (context.resolveRemoteSource().isEmpty() == false) { | ||
context.addValidationError(REMOTE_SOURCE_INDICES_NOT_SUPPORTED); | ||
} | ||
listener.onResponse(context); | ||
} | ||
} | ||
|
||
private static String getMessage(String message, Object... args) { | ||
return new MessageFormat(message, Locale.ROOT).format(args); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unused.