Skip to content
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

Wildcard cluster names for cross cluster search #23985

Merged
merged 10 commits into from
Apr 11, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
* {@link RemoteClusterService#REMOTE_CONNECTIONS_PER_CLUSTER} until either all eligible nodes are exhausted or the maximum number of
* connections per cluster has been reached.
*/
public final class RemoteClusterConnection extends AbstractComponent implements TransportConnectionListener, Closeable {
final class RemoteClusterConnection extends AbstractComponent implements TransportConnectionListener, Closeable {

private final TransportService transportService;
private final ConnectionProfile remoteProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Map<String, List<String>> groupClusterIndices(String[] requestIndices, Predicate
if (i >= 0) {
String remoteClusterName = index.substring(0, i);
List<String> clusters = clusterNameResolver.resolveClusterNames(remoteClusterNames, remoteClusterName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we maybe return an emtpy list instead of null, I think we don't necessarily need the null invariant?

if (clusters != null) {
if (clusters.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this should be cluster.isEmpty() == false?

if (indexExists.test(index)) {
// we use : as a separator for remote clusters. might conflict if there is an index that is actually named
// remote_cluster_alias:index_name - for this case we fail the request. the user can easily change the cluster alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,33 @@
import java.util.Set;
import java.util.stream.Collectors;

public class ClusterNameExpressionResolver extends AbstractComponent {
/**
* Resolves cluster names from an expression. The expression must be the exact match of a cluster
* name or must be a wildcard expression.
*/
public final class ClusterNameExpressionResolver extends AbstractComponent {

private final WildcardExpressionResolver wildcardResolver = new WildcardExpressionResolver();

public ClusterNameExpressionResolver(Settings settings) {
super(settings);
new WildcardExpressionResolver();
}

/**
* Resolves the provided cluster expression to matching cluster names. This method only
* supports exact or wildcard matches.
*
* @param remoteClusters the aliases for remote clusters
* @param clusterExpression the expressions that can be resolved to cluster names.
* @return the resolved cluster aliases.
*/
public List<String> resolveClusterNames(Set<String> remoteClusters, String clusterExpression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please add some javadocs what this can resolve etc?

if (remoteClusters.contains(clusterExpression)) {
return Collections.singletonList(clusterExpression);
} else if (Regex.isSimpleMatchPattern(clusterExpression)) {
return wildcardResolver.resolve(remoteClusters, clusterExpression);
} else {
return null;
return Collections.emptyList();
}
}

Expand All @@ -57,7 +68,7 @@ private List<String> resolve(Set<String> remoteClusters, String clusterExpressio

Set<String> matches = matches(remoteClusters, clusterExpression);
if (matches.isEmpty()) {
return null;
return Collections.emptyList();
} else {
return new ArrayList<>(matches);
}
Expand Down