Search in sources :

Example 1 with HostSpec

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;
}
Also used : ArrayList(java.util.ArrayList) HostSpec(com.yahoo.config.provision.HostSpec)

Example 2 with HostSpec

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;
}
Also used : HostSpec(com.yahoo.config.provision.HostSpec)

Example 3 with 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;
}
Also used : ClusterMembership(com.yahoo.config.provision.ClusterMembership) HostSpec(com.yahoo.config.provision.HostSpec)

Example 4 with HostSpec

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;
}
Also used : ClusterMembership(com.yahoo.config.provision.ClusterMembership) HostSpec(com.yahoo.config.provision.HostSpec) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with HostSpec

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"));
}
Also used : HostSpec(com.yahoo.config.provision.HostSpec) Test(org.junit.Test)

Aggregations

HostSpec (com.yahoo.config.provision.HostSpec)33 Test (org.junit.Test)18 Zone (com.yahoo.config.provision.Zone)14 ApplicationId (com.yahoo.config.provision.ApplicationId)13 Node (com.yahoo.vespa.hosted.provision.Node)12 ClusterSpec (com.yahoo.config.provision.ClusterSpec)10 HashSet (java.util.HashSet)7 NestedTransaction (com.yahoo.transaction.NestedTransaction)6 Version (com.yahoo.component.Version)5 Capacity (com.yahoo.config.provision.Capacity)5 Flavor (com.yahoo.config.provision.Flavor)5 List (java.util.List)5 ClusterMembership (com.yahoo.config.provision.ClusterMembership)4 Environment (com.yahoo.config.provision.Environment)4 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)4 Collections (java.util.Collections)4 RegionName (com.yahoo.config.provision.RegionName)3 NodeList (com.yahoo.vespa.hosted.provision.NodeList)3 JobControl (com.yahoo.vespa.hosted.provision.maintenance.JobControl)3 Agent (com.yahoo.vespa.hosted.provision.node.Agent)3