diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-12-14 23:58:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 23:58:32 +0100 |
commit | 2aadcdb605af1a01d5a4908dc4522ca08fb26529 (patch) | |
tree | 30ca48676bddf9907c946541a7829a19bc3a1fa2 /config-model/src/main/java/com | |
parent | 40b64499098827b162b5d6881f2dc33ee19cc944 (diff) |
Revert "Revert "Revert "Bratseth/select 1 host by index"""
Diffstat (limited to 'config-model/src/main/java/com')
13 files changed, 51 insertions, 99 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/ApplicationConfigProducerRoot.java b/config-model/src/main/java/com/yahoo/config/model/ApplicationConfigProducerRoot.java index 912968747df..30d83a32ff9 100644 --- a/config-model/src/main/java/com/yahoo/config/model/ApplicationConfigProducerRoot.java +++ b/config-model/src/main/java/com/yahoo/config/model/ApplicationConfigProducerRoot.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; @@ -206,7 +207,7 @@ public class ApplicationConfigProducerRoot extends AbstractConfigProducer<Abstra builder.vespaVersion(vespaVersion.toSerializedForm()); for (HostResource modelHost : getHostSystem().getHosts()) { builder.hosts(new Hosts.Builder() - .name(modelHost.getHostname()) + .name(modelHost.getHostName()) .services(getServices(modelHost)) ); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java index 3b75be5167d..659d5b65a4c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java @@ -315,7 +315,7 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon * @return The hostname on which this service runs. */ public String getHostName() { - return hostResource.getHostname(); + return hostResource.getHostName(); } /** diff --git a/config-model/src/main/java/com/yahoo/vespa/model/Host.java b/config-model/src/main/java/com/yahoo/vespa/model/Host.java index 0adfe9e4bdb..e4e1e029a1a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/Host.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/Host.java @@ -67,7 +67,7 @@ public final class Host extends AbstractConfigProducer<AbstractConfigProducer<?> runsConfigServer = false; } - public String getHostname() { + public String getHostName() { return hostname; } @@ -77,7 +77,7 @@ public final class Host extends AbstractConfigProducer<AbstractConfigProducer<?> /** Returns the string representation of this Host object. */ public String toString() { - return "host '" + getHostname() + "'"; + return "host '" + getHostName() + "'"; } @Override 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 72309d4c266..5e74a2ebc8a 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,9 +7,7 @@ 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; @@ -207,7 +205,7 @@ public class HostResource implements Comparable<HostResource> { } public HostInfo getHostInfo() { - return new HostInfo(getHostname(), services.values().stream() + return new HostInfo(getHostName(), services.values().stream() .map(Service::getServiceInfo) .collect(Collectors.toSet())); } @@ -244,11 +242,11 @@ public class HostResource implements Comparable<HostResource> { @Override public String toString() { - return "host '" + host.getHostname() + "'"; + return "host '" + host.getHostName() + "'"; } - public String getHostname() { - return host.getHostname(); + public String getHostName() { + return host.getHostName(); } @Override @@ -266,43 +264,4 @@ public class HostResource implements Comparable<HostResource> { return this.host.compareTo(other.host); } - /** - * Compares by the index of the primary membership, if both hosts are members in at least one cluster at this time. - * Compare by hostname otherwise. - */ - public int comparePrimarilyByIndexTo(HostResource other) { - Optional<ClusterMembership> thisMembership = this.primaryClusterMembership(); - Optional<ClusterMembership> otherMembership = other.primaryClusterMembership(); - if (thisMembership.isPresent() && otherMembership.isPresent()) - return Integer.compare(thisMembership.get().index(), otherMembership.get().index()); - else - return this.getHostname().compareTo(other.getHostname()); - } - - /** - * 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 targetHostsSelectedByIndex) { - targetHostsSelectedByIndex = Math.min(Math.min(targetHostsSelectedByIndex, count), hosts.size()); - - List<HostResource> hostsSortedByName = new ArrayList<>(hosts); - Collections.sort(hostsSortedByName); - - List<HostResource> hostsSortedByIndex = new ArrayList<>(hosts); - hostsSortedByIndex.sort((a, b) -> a.comparePrimarilyByIndexTo(b)); - return pickHosts(hostsSortedByName, hostsSortedByIndex, count, targetHostsSelectedByIndex); - } - public static List<HostResource> pickHosts(List<HostResource> hostsSelectedByName, List<HostResource> hostsSelectedByIndex, - int count, int targetHostsSelectedByIndex) { - hostsSelectedByName = hostsSelectedByName.subList(0, Math.min(count - targetHostsSelectedByIndex, hostsSelectedByName.size())); - hostsSelectedByIndex.removeAll(hostsSelectedByName); - hostsSelectedByIndex = hostsSelectedByIndex.subList(0, Math.min(targetHostsSelectedByIndex, hostsSelectedByIndex.size())); - - List<HostResource> finalHosts = new ArrayList<>(); - finalHosts.addAll(hostsSelectedByName); - finalHosts.addAll(hostsSelectedByIndex); - return finalHosts; - } - } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java index 6ef6c208c0a..2db9b6acece 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java @@ -101,7 +101,7 @@ public class HostSystem extends AbstractConfigProducer<Host> { public HostResource getHost(String hostAlias) { HostSpec hostSpec = provisioner.allocateHost(hostAlias); for (HostResource resource : hostname2host.values()) { - if (resource.getHostname().equals(hostSpec.hostname())) { + if (resource.getHostName().equals(hostSpec.hostname())) { hostSpec.membership().ifPresent(resource::addClusterMembership); return resource; } @@ -114,8 +114,8 @@ public class HostSystem extends AbstractConfigProducer<Host> { HostResource hostResource = new HostResource(host); hostResource.setFlavor(hostSpec.flavor()); hostSpec.membership().ifPresent(hostResource::addClusterMembership); - hostname2host.put(host.getHostname(), hostResource); - log.log(DEBUG, () -> "Added new host resource for " + host.getHostname() + " with flavor " + hostResource.getFlavor()); + hostname2host.put(host.getHostName(), hostResource); + log.log(DEBUG, () -> "Added new host resource for " + host.getHostName() + " with flavor " + hostResource.getFlavor()); return hostResource; } @@ -136,16 +136,16 @@ public class HostSystem extends AbstractConfigProducer<Host> { retAllocatedHosts.put(host, spec.membership().orElse(null)); if (! host.getFlavor().isPresent()) { host.setFlavor(spec.flavor()); - log.log(DEBUG, () -> "Host resource " + host.getHostname() + " had no flavor, setting to " + spec.flavor()); + log.log(DEBUG, () -> "Host resource " + host.getHostName() + " had no flavor, setting to " + spec.flavor()); } } - retAllocatedHosts.keySet().forEach(host -> log.log(DEBUG, () -> "Allocated host " + host.getHostname() + " with flavor " + host.getFlavor())); + retAllocatedHosts.keySet().forEach(host -> log.log(DEBUG, () -> "Allocated host " + host.getHostName() + " with flavor " + host.getFlavor())); return retAllocatedHosts; } private Optional<HostResource> getExistingHost(HostSpec key) { List<HostResource> hosts = hostname2host.values().stream() - .filter(resource -> resource.getHostname().equals(key.hostname())) + .filter(resource -> resource.getHostName().equals(key.hostname())) .collect(Collectors.toList()); if (hosts.isEmpty()) { return Optional.empty(); @@ -156,12 +156,12 @@ public class HostSystem extends AbstractConfigProducer<Host> { } public void addBoundHost(HostResource host) { - hostname2host.put(host.getHostname(), host); + hostname2host.put(host.getHostName(), host); } Set<HostSpec> getHostSpecs() { return getHosts().stream() - .map(host -> new HostSpec(host.getHostname(), Collections.emptyList(), + .map(host -> new HostSpec(host.getHostName(), Collections.emptyList(), host.getFlavor(), host.primaryClusterMembership())) .collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java index 59b7388f5bb..d892d70e0de 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java @@ -1,26 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.admin; -import com.yahoo.cloud.config.SlobroksConfig; -import com.yahoo.cloud.config.ZookeepersConfig; import com.yahoo.cloud.config.log.LogdConfig; +import com.yahoo.cloud.config.ZookeepersConfig; import com.yahoo.config.model.api.ConfigServerSpec; import com.yahoo.config.model.deploy.DeployProperties; import com.yahoo.config.model.producer.AbstractConfigProducer; +import com.yahoo.cloud.config.SlobroksConfig; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Zone; -import com.yahoo.vespa.model.AbstractService; -import com.yahoo.vespa.model.ConfigProxy; -import com.yahoo.vespa.model.ConfigSentinel; -import com.yahoo.vespa.model.HostResource; -import com.yahoo.vespa.model.Logd; +import com.yahoo.vespa.model.*; import com.yahoo.vespa.model.admin.monitoring.MetricsConsumer; import com.yahoo.vespa.model.admin.monitoring.Monitoring; import com.yahoo.vespa.model.admin.monitoring.builder.Metrics; import com.yahoo.vespa.model.container.ContainerCluster; import com.yahoo.vespa.model.filedistribution.DummyFileDistributionConfigProducer; -import com.yahoo.vespa.model.filedistribution.FileDistributionConfigProducer; import com.yahoo.vespa.model.filedistribution.FileDistributionConfigProvider; +import com.yahoo.vespa.model.filedistribution.FileDistributionConfigProducer; import com.yahoo.vespa.model.filedistribution.FileDistributor; import com.yahoo.vespa.model.filedistribution.FileDistributorService; @@ -30,6 +26,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import com.yahoo.vespa.model.HostResource; + /** * This is the admin pseudo-plugin of the Vespa model, responsible for * creating all admin services. @@ -225,12 +223,12 @@ public class Admin extends AbstractConfigProducer implements Serializable { if (fileDistribution.getOptions().disableFiledistributor()) { DummyFileDistributionConfigProducer dummyFileDistributionConfigProducer = new DummyFileDistributionConfigProducer(fileDistribution, - host.getHost().getHostname(), + host.getHost().getHostName(), configProvider); fileDistribution.addFileDistributionConfigProducer(host.getHost(), dummyFileDistributionConfigProducer); } else { FileDistributorService fds = new FileDistributorService(fileDistribution, - host.getHost().getHostname(), + host.getHost().getHostName(), configProvider); fds.setHostResource(host); fds.initService(); 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 1f7c1ba676c..a7a785cea43 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,7 +19,6 @@ 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. @@ -120,11 +119,12 @@ 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 = model.getCluster().getContainers().stream() - .filter(container -> retired == container.isRetired()) - .map(Container::getHostResource) - .collect(Collectors.toList()); - return HostResource.pickHosts(hosts, count, 1); + 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())); } 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 db849d0ae50..7654fbc217b 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 @@ -328,11 +328,9 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri } private List<HostResource> drawControllerHosts(int count, StorageGroup rootGroup, Collection<ContainerModel> containers) { - List<HostResource> hostsByName = drawContentHostsRecursively(count, false, rootGroup); - List<HostResource> hostsByIndex = drawContentHostsRecursively(count, true, rootGroup); + List<HostResource> hosts = drawContentHostsRecursively(count, rootGroup); // if (hosts.size() < count) // supply with containers TODO: Currently disabled due to leading to topology change problems // hosts.addAll(drawContainerHosts(count - hosts.size(), containers, new HashSet<>(hosts))); - List<HostResource> hosts = HostResource.pickHosts(hostsByName, hostsByIndex, count, 1); if (hosts.size() % 2 == 0) // ZK clusters of even sizes are less available (even in the size=2 case) hosts = hosts.subList(0, hosts.size()-1); return hosts; @@ -359,7 +357,7 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri // have one cluster controller List<HostResource> uniqueHostsWithoutClusterController = allHosts.stream() .filter(h -> ! usedHosts.contains(h)) - .filter(h -> ! hostHasClusterController(h.getHostname(), allHosts)) + .filter(h -> ! hostHasClusterController(h.getHostName(), allHosts)) .distinct() .collect(Collectors.toList()); @@ -383,7 +381,7 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri /** Returns whether any host having the given hostname has a cluster controller */ private boolean hostHasClusterController(String hostname, List<HostResource> hosts) { for (HostResource host : hosts) { - if ( ! host.getHostname().equals(hostname)) continue; + if ( ! host.getHostName().equals(hostname)) continue; if (hasClusterController(host)) return true; @@ -405,24 +403,20 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri */ // Note: This method cannot be changed to draw different nodes without ensuring that it will draw nodes // which overlaps with previously drawn nodes as this will prevent rolling upgrade - private List<HostResource> drawContentHostsRecursively(int count, boolean byIndex, StorageGroup group) { + private List<HostResource> drawContentHostsRecursively(int count, StorageGroup group) { Set<HostResource> hosts = new HashSet<>(); if (group.getNodes().isEmpty()) { int hostsPerSubgroup = (int)Math.ceil((double)count / group.getSubgroups().size()); for (StorageGroup subgroup : group.getSubgroups()) - hosts.addAll(drawContentHostsRecursively(hostsPerSubgroup, byIndex, subgroup)); + hosts.addAll(drawContentHostsRecursively(hostsPerSubgroup, subgroup)); } else { hosts.addAll(group.getNodes().stream() - .filter(node -> ! node.isRetired()) // Avoid retired controllers to avoid surprises on expiry - .map(StorageNode::getHostResource).collect(Collectors.toList())); + .filter(node -> ! node.isRetired()) // Avoid retired controllers to avoid surprises on expiry + .map(StorageNode::getHostResource).collect(Collectors.toList())); } - List<HostResource> sortedHosts = new ArrayList<>(hosts); - if (byIndex) - sortedHosts.sort((a, b) -> (a.comparePrimarilyByIndexTo(b))); - else // by name - Collections.sort(sortedHosts); + Collections.sort(sortedHosts); sortedHosts = sortedHosts.subList(0, Math.min(count, hosts.size())); return sortedHosts; } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProvider.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProvider.java index a78eb1f74f9..33cc581c3a8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProvider.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProvider.java @@ -33,14 +33,14 @@ public class FileDistributionConfigProvider { fileDistributionOptions.getConfig(builder); builder.torrentport(FileDistributorService.BASEPORT + 1); builder.stateport(FileDistributorService.BASEPORT + 2); - builder.hostname(host.getHostname()); + builder.hostname(host.getHostName()); builder.filedbpath(FileDistribution.getDefaultFileDBPath().toString()); } public void getConfig(FiledistributorrpcConfig.Builder builder) { // If disabled config proxy should act as file distributor, so use config proxy port int port = (fileDistributionOptions.disableFiledistributor()) ? ConfigProxy.BASEPORT : FileDistributorService.BASEPORT; - builder.connectionspec("tcp/" + host.getHostname() + ":" + port); + builder.connectionspec("tcp/" + host.getHostName() + ":" + port); } public void getConfig(FilereferencesConfig.Builder builder) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java index f3aad88a446..8fcece3aa80 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java @@ -78,7 +78,7 @@ public class FileDistributor { } public Set<String> getTargetHostnames() { - return getTargetHosts().stream().map(Host::getHostname).collect(Collectors.toSet()); + return getTargetHosts().stream().map(Host::getHostName).collect(Collectors.toSet()); } /** Returns the host which is the source of the files */ @@ -94,9 +94,9 @@ public class FileDistributor { public void sendDeployedFiles(FileDistribution dbHandler) { String fileSourceHost = fileSourceHost(); for (Host host : getTargetHosts()) { - if ( ! host.getHostname().equals(fileSourceHost)) { - dbHandler.sendDeployedFiles(host.getHostname(), filesToSendToHost(host)); - dbHandler.startDownload(host.getHostname(), filesToSendToHost(host)); + if ( ! host.getHostName().equals(fileSourceHost)) { + dbHandler.sendDeployedFiles(host.getHostName(), filesToSendToHost(host)); + dbHandler.startDownload(host.getHostName(), filesToSendToHost(host)); } } dbHandler.sendDeployedFiles(fileSourceHost, allFilesToSend()); @@ -108,5 +108,5 @@ public class FileDistributor { public void reloadDeployFileDistributor(FileDistribution dbHandler) { dbHandler.reloadDeployFileDistributor(); } - + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/Dispatch.java b/config-model/src/main/java/com/yahoo/vespa/model/search/Dispatch.java index 87146447dd1..789c5562d9c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/Dispatch.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/Dispatch.java @@ -96,7 +96,7 @@ public class Dispatch extends AbstractService implements SearchInterface, public int getMaxThreads() { return 500*2; } public String getHostname() { - return getHost().getHostname(); + return getHost().getHostName(); } @Override @@ -105,7 +105,7 @@ public class Dispatch extends AbstractService implements SearchInterface, } public String getDispatcherConnectSpec() { - return "tcp/" + getHost().getHostname() + ":" + getDispatchPort(); + return "tcp/" + getHost().getHostName() + ":" + getDispatchPort(); } public DispatchGroup getDispatchGroup() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/IndexedSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/search/IndexedSearchCluster.java index 4925b88e608..8d7d289b99f 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/IndexedSearchCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/IndexedSearchCluster.java @@ -200,7 +200,7 @@ public abstract class IndexedSearchCluster extends SearchCluster String containerClusterName = containerCluster.getName(); log.log(LogLevel.DEBUG, "Adding tld with index " + containerIndex + " for content cluster " + this.getClusterName() + ", container cluster " + containerClusterName + " (container id " + containerSubId + - ") on host " + container.getHostResource().getHostname()); + ") on host " + container.getHostResource().getHostName()); rootDispatch.addDispatcher(createTld(tldParent, container.getHostResource(), containerClusterName, containerIndex)); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/SearchNode.java b/config-model/src/main/java/com/yahoo/vespa/model/search/SearchNode.java index 8420a1f4b91..819d5904c25 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/SearchNode.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/SearchNode.java @@ -183,7 +183,7 @@ public class SearchNode extends AbstractService implements * @return The connection string. */ public String getDispatcherConnectSpec() { - return "tcp/" + getHost().getHostname() + ":" + getDispatchPort(); + return "tcp/" + getHost().getHostName() + ":" + getDispatchPort(); } public int getDispatchPort() { @@ -247,7 +247,7 @@ public class SearchNode extends AbstractService implements partition(getNodeSpec().partitionId()). clustername(getClusterName()). basedir(getBaseDir()). - tlsspec("tcp/" + getHost().getHostname() + ":" + getTransactionLogServer().getTlsPort()). + tlsspec("tcp/" + getHost().getHostName() + ":" + getTransactionLogServer().getTlsPort()). tlsconfigid(getConfigId()). slobrokconfigid(getClusterConfigId()). routingconfigid(getClusterConfigId()). |