summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-09-25 08:56:13 +0200
committerGitHub <noreply@github.com>2019-09-25 08:56:13 +0200
commit2c1a51763f6e48439f50301958f4a270892eb238 (patch)
tree825f5dd1a835a4fea99b9873bb49c03109628616 /node-repository
parent464fe377d8b518408c151cf0e434671af5cff6c0 (diff)
parentb09dcca5aee910f2ac7d6f5cb2169a149c27be80 (diff)
Merge pull request #10780 from vespa-engine/mpolden/write-new-node-events
Write new node events
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java19
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java4
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/SerializationTest.java14
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/docker-node1-os-upgrade-complete.json5
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/dockerhost1-with-firmware-data.json5
5 files changed, 42 insertions, 5 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 bdcb96c1861..fa439e50fbd 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
@@ -1,6 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision;
+import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.Flavor;
@@ -287,6 +288,24 @@ public final class Node {
return this.with(newStatus).with(newHistory);
}
+ /** Returns a copy of this node with the current OS version set to the given version at the given instant */
+ public Node withCurrentOsVersion(Version version, Instant instant) {
+ var newStatus = status.withOsVersion(version);
+ var newHistory = history();
+ // Only update history if version has changed
+ if (status.osVersion().isEmpty() || !status.osVersion().get().equals(version)) {
+ newHistory = history.with(new History.Event(History.Event.Type.osUpgraded, Agent.system, instant));
+ }
+ return this.with(newStatus).with(newHistory);
+ }
+
+ /** Returns a copy of this node with firmware verified at the given instant */
+ public Node withFirmwareVerifiedAt(Instant instant) {
+ var newStatus = status.withFirmwareVerifiedAt(instant);
+ var newHistory = history.with(new History.Event(History.Event.Type.firmwareVerified, Agent.system, instant));
+ return this.with(newStatus).with(newHistory);
+ }
+
/** Returns a copy of this node with the given history. */
public Node with(History history) {
return new Node(id, ipConfig, hostname, parentHostname, flavor, status, state, allocation, history, type, reports, modelName);
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
index 8dcf3c260f5..5f4c300b496 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodePatcher.java
@@ -120,9 +120,9 @@ public class NodePatcher {
case "currentVespaVersion" :
return node.with(node.status().withVespaVersion(Version.fromString(asString(value))));
case "currentOsVersion" :
- return node.with(node.status().withOsVersion(Version.fromString(asString(value))));
+ return node.withCurrentOsVersion(Version.fromString(asString(value)), clock.instant());
case "currentFirmwareCheck":
- return node.with(node.status().withFirmwareVerifiedAt(Instant.ofEpochMilli(asLong(value))));
+ return node.withFirmwareVerifiedAt(Instant.ofEpochMilli(asLong(value)));
case "failCount" :
return node.with(node.status().setFailCount(asLong(value).intValue()));
case "flavor" :
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 23699879ceb..0cfdf80a8a1 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,10 +325,17 @@ public class SerializationTest {
assertFalse(serialized.status().osVersion().isPresent());
// Update OS version
- serialized = serialized.with(serialized.status()
- .withOsVersion(Version.fromString("7.1")));
+ serialized = serialized.withCurrentOsVersion(Version.fromString("7.1"), Instant.ofEpochMilli(123))
+ // Another update for same version:
+ .withCurrentOsVersion(Version.fromString("7.1"), Instant.ofEpochMilli(456));
serialized = nodeSerializer.fromJson(State.provisioned, nodeSerializer.toJson(serialized));
assertEquals(Version.fromString("7.1"), serialized.status().osVersion().get());
+ var osUpgradedEvents = serialized.history().events().stream()
+ .filter(event -> event.type() == History.Event.Type.osUpgraded)
+ .collect(Collectors.toList());
+ assertEquals("OS upgraded event is added", 1, osUpgradedEvents.size());
+ assertEquals("Duplicate updates of same version uses earliest instant", Instant.ofEpochMilli(123),
+ osUpgradedEvents.get(0).at());
}
@Test
@@ -336,9 +343,10 @@ public class SerializationTest {
Node node = nodeSerializer.fromJson(State.active, nodeSerializer.toJson(createNode()));
assertFalse(node.status().firmwareVerifiedAt().isPresent());
- node = node.with(node.status().withFirmwareVerifiedAt(Instant.ofEpochMilli(100)));
+ node = node.withFirmwareVerifiedAt(Instant.ofEpochMilli(100));
node = nodeSerializer.fromJson(State.active, nodeSerializer.toJson(node));
assertEquals(100, node.status().firmwareVerifiedAt().get().toEpochMilli());
+ assertEquals(Instant.ofEpochMilli(100), node.history().event(History.Event.Type.firmwareVerified).get().at());
}
@Test
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/docker-node1-os-upgrade-complete.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/docker-node1-os-upgrade-complete.json
index f5068924084..31bdfe7d6e3 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/docker-node1-os-upgrade-complete.json
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/docker-node1-os-upgrade-complete.json
@@ -57,6 +57,11 @@
"event": "activated",
"at": 123,
"agent": "application"
+ },
+ {
+ "event": "osUpgraded",
+ "at": 123,
+ "agent": "system"
}
],
"ipAddresses": [
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/dockerhost1-with-firmware-data.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/dockerhost1-with-firmware-data.json
index 53982c78042..24e64248b1c 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/dockerhost1-with-firmware-data.json
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/dockerhost1-with-firmware-data.json
@@ -57,6 +57,11 @@
"event": "activated",
"at": 123,
"agent": "application"
+ },
+ {
+ "event": "firmwareVerified",
+ "at": 100,
+ "agent": "system"
}
],
"ipAddresses": [