diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-03-17 12:37:31 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-03-17 12:37:31 +0100 |
commit | 195d5f4848e3f85368f7279e4b3956d8f2b740b2 (patch) | |
tree | 01898f91ee784587fbf12ab6b28b2b545b216e6e /config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java | |
parent | d04a6cbda7d2cfcbf649039b2f89d2769546dc5e (diff) |
Use two builder methods, request() and specification()
request() should be used when requesting a cluster, same as old
static method called request(). specification() should be used when
creating a clsuter spec for an existing cluster, same as old
static method from(). specification() will throw an exception
if some required fields are not set
Diffstat (limited to 'config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java')
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java index 45a276a83b2..70d0a7a1929 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java @@ -100,14 +100,21 @@ public final class ClusterSpec { return new ClusterSpec(type, id, Optional.of(groupId), vespaVersion, exclusive, combinedId, dockerImageRepo); } - public static Builder builder(Type type, Id id) { - return new Builder(type, id); + /** Creates a ClusterSpec when requesting a cluster */ + public static Builder request(Type type, Id id) { + return new Builder(type, id, false); + } + + /** Creates a ClusterSpec for an existing cluster, group id and vespa version needs to be set */ + public static Builder specification(Type type, Id id) { + return new Builder(type, id, true); } public static class Builder { private final Type type; private final Id id; + private final boolean specification; private Optional<Group> groupId = Optional.empty(); private Optional<String> dockerImageRepo = Optional.empty(); @@ -115,13 +122,17 @@ public final class ClusterSpec { private boolean exclusive = false; private Optional<Id> combinedId = Optional.empty(); - - Builder(Type type, Id id) { + Builder(Type type, Id id, boolean specification) { this.type = type; this.id = id; + this.specification = specification; } public ClusterSpec build() { + if (specification) { + if (groupId.isEmpty()) throw new IllegalArgumentException("Creating a ClusterSpec with specification() requires groupId to be set"); + if (vespaVersion == null) throw new IllegalArgumentException("Creating a ClusterSpec with specification() requires vespaVersion to be set"); + } return new ClusterSpec(type, id, groupId, vespaVersion, exclusive, combinedId, dockerImageRepo); } |