summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-05-30 09:24:17 +0200
committervalerijf <valerijf@yahoo-inc.com>2017-05-30 09:24:17 +0200
commit0dca24d993183dcc9a2b10cbebb79f2a8fa9b618 (patch)
treef20c93a682df33b32d442b82ad9e92d3a291aa38 /node-repository
parenteafee523715af6137523fb084977c8d51fafe51d (diff)
Add wantToUnprovision to Status
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Status.java39
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java5
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java14
3 files changed, 45 insertions, 13 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Status.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Status.java
index 7946b093b10..00cd1128b89 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Status.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Status.java
@@ -22,6 +22,7 @@ public class Status {
private final int failCount;
private final Optional<HardwareFailureType> hardwareFailure;
private final boolean wantToRetire;
+ private final boolean wantToUnprovision;
public enum HardwareFailureType {
@@ -40,7 +41,8 @@ public class Status {
Optional<String> stateVersion,
int failCount,
Optional<HardwareFailureType> hardwareFailure,
- boolean wantToRetire) {
+ boolean wantToRetire,
+ boolean wantToUnprovision) {
this.reboot = generation;
this.vespaVersion = vespaVersion;
this.hostedVersion = hostedVersion;
@@ -48,28 +50,29 @@ public class Status {
this.failCount = failCount;
this.hardwareFailure = hardwareFailure;
this.wantToRetire = wantToRetire;
+ this.wantToUnprovision = wantToUnprovision;
}
/** Returns a copy of this with the reboot generation changed */
- public Status withReboot(Generation reboot) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire); }
+ public Status withReboot(Generation reboot) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision); }
/** Returns the reboot generation of this node */
public Generation reboot() { return reboot; }
/** Returns a copy of this with the vespa version changed */
- public Status withVespaVersion(Version version) { return new Status(reboot, Optional.of(version), hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire); }
+ public Status withVespaVersion(Version version) { return new Status(reboot, Optional.of(version), hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision); }
/** Returns the Vespa version installed on the node, if known */
public Optional<Version> vespaVersion() { return vespaVersion; }
/** Returns a copy of this with the hosted version changed */
- public Status withHostedVersion(Version version) { return new Status(reboot, vespaVersion, Optional.of(version), stateVersion, failCount, hardwareFailure, wantToRetire); }
+ public Status withHostedVersion(Version version) { return new Status(reboot, vespaVersion, Optional.of(version), stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision); }
/** Returns the hosted version installed on the node, if known */
public Optional<Version> hostedVersion() { return hostedVersion; }
/** Returns a copy of this with the state version changed */
- public Status withStateVersion(String version) { return new Status(reboot, vespaVersion, hostedVersion, Optional.of(version), failCount, hardwareFailure, wantToRetire); }
+ public Status withStateVersion(String version) { return new Status(reboot, vespaVersion, hostedVersion, Optional.of(version), failCount, hardwareFailure, wantToRetire, wantToUnprovision); }
/**
* Returns the state version the node last successfully converged with.
@@ -85,29 +88,29 @@ public class Status {
.filter(image -> !image.isEmpty())
.map(DockerImage::new)
.map(DockerImage::tagAsVersion);
- return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire);
+ return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision);
}
/** Returns the current docker image the node is running, if known. */
public Optional<String> dockerImage() { return vespaVersion.map(DockerImage.defaultImage::withTag).map(DockerImage::toString); }
- public Status withIncreasedFailCount() { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount + 1, hardwareFailure, wantToRetire); }
+ public Status withIncreasedFailCount() { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount + 1, hardwareFailure, wantToRetire, wantToUnprovision); }
- public Status withDecreasedFailCount() { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount - 1, hardwareFailure, wantToRetire); }
+ public Status withDecreasedFailCount() { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount - 1, hardwareFailure, wantToRetire, wantToUnprovision); }
- public Status setFailCount(Integer value) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, value, hardwareFailure, wantToRetire); }
+ public Status setFailCount(Integer value) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, value, hardwareFailure, wantToRetire, wantToUnprovision); }
/** Returns how many times this node has been moved to the failed state. */
public int failCount() { return failCount; }
- public Status withHardwareFailure(Optional<HardwareFailureType> hardwareFailure) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire); }
+ public Status withHardwareFailure(Optional<HardwareFailureType> hardwareFailure) { return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision); }
/** Returns the type of the last hardware failure detected on this node, or empty if none */
public Optional<HardwareFailureType> hardwareFailure() { return hardwareFailure; }
/** Returns a copy of this with the want to retire flag changed */
public Status withWantToRetire(boolean wantToRetire) {
- return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire);
+ return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision);
}
/**
@@ -118,7 +121,19 @@ public class Status {
return wantToRetire;
}
+ /** Returns a copy of this with the want to unprovision flag changed */
+ public Status withWantToUnprovision(boolean wantToUnprovision) {
+ return new Status(reboot, vespaVersion, hostedVersion, stateVersion, failCount, hardwareFailure, wantToRetire, wantToUnprovision);
+ }
+
+ /**
+ * Returns whether this node should be unprovisioned when possible.
+ */
+ public boolean wantToUnprovision() {
+ return wantToUnprovision;
+ }
+
/** Returns the initial status of a newly provisioned node */
- public static Status initial() { return new Status(Generation.inital(), Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false); }
+ public static Status initial() { return new Status(Generation.inital(), Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, false); }
}
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 8612dbd607e..55d5a7defec 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
@@ -60,6 +60,7 @@ public class NodeSerializer {
private static final String hardwareFailureKey = "hardwareFailure";
private static final String nodeTypeKey = "type";
private static final String wantToRetireKey = "wantToRetire";
+ private static final String wantToUnprovisionKey = "wantToUnprovision";
// Configuration fields
private static final String flavorKey = "flavor";
@@ -112,6 +113,7 @@ public class NodeSerializer {
object.setLong(failCountKey, node.status().failCount());
node.status().hardwareFailure().ifPresent(failure -> object.setString(hardwareFailureKey, toString(failure)));
object.setBool(wantToRetireKey, node.status().wantToRetire());
+ object.setBool(wantToUnprovisionKey, node.status().wantToUnprovision());
node.allocation().ifPresent(allocation -> toSlime(allocation, object.setObject(instanceKey)));
toSlime(node.history(), object.setArray(historyKey));
object.setString(nodeTypeKey, toString(node.type()));
@@ -170,7 +172,8 @@ public class NodeSerializer {
optionalString(object.field(stateVersionKey)),
(int)object.field(failCountKey).asLong(),
hardwareFailureFromSlime(object.field(hardwareFailureKey)),
- object.field(wantToRetireKey).asBool());
+ object.field(wantToRetireKey).asBool(),
+ object.field(wantToUnprovisionKey).asBool());
}
private Flavor flavorFromSlime(Inspector object) {
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java
index 2e64b0745c9..9e0df3364f0 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java
@@ -325,6 +325,20 @@ public class SerializationTest {
}
@Test
+ public void want_to_unprovision_defaults_to_false() {
+ String nodeData =
+ "{\n" +
+ " \"type\" : \"tenant\",\n" +
+ " \"flavor\" : \"large\",\n" +
+ " \"openStackId\" : \"myId\",\n" +
+ " \"hostname\" : \"myHostname\",\n" +
+ " \"ipAddresses\" : [\"127.0.0.1\"]\n" +
+ "}";
+ Node node = nodeSerializer.fromJson(State.provisioned, Utf8.toBytes(nodeData));
+ assertFalse(node.status().wantToUnprovision());
+ }
+
+ @Test
public void vespa_version_serialization() throws Exception {
String nodeWithWantedVespaVersion =
"{\n" +