From 528ee45baf83349d2bb11112273f04e4de8c7274 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Tue, 27 Oct 2020 15:10:13 +0100 Subject: Docker image -> container image --- .../yahoo/vespa/hosted/provision/node/Status.java | 30 +++++++++++----------- .../provision/persistence/NodeSerializer.java | 18 ++++++------- .../provisioning/NodeRepositoryProvisioner.java | 3 +-- .../hosted/provision/restapi/NodePatcher.java | 7 +++-- .../hosted/provision/restapi/NodesResponse.java | 2 +- .../provision/testutils/MockNodeRepository.java | 6 ++--- .../provision/provisioning/ProvisioningTest.java | 4 +-- 7 files changed, 34 insertions(+), 36 deletions(-) (limited to 'node-repository') 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 3e5ef81e614..71e60c92cb0 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 @@ -17,7 +17,7 @@ public class Status { private final Generation reboot; private final Optional vespaVersion; - private final Optional dockerImage; + private final Optional containerImage; private final int failCount; private final boolean wantToRetire; private final boolean wantToDeprovision; @@ -26,7 +26,7 @@ public class Status { public Status(Generation generation, Optional vespaVersion, - Optional dockerImage, + Optional containerImage, int failCount, boolean wantToRetire, boolean wantToDeprovision, @@ -34,7 +34,7 @@ public class Status { Optional firmwareVerifiedAt) { this.reboot = Objects.requireNonNull(generation, "Generation must be non-null"); this.vespaVersion = Objects.requireNonNull(vespaVersion, "Vespa version must be non-null").filter(v -> !Version.emptyVersion.equals(v)); - this.dockerImage = Objects.requireNonNull(dockerImage, "Docker image must be non-null").filter(d -> !DockerImage.EMPTY.equals(d)); + this.containerImage = Objects.requireNonNull(containerImage, "Container image must be non-null").filter(d -> !DockerImage.EMPTY.equals(d)); this.failCount = failCount; if (wantToDeprovision && !wantToRetire) { throw new IllegalArgumentException("Node cannot be marked wantToDeprovision unless it's also marked wantToRetire"); @@ -46,35 +46,35 @@ public class Status { } /** Returns a copy of this with the reboot generation changed */ - public Status withReboot(Generation reboot) { return new Status(reboot, vespaVersion, dockerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + public Status withReboot(Generation reboot) { return new Status(reboot, vespaVersion, containerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } /** 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), dockerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + public Status withVespaVersion(Version version) { return new Status(reboot, Optional.of(version), containerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } /** Returns the Vespa version installed on the node, if known */ public Optional vespaVersion() { return vespaVersion; } - /** Returns a copy of this with the docker image changed */ - public Status withDockerImage(DockerImage dockerImage) { return new Status(reboot, vespaVersion, Optional.of(dockerImage), failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + /** Returns a copy of this with the container image changed */ + public Status withContainerImage(DockerImage containerImage) { return new Status(reboot, vespaVersion, Optional.of(containerImage), failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } - /** Returns the docker image the node is running, if known */ - public Optional dockerImage() { return dockerImage; } + /** Returns the container image the node is running, if any */ + public Optional containerImage() { return containerImage; } - public Status withIncreasedFailCount() { return new Status(reboot, vespaVersion, dockerImage, failCount + 1, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + public Status withIncreasedFailCount() { return new Status(reboot, vespaVersion, containerImage, failCount + 1, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } - public Status withDecreasedFailCount() { return new Status(reboot, vespaVersion, dockerImage, failCount - 1, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + public Status withDecreasedFailCount() { return new Status(reboot, vespaVersion, containerImage, failCount - 1, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } - public Status withFailCount(int value) { return new Status(reboot, vespaVersion, dockerImage, value, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } + public Status withFailCount(int value) { return new Status(reboot, vespaVersion, containerImage, value, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } /** Returns how many times this node has been moved to the failed state. */ public int failCount() { return failCount; } /** Returns a copy of this with the want to retire/deprovision flags changed */ public Status withWantToRetire(boolean wantToRetire, boolean wantToDeprovision) { - return new Status(reboot, vespaVersion, dockerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); + return new Status(reboot, vespaVersion, containerImage, failCount, wantToRetire, wantToDeprovision, osVersion, firmwareVerifiedAt); } /** @@ -94,7 +94,7 @@ public class Status { /** Returns a copy of this with the OS version set to given version */ public Status withOsVersion(OsVersion version) { - return new Status(reboot, vespaVersion, dockerImage, failCount, wantToRetire, wantToDeprovision, version, firmwareVerifiedAt); + return new Status(reboot, vespaVersion, containerImage, failCount, wantToRetire, wantToDeprovision, version, firmwareVerifiedAt); } /** Returns the OS version of this node */ @@ -104,7 +104,7 @@ public class Status { /** Returns a copy of this with the firmwareVerifiedAt set to the given instant. */ public Status withFirmwareVerifiedAt(Instant instant) { - return new Status(reboot, vespaVersion, dockerImage, failCount, wantToRetire, wantToDeprovision, osVersion, Optional.of(instant)); + return new Status(reboot, vespaVersion, containerImage, failCount, wantToRetire, wantToDeprovision, osVersion, Optional.of(instant)); } /** Returns the last time this node had firmware that was verified to be up to date. */ 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 c5cf1847156..d2256344854 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 @@ -73,7 +73,7 @@ public class NodeSerializer { private static final String rebootGenerationKey = "rebootGeneration"; private static final String currentRebootGenerationKey = "currentRebootGeneration"; private static final String vespaVersionKey = "vespaVersion"; - private static final String currentDockerImageKey = "currentDockerImage"; + private static final String currentContainerImageKey = "currentDockerImage"; private static final String failCountKey = "failCount"; private static final String nodeTypeKey = "type"; private static final String wantToRetireKey = "wantToRetire"; @@ -103,7 +103,7 @@ public class NodeSerializer { private static final String removableKey = "removable"; // Saved as part of allocation instead of serviceId, since serviceId serialized form is not easily extendable. private static final String wantedVespaVersionKey = "wantedVespaVersion"; - private static final String wantedDockerImageRepoKey = "wantedDockerImageRepo"; + private static final String wantedContainerImageRepoKey = "wantedDockerImageRepo"; // History event fields private static final String historyEventTypeKey = "type"; @@ -153,7 +153,7 @@ public class NodeSerializer { object.setLong(rebootGenerationKey, node.status().reboot().wanted()); object.setLong(currentRebootGenerationKey, node.status().reboot().current()); node.status().vespaVersion().ifPresent(version -> object.setString(vespaVersionKey, version.toString())); - node.status().dockerImage().ifPresent(image -> object.setString(currentDockerImageKey, image.asString())); + node.status().containerImage().ifPresent(image -> object.setString(currentContainerImageKey, image.asString())); object.setLong(failCountKey, node.status().failCount()); object.setBool(wantToRetireKey, node.status().wantToRetire()); object.setBool(wantToDeprovisionKey, node.status().wantToDeprovision()); @@ -193,7 +193,7 @@ public class NodeSerializer { object.setLong(currentRestartGenerationKey, allocation.restartGeneration().current()); object.setBool(removableKey, allocation.isRemovable()); object.setString(wantedVespaVersionKey, allocation.membership().cluster().vespaVersion().toString()); - allocation.membership().cluster().dockerImageRepo().ifPresent(repo -> object.setString(wantedDockerImageRepoKey, repo.untagged())); + allocation.membership().cluster().dockerImageRepo().ifPresent(repo -> object.setString(wantedContainerImageRepoKey, repo.untagged())); allocation.networkPorts().ifPresent(ports -> NetworkPortsSerializer.toSlime(ports, object.setArray(networkPortsKey))); } @@ -251,7 +251,7 @@ public class NodeSerializer { private Status statusFromSlime(Inspector object) { return new Status(generationFromSlime(object, rebootGenerationKey, currentRebootGenerationKey), versionFromSlime(object.field(vespaVersionKey)), - dockerImageFromSlime(object.field(currentDockerImageKey)), + containerImageFromSlime(object.field(currentContainerImageKey)), (int) object.field(failCountKey).asLong(), object.field(wantToRetireKey).asBool(), object.field(wantToDeprovisionKey).asBool(), @@ -319,9 +319,9 @@ public class NodeSerializer { } private ClusterMembership clusterMembershipFromSlime(Inspector object) { - return ClusterMembership.from(object.field(serviceIdKey).asString(), + return ClusterMembership.from(object.field(serviceIdKey).asString(), versionFromSlime(object.field(wantedVespaVersionKey)).get(), - dockerImageRepoFromSlime(object.field(wantedDockerImageRepoKey))); + containerImageRepoFromSlime(object.field(wantedContainerImageRepoKey))); } private Optional versionFromSlime(Inspector object) { @@ -329,12 +329,12 @@ public class NodeSerializer { return Optional.of(Version.fromString(object.asString())); } - private Optional dockerImageRepoFromSlime(Inspector object) { + private Optional containerImageRepoFromSlime(Inspector object) { if ( ! object.valid() || object.asString().isEmpty()) return Optional.empty(); return Optional.of(DockerImage.fromString(object.asString())); } - private Optional dockerImageFromSlime(Inspector object) { + private Optional containerImageFromSlime(Inspector object) { if ( ! object.valid()) return Optional.empty(); return Optional.of(DockerImage.fromString(object.asString())); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java index 027aae58335..4d103e9d31a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java @@ -17,7 +17,6 @@ import com.yahoo.config.provision.ProvisionLogger; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.Zone; import com.yahoo.transaction.Mutex; -import com.yahoo.transaction.NestedTransaction; import com.yahoo.vespa.flags.FetchVector; import com.yahoo.vespa.flags.FlagSource; import com.yahoo.vespa.flags.Flags; @@ -218,7 +217,7 @@ public class NodeRepositoryProvisioner implements Provisioner { nodeAllocation.membership(), node.status().vespaVersion(), nodeAllocation.networkPorts(), - node.status().dockerImage())); + node.status().containerImage())); if (nodeAllocation.networkPorts().isPresent()) { log.log(Level.FINE, () -> "Prepared node " + node.hostname() + " has port allocations"); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java index 834bed00bd0..726ce522c63 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.provision.restapi; import com.google.common.base.Suppliers; import com.yahoo.component.Version; import com.yahoo.config.provision.DockerImage; -import com.yahoo.config.provision.Flavor; import com.yahoo.config.provision.NodeFlavors; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.TenantName; @@ -99,9 +98,9 @@ public class NodePatcher { case "currentRestartGeneration" : return patchCurrentRestartGeneration(node, asLong(value)); case "currentDockerImage" : - if (node.flavor().getType() != Flavor.Type.DOCKER_CONTAINER) - throw new IllegalArgumentException("Docker image can only be set for docker containers"); - return node.with(node.status().withDockerImage(DockerImage.fromString(asString(value)))); + if (node.type().isHost()) + throw new IllegalArgumentException("Container image can only be set for child nodes"); + return node.with(node.status().withContainerImage(DockerImage.fromString(asString(value)))); case "vespaVersion" : case "currentVespaVersion" : return node.with(node.status().withVespaVersion(Version.fromString(asString(value)))); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java index 30e1c4a9b54..511b397be1a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java @@ -219,7 +219,7 @@ class NodesResponse extends HttpResponse { // Hack: For non-docker nodes, return current docker image as default prefix + current Vespa version // TODO: Remove current + wanted docker image from response for non-docker types private Optional currentDockerImage(Node node) { - return node.status().dockerImage() + return node.status().containerImage() .or(() -> Optional.of(node) .filter(n -> n.flavor().getType() != Flavor.Type.DOCKER_CONTAINER) .flatMap(n -> n.status().vespaVersion() diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockNodeRepository.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockNodeRepository.java index f9bddc6f3f4..fb78e76f0c7 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockNodeRepository.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockNodeRepository.java @@ -90,7 +90,7 @@ public class MockNodeRepository extends NodeRepository { .parentHostname("dockerhost1.yahoo.com") .status(Status.initial() .withVespaVersion(new Version("6.41.0")) - .withDockerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:6.41.0"))) + .withContainerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:6.41.0"))) .build(); nodes.add(node4); @@ -98,7 +98,7 @@ public class MockNodeRepository extends NodeRepository { .parentHostname("dockerhost2.yahoo.com") .status(Status.initial() .withVespaVersion(new Version("1.2.3")) - .withDockerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:1.2.3"))) + .withContainerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:1.2.3"))) .build(); nodes.add(node5); @@ -112,7 +112,7 @@ public class MockNodeRepository extends NodeRepository { .parentHostname("parent1.yahoo.com") .status(Status.initial() .withVespaVersion(Version.fromString("5.104.142")) - .withDockerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:5.104.142"))) + .withContainerImage(DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa:5.104.142"))) .build(); nodes.add(node10); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java index 7a0d9fa5047..f22ddfb81c9 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java @@ -175,7 +175,7 @@ public class ProvisioningTest { HostSpec host1 = state1.container0.iterator().next(); Node node1 = tester.nodeRepository().getNode(host1.hostname()).get(); DockerImage dockerImage = DockerImage.fromString(dockerImageRepo).withTag(Version.fromString("1.2.3")); - tester.nodeRepository().write(node1.with(node1.status().withDockerImage(dockerImage)), () -> {}); + tester.nodeRepository().write(node1.with(node1.status().withContainerImage(dockerImage)), () -> {}); // redeploy SystemState state2 = prepare(application1, tester, 1, 1, 1 ,1 , false, defaultResources, "1.2.3", Optional.of(dockerImageRepo)); @@ -183,7 +183,7 @@ public class ProvisioningTest { host1 = state2.container0.iterator().next(); node1 = tester.nodeRepository().getNode(host1.hostname()).get(); - assertEquals(dockerImage, node1.status().dockerImage().get()); + assertEquals(dockerImage, node1.status().containerImage().get()); } @Test -- cgit v1.2.3