diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-09-23 09:20:38 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-09-24 09:29:30 +0200 |
commit | 76bc54dc3de81c560df16b25b50ad8632bb87128 (patch) | |
tree | 5ca3c0ebf7c13e8245d370f15885d970d609af3f /node-repository | |
parent | a975345f861f8560def95fa3e92364ecaa0bd225 (diff) |
Write osUpgraded event
Diffstat (limited to 'node-repository')
4 files changed, 27 insertions, 3 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..61d5909ce6f 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,17 @@ 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 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..8ec21a246bc 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,7 +120,7 @@ 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)))); case "failCount" : 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..60d88ad1bb4 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 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": [ |