use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.
the class InMemoryProvisioner method prepare.
@Override
public List<HostSpec> prepare(ClusterSpec cluster, Capacity requestedCapacity, int groups, ProvisionLogger logger) {
if (cluster.group().isPresent() && groups > 1)
throw new IllegalArgumentException("Cannot both be specifying a group and ask for groups to be created");
if (requestedCapacity.nodeCount() % groups != 0)
throw new IllegalArgumentException("Requested " + requestedCapacity.nodeCount() + " nodes in " + groups + " groups, but the node count is not divisible into this number of groups");
int capacity = failOnOutOfCapacity || requestedCapacity.isRequired() ? requestedCapacity.nodeCount() : Math.min(requestedCapacity.nodeCount(), freeNodes.get("default").size() + totalAllocatedTo(cluster));
if (groups > capacity)
groups = capacity;
String flavor = requestedCapacity.flavor().orElse("default");
List<HostSpec> allocation = new ArrayList<>();
if (groups == 1) {
allocation.addAll(allocateHostGroup(cluster.with(Optional.of(ClusterSpec.Group.from(0))), flavor, capacity, startIndexForClusters));
} else {
for (int i = 0; i < groups; i++) {
allocation.addAll(allocateHostGroup(cluster.with(Optional.of(ClusterSpec.Group.from(i))), flavor, capacity / groups, allocation.size()));
}
}
for (ListIterator<HostSpec> i = allocation.listIterator(); i.hasNext(); ) {
HostSpec host = i.next();
if (retiredHostNames.contains(host.hostname()))
i.set(retire(host));
}
return allocation;
}
use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.
the class InMemoryProvisioner method allocateHost.
@Override
public HostSpec allocateHost(String alias) {
if (legacyMapping.containsKey(alias))
return legacyMapping.get(alias);
List<Host> defaultHosts = freeNodes.get("default");
if (defaultHosts.isEmpty())
throw new IllegalArgumentException("No more hosts of default flavor available");
Host newHost = freeNodes.removeValue("default", 0);
HostSpec hostSpec = new HostSpec(newHost.hostname(), newHost.aliases(), newHost.flavor(), Optional.empty());
legacyMapping.put(alias, hostSpec);
return hostSpec;
}
use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.
the class InMemoryProvisioner method allocateHostGroup.
private List<HostSpec> allocateHostGroup(ClusterSpec clusterGroup, String flavor, int nodesInGroup, int startIndex) {
List<HostSpec> allocation = allocations.getOrDefault(clusterGroup, new ArrayList<>());
allocations.put(clusterGroup, allocation);
int nextIndex = nextIndexInCluster.getOrDefault(new Pair<>(clusterGroup.type(), clusterGroup.id()), startIndex);
while (allocation.size() < nodesInGroup) {
if (freeNodes.get(flavor).isEmpty())
throw new IllegalArgumentException("Insufficient capacity of flavor '" + flavor + "'");
Host newHost = freeNodes.removeValue(flavor, 0);
ClusterMembership membership = ClusterMembership.from(clusterGroup, nextIndex++);
allocation.add(new HostSpec(newHost.hostname(), newHost.aliases(), newHost.flavor(), Optional.of(membership)));
}
nextIndexInCluster.put(new Pair<>(clusterGroup.type(), clusterGroup.id()), nextIndex);
while (allocation.size() > nodesInGroup) allocation.remove(0);
return allocation;
}
use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.
the class HostSystem method allocateHosts.
public Map<HostResource, ClusterMembership> allocateHosts(ClusterSpec cluster, Capacity capacity, int groups, DeployLogger logger) {
List<HostSpec> allocatedHosts = provisioner.prepare(cluster, capacity, groups, new ProvisionDeployLogger(logger));
// TODO: Even if HostResource owns a set of memberships, we need to return a map because the caller needs the current membership.
Map<HostResource, ClusterMembership> retAllocatedHosts = new LinkedHashMap<>();
for (HostSpec spec : allocatedHosts) {
// This is needed for single node host provisioner to work in unit tests for hosted vespa applications.
HostResource host = getExistingHost(spec).orElseGet(() -> addNewHost(spec));
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());
}
}
retAllocatedHosts.keySet().forEach(host -> log.log(DEBUG, () -> "Allocated host " + host.getHostname() + " with flavor " + host.getFlavor()));
return retAllocatedHosts;
}
use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.
the class HostsXmlProvisionerTest method require_singlenode_HostAlias_is_used_if_hosts_xml.
@Test
public void require_singlenode_HostAlias_is_used_if_hosts_xml() {
String servicesXml = "<jdisc id='default' version='1.0' />";
HostsXmlProvisioner hostProvisioner = createProvisioner(oneHost);
HostSpec hostSpec = hostProvisioner.allocateHost(Container.SINGLENODE_CONTAINER_SERVICESPEC);
assertThat(hostSpec.hostname(), is("test1.yahoo.com"));
}
Aggregations