private void checkVersion(Element spec) { String version = spec.getAttribute("version"); if ( ! Version.fromString(version).equals(new Version(1))) { throw new RuntimeException("Expected container version to be 1.0, but got " + version); } }
@Override public int compare(Version v1, Version v2) { return v1.compareTo(v2); } }
/** Creates a version specification that only matches this version */ public VersionSpecification toSpecification() { if (this == emptyVersion) return VersionSpecification.emptyVersionSpecification; else { return new VersionSpecification(getMajor(), getMinor(), getMicro(), getQualifier()); } }
/** * A version 6.163.20 will be returned as a number 163.020. The major * version can normally be inferred. As long as the micro version stays * below 1000 these numbers sort like Version. */ private static double getVersionAsNumber(Version version) { return version.getMinor() + version.getMicro() / 1000.0; }
public VespaModelFactory(ConfigModelRegistry configModelRegistry, Clock clock) { this(new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, clock); } public VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock) {
public boolean upgrading() { return !current.equals(wanted); } }
/** Set the target OS version for nodes of given type */ public void setTarget(NodeType nodeType, Version newTarget, boolean force) { if (!nodeType.isDockerHost()) { throw new IllegalArgumentException("Setting target OS version for " + nodeType + " nodes is unsupported"); } if (newTarget.isEmpty()) { throw new IllegalArgumentException("Invalid target version: " + newTarget.toFullString()); } try (Lock lock = db.lockOsVersions()) { Map<NodeType, Version> osVersions = db.readOsVersions(); Optional<Version> oldTarget = Optional.ofNullable(osVersions.get(nodeType)); if (oldTarget.filter(v -> v.equals(newTarget)).isPresent()) { return; // Old target matches new target, nothing to do } if (!force && oldTarget.filter(v -> v.isAfter(newTarget)).isPresent()) { throw new IllegalArgumentException("Cannot set target OS version to " + newTarget + " without setting 'force', as it's lower than the current version: " + oldTarget.get()); } osVersions.put(nodeType, newTarget); db.writeOsVersions(osVersions); createCache(); // Throw away current cache log.info("Set OS target version for " + nodeType + " nodes to " + newTarget.toFullString()); } }
private ComponentId(SpecSplitter splitter) { this(splitter.name, Version.fromString(splitter.version), splitter.namespace); }
/** * Returns the string representation of this version identifier as major.minor.micro.qualifier, * omitting .qualifier if qualifier empty or unspecified * <p> * This string form is part of the API of Version and will never change. */ public String toFullString() { StringBuilder b = new StringBuilder(); b.append(getMajor()); b.append("."); b.append(getMinor()); b.append("."); b.append(getMicro()); if (! qualifier.isEmpty()) { b.append("."); b.append(qualifier); } return b.toString(); }
node4 = node4.with(node4.status().withVespaVersion(new Version("6.41.0"))); nodes.add(node4); nodes.add(node5.with(node5.status().withVespaVersion(new Version("1.2.3")))); Status node10newStatus = node10.status(); node10newStatus = node10newStatus .withVespaVersion(Version.fromString("5.104.142")); node10 = node10.with(node10newStatus); nodes.add(node10); ClusterSpec zoneCluster = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("node-admin"), Version.fromString("6.42"), false, Set.of(RotationName.from("us-cluster"))); ClusterSpec cluster1 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("id1"), Version.fromString("6.42"), false, Collections.emptySet()); provisioner.prepare(app1, cluster1, Capacity.fromNodeCount(2), 1, null); ClusterSpec cluster2 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("id2"), Version.fromString("6.42"), false, Collections.emptySet()); activate(provisioner.prepare(app2, cluster2, Capacity.fromNodeCount(2), 1, null), app2, provisioner);
private void traceVespaVersion(Query query) { query.trace("Vespa version: " + Vtag.currentVersion.toString(), false, 4); }
private MessageResponse setTargetVersions(HttpRequest request) { NodeType nodeType = NodeType.valueOf(lastElement(request.getUri().getPath()).toLowerCase()); Inspector inspector = toSlime(request.getData()).get(); List<String> messageParts = new ArrayList<>(3); boolean force = inspector.field("force").asBool(); Inspector versionField = inspector.field("version"); Inspector osVersionField = inspector.field("osVersion"); if (versionField.valid()) { Version version = Version.fromString(versionField.asString()); maintenance.infrastructureVersions().setTargetVersion(nodeType, version, force); messageParts.add("version to " + version.toFullString()); } if (osVersionField.valid()) { String v = osVersionField.asString(); if (v.isEmpty()) { nodeRepository.osVersions().removeTarget(nodeType); messageParts.add("osVersion to null"); } else { Version osVersion = Version.fromString(v); nodeRepository.osVersions().setTarget(nodeType, osVersion, force); messageParts.add("osVersion to " + osVersion.toFullString()); } } if (messageParts.isEmpty()) { throw new IllegalArgumentException("At least one of 'version' and 'osVersion' must be set"); } return new MessageResponse("Set " + String.join(", ", messageParts) + " for nodes of type " + nodeType); }
/** Returns the Docker image tagged with the given version */ public DockerImage withTag(Version version) { return new DockerImage(name + ":" + version.toFullString()); }
throw new IllegalArgumentException("Cannot set version for type " + nodeType); if (newTargetVersion.isEmpty()) { throw new IllegalArgumentException("Invalid target version: " + newTargetVersion.toFullString()); if (currentTargetVersion.get().isAfter(newTargetVersion)) throw new IllegalArgumentException(String.format("Cannot downgrade version without setting 'force'. " + "Current target version: %s, attempted to set target version: %s", currentTargetVersion.get().toFullString(), newTargetVersion.toFullString())); logger.info("Set target version for " + nodeType + " to " + newTargetVersion.toFullString());
File schemaPath = new File(pathPrefix + "version/" + vespaVersion.getMajor() + ".x/schema/");
object.setLong("currentRestartGeneration", node.allocation().get().restartGeneration().current()); object.setString("wantedDockerImage", nodeRepository.dockerImage().withTag(node.allocation().get().membership().cluster().vespaVersion()).asString()); object.setString("wantedVespaVersion", node.allocation().get().membership().cluster().vespaVersion().toFullString()); try { object.setBool("allowedToBeDown", node.status().osVersion().ifPresent(version -> object.setString("currentOsVersion", version.toFullString())); nodeRepository.osVersions().targetFor(node.type()).ifPresent(version -> object.setString("wantedOsVersion", version.toFullString())); node.status().firmwareVerifiedAt().ifPresent(instant -> object.setLong("currentFirmwareCheck", instant.toEpochMilli())); if (node.type().isDockerHost()) nodeRepository.firmwareChecks().requiredAfter().ifPresent(after -> object.setLong("wantedFirmwareCheck", after.toEpochMilli())); node.status().vespaVersion() .filter(version -> !version.isEmpty()) .ifPresent(version -> { object.setString("vespaVersion", version.toFullString()); object.setString("currentDockerImage", nodeRepository.dockerImage().withTag(version).asString()); });
/** Returns new Version(versionString), or Version.emptyVersion if the input string is null or "" */ public static Version fromString(String versionString) { if (versionString == null) { return emptyVersion; } else { return new Version(versionString); } }
/** Returns whether this equals the empty version */ public boolean isEmpty() { return this.equals(emptyVersion); }