summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2019-02-06 14:37:43 +0000
committerArne Juul <arnej@yahoo-inc.com>2019-02-20 10:30:08 +0000
commit92599c56d62226a32e1e4df4321123c9691db73d (patch)
tree7e981d971920da1536443289d511198af265b432 /node-repository
parent85e394563c8b711a1a0307c8ac5953c1817f5629 (diff)
add list of network port allocations
* add port suffixes to identify individual ports for a service * stash port reservations from current config model
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java1
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Allocation.java29
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java9
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Activator.java26
4 files changed, 57 insertions, 8 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
index 668795f362b..4fef3d8ebf7 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java
@@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableSet;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.Flavor;
+import com.yahoo.config.provision.NetworkPorts;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.Allocation;
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Allocation.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Allocation.java
index 8a331209efc..53e1ae3721e 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Allocation.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Allocation.java
@@ -3,6 +3,9 @@ package com.yahoo.vespa.hosted.provision.node;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterMembership;
+import com.yahoo.config.provision.NetworkPorts;
+
+import java.util.Optional;
/**
* The allocation of a node
@@ -24,12 +27,21 @@ public class Allocation {
/** This node can (and should) be removed from the cluster on the next deployment */
private final boolean removable;
+ private final Optional<NetworkPorts> networkPorts;
+
+
public Allocation(ApplicationId owner, ClusterMembership clusterMembership,
Generation restartGeneration, boolean removable) {
+ this(owner, clusterMembership, restartGeneration, removable, Optional.empty());
+ }
+
+ public Allocation(ApplicationId owner, ClusterMembership clusterMembership,
+ Generation restartGeneration, boolean removable, Optional<NetworkPorts> networkPorts) {
this.owner = owner;
this.clusterMembership = clusterMembership;
this.restartGeneration = restartGeneration;
this.removable = removable;
+ this.networkPorts = networkPorts;
}
/** Returns the id of the application this is allocated to */
@@ -41,14 +53,17 @@ public class Allocation {
/** Returns the restart generation (wanted and current) of this */
public Generation restartGeneration() { return restartGeneration; }
+ /** Returns network ports allocations (or empty if not recorded) */
+ public Optional<NetworkPorts> networkPorts() { return networkPorts; }
+
/** Returns a copy of this which is retired */
public Allocation retire() {
- return new Allocation(owner, clusterMembership.retire(), restartGeneration, removable);
+ return new Allocation(owner, clusterMembership.retire(), restartGeneration, removable, networkPorts);
}
/** Returns a copy of this which is not retired */
public Allocation unretire() {
- return new Allocation(owner, clusterMembership.unretire(), restartGeneration, removable);
+ return new Allocation(owner, clusterMembership.unretire(), restartGeneration, removable, networkPorts);
}
/** Return whether this node is ready to be removed from the application */
@@ -56,16 +71,20 @@ public class Allocation {
/** Returns a copy of this with the current restart generation set to generation */
public Allocation withRestart(Generation generation) {
- return new Allocation(owner, clusterMembership, generation, removable);
+ return new Allocation(owner, clusterMembership, generation, removable, networkPorts);
}
/** Returns a copy of this allocation where removable is set to true */
public Allocation removable() {
- return new Allocation(owner, clusterMembership, restartGeneration, true);
+ return new Allocation(owner, clusterMembership, restartGeneration, true, networkPorts);
}
public Allocation with(ClusterMembership newMembership) {
- return new Allocation(owner, newMembership, restartGeneration, removable);
+ return new Allocation(owner, newMembership, restartGeneration, removable, networkPorts);
+ }
+
+ public Allocation withNetworkPorts(NetworkPorts ports) {
+ return new Allocation(owner, clusterMembership, restartGeneration, removable, Optional.of(ports));
}
@Override
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java
index 54668c4eda1..bb4dab3b97b 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java
@@ -10,6 +10,8 @@ import com.yahoo.config.provision.Flavor;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeType;
+import com.yahoo.config.provision.NetworkPorts;
+import com.yahoo.config.provision.NetworkPortsSerializer;
import com.yahoo.config.provision.TenantName;
import com.yahoo.slime.ArrayTraverser;
import com.yahoo.slime.Cursor;
@@ -85,6 +87,9 @@ public class NodeSerializer {
private static final String atKey = "at";
private static final String agentKey = "agent"; // retired events only
+ // Network port fields
+ private static final String networkPortsKey = "networkPorts";
+
// ---------------- Serialization ----------------------------------------------------
public NodeSerializer(NodeFlavors flavors) {
@@ -136,6 +141,7 @@ public class NodeSerializer {
object.setLong(currentRestartGenerationKey, allocation.restartGeneration().current());
object.setBool(removableKey, allocation.isRemovable());
object.setString(wantedVespaVersionKey, allocation.membership().cluster().vespaVersion().toString());
+ allocation.networkPorts().ifPresent(ports -> NetworkPortsSerializer.toSlime(ports, object.setArray(networkPortsKey)));
}
private void toSlime(History history, Cursor array) {
@@ -197,7 +203,8 @@ public class NodeSerializer {
return Optional.of(new Allocation(applicationIdFromSlime(object),
clusterMembershipFromSlime(object),
generationFromSlime(object, restartGenerationKey, currentRestartGenerationKey),
- object.field(removableKey).asBool()));
+ object.field(removableKey).asBool(),
+ NetworkPortsSerializer.fromSlime(object.field(networkPortsKey))));
}
private ApplicationId applicationIdFromSlime(Inspector object) {
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 f48f0c1bdce..4626a600d2c 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
@@ -9,6 +9,7 @@ import com.yahoo.transaction.NestedTransaction;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeList;
import com.yahoo.vespa.hosted.provision.NodeRepository;
+import com.yahoo.vespa.hosted.provision.node.Allocation;
import java.util.ArrayList;
import java.util.Collection;
@@ -73,7 +74,7 @@ class Activator {
activeToRemove = activeToRemove.stream().map(Node::unretire).collect(Collectors.toList()); // only active nodes can be retired
nodeRepository.deactivate(activeToRemove, transaction);
nodeRepository.activate(updateFrom(hosts, continuedActive), transaction); // update active with any changes
- nodeRepository.activate(reservedToActivate, transaction);
+ nodeRepository.activate(updatePortsFrom(hosts, reservedToActivate), transaction);
}
}
@@ -133,7 +134,11 @@ class Activator {
for (Node node : nodes) {
HostSpec hostSpec = getHost(node.hostname(), hosts);
node = hostSpec.membership().get().retired() ? node.retire(nodeRepository.clock().instant()) : node.unretire();
- node = node.with(node.allocation().get().with(hostSpec.membership().get()));
+ Allocation allocation = node.allocation().get().with(hostSpec.membership().get());
+ if (hostSpec.networkPorts().isPresent()) {
+ allocation = allocation.withNetworkPorts(hostSpec.networkPorts().get());
+ }
+ node = node.with(allocation);
if (hostSpec.flavor().isPresent()) // Docker nodes may change flavor
node = node.with(hostSpec.flavor().get());
updated.add(node);
@@ -141,6 +146,23 @@ class Activator {
return updated;
}
+ /**
+ * Returns the input nodes with any port allocations from the hosts
+ */
+ private List<Node> updatePortsFrom(Collection<HostSpec> hosts, List<Node> nodes) {
+ List<Node> updated = new ArrayList<>();
+ for (Node node : nodes) {
+ HostSpec hostSpec = getHost(node.hostname(), hosts);
+ Allocation allocation = node.allocation().get();
+ if (hostSpec.networkPorts().isPresent()) {
+ allocation = allocation.withNetworkPorts(hostSpec.networkPorts().get());
+ node = node.with(allocation);
+ }
+ updated.add(node);
+ }
+ return updated;
+ }
+
private HostSpec getHost(String hostname, Collection<HostSpec> fromHosts) {
for (HostSpec host : fromHosts)
if (host.hostname().equals(hostname))