Search in sources :

Example 1 with ClusterMembership

use of com.yahoo.config.provision.ClusterMembership 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 2 with ClusterMembership

use of com.yahoo.config.provision.ClusterMembership 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 3 with ClusterMembership

use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.

the class ContainerModelBuilder method createNodesFromHosts.

private List<Container> createNodesFromHosts(Map<HostResource, ClusterMembership> hosts, ContainerCluster cluster) {
    List<Container> nodes = new ArrayList<>();
    for (Map.Entry<HostResource, ClusterMembership> entry : hosts.entrySet()) {
        String id = "container." + entry.getValue().index();
        Container container = new Container(cluster, id, entry.getValue().retired(), entry.getValue().index());
        container.setHostResource(entry.getKey());
        container.initService();
        nodes.add(container);
    }
    return nodes;
}
Also used : HostResource(com.yahoo.vespa.model.HostResource) Container(com.yahoo.vespa.model.container.Container) ClusterMembership(com.yahoo.config.provision.ClusterMembership) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 4 with ClusterMembership

use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.

the class ContainerModelBuilder method getHostResourceFromContentClusters.

/**
 * This is used in case we are on hosted Vespa and no nodes tag is supplied:
 * If there are content clusters this will pick the first host in the first cluster as the container node.
 * If there are no content clusters this will return empty (such that the node can be created by the container here).
 */
private Optional<HostResource> getHostResourceFromContentClusters(ContainerCluster cluster, Element containersElement, ConfigModelContext context) {
    Optional<Element> services = servicesRootOf(containersElement);
    if (!services.isPresent())
        return Optional.empty();
    List<Element> contentServices = XML.getChildren(services.get(), "content");
    if (contentServices.isEmpty())
        return Optional.empty();
    Element contentNodesElementOrNull = XML.getChild(contentServices.get(0), "nodes");
    NodesSpecification nodesSpec;
    if (contentNodesElementOrNull == null)
        nodesSpec = NodesSpecification.nonDedicated(1, context.getDeployState().getWantedNodeVespaVersion());
    else
        nodesSpec = NodesSpecification.from(new ModelElement(contentNodesElementOrNull), context.getDeployState().getWantedNodeVespaVersion());
    Map<HostResource, ClusterMembership> hosts = StorageGroup.provisionHosts(nodesSpec, contentServices.get(0).getAttribute("id"), cluster.getRoot().getHostSystem(), context.getDeployLogger());
    return Optional.of(hosts.keySet().iterator().next());
}
Also used : HostResource(com.yahoo.vespa.model.HostResource) ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) NodesSpecification(com.yahoo.vespa.model.builder.xml.dom.NodesSpecification) ClusterMembership(com.yahoo.config.provision.ClusterMembership) ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) Element(org.w3c.dom.Element)

Example 5 with ClusterMembership

use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.

the class ModelProvisioningTest method testClusterMembership.

@Test
public void testClusterMembership() {
    String xmlWithNodes = "<?xml version='1.0' encoding='utf-8' ?>" + "<services>" + "  <container version='1.0' id='container1'>" + "     <nodes count='1'/>" + "  </container>" + "</services>";
    VespaModelTester tester = new VespaModelTester();
    tester.addHosts(1);
    VespaModel model = tester.createModel(xmlWithNodes, true);
    assertEquals(1, model.getHostSystem().getHosts().size());
    HostResource host = model.getHostSystem().getHosts().iterator().next();
    assertEquals(1, host.clusterMemberships().size());
    ClusterMembership membership = host.clusterMemberships().iterator().next();
    assertEquals("container", membership.cluster().type().name());
    assertEquals("container1", membership.cluster().id().value());
}
Also used : HostResource(com.yahoo.vespa.model.HostResource) ClusterMembership(com.yahoo.config.provision.ClusterMembership) VespaModelTester(com.yahoo.vespa.model.test.VespaModelTester) VespaModel(com.yahoo.vespa.model.VespaModel) Test(org.junit.Test)

Aggregations

ClusterMembership (com.yahoo.config.provision.ClusterMembership)11 HostResource (com.yahoo.vespa.model.HostResource)6 ClusterSpec (com.yahoo.config.provision.ClusterSpec)3 Node (com.yahoo.vespa.hosted.provision.Node)3 ModelElement (com.yahoo.vespa.model.builder.xml.dom.ModelElement)3 HostSpec (com.yahoo.config.provision.HostSpec)2 NodesSpecification (com.yahoo.vespa.model.builder.xml.dom.NodesSpecification)2 ArrayList (java.util.ArrayList)2 Element (org.w3c.dom.Element)2 NodeType (com.yahoo.config.provision.NodeType)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1 CuratorTransaction (com.yahoo.vespa.curator.transaction.CuratorTransaction)1 VespaModel (com.yahoo.vespa.model.VespaModel)1 Container (com.yahoo.vespa.model.container.Container)1 VespaModelTester (com.yahoo.vespa.model.test.VespaModelTester)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1