summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-11-22 12:42:17 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2017-11-22 12:42:17 +0100
commit0bb6d1edd6b505fb57ba47f80d49918eecdb47df (patch)
treeac908afa889eb21c10080cb671c8c9f6d45b1b2d /config-model
parent810fb8b89d2823bad2bccb418fa2c296f7af5f9c (diff)
Prepare to select slobroks by index (no change)
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/HostResource.java25
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV4Builder.java12
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java19
3 files changed, 32 insertions, 24 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java b/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java
index 5e74a2ebc8a..bec20daf120 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java
@@ -7,7 +7,9 @@ import com.yahoo.config.provision.Flavor;
import javax.annotation.Nullable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -264,4 +266,27 @@ public class HostResource implements Comparable<HostResource> {
return this.host.compareTo(other.host);
}
+ /**
+ * Picks hosts by some mixture of host name and index
+ * (where the mix of one or the other is decided by the last parameter).
+ */
+ public static List<HostResource> pickHosts(Collection<HostResource> hosts, int count, int targetHostsSortedByIndex) {
+ targetHostsSortedByIndex = Math.min(Math.min(targetHostsSortedByIndex, count), hosts.size());
+
+ List<HostResource> hostsSortedByName = new ArrayList<>(hosts);
+ Collections.sort(hostsSortedByName);
+
+ List<HostResource> hostsSortedByIndex = new ArrayList<>(hosts);
+ hostsSortedByIndex.sort(Comparator.comparingInt(host -> host.primaryClusterMembership().get().index()));
+
+ hostsSortedByName = hostsSortedByName.subList(0, Math.min(count - targetHostsSortedByIndex, hostsSortedByName.size()));
+ hostsSortedByIndex.removeAll(hostsSortedByName);
+ hostsSortedByIndex = hostsSortedByIndex.subList(0, Math.min(targetHostsSortedByIndex, hostsSortedByIndex.size()));
+
+ List<HostResource> finalHosts = new ArrayList<>();
+ finalHosts.addAll(hostsSortedByName);
+ finalHosts.addAll(hostsSortedByIndex);
+ return finalHosts;
+ }
+
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV4Builder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV4Builder.java
index cb8ec205395..fa6fa805f1e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV4Builder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminV4Builder.java
@@ -19,6 +19,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Builds the admin model from a version 4 XML tag, or as a default when an admin 3 tag or no admin tag is used.
@@ -117,12 +118,11 @@ public class DomAdminV4Builder extends DomAdminBuilderBase {
/** Returns the count first containers in the current model having isRetired set to the given value */
private List<HostResource> sortedContainerHostsFrom(ContainerModel model, int count, boolean retired) {
- List<HostResource> hosts = new ArrayList<>();
- for (Container container : model.getCluster().getContainers())
- if (retired == container.isRetired())
- hosts.add(container.getHostResource());
- Collections.sort(hosts);
- return hosts.subList(0, Math.min(count, hosts.size()));
+ List<HostResource> hosts = model.getCluster().getContainers().stream()
+ .filter(container -> retired == container.isRetired())
+ .map(Container::getHostResource)
+ .collect(Collectors.toList());
+ return HostResource.pickHosts(hosts, count, 0);
}
private void createLogserver(Admin admin, Collection<HostResource> hosts) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
index 8c2178bd581..376b7ea595a 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java
@@ -416,24 +416,7 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri
.map(StorageNode::getHostResource).collect(Collectors.toList()));
}
- int targetHostsSortedByIndex = 0;
-
- targetHostsSortedByIndex = Math.min(Math.min(targetHostsSortedByIndex, count), hosts.size());
-
- List<HostResource> hostsSortedByName = new ArrayList<>(hosts);
- Collections.sort(hostsSortedByName);
-
- List<HostResource> hostsSortedByIndex = new ArrayList<>(hosts);
- hostsSortedByIndex.sort(Comparator.comparingInt(host -> host.primaryClusterMembership().get().index()));
-
- hostsSortedByName = hostsSortedByName.subList(0, Math.min(count - targetHostsSortedByIndex, hostsSortedByName.size()));
- hostsSortedByIndex.removeAll(hostsSortedByName);
- hostsSortedByIndex = hostsSortedByIndex.subList(0, Math.min(targetHostsSortedByIndex, hostsSortedByIndex.size()));
-
- List<HostResource> finalHosts = new ArrayList<>();
- finalHosts.addAll(hostsSortedByName);
- finalHosts.addAll(hostsSortedByIndex);
- return finalHosts;
+ return HostResource.pickHosts(hosts, count, 0);
}
private ContainerCluster createClusterControllers(AbstractConfigProducer parent, Collection<HostResource> hosts, String name, boolean multitenant) {