Skip to content

Commit

Permalink
Merge pull request #32386 from vespa-engine/mpolden/consider-dimension
Browse files Browse the repository at this point in the history
Consider application dimension in HostRenamer
  • Loading branch information
freva authored Sep 10, 2024
2 parents 685285f + 98a5dfa commit b55c3be
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import java.time.Duration;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* @author mpolden
Expand All @@ -35,13 +37,12 @@ public HostRenamer(NodeRepository nodeRepository, Duration interval, Metric metr
protected double maintain() {
if (!nodeRepository().nodes().isWorking()) return 0.0;
NodeList allNodes = nodeRepository().nodes().list();
String hostnameScheme = hostnameSchemeFlag.value();
NodeList activeHosts = allNodes.nodeType(NodeType.host).state(Node.State.active);
Set<ApplicationId> retiringApplications = applicationsOnRetiringHosts(activeHosts, allNodes);
for (var host : activeHosts) {
if (!changeHostname(host, hostnameScheme)) continue;

Set<ApplicationId> applicationsOnHost = applicationsOn(host, allNodes);
if (!changeHostname(host, applicationsOnHost)) continue;

if (Collections.disjoint(retiringApplications, applicationsOnHost)) {
LOG.info("Deprovisioning " + host + " to change its hostname");
nodeRepository().nodes().deprovision(host.hostname(), Agent.system, nodeRepository().clock().instant());
Expand All @@ -67,8 +68,19 @@ private Set<ApplicationId> applicationsOnRetiringHosts(NodeList activeHosts, Nod
return applications;
}

private static boolean changeHostname(Node node, String wantedScheme) {
return !node.hostname().endsWith(".vespa-cloud.net") && "standard".equals(wantedScheme);
private boolean changeHostname(Node node, Set<ApplicationId> instances) {
if (node.hostname().endsWith(".vespa-cloud.net")) {
return false;
}
Set<String> wantedSchemes;
if (instances.isEmpty()) {
wantedSchemes = Set.of(hostnameSchemeFlag.value());
} else {
wantedSchemes = instances.stream()
.map(instance -> hostnameSchemeFlag.withApplicationId(Optional.of(instance)).value())
.collect(Collectors.toSet());
}
return wantedSchemes.size() == 1 && wantedSchemes.iterator().next().equals("standard");
}

}

0 comments on commit b55c3be

Please sign in to comment.