diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-01-05 14:50:46 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-01-05 14:50:46 +0100 |
commit | be5ea0ad39c15c13fb85a70d9990165499a92896 (patch) | |
tree | e92462f5f130fa68f40175ec7d987c661dd9ae0f /vespaclient-core/src/main/java | |
parent | 6382cb8513ab166e4e4184e0ddebd60f97fb6bb3 (diff) |
Revert "Revert "Jonmv/remove storage policy""
This reverts commit 75b2e4c11ea6463c335f1c77dab3fdb5493e5600.
Diffstat (limited to 'vespaclient-core/src/main/java')
-rw-r--r-- | vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterDef.java | 12 | ||||
-rw-r--r-- | vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java | 26 |
2 files changed, 15 insertions, 23 deletions
diff --git a/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterDef.java b/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterDef.java index 95bd9cf1cb5..f3b8c189fc5 100644 --- a/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterDef.java +++ b/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterDef.java @@ -2,14 +2,8 @@ package com.yahoo.vespaclient; public class ClusterDef { - public ClusterDef(String name, String configId) { - this.name = name; - this.configId = configId; - } - - String name; - String configId; - + private final String name; + public ClusterDef(String name) { this.name = name; } public String getName() { return name; } - public String getConfigId() { return configId; } + public String getRoute() { return name + "-direct"; } } diff --git a/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java b/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java index 4525ffcae39..2c3a0b72ed5 100644 --- a/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java +++ b/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java @@ -4,40 +4,38 @@ package com.yahoo.vespaclient; import com.yahoo.cloud.config.ClusterListConfig; import com.yahoo.config.subscription.ConfigGetter; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** A list of content clusters, either obtained from a list, a given config or by self-subscribing */ public class ClusterList { - List<ClusterDef> contentClusters = new ArrayList<>(); + private final List<ClusterDef> contentClusters; public ClusterList() { - this(new ArrayList<>()); + this(List.of()); } public ClusterList(List<ClusterDef> contentClusters) { - this.contentClusters = contentClusters; + this.contentClusters = List.copyOf(contentClusters); } public ClusterList(String configId) { - configure(new ConfigGetter<>(ClusterListConfig.class).getConfig(configId)); + this(new ConfigGetter<>(ClusterListConfig.class).getConfig(configId)); } public ClusterList(ClusterListConfig config) { - configure(config); + this(parse(config)); } - private void configure(ClusterListConfig config) { - contentClusters.clear(); // TODO: Create a new - for (int i = 0; i < config.storage().size(); i++) - contentClusters.add(new ClusterDef(config.storage(i).name(), config.storage(i).configid())); + public List<ClusterDef> getStorageClusters() { + return contentClusters; } - /** Returns a reference to the mutable list */ - public List<ClusterDef> getStorageClusters() { - return contentClusters; // TODO: Use immutable list + private static List<ClusterDef> parse(ClusterListConfig config) { + return config.storage().stream() + .map(storage -> new ClusterDef(storage.name())) + .collect(Collectors.toUnmodifiableList()); } } |