summaryrefslogtreecommitdiffstats
path: root/node-repository/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'node-repository/src/test/java/com')
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/OsUpgradeActivatorTest.java127
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/os/OsVersionsTest.java41
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/OsVersionsSerializerTest.java37
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java10
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java13
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/maintenance.json3
6 files changed, 56 insertions, 175 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/OsUpgradeActivatorTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/OsUpgradeActivatorTest.java
deleted file mode 100644
index 158951969eb..00000000000
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/OsUpgradeActivatorTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.provision.maintenance;
-
-import com.yahoo.component.Version;
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.config.provision.ClusterMembership;
-import com.yahoo.config.provision.ClusterSpec;
-import com.yahoo.config.provision.NodeType;
-import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.node.Allocation;
-import com.yahoo.vespa.hosted.provision.node.Status;
-import com.yahoo.vespa.hosted.provision.os.OsVersion;
-import com.yahoo.vespa.hosted.provision.provisioning.ProvisioningTester;
-import org.junit.Test;
-
-import java.time.Duration;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author mpolden
- */
-public class OsUpgradeActivatorTest {
-
- private final ProvisioningTester tester = new ProvisioningTester.Builder().build();
-
- @Test
- public void activates_upgrade() {
- var osVersions = tester.nodeRepository().osVersions();
- var osUpgradeActivator = new OsUpgradeActivator(tester.nodeRepository(), Duration.ofDays(1));
- var version0 = Version.fromString("7.0");
-
- // Create infrastructure nodes
- var configHostApplication = ApplicationId.from("hosted-vespa", "configserver-host", "default");
- var configHostNodes = tester.makeReadyNodes(3, "default", NodeType.confighost);
- tester.prepareAndActivateInfraApplication(configHostApplication, NodeType.confighost, version0);
-
- var tenantHostApplication = ApplicationId.from("hosted-vespa", "tenant-host", "default");
- var tenantHostNodes = tester.makeReadyNodes(3, "default", NodeType.host);
- tester.prepareAndActivateInfraApplication(tenantHostApplication, NodeType.host, version0);
-
- // All nodes are on initial version
- assertEquals(version0, minWantedVersion(NodeType.confighost, NodeType.host));
- completeUpgradeOf(configHostNodes);
- completeUpgradeOf(tenantHostNodes);
- assertEquals("All nodes are on initial version", version0, minCurrentVersion(NodeType.confighost, NodeType.host));
-
- // New OS target version is set
- var osVersion0 = Version.fromString("8.0");
- osVersions.setTarget(NodeType.host, osVersion0, false);
- osVersions.setTarget(NodeType.confighost, osVersion0, false);
-
- // New OS version is activated as there is no ongoing Vespa upgrade
- osUpgradeActivator.maintain();
- assertTrue("OS version " + osVersion0 + " is active", isOsVersionActive(NodeType.confighost, NodeType.host));
-
- // Tenant hosts start upgrading to next Vespa version
- var version1 = Version.fromString("7.1");
- tester.prepareAndActivateInfraApplication(tenantHostApplication, NodeType.host, version1);
- assertEquals("Wanted version of " + NodeType.host + " is raised", version1,
- minWantedVersion(NodeType.host));
-
- // Activator pauses upgrade for tenant hosts only
- osUpgradeActivator.maintain();
- assertTrue("OS version " + osVersion0 + " is active", isOsVersionActive(NodeType.confighost));
- assertFalse("OS version " + osVersion0 + " is inactive", isOsVersionActive(NodeType.host));
-
- // Tenant hosts complete their Vespa upgrade
- completeUpgradeOf(tenantHostNodes);
- assertEquals("Tenant hosts upgraded", version1, minCurrentVersion(NodeType.host));
-
- // Activator resumes OS upgrade of tenant hosts
- osUpgradeActivator.run();
- assertTrue("OS version " + osVersion0 + " is active", isOsVersionActive(NodeType.confighost, NodeType.host));
- }
-
- private boolean isOsVersionActive(NodeType... types) {
- var active = true;
- for (var type : types) {
- active &= tester.nodeRepository().osVersions().targetFor(type).map(OsVersion::active).orElse(false);
- }
- return active;
- }
-
- private void completeUpgradeOf(List<Node> nodes) {
- for (var node : nodes) {
- try (var lock = tester.nodeRepository().lock(node)) {
- node = tester.nodeRepository().getNode(node.hostname()).get();
- node = node.with(node.status().withVespaVersion(node.allocation().get().membership().cluster().vespaVersion()));
- tester.nodeRepository().write(node, lock);
- }
- }
- }
-
- private Stream<Node> streamNodes(NodeType... types) {
- Stream<Node> stream = Stream.empty();
- for (var type : types) {
- stream = Stream.concat(stream, tester.nodeRepository().getNodes(type).stream());
- }
- return stream;
- }
-
- private Version minCurrentVersion(NodeType... types) {
- return streamNodes(types).map(Node::status)
- .map(Status::vespaVersion)
- .flatMap(Optional::stream)
- .min(Comparator.naturalOrder())
- .orElse(Version.emptyVersion);
- }
-
- private Version minWantedVersion(NodeType... types) {
- return streamNodes(types).map(Node::allocation)
- .flatMap(Optional::stream)
- .map(Allocation::membership)
- .map(ClusterMembership::cluster)
- .map(ClusterSpec::vespaVersion)
- .min(Comparator.naturalOrder())
- .orElse(Version.emptyVersion);
- }
-
-}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/os/OsVersionsTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/os/OsVersionsTest.java
index 47640e1c00b..06f9dcfae68 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/os/OsVersionsTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/os/OsVersionsTest.java
@@ -1,4 +1,4 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.os;
import com.yahoo.component.Version;
@@ -7,6 +7,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepositoryTester;
import org.junit.Test;
import java.time.Duration;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -20,46 +21,38 @@ import static org.junit.Assert.fail;
*/
public class OsVersionsTest {
+ private final OsVersions versions = new OsVersions(
+ new NodeRepositoryTester().nodeRepository().database(),
+ Duration.ofDays(1) // Long TTL to avoid timed expiry during test
+ );
+
@Test
public void test_versions() {
- var versions = new OsVersions(new NodeRepositoryTester().nodeRepository().database(), Duration.ofDays(1));
-
assertTrue("No versions set", versions.targets().isEmpty());
assertSame("Caches empty target versions", versions.targets(), versions.targets());
// Upgrade OS
- var version1 = new OsVersion(Version.fromString("7.1"), false);
- versions.setTarget(NodeType.host, version1.version(), false);
- var targetVersions = versions.targets();
+ Version version1 = Version.fromString("7.1");
+ versions.setTarget(NodeType.host, version1, false);
+ Map<NodeType, OsVersion> targetVersions = versions.targets();
assertSame("Caches target versions", targetVersions, versions.targets());
- assertEquals(version1, versions.targetFor(NodeType.host).get());
+ assertEquals(version1, versions.targetFor(NodeType.host).get().version());
// Upgrade OS again
- var version2 = new OsVersion(Version.fromString("7.2"), false);
- versions.setTarget(NodeType.host, version2.version(), false);
+ Version version2 = Version.fromString("7.2");
+ versions.setTarget(NodeType.host, version2, false);
assertNotSame("Cache invalidated", targetVersions, versions.targets());
- assertEquals(version2, versions.targetFor(NodeType.host).get());
-
- // Target can be (de)activated
- versions.setActive(NodeType.host, true);
- assertTrue("Target version activated", versions.targetFor(NodeType.host).get().active());
-
- // Re-setting the same version does not affect active status
- versions.setTarget(NodeType.host, version2.version(), false);
- assertTrue("Target version remains active", versions.targetFor(NodeType.host).get().active());
-
- versions.setActive(NodeType.host, false);
- assertFalse("Target version deactivated", versions.targetFor(NodeType.host).get().active());
+ assertEquals(version2, versions.targetFor(NodeType.host).get().version());
// Downgrading fails
try {
- versions.setTarget(NodeType.host, version1.version(), false);
+ versions.setTarget(NodeType.host, version1, false);
fail("Expected exception");
} catch (IllegalArgumentException ignored) {}
// Forcing downgrade succeeds
- versions.setTarget(NodeType.host, version1.version(), true);
- assertEquals(version1, versions.targetFor(NodeType.host).get());
+ versions.setTarget(NodeType.host, version1, true);
+ assertEquals(version1, versions.targetFor(NodeType.host).get().version());
// Target can be removed
versions.removeTarget(NodeType.host);
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/OsVersionsSerializerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/OsVersionsSerializerTest.java
index c6583292da8..4aec5b8370e 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/OsVersionsSerializerTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/OsVersionsSerializerTest.java
@@ -6,24 +6,55 @@ import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.os.OsVersion;
import org.junit.Test;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
/**
* @author mpolden
*/
public class OsVersionsSerializerTest {
+ // TODO(mpolden): Remove once no longer supported
@Test
- public void serialization() {
+ public void legacy_format() {
+ var json = "{\"host\":\"1.2.3\",\"proxyhost\":\"4.5.6\",\"confighost\":\"7.8.9\"}";
+ var serializedFromString = OsVersionsSerializer.fromJson(json.getBytes(StandardCharsets.UTF_8));
var versions = Map.of(
NodeType.host, new OsVersion(Version.fromString("1.2.3"), true),
- NodeType.proxyhost, new OsVersion(Version.fromString("4.5.6"), false),
+ NodeType.proxyhost, new OsVersion(Version.fromString("4.5.6"), true),
NodeType.confighost, new OsVersion(Version.fromString("7.8.9"), true)
);
+ assertEquals(versions, serializedFromString);
+
var serialized = OsVersionsSerializer.fromJson(OsVersionsSerializer.toJson(versions));
assertEquals(serialized, versions);
}
+ @Test
+ public void read_future_format() {
+ var json = "{\n" +
+ " \"host\": {\n" +
+ " \"version\": \"1.2.3\",\n" +
+ " \"active\": false\n" +
+ " " +
+ "},\n" +
+ " \"proxyhost\": {\n" +
+ " \"version\": \"4.5.6\",\n" +
+ " \"active\": true\n" +
+ " },\n" +
+ " \"confighost\": {\n" +
+ " \"version\": \"7.8.9\",\n" +
+ " \"active\": true\n" +
+ " }\n" +
+ "}";
+ var versions = OsVersionsSerializer.fromJson(json.getBytes(StandardCharsets.UTF_8));
+ assertEquals(Map.of(
+ NodeType.host, new OsVersion(Version.fromString("1.2.3"), false),
+ NodeType.proxyhost, new OsVersion(Version.fromString("4.5.6"), true),
+ NodeType.confighost, new OsVersion(Version.fromString("7.8.9"), true)
+ ), versions);
+ }
+
}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java
index b737ad56fe2..dee32513457 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java
@@ -1,4 +1,4 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.provisioning;
import com.yahoo.component.Version;
@@ -156,17 +156,13 @@ public class ProvisioningTester {
assertEquals(toHostNames(hosts), toHostNames(nodeRepository.getNodes(application, Node.State.active)));
}
- public void prepareAndActivateInfraApplication(ApplicationId application, NodeType nodeType, Version version) {
- ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from(nodeType.toString()), version, false);
+ public void prepareAndActivateInfraApplication(ApplicationId application, NodeType nodeType) {
+ ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from(nodeType.toString()), Version.fromString("6.42"), false);
Capacity capacity = Capacity.fromRequiredNodeType(nodeType);
List<HostSpec> hostSpecs = prepare(application, cluster, capacity, 1, true);
activate(application, hostSpecs);
}
- public void prepareAndActivateInfraApplication(ApplicationId application, NodeType nodeType) {
- prepareAndActivateInfraApplication(application, nodeType, Version.fromString("6.42"));
- }
-
public void deactivate(ApplicationId applicationId) {
NestedTransaction deactivateTransaction = new NestedTransaction();
nodeRepository.deactivate(applicationId, deactivateTransaction);
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
index d3848866ba5..fa2ddc841cb 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java
@@ -1,4 +1,4 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.restapi.v2;
import com.yahoo.application.Networking;
@@ -11,10 +11,7 @@ import com.yahoo.slime.Cursor;
import com.yahoo.slime.Slime;
import com.yahoo.text.Utf8;
import com.yahoo.vespa.config.SlimeUtils;
-import com.yahoo.vespa.hosted.provision.NodeRepository;
-import com.yahoo.vespa.hosted.provision.maintenance.OsUpgradeActivator;
import com.yahoo.vespa.hosted.provision.testutils.ContainerConfig;
-import com.yahoo.vespa.hosted.provision.testutils.MockNodeRepository;
import org.junit.After;
import org.junit.Before;
import org.junit.ComparisonFailure;
@@ -24,7 +21,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.StandardCharsets;
-import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
@@ -746,7 +742,7 @@ public class RestApiTest {
Utf8.toBytes("{\"osVersion\": \"7.5.2\"}"),
Request.Method.PATCH),
400,
- "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Node type 'config' does not support OS upgrades\"}");
+ "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Setting target OS version for config nodes is unsupported\"}");
// Attempt to downgrade OS
assertResponse(new Request("http://localhost:8080/nodes/v2/upgrade/confighost",
@@ -797,11 +793,6 @@ public class RestApiTest {
Request.Method.PATCH),
"{\"message\":\"Set osVersion to 7.5.2 for nodes of type host\"}");
- // Activate target
- var nodeRepository = (NodeRepository) container.components().getComponent(MockNodeRepository.class.getName());
- var osUpgradeActivator = new OsUpgradeActivator(nodeRepository, Duration.ofDays(1));
- osUpgradeActivator.run();
-
// Other node type does not return wanted OS version
Response r = container.handleRequest(new Request("http://localhost:8080/nodes/v2/node/host1.yahoo.com"));
assertFalse("Response omits wantedOsVersions field", r.getBodyAsString().contains("wantedOsVersion"));
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/maintenance.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/maintenance.json
index cfb39e7e5b1..28881717e7c 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/maintenance.json
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/maintenance.json
@@ -31,9 +31,6 @@
"name": "OperatorChangeApplicationMaintainer"
},
{
- "name": "OsUpgradeActivator"
- },
- {
"name": "PeriodicApplicationMaintainer"
},
{