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;
}
Aggregations