Skip to content

Commit

Permalink
Deprecate com.yahoo.config.provision.Version
Browse files Browse the repository at this point in the history
We have com.yahoo.component.Version, and one is enough.
  • Loading branch information
Jon Bratseth committed Dec 1, 2018
1 parent c0513ac commit 051c699
Show file tree
Hide file tree
Showing 57 changed files with 315 additions and 193 deletions.
16 changes: 12 additions & 4 deletions component/src/main/java/com/yahoo/component/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ private String toStringValue() {

/**
* Returns the string representation of this version identifier as major.minor.micro.qualifier,
* omitting .qualifier if qualifier was empty or unspecified
* 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();
Expand Down Expand Up @@ -284,9 +286,13 @@ public String toFullString() {
* Returns the string representation of this version identifier as major.minor.micro.qualifier,
* omitting the remaining parts after reaching the first unspecified component.
* Unspecified version component is equivalent to 0 (or the empty string for qualifier).
* <p>
* The string representation of a Version specified here is a part of the API and will never change.
*/
@Override
public String toString() { return stringValue; }

@Override
public int hashCode() { return stringValue.hashCode(); }

/** Returns whether this equals the empty version */
Expand All @@ -306,8 +312,9 @@ public String toFullString() {
* <code>Version</code> and is equal to this object;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
if (!(object instanceof Version)) return false;
if ( ! (object instanceof Version)) return false;
Version other = (Version) object;
if (this.major != other.major) return false;
if (this.minor != other.minor) return false;
Expand All @@ -317,8 +324,8 @@ public boolean equals(Object object) {

@SuppressWarnings("unused")
private boolean equals(Object o1, Object o2) {
if (o1==null && o2==null) return true;
if (o1==null || o2==null) return false;
if (o1 == null && o2 == null) return true;
if (o1 == null || o2 == null) return false;
return o1.equals(o2);
}

Expand All @@ -345,6 +352,7 @@ private boolean equals(Object o1, Object o2) {
* less than, equal to, or greater than the specified <code>Version</code> object.
* @throws ClassCastException if the specified object is not a <code>Version</code>.
*/
@Override
public int compareTo(Version other) {
if (other == this) return 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @author arnej27959
* @author bratseth
*/

public final class VersionSpecification implements Comparable<VersionSpecification> {

private Integer major = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.application.provider;

import com.yahoo.component.Version;
import com.yahoo.component.Vtag;
import com.yahoo.config.application.ConfigDefinitionDir;
import com.yahoo.config.application.Xml;
Expand All @@ -12,7 +13,6 @@
import com.yahoo.config.codegen.DefParser;
import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.provision.Version;
import com.yahoo.config.provision.Zone;
import com.yahoo.path.Path;
import com.yahoo.io.HexDump;
Expand Down Expand Up @@ -45,7 +45,6 @@
import java.util.*;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static com.yahoo.text.Lowercase.toLowerCase;

Expand Down Expand Up @@ -571,7 +570,7 @@ public File getAppDir() throws IOException {
return appDir.getCanonicalFile();
}

public static ApplicationMetaData readMetaData(File appDir) {
private static ApplicationMetaData readMetaData(File appDir) {
ApplicationMetaData defaultMetaData = new ApplicationMetaData(appDir, "n/a", "n/a", 0l, false, "", 0l, 0l);
File metaFile = new File(appDir, META_FILE_NAME);
if (!metaFile.exists()) {
Expand Down Expand Up @@ -642,13 +641,12 @@ public File getFileReference(Path pathRelativeToAppDir) {

@Override
public void validateXML() throws IOException {
validateXML(Optional.empty());
validateXMLFor(Optional.empty());
}

@Override
public void validateXML(Optional<Version> vespaVersion) throws IOException {
com.yahoo.component.Version modelVersion =
vespaVersion.map(v -> new com.yahoo.component.Version(vespaVersion.toString())).orElse(Vtag.currentVersion);
public void validateXMLFor(Optional<Version> vespaVersion) throws IOException {
Version modelVersion = vespaVersion.orElse(Vtag.currentVersion);
ApplicationPackageXmlFilesValidator validator = ApplicationPackageXmlFilesValidator.create(appDir, modelVersion);
validator.checkApplication();
validator.checkIncludedDirs(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.yahoo.config.application.api;

import com.yahoo.config.provision.AllocatedHosts;
import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;
import com.yahoo.config.provision.Zone;
import com.yahoo.io.IOUtils;
import com.yahoo.io.reader.NamedReader;
Expand All @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

/**
* Represents an application package, that is, used as input when creating a VespaModel and as
Expand Down Expand Up @@ -184,7 +185,17 @@ default Optional<Integer> getMajorVersion() {
Optional<Reader> getDeployment();
Optional<Reader> getValidationOverrides();

List<ComponentInfo> getComponentsInfo(Version vespaVersion);
/** @deprecated do not override or call. Use the other Version class */
@Deprecated
default List<ComponentInfo> getComponentsInfo(com.yahoo.config.provision.Version vespaVersion) {
return getComponentsInfo(vespaVersion.toVersion());
}

// TODO: Remove the default implementation after December 2018
@SuppressWarnings("deprecation")
default List<ComponentInfo> getComponentsInfo(Version vespaVersion) {
return getComponentsInfo(com.yahoo.config.provision.Version.from(vespaVersion));
}

/**
* Reads a ranking expression from file to a string and returns it.
Expand Down Expand Up @@ -237,7 +248,13 @@ default void validateXML() throws IOException {
throw new UnsupportedOperationException("This application package cannot validate XML");
}

default void validateXML(Optional<Version> vespaVersion) throws IOException {
/** @deprecated do not override or call. Use the other Version class */
@Deprecated
default void validateXML(Optional<com.yahoo.config.provision.Version> vespaVersion) throws IOException {
validateXMLFor(vespaVersion.map(com.yahoo.config.provision.Version::toVersion));
}

default void validateXMLFor(Optional<Version> vespaVersion) throws IOException {
throw new UnsupportedOperationException("This application package cannot validate XML");
}

Expand All @@ -252,7 +269,7 @@ default void writeMetaData() throws IOException {
*/
// TODO: Remove on Vespa 7
@Deprecated
default Map<Version, AllocatedHosts> getProvisionInfoMap() {
default Map<com.yahoo.config.provision.Version, AllocatedHosts> getProvisionInfoMap() {
return Collections.emptyMap();
}

Expand All @@ -261,7 +278,16 @@ default Optional<AllocatedHosts> getAllocatedHosts() {
return Optional.empty();
}

default Map<Version, FileRegistry> getFileRegistryMap() {
/** @deprecated do not override or call. Use getFileRegistries */
@Deprecated
default Map<com.yahoo.config.provision.Version, FileRegistry> getFileRegistryMap() {
return getFileRegistries().entrySet()
.stream()
.collect(Collectors.toMap(e -> com.yahoo.config.provision.Version.from(e.getKey()),
e -> e.getValue()));
}

default Map<Version, FileRegistry> getFileRegistries() {
return Collections.emptyMap();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.api;

import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;

/**
* Factory for config models.
Expand All @@ -13,7 +13,14 @@ public interface ModelFactory {
*
* @return the version of a {@link Model} instance that this factory can create.
*/
Version getVersion();
@SuppressWarnings("deprecation")
default Version version() { // TODO: Remove this default implementationm after December 2018
return getVersion().toVersion();
}

/** @deprecated use and override version(). TODO: Remove this method after December 2018 */
@Deprecated
default com.yahoo.config.provision.Version getVersion() { return com.yahoo.config.provision.Version.from(version()); }

/**
* Creates an instance of a {@link Model}. The resulting instance will be used to serve config. No model
Expand All @@ -34,4 +41,5 @@ public interface ModelFactory {
* @return a {@link ModelCreateResult} instance.
*/
ModelCreateResult createAndValidateModel(ModelContext modelContext, ValidationParameters validationParameters);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model;

import com.yahoo.cloud.config.*;
import com.yahoo.cloud.config.ApplicationIdConfig;
import com.yahoo.cloud.config.ClusterListConfig;
import com.yahoo.cloud.config.ModelConfig;
import com.yahoo.cloud.config.SlobroksConfig;
import com.yahoo.cloud.config.ZookeepersConfig;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;
import com.yahoo.vespa.config.content.LoadTypeConfig;
import com.yahoo.cloud.config.ModelConfig.Hosts;
import com.yahoo.cloud.config.ModelConfig.Hosts.Services;
Expand All @@ -18,7 +22,12 @@
import com.yahoo.vespa.configmodel.producers.DocumentManager;
import com.yahoo.vespa.configmodel.producers.DocumentTypes;
import com.yahoo.vespa.documentmodel.DocumentModel;
import com.yahoo.vespa.model.*;
import com.yahoo.vespa.model.ConfigProducer;
import com.yahoo.vespa.model.HostResource;
import com.yahoo.vespa.model.HostSystem;
import com.yahoo.vespa.model.PortsMeta;
import com.yahoo.vespa.model.Service;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.admin.Admin;
import com.yahoo.vespa.model.clients.Clients;
import com.yahoo.vespa.model.content.cluster.ContentCluster;
Expand Down Expand Up @@ -204,7 +213,7 @@ public void getConfig(ClusterListConfig.Builder builder) {

@Override
public void getConfig(ModelConfig.Builder builder) {
builder.vespaVersion(vespaVersion.toSerializedForm());
builder.vespaVersion(vespaVersion.toFullString());
for (HostResource modelHost : getHostSystem().getHosts()) {
builder.hosts(new Hosts.Builder()
.name(modelHost.getHostname())
Expand Down Expand Up @@ -279,4 +288,5 @@ public void getConfig(ApplicationIdConfig.Builder builder) {
builder.application(applicationId.application().value());
builder.instance(applicationId.instance().value());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.yahoo.config.model.api.ConfigServerSpec;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;

import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -104,7 +104,7 @@ public static class Builder {
private URI ztsUrl;
private String athenzDnsSuffix;
private boolean hostedVespa = false;
private Version vespaVersion = Version.fromIntValues(1, 0, 0);
private Version vespaVersion = new Version(1, 0, 0);
private boolean isBootstrap = false;
private boolean isFirstTimeDeployment = false;
private boolean useDedicatedNodeForLogserver = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import com.yahoo.config.application.api.ComponentInfo;
import com.yahoo.config.application.api.UnparsedConfigDefinition;
import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;
import com.yahoo.io.IOUtils;
import com.yahoo.path.Path;
import com.yahoo.io.reader.NamedReader;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
import com.yahoo.searchdefinition.*;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.vespa.config.ConfigDefinitionKey;
import com.yahoo.config.application.api.ApplicationPackage;
Expand All @@ -25,7 +26,13 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.yahoo.config.model.builder.xml.ConfigModelBuilder;
import com.yahoo.config.model.deploy.DeployProperties;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.Version;
import com.yahoo.component.Version;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.config.VespaVersion;
import com.yahoo.vespa.model.application.validation.Validation;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class VespaModelFactory implements ModelFactory {
public VespaModelFactory(ComponentRegistry<ConfigModelPlugin> pluginRegistry,
ComponentRegistry<MlModelImporter> modelImporters,
Zone zone) {
this.version = Version.fromIntValues(VespaVersion.major, VespaVersion.minor, VespaVersion.micro);
this.version = new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro);
List<ConfigModelBuilder> modelBuilders = new ArrayList<>();
for (ConfigModelPlugin plugin : pluginRegistry.allComponents()) {
if (plugin instanceof ConfigModelBuilder) {
Expand All @@ -71,7 +71,7 @@ public VespaModelFactory(ConfigModelRegistry configModelRegistry) {
this(configModelRegistry, Clock.systemUTC());
}
public VespaModelFactory(ConfigModelRegistry configModelRegistry, Clock clock) {
this(Version.fromIntValues(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, clock);
this(new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, clock);
}
public VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock) {
this.version = version;
Expand All @@ -88,7 +88,7 @@ public VespaModelFactory(Version version, ConfigModelRegistry configModelRegistr

/** Returns the version this model is build for */
@Override
public Version getVersion() { return version; }
public Version version() { return version; }

@Override
public Model createModel(ModelContext modelContext) {
Expand Down Expand Up @@ -157,7 +157,7 @@ private DeployProperties createDeployProperties(ModelContext.Properties properti
.athenzDnsSuffix(properties.athenzDnsSuffix())
.multitenant(properties.multitenant())
.hostedVespa(properties.hostedVespa())
.vespaVersion(getVersion())
.vespaVersion(version())
.isBootstrap(properties.isBootstrap())
.isFirstTimeDeployment(properties.isFirstTimeDeployment())
.useDedicatedNodeForLogserver(properties.useDedicatedNodeForLogserver())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ public DomRootBuilder(String name) {

@Override
protected ApplicationConfigProducerRoot doBuild(DeployState deployState, AbstractConfigProducer parent, Element producerSpec) {
ApplicationConfigProducerRoot root = new ApplicationConfigProducerRoot(parent, name,
deployState.getDocumentModel(),
deployState.getProperties().vespaVersion(),
deployState.getProperties().applicationId());
ApplicationConfigProducerRoot root = new ApplicationConfigProducerRoot(parent,
name,
deployState.getDocumentModel(),
deployState.getProperties().vespaVersion(),
deployState.getProperties().applicationId());
root.setHostSystem(new HostSystem(root, "hosts", deployState.getProvisioner(), deployState.getDeployLogger()));
new Client(root);
return root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ private void toSlime(HostSpec host, Cursor cursor) {
cursor.setString(hostSpecHostName, host.hostname());
host.membership().ifPresent(membership -> {
cursor.setString(hostSpecMembership, membership.stringValue());
cursor.setString(hostSpecVespaVersion, membership.cluster().vespaVersion().toString());
cursor.setString(hostSpecVespaVersion, membership.cluster().vespaVersion().toFullString());
});
host.flavor().ifPresent(flavor -> cursor.setString(hostSpecFlavor, flavor.name()));
host.version().ifPresent(version -> cursor.setString(hostSpecCurrentVespaVersion, version.toString()));
host.version().ifPresent(version -> cursor.setString(hostSpecCurrentVespaVersion, version.toFullString()));
}

/** Returns the hosts of this allocation */
Expand Down
Loading

0 comments on commit 051c699

Please sign in to comment.