summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-04-08 22:53:40 +0200
committerJon Bratseth <bratseth@gmail.com>2021-04-08 22:53:40 +0200
commitce14456b95c202262d3496441b2920ce7e74b8ac (patch)
treef0f290705c13c5ed78c40976c24358a6ae52d969 /node-repository
parent9e74aa13acef30d8c008f91d7231c515820a2622 (diff)
More NodeList
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java
index cd0ec2c5d66..99c60b51083 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java
@@ -69,12 +69,12 @@ class Activator {
NodeList allNodes = nodeRepository.nodes().list();
NodeList applicationNodes = allNodes.owner(application);
- List<Node> reserved = applicationNodes.state(Node.State.reserved).asList();
- List<Node> reservedToActivate = updatePortsFrom(hosts, retainHostsInList(hostnames, reserved));
- List<Node> oldActive = applicationNodes.state(Node.State.active).asList(); // All nodes active now
- List<Node> continuedActive = retainHostsInList(hostnames, oldActive);
+ NodeList reserved = updatePortsFrom(hosts, applicationNodes.state(Node.State.reserved)
+ .matching(node -> hostnames.contains(node.hostname())));
+ NodeList oldActive = applicationNodes.state(Node.State.active); // All nodes active now
+ NodeList continuedActive = oldActive.matching(node -> hostnames.contains(node.hostname()));
List<Node> newActive = updateFrom(hosts, continuedActive, activationTime); // All nodes that will be active when this is committed
- newActive.addAll(reservedToActivate);
+ newActive.addAll(reserved.asList());
if ( ! containsAll(hostnames, newActive))
throw new IllegalArgumentException("Activation of " + application + " failed. " +
"Could not find all requested hosts." +
@@ -84,21 +84,20 @@ class Activator {
"\nThis might happen if the time from reserving host to activation takes " +
"longer time than reservation expiry (the hosts will then no longer be reserved)");
- validateParentHosts(application, allNodes, reservedToActivate);
+ validateParentHosts(application, allNodes, reserved);
- List<Node> activeToRemove = removeHostsFromList(hostnames, oldActive);
- activeToRemove = activeToRemove.stream().map(Node::unretire).collect(Collectors.toList()); // only active nodes can be retired. TODO: Move this line to deactivate
+ NodeList activeToRemove = oldActive.matching(node -> ! hostnames.contains(node.hostname()));
+ activeToRemove = NodeList.copyOf(activeToRemove.mapToList(Node::unretire)); // only active nodes can be retired. TODO: Move this line to deactivate
deactivate(activeToRemove, transaction); // TODO: Pass activation time in this call and next line
nodeRepository.nodes().activate(newActive, transaction.nested()); // activate also continued active to update node state
rememberResourceChange(transaction, generation, activationTime,
- NodeList.copyOf(oldActive).not().retired(),
+ oldActive.not().retired(),
NodeList.copyOf(newActive).not().retired());
- unreserveParentsOf(reservedToActivate);
+ unreserveParentsOf(reserved);
}
- private void deactivate(List<Node> toDeactivateList, ApplicationTransaction transaction) {
- NodeList toDeactivate = NodeList.copyOf(toDeactivateList);
+ private void deactivate(NodeList toDeactivate, ApplicationTransaction transaction) {
nodeRepository.nodes().deactivate(toDeactivate.not().failing().asList(), transaction);
nodeRepository.nodes().fail(toDeactivate.failing().asList(), transaction);
}
@@ -130,7 +129,7 @@ class Activator {
}
/** When a tenant node is activated on a host, we can open up that host for use by others */
- private void unreserveParentsOf(List<Node> nodes) {
+ private void unreserveParentsOf(NodeList nodes) {
for (Node node : nodes) {
if ( node.parentHostname().isEmpty()) continue;
Optional<Node> parentNode = nodeRepository.nodes().node(node.parentHostname().get());
@@ -160,7 +159,7 @@ class Activator {
.collect(Collectors.toUnmodifiableSet());
}
- private static void validateParentHosts(ApplicationId application, NodeList nodes, List<Node> potentialChildren) {
+ private static void validateParentHosts(ApplicationId application, NodeList nodes, NodeList potentialChildren) {
Set<String> parentHostnames = potentialChildren.stream()
.map(Node::parentHostname)
.flatMap(Optional::stream)
@@ -197,15 +196,7 @@ class Activator {
}
}
- private List<Node> retainHostsInList(Set<String> hosts, List<Node> nodes) {
- return nodes.stream().filter(node -> hosts.contains(node.hostname())).collect(Collectors.toList());
- }
-
- private List<Node> removeHostsFromList(Set<String> hosts, List<Node> nodes) {
- return nodes.stream().filter(node -> ! hosts.contains(node.hostname())).collect(Collectors.toList());
- }
-
- private Set<String> toHostNames(List<Node> nodes) {
+ private Set<String> toHostNames(NodeList nodes) {
return nodes.stream().map(Node::hostname).collect(Collectors.toSet());
}
@@ -217,7 +208,7 @@ class Activator {
}
/** Returns the input nodes with the changes resulting from applying the settings in hosts to the given list of nodes. */
- private List<Node> updateFrom(Collection<HostSpec> hosts, List<Node> nodes, Instant at) {
+ private List<Node> updateFrom(Collection<HostSpec> hosts, NodeList nodes, Instant at) {
List<Node> updated = new ArrayList<>();
for (Node node : nodes) {
HostSpec hostSpec = getHost(node.hostname(), hosts);
@@ -239,7 +230,7 @@ class Activator {
/**
* Returns the input nodes with any port allocations from the hosts
*/
- private List<Node> updatePortsFrom(Collection<HostSpec> hosts, List<Node> nodes) {
+ private NodeList updatePortsFrom(Collection<HostSpec> hosts, NodeList nodes) {
List<Node> updated = new ArrayList<>();
for (Node node : nodes) {
HostSpec hostSpec = getHost(node.hostname(), hosts);
@@ -250,7 +241,7 @@ class Activator {
}
updated.add(node);
}
- return updated;
+ return NodeList.copyOf(updated);
}
private HostSpec getHost(String hostname, Collection<HostSpec> fromHosts) {