Search in sources :

Example 11 with ClusterMembership

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

the class NodeAllocation method offer.

/**
 * Offer some nodes to this. The nodes may have an allocation to a different application or cluster,
 * an allocation to this cluster, or no current allocation (in which case one is assigned).
 *
 * Note that if unallocated nodes are offered before allocated nodes, this will unnecessarily
 * reject allocated nodes due to index duplicates.
 *
 * @param nodesPrioritized the nodes which are potentially on offer. These may belong to a different application etc.
 * @return the subset of offeredNodes which was accepted, with the correct allocation assigned
 */
List<Node> offer(List<PrioritizableNode> nodesPrioritized) {
    List<Node> accepted = new ArrayList<>();
    for (PrioritizableNode offeredPriority : nodesPrioritized) {
        Node offered = offeredPriority.node;
        if (offered.allocation().isPresent()) {
            boolean wantToRetireNode = false;
            ClusterMembership membership = offered.allocation().get().membership();
            // wrong application
            if (!offered.allocation().get().owner().equals(application))
                continue;
            // wrong cluster id/type
            if (!membership.cluster().equalsIgnoringGroupAndVespaVersion(cluster))
                continue;
            // wrong group and we can't or have no reason to change it
            if ((!offeredPriority.isSurplusNode || saturated()) && !membership.cluster().group().equals(cluster.group()))
                continue;
            // don't accept; causes removal
            if (offered.allocation().get().isRemovable())
                continue;
            // duplicate index (just to be sure)
            if (indexes.contains(membership.index()))
                continue;
            // conditions on which we want to retire nodes that were allocated previously
            if (offeredNodeHasParentHostnameAlreadyAccepted(this.nodes, offered))
                wantToRetireNode = true;
            if (!hasCompatibleFlavor(offered))
                wantToRetireNode = true;
            if (offered.flavor().isRetired())
                wantToRetireNode = true;
            if (offered.status().wantToRetire())
                wantToRetireNode = true;
            if (requestedNodes.isExclusive() && !hostsOnly(application.tenant(), offered.parentHostname()))
                wantToRetireNode = true;
            if ((!saturated() && hasCompatibleFlavor(offered)) || acceptToRetire(offered)) {
                accepted.add(acceptNode(offeredPriority, wantToRetireNode));
            }
        } else if (!saturated() && hasCompatibleFlavor(offered)) {
            if (offeredNodeHasParentHostnameAlreadyAccepted(this.nodes, offered)) {
                ++rejectedWithClashingParentHost;
                continue;
            }
            if (!exclusiveTo(application.tenant(), offered.parentHostname())) {
                ++rejectedDueToExclusivity;
                continue;
            }
            if (requestedNodes.isExclusive() && !hostsOnly(application.tenant(), offered.parentHostname())) {
                ++rejectedDueToExclusivity;
                continue;
            }
            if (offered.flavor().isRetired()) {
                continue;
            }
            if (offered.status().wantToRetire()) {
                continue;
            }
            offeredPriority.node = offered.allocate(application, ClusterMembership.from(cluster, highestIndex.add(1)), nodeRepository.clock().instant());
            accepted.add(acceptNode(offeredPriority, false));
        }
    }
    return accepted;
}
Also used : ClusterMembership(com.yahoo.config.provision.ClusterMembership) Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList)

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