From ce1185fc0558f2fe586e7f39e72c72dfaa68f56c Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Tue, 16 Apr 2019 12:40:23 +0200 Subject: Fill Selection --- .../java/com/yahoo/vespa/tenant/cd/Selection.java | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) 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); + } + } -- cgit v1.2.3