summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-04-16 12:40:23 +0200
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-06 13:03:28 +0200
commitce1185fc0558f2fe586e7f39e72c72dfaa68f56c (patch)
tree37b98b4cb472fd925e6221dc6304c3db74839815 /tenant-cd
parent6a0dda8a443641710e95b845b9c54f7a5d7b9980 (diff)
Fill Selection
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/Selection.java50
1 files changed, 49 insertions, 1 deletions
diff --git a/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/Selection.java b/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/Selection.java
index b06ac67950a..2c405c4ceec 100644
--- a/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/Selection.java
+++ b/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/Selection.java
@@ -1,10 +1,58 @@
package com.yahoo.vespa.tenant.cd;
/**
- * A document selection expression, used for streaming search and visit against a {@link Endpoint}.
+ * A document selection expression, type and cluster, which can be used to visit an {@link Endpoint}.
*
* @author jonmv
*/
public class Selection {
+ private final String selection;
+ private final String namespace;
+ private final String type;
+ private final String group;
+ private final String cluster;
+ private final int concurrency;
+
+ public Selection(String selection, String namespace, String type, String group, String cluster, int concurrency) {
+ this.selection = selection;
+ this.namespace = namespace;
+ this.type = type;
+ this.group = group;
+ this.cluster = cluster;
+ this.concurrency = concurrency;
+ }
+
+ /** Returns a new selection which will visit documents in the given cluster. */
+ public static Selection in(String cluster) {
+ if (cluster.isBlank()) throw new IllegalArgumentException("Cluster name can not be blank.");
+ return new Selection(null, null, null, cluster, null, 1);
+ }
+
+ /** Returns a new selection which will visit documents in the given namespace and of the given type. */
+ public static Selection of(String namespace, String type) {
+ if (namespace.isBlank()) throw new IllegalArgumentException("Namespace can not be blank.");
+ if (type.isBlank()) throw new IllegalArgumentException("Document type can not be blank.");
+ return new Selection(null, namespace, type, null, null, 1);
+ }
+
+ /** Returns a copy of this with the given selection criterion set. */
+ public Selection matching(String selection) {
+ if (selection.isBlank()) throw new IllegalArgumentException("Selection can not be blank.");
+ return new Selection(selection, namespace, type, cluster, group, concurrency);
+ }
+
+ /** Returns a copy of this selection, with the group set to the specified value. Requires namespace and type to be set. */
+ public Selection limitedTo(String group) {
+ if (namespace == null || type == null) throw new IllegalArgumentException("Namespace and type must be specified to set group.");
+ if (group.isBlank()) throw new IllegalArgumentException("Group name can not be blank.");
+ return new Selection(selection, namespace, type, cluster, group, concurrency);
+ }
+
+ /** Returns a copy of this, with concurrency set to the given positive value. */
+ public Selection concurrently(int concurrency) {
+ if (concurrency < 1) throw new IllegalArgumentException("Concurrency must be a positive integer.");
+ return new Selection(selection, namespace, type, cluster, group, concurrency);
+ }
+
}