From 5da8ce8318efda1fdcc367d97dc294feaf6285cc Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 26 May 2017 18:36:32 -0400 Subject: [PATCH] Remove the need for _UNRELEASED suffix in versions (#24798) Removes the need for the `_UNRELEASED` suffix on versions by detecting if a version should be unreleased or not based on the versions around it. This should make it simpler to automate the task of adding a new version label. --- build.gradle | 59 ++++++- .../org/elasticsearch/gradle/Version.groovy | 10 +- core/build.gradle | 40 ----- .../main/java/org/elasticsearch/Version.java | 34 ++-- .../action/DocWriteResponse.java | 4 +- .../cluster/state/ClusterStateResponse.java | 4 +- .../indices/create/CreateIndexRequest.java | 2 +- .../shards/IndicesShardStoresResponse.java | 6 +- .../admin/indices/stats/ShardStats.java | 4 +- .../template/put/PutIndexTemplateRequest.java | 4 +- .../action/bulk/BulkItemRequest.java | 6 +- .../action/bulk/BulkItemResponse.java | 4 +- .../fieldcaps/FieldCapabilitiesRequest.java | 4 +- .../fieldcaps/FieldCapabilitiesResponse.java | 4 +- .../action/index/IndexRequest.java | 4 +- .../TransportReplicationAction.java | 8 +- .../cluster/block/ClusterBlock.java | 4 +- .../metadata/IndexTemplateMetaData.java | 4 +- .../cluster/metadata/MappingMetaData.java | 4 +- .../cluster/routing/OperationRouting.java | 2 +- .../common/settings/Settings.java | 2 +- .../common/transport/TransportAddress.java | 4 +- ...ransportNodesListGatewayStartedShards.java | 4 +- .../elasticsearch/index/IndexSortConfig.java | 4 +- .../index/engine/InternalEngine.java | 10 +- .../elasticsearch/index/engine/Segment.java | 4 +- .../index/mapper/AllFieldMapper.java | 2 +- .../index/mapper/BooleanFieldMapper.java | 2 +- .../index/mapper/DynamicTemplate.java | 2 +- .../index/mapper/MapperService.java | 2 +- .../index/mapper/TypeParsers.java | 4 +- .../index/query/BoolQueryBuilder.java | 4 +- .../index/query/CommonTermsQueryBuilder.java | 4 +- .../index/query/InnerHitBuilder.java | 20 +-- .../index/query/NestedQueryBuilder.java | 2 +- .../seqno/GlobalCheckpointSyncAction.java | 2 +- .../elasticsearch/index/shard/IndexShard.java | 2 +- .../elasticsearch/index/store/StoreStats.java | 4 +- .../cluster/IndicesClusterStateService.java | 2 +- .../RecoveryFinalizeRecoveryRequest.java | 4 +- ...ryPrepareForTranslogOperationsRequest.java | 4 +- .../RecoveryTranslogOperationsResponse.java | 4 +- .../recovery/StartRecoveryRequest.java | 4 +- .../org/elasticsearch/monitor/fs/FsInfo.java | 8 +- .../search/aggregations/InternalOrder.java | 4 +- .../search/collapse/CollapseBuilder.java | 4 +- .../elasticsearch/snapshots/SnapshotInfo.java | 2 +- .../elasticsearch/threadpool/ThreadPool.java | 2 +- .../java/org/elasticsearch/VersionTests.java | 38 ++-- .../common/settings/SettingsTests.java | 2 +- .../index/engine/InternalEngineTests.java | 2 +- .../index/mapper/DynamicTemplateTests.java | 2 +- .../recovery/StartRecoveryRequestTests.java | 2 +- .../aggregations/InternalOrderTests.java | 2 +- .../mustache/MultiSearchTemplateRequest.java | 4 +- .../join/query/HasChildQueryBuilder.java | 2 +- .../join/query/HasParentQueryBuilder.java | 2 +- .../upgrades/FullClusterRestartIT.java | 2 +- .../elasticsearch/backwards/IndexingIT.java | 8 +- .../org/elasticsearch/test/VersionUtils.java | 119 ++++++++----- .../elasticsearch/test/VersionUtilsTests.java | 162 ++++++++++++++++++ .../test/test/VersionUtilsTests.java | 85 --------- 62 files changed, 441 insertions(+), 318 deletions(-) create mode 100644 test/framework/src/test/java/org/elasticsearch/test/VersionUtilsTests.java delete mode 100644 test/framework/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java diff --git a/build.gradle b/build.gradle index 20467d842f5..7d6b760a19c 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,12 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) { } } -// introspect all versions of ES that may be tested agains for backwards compatibility +/* Introspect all versions of ES that may be tested agains for backwards + * compatibility. It is *super* important that this logic is the same as the + * logic in VersionUtils.java, modulo alphas, betas, and rcs which are ignored + * in gradle because they don't have any backwards compatibility guarantees + * but are not ignored in VersionUtils.java because the tests expect them not + * to be. */ Version currentVersion = Version.fromString(VersionProperties.elasticsearch.minus('-SNAPSHOT')) int prevMajor = currentVersion.major - 1 File versionFile = file('core/src/main/java/org/elasticsearch/Version.java') @@ -72,13 +77,14 @@ List versions = [] int prevMinorIndex = -1 // index in the versions list of the last minor from the prev major int lastPrevMinor = -1 // the minor version number from the prev major we most recently seen for (String line : versionLines) { - Matcher match = line =~ /\W+public static final Version V_(\d+)_(\d+)_(\d+)(_UNRELEASED)? .*/ + /* Note that this skips alphas and betas which is fine because they aren't + * compatible with anything. */ + Matcher match = line =~ /\W+public static final Version V_(\d+)_(\d+)_(\d+) .*/ if (match.matches()) { int major = Integer.parseInt(match.group(1)) int minor = Integer.parseInt(match.group(2)) int bugfix = Integer.parseInt(match.group(3)) - boolean unreleased = match.group(4) != null - Version foundVersion = new Version(major, minor, bugfix, false, unreleased) + Version foundVersion = new Version(major, minor, bugfix, false) if (currentVersion != foundVersion) { versions.add(foundVersion) } @@ -98,8 +104,11 @@ if (currentVersion.bugfix == 0) { // unreleased version of closest branch. So for those cases, the version includes -SNAPSHOT, // and the bwc distribution will checkout and build that version. Version last = versions[-1] - versions[-1] = new Version(last.major, last.minor, last.bugfix, - true, last.unreleased) + versions[-1] = new Version(last.major, last.minor, last.bugfix, true) + if (last.bugfix == 0) { + versions[-2] = new Version( + versions[-2].major, versions[-2].minor, versions[-2].bugfix, true) + } } // injecting groovy property variables into all projects @@ -114,6 +123,44 @@ allprojects { } } +task('verifyVersions') { + description 'Verifies that all released versions that are indexed compatible are listed in Version.java.' + group 'Verification' + enabled = false == gradle.startParameter.isOffline() + doLast { + // Read the list from maven central + Node xml + new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s -> + xml = new XmlParser().parse(s) + } + Set knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }) + + // Limit the known versions to those that should be index compatible + knownVersions = knownVersions.findAll { Integer.parseInt(it.split('\\.')[0]) >= prevMajor } + + /* Limit the listed versions to those that have been marked as released. + * Versions not marked as released don't get the same testing and we want + * to make sure that we flip all unreleased versions to released as soon + * as possible after release. */ + Set actualVersions = new TreeSet<>( + indexCompatVersions + .findAll { false == it.snapshot } + .collect { it.toString() }) + + // TODO this is almost certainly going to fail on 5.4 when we release 5.5.0 + + // Finally, compare! + if (!knownVersions.equals(actualVersions)) { + throw new GradleException("out-of-date versions\nActual :" + + actualVersions + "\nExpected:" + knownVersions + + "; update Version.java") + } + } +} +task('precommit') { + dependsOn(verifyVersions) +} + subprojects { project.afterEvaluate { // include license and notice in jars diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy index 03fe4c34281..1c236c6c44c 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy @@ -29,20 +29,14 @@ public class Version { final int bugfix final int id final boolean snapshot - /** - * Is the vesion listed as {@code _UNRELEASED} in Version.java. - */ - final boolean unreleased - public Version(int major, int minor, int bugfix, boolean snapshot, - boolean unreleased) { + public Version(int major, int minor, int bugfix, boolean snapshot) { this.major = major this.minor = minor this.bugfix = bugfix this.snapshot = snapshot this.id = major * 100000 + minor * 1000 + bugfix * 10 + (snapshot ? 1 : 0) - this.unreleased = unreleased } public static Version fromString(String s) { @@ -54,7 +48,7 @@ public class Version { bugfix = bugfix.split('-')[0] } return new Version(parts[0] as int, parts[1] as int, bugfix as int, - snapshot, false) + snapshot) } @Override diff --git a/core/build.gradle b/core/build.gradle index 516aeb1d0eb..141c647f488 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -277,43 +277,3 @@ if (isEclipse == false || project.path == ":core-tests") { check.dependsOn integTest integTest.mustRunAfter test } - -task('verifyVersions') { - description 'Verifies that all released versions that are indexed compatible are listed in Version.java.' - group 'Verification' - enabled = false == gradle.startParameter.isOffline() - doLast { - // Read the list from maven central - Node xml - new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s -> - xml = new XmlParser().parse(s) - } - Set knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }) - - // Limit the known versions to those that should be wire compatible - String currentVersion = versions.elasticsearch.minus('-SNAPSHOT') - int prevMajor = Integer.parseInt(currentVersion.split('\\.')[0]) - 1 - if (prevMajor == 4) { - // 4 didn't exist, it was 2. - prevMajor = 2; - } - knownVersions = knownVersions.findAll { Integer.parseInt(it.split('\\.')[0]) >= prevMajor } - - /* Limit the listed versions to those that have been marked as released. - * Versions not marked as released don't get the same testing and we want - * to make sure that we flip all unreleased versions to released as soon - * as possible after release. */ - Set actualVersions = new TreeSet<>( - indexCompatVersions - .findAll { false == it.unreleased } - .collect { it.toString() }) - - // Finally, compare! - if (!knownVersions.equals(actualVersions)) { - throw new GradleException("out-of-date versions\nActual :" + - actualVersions + "\nExpected:" + knownVersions + - "; update Version.java") - } - } -} -check.dependsOn(verifyVersions) diff --git a/core/src/main/java/org/elasticsearch/Version.java b/core/src/main/java/org/elasticsearch/Version.java index 15417c5433b..a9a63b151a3 100644 --- a/core/src/main/java/org/elasticsearch/Version.java +++ b/core/src/main/java/org/elasticsearch/Version.java @@ -74,15 +74,17 @@ public class Version implements Comparable { public static final Version V_5_3_2 = new Version(V_5_3_2_ID, org.apache.lucene.util.Version.LUCENE_6_4_2); public static final int V_5_4_0_ID = 5040099; public static final Version V_5_4_0 = new Version(V_5_4_0_ID, org.apache.lucene.util.Version.LUCENE_6_5_0); - public static final int V_5_5_0_ID_UNRELEASED = 5050099; - public static final Version V_5_5_0_UNRELEASED = new Version(V_5_5_0_ID_UNRELEASED, org.apache.lucene.util.Version.LUCENE_6_5_1); - public static final int V_6_0_0_alpha1_ID_UNRELEASED = 6000001; - public static final Version V_6_0_0_alpha1_UNRELEASED = - new Version(V_6_0_0_alpha1_ID_UNRELEASED, org.apache.lucene.util.Version.LUCENE_7_0_0); - public static final int V_6_0_0_alpha2_ID_UNRELEASED = 6000002; - public static final Version V_6_0_0_alpha2_UNRELEASED = - new Version(V_6_0_0_alpha2_ID_UNRELEASED, org.apache.lucene.util.Version.LUCENE_7_0_0); - public static final Version CURRENT = V_6_0_0_alpha2_UNRELEASED; + public static final int V_5_4_1_ID = 5040199; + public static final Version V_5_4_1 = new Version(V_5_4_1_ID, org.apache.lucene.util.Version.LUCENE_6_5_0); + public static final int V_5_5_0_ID = 5050099; + public static final Version V_5_5_0 = new Version(V_5_5_0_ID, org.apache.lucene.util.Version.LUCENE_6_5_0); + public static final int V_6_0_0_alpha1_ID = 6000001; + public static final Version V_6_0_0_alpha1 = + new Version(V_6_0_0_alpha1_ID, org.apache.lucene.util.Version.LUCENE_7_0_0); + public static final int V_6_0_0_alpha2_ID = 6000002; + public static final Version V_6_0_0_alpha2 = + new Version(V_6_0_0_alpha2_ID, org.apache.lucene.util.Version.LUCENE_7_0_0); + public static final Version CURRENT = V_6_0_0_alpha2; // unreleased versions must be added to the above list with the suffix _UNRELEASED (with the exception of CURRENT) @@ -97,12 +99,14 @@ public class Version implements Comparable { public static Version fromId(int id) { switch (id) { - case V_6_0_0_alpha2_ID_UNRELEASED: - return V_6_0_0_alpha2_UNRELEASED; - case V_6_0_0_alpha1_ID_UNRELEASED: - return V_6_0_0_alpha1_UNRELEASED; - case V_5_5_0_ID_UNRELEASED: - return V_5_5_0_UNRELEASED; + case V_6_0_0_alpha2_ID: + return V_6_0_0_alpha2; + case V_6_0_0_alpha1_ID: + return V_6_0_0_alpha1; + case V_5_5_0_ID: + return V_5_5_0; + case V_5_4_1_ID: + return V_5_4_1; case V_5_4_0_ID: return V_5_4_0; case V_5_3_2_ID: diff --git a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java index aacb0ff17e7..64f63025279 100644 --- a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java +++ b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java @@ -261,7 +261,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr type = in.readString(); id = in.readString(); version = in.readZLong(); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { seqNo = in.readZLong(); primaryTerm = in.readVLong(); } else { @@ -279,7 +279,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr out.writeString(type); out.writeString(id); out.writeZLong(version); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeZLong(seqNo); out.writeVLong(primaryTerm); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java index 4fc1c9c96fa..cdc869e529d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java @@ -79,7 +79,7 @@ public class ClusterStateResponse extends ActionResponse { super.readFrom(in); clusterName = new ClusterName(in); clusterState = ClusterState.readFrom(in, null); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { totalCompressedSize = new ByteSizeValue(in); } else { // in a mixed cluster, if a pre 6.0 node processes the get cluster state @@ -95,7 +95,7 @@ public class ClusterStateResponse extends ActionResponse { super.writeTo(out); clusterName.writeTo(out); clusterState.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { totalCompressedSize.writeTo(out); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index a294d6cb771..0139726903b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -492,7 +492,7 @@ public class CreateIndexRequest extends AcknowledgedRequest for (int i = 0; i < size; i++) { final String type = in.readString(); String source = in.readString(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to 5.3.0 after backport + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // TODO change to 5.3.0 after backport // we do not know the content type that comes from earlier versions so we autodetect and convert source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source)); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java index 6ad389c13d9..8cded12b030 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.shards; import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; @@ -34,7 +35,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.shard.ShardStateMetaData; import java.io.IOException; import java.util.ArrayList; @@ -165,7 +165,7 @@ public class IndicesShardStoresResponse extends ActionResponse implements ToXCon @Override public void readFrom(StreamInput in) throws IOException { node = new DiscoveryNode(in); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // legacy version in.readLong(); } @@ -179,7 +179,7 @@ public class IndicesShardStoresResponse extends ActionResponse implements ToXCon @Override public void writeTo(StreamOutput out) throws IOException { node.writeTo(out); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // legacy version out.writeLong(-1L); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/ShardStats.java b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/ShardStats.java index 150b7c6a52b..3d1e567fa1c 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/ShardStats.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/ShardStats.java @@ -104,7 +104,7 @@ public class ShardStats implements Streamable, Writeable, ToXContent { statePath = in.readString(); dataPath = in.readString(); isCustomDataPath = in.readBoolean(); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { seqNoStats = in.readOptionalWriteable(SeqNoStats::new); } } @@ -117,7 +117,7 @@ public class ShardStats implements Streamable, Writeable, ToXContent { out.writeString(statePath); out.writeString(dataPath); out.writeBoolean(isCustomDataPath); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeOptionalWriteable(seqNoStats); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index 18060d57f09..99ad163f48d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -475,7 +475,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest 0 ? indexPatterns.get(0) : ""); diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkItemRequest.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkItemRequest.java index 50da1476f49..39e03277c37 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkItemRequest.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkItemRequest.java @@ -78,7 +78,7 @@ public class BulkItemRequest implements Streamable { if (in.readBoolean()) { primaryResponse = BulkItemResponse.readBulkItem(in); } - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO remove once backported + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // TODO remove once backported boolean ignoreOnReplica = in.readBoolean(); if (ignoreOnReplica == false && primaryResponse != null) { assert primaryResponse.isFailed() == false : "expected no failure on the primary response"; @@ -89,7 +89,7 @@ public class BulkItemRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(id); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO remove once backported + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // TODO remove once backported // old nodes expect updated version and version type on the request if (primaryResponse != null) { request.version(primaryResponse.getVersion()); @@ -102,7 +102,7 @@ public class BulkItemRequest implements Streamable { DocWriteRequest.writeDocumentRequest(out, request); } out.writeOptionalStreamable(primaryResponse); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO remove once backported + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // TODO remove once backported if (primaryResponse != null) { out.writeBoolean(primaryResponse.isFailed() || primaryResponse.getResponse().getResult() == DocWriteResponse.Result.NOOP); diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java index 0ddd01187a6..daf10521f9e 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java @@ -211,7 +211,7 @@ public class BulkItemResponse implements Streamable, StatusToXContentObject { id = in.readOptionalString(); cause = in.readException(); status = ExceptionsHelper.status(cause); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { seqNo = in.readZLong(); } else { seqNo = SequenceNumbersService.UNASSIGNED_SEQ_NO; @@ -224,7 +224,7 @@ public class BulkItemResponse implements Streamable, StatusToXContentObject { out.writeString(getType()); out.writeOptionalString(getId()); out.writeException(getCause()); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeZLong(getSeqNo()); } } diff --git a/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java b/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java index 7a47405d92b..b04f8820763 100644 --- a/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java +++ b/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java @@ -78,7 +78,7 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind public void readFrom(StreamInput in) throws IOException { super.readFrom(in); fields = in.readStringArray(); - if (in.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_5_5_0)) { indices = in.readStringArray(); indicesOptions = IndicesOptions.readIndicesOptions(in); mergeResults = in.readBoolean(); @@ -91,7 +91,7 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeStringArray(fields); - if (out.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_5_5_0)) { out.writeStringArray(indices); indicesOptions.writeIndicesOptions(out); out.writeBoolean(mergeResults); diff --git a/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java b/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java index 00c424e1fe7..ae5db583567 100644 --- a/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java +++ b/core/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java @@ -86,7 +86,7 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont super.readFrom(in); this.responseMap = in.readMap(StreamInput::readString, FieldCapabilitiesResponse::readField); - if (in.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_5_5_0)) { indexResponses = in.readList(FieldCapabilitiesIndexResponse::new); } else { indexResponses = Collections.emptyList(); @@ -101,7 +101,7 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeMap(responseMap, StreamOutput::writeString, FieldCapabilitiesResponse::writeField); - if (out.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_5_5_0)) { out.writeList(indexResponses); } diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java index ee9a5b2dfe6..552780e7395 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -523,7 +523,7 @@ public class IndexRequest extends ReplicatedWriteRequest implement id = in.readOptionalString(); routing = in.readOptionalString(); parent = in.readOptionalString(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { in.readOptionalString(); // timestamp in.readOptionalWriteable(TimeValue::new); // ttl } @@ -548,7 +548,7 @@ public class IndexRequest extends ReplicatedWriteRequest implement out.writeOptionalString(id); out.writeOptionalString(routing); out.writeOptionalString(parent); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // Serialize a fake timestamp. 5.x expect this value to be set by the #process method so we can't use null. // On the other hand, indices created on 5.x do not index the timestamp field. Therefore passing a 0 (or any value) for // the transport layer OK as it will be ignored. diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java index b3dcf6fe1ef..946692f1826 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java @@ -1011,7 +1011,7 @@ public abstract class TransportReplicationAction< @Override public void readFrom(StreamInput in) throws IOException { - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { super.readFrom(in); localCheckpoint = in.readZLong(); allocationId = in.readString(); @@ -1022,7 +1022,7 @@ public abstract class TransportReplicationAction< @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { super.writeTo(out); out.writeZLong(localCheckpoint); out.writeString(allocationId); @@ -1191,7 +1191,7 @@ public abstract class TransportReplicationAction< @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { globalCheckpoint = in.readZLong(); } } @@ -1199,7 +1199,7 @@ public abstract class TransportReplicationAction< @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeZLong(globalCheckpoint); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java index 133c20411fb..2caaa0bddf3 100644 --- a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java +++ b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java @@ -138,7 +138,7 @@ public class ClusterBlock implements Streamable, ToXContent { retryable = in.readBoolean(); disableStatePersistence = in.readBoolean(); status = RestStatus.readFrom(in); - if (in.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_5_5_0)) { allowReleaseResources = in.readBoolean(); } else { allowReleaseResources = false; @@ -156,7 +156,7 @@ public class ClusterBlock implements Streamable, ToXContent { out.writeBoolean(retryable); out.writeBoolean(disableStatePersistence); RestStatus.writeTo(out, status); - if (out.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_5_5_0)) { out.writeBoolean(allowReleaseResources); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java index 5bba34904d0..b22106d9710 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java @@ -210,7 +210,7 @@ public class IndexTemplateMetaData extends AbstractDiffable 0 ? patterns.get(0) : ""); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java index 08d5211e12d..1f6aeb11220 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java @@ -196,7 +196,7 @@ public class MappingMetaData extends AbstractDiffable { source().writeTo(out); // routing out.writeBoolean(routing().required()); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // timestamp out.writeBoolean(false); // enabled out.writeString(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.format()); @@ -233,7 +233,7 @@ public class MappingMetaData extends AbstractDiffable { source = CompressedXContent.readCompressedString(in); // routing routing = new Routing(in.readBoolean()); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // timestamp boolean enabled = in.readBoolean(); if (enabled) { diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 6068d61aaed..8a88ee1751a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -179,7 +179,7 @@ public class OperationRouting extends AbstractComponent { } // if not, then use it as the index int routingHash = Murmur3HashFunction.hash(preference); - if (nodes.getMinNodeVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (nodes.getMinNodeVersion().onOrAfter(Version.V_6_0_0_alpha1)) { // The AllocationService lists shards in a fixed order based on nodes // so earlier versions of this class would have a tendency to // select the same node across different shardIds. diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index d3071eb58f0..b0a1f2ed09f 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -344,7 +344,7 @@ public final class Settings implements ToXContent { final String setting, final Boolean defaultValue, final DeprecationLogger deprecationLogger) { - if (indexVersion.before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (indexVersion.before(Version.V_6_0_0_alpha1)) { //Only emit a warning if the setting's value is not a proper boolean final String value = get(setting, "false"); if (Booleans.isBoolean(value) == false) { diff --git a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java index 5ed7f40fad0..965811f42ac 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java @@ -78,7 +78,7 @@ public final class TransportAddress implements Writeable { * {@link Version#V_5_0_2} as the hostString was not serialized */ public TransportAddress(StreamInput in, @Nullable String hostString) throws IOException { - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // bwc layer for 5.x where we had more than one transport address + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // bwc layer for 5.x where we had more than one transport address final short i = in.readShort(); if(i != 1) { // we fail hard to ensure nobody tries to use some custom transport address impl even if that is difficult to add throw new AssertionError("illegal transport ID from node of version: " + in.getVersion() + " got: " + i + " expected: 1"); @@ -101,7 +101,7 @@ public final class TransportAddress implements Writeable { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeShort((short)1); // this maps to InetSocketTransportAddress in 5.x } byte[] bytes = address.getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 0dc9647c126..f2b046acd97 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -290,7 +290,7 @@ public class TransportNodesListGatewayStartedShards extends @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // legacy version in.readLong(); } @@ -304,7 +304,7 @@ public class TransportNodesListGatewayStartedShards extends @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // legacy version out.writeLong(-1L); } diff --git a/core/src/main/java/org/elasticsearch/index/IndexSortConfig.java b/core/src/main/java/org/elasticsearch/index/IndexSortConfig.java index 1d3f5f0fc23..7ec5acbe3ab 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSortConfig.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSortConfig.java @@ -120,13 +120,13 @@ public final class IndexSortConfig { .map((name) -> new FieldSortSpec(name)) .toArray(FieldSortSpec[]::new); - if (sortSpecs.length > 0 && indexSettings.getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (sortSpecs.length > 0 && indexSettings.getIndexVersionCreated().before(Version.V_6_0_0_alpha1)) { /** * This index might be assigned to a node where the index sorting feature is not available * (ie. versions prior to {@link Version.V_6_0_0_alpha1_UNRELEASED}) so we must fail here rather than later. */ throw new IllegalArgumentException("unsupported index.version.created:" + indexSettings.getIndexVersionCreated() + - ", can't set index.sort on versions prior to " + Version.V_6_0_0_alpha1_UNRELEASED); + ", can't set index.sort on versions prior to " + Version.V_6_0_0_alpha1); } if (INDEX_SORT_ORDER_SETTING.exists(settings)) { diff --git a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 03007d96b9f..ca653ff4124 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -550,14 +550,14 @@ public class InternalEngine extends Engine { } private boolean assertIncomingSequenceNumber(final Engine.Operation.Origin origin, final long seqNo) { - if (engineConfig.getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED) && origin == Operation.Origin.LOCAL_TRANSLOG_RECOVERY) { + if (engineConfig.getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1) && origin == Operation.Origin.LOCAL_TRANSLOG_RECOVERY) { // legacy support assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "old op recovering but it already has a seq no.;" + " index version: " + engineConfig.getIndexSettings().getIndexVersionCreated() + ", seqNo: " + seqNo; } else if (origin == Operation.Origin.PRIMARY) { // sequence number should not be set when operation origin is primary assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "primary ops should never have an assigned seq no.; seqNo: " + seqNo; - } else if (engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + } else if (engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { // sequence number should be set when operation origin is not primary assert seqNo >= 0 : "recovery or replica ops should have an assigned seq no.; origin: " + origin; } @@ -565,7 +565,7 @@ public class InternalEngine extends Engine { } private boolean assertSequenceNumberBeforeIndexing(final Engine.Operation.Origin origin, final long seqNo) { - if (engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED) || + if (engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1) || origin == Operation.Origin.PRIMARY) { // sequence number should be set when operation origin is primary or when all shards are on new nodes assert seqNo >= 0 : "ops should have an assigned seq no.; origin: " + origin; @@ -679,7 +679,7 @@ public class InternalEngine extends Engine { } else { // This can happen if the primary is still on an old node and send traffic without seq# or we recover from translog // created by an old version. - assert config().getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED) : + assert config().getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1) : "index is newly created but op has no sequence numbers. op: " + index; opVsLucene = compareOpToLuceneDocBasedOnVersions(index); } @@ -963,7 +963,7 @@ public class InternalEngine extends Engine { if (delete.seqNo() != SequenceNumbersService.UNASSIGNED_SEQ_NO) { opVsLucene = compareOpToLuceneDocBasedOnSeqNo(delete); } else { - assert config().getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED) : + assert config().getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1) : "index is newly created but op has no sequence numbers. op: " + delete; opVsLucene = compareOpToLuceneDocBasedOnVersions(delete); } diff --git a/core/src/main/java/org/elasticsearch/index/engine/Segment.java b/core/src/main/java/org/elasticsearch/index/engine/Segment.java index 4de85d0020d..b9df3099704 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/Segment.java +++ b/core/src/main/java/org/elasticsearch/index/engine/Segment.java @@ -168,7 +168,7 @@ public class Segment implements Streamable { // verbose mode ramTree = readRamTree(in); } - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { segmentSort = readSegmentSort(in); } else { segmentSort = null; @@ -193,7 +193,7 @@ public class Segment implements Streamable { if (verbose) { writeRamTree(out, ramTree); } - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { writeSegmentSort(out, segmentSort); } } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java index 85403ccc03b..f3001db3926 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java @@ -104,7 +104,7 @@ public class AllFieldMapper extends MetadataFieldMapper { public MetadataFieldMapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { if (node.isEmpty() == false && - parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { throw new IllegalArgumentException("[_all] is disabled in 6.0. As a replacement, you can use an [copy_to] " + "on mapping fields to create your own catch all field."); } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java index 7bd8c79ee67..93c8759d1dc 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -233,7 +233,7 @@ public class BooleanFieldMapper extends FieldMapper { value = fieldType().nullValue(); } } else { - if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1)) { value = context.parser().booleanValue(); } else { value = context.parser().booleanValueLenient(); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java index ca8fcd1ffd8..0570cd73252 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java @@ -205,7 +205,7 @@ public class DynamicTemplate implements ToXContent { try { xcontentFieldType = XContentFieldType.fromString(matchMappingType); } catch (IllegalArgumentException e) { - if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1)) { throw e; } else { DEPRECATION_LOGGER.deprecated("match_mapping_type [" + matchMappingType + "] is invalid and will be ignored: " diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 4d68deef3b7..50f424c268f 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -102,7 +102,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { Function defValue = settings -> { boolean singleType = true; if (settings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null) != null) { - singleType = Version.indexCreated(settings).onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED); + singleType = Version.indexCreated(settings).onOrAfter(Version.V_6_0_0_alpha1); } return Boolean.valueOf(singleType).toString(); }; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java b/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java index 5b2ec6b2d93..18928246772 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java @@ -55,7 +55,7 @@ public class TypeParsers { //TODO 22298: Remove this method and have all call-sites use XContentMapValues.nodeBooleanValue(node) directly. public static boolean nodeBooleanValue(String fieldName, String propertyName, Object node, Mapper.TypeParser.ParserContext parserContext) { - if (parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { return XContentMapValues.nodeBooleanValue(node, fieldName + "." + propertyName); } else { return nodeBooleanValueLenient(fieldName, propertyName, node); @@ -247,7 +247,7 @@ public class TypeParsers { if (parserContext.isWithinMultiField()) { throw new MapperParsingException("include_in_all in multi fields is not allowed. Found the include_in_all in field [" + name + "] which is within a multi field."); - } else if (parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + } else if (parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { throw new MapperParsingException("[include_in_all] is not allowed for indices created on or after version 6.0.0 as " + "[_all] is deprecated. As a replacement, you can use an [copy_to] on mapping fields to create your " + "own catch all field."); diff --git a/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java index c02ff4175c9..cab2aee910f 100644 --- a/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java @@ -88,7 +88,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder { shouldClauses.addAll(readQueries(in)); filterClauses.addAll(readQueries(in)); adjustPureNegative = in.readBoolean(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { in.readBoolean(); // disable_coord } minimumShouldMatch = in.readOptionalString(); @@ -101,7 +101,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder { writeQueries(out, shouldClauses); writeQueries(out, filterClauses); out.writeBoolean(adjustPureNegative); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeBoolean(true); // disable_coord } out.writeOptionalString(minimumShouldMatch); diff --git a/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java index e5fff943cd3..63b09540a18 100644 --- a/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java @@ -111,7 +111,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder= " + Version.V_5_5_0_UNRELEASED.toString()); + if (out.getVersion().before(Version.V_5_5_0)) { + throw new IOException("Invalid output version, must >= " + Version.V_5_5_0.toString()); } out.writeOptionalString(name); out.writeBoolean(ignoreUnmapped); @@ -207,8 +207,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl * Should only be used to send nested inner hits to nodes pre 5.5. */ protected void writeToNestedBWC(StreamOutput out, QueryBuilder query, String nestedPath) throws IOException { - assert out.getVersion().before(Version.V_5_5_0_UNRELEASED) : - "invalid output version, must be < " + Version.V_5_5_0_UNRELEASED.toString(); + assert out.getVersion().before(Version.V_5_5_0) : + "invalid output version, must be < " + Version.V_5_5_0.toString(); writeToBWC(out, query, nestedPath, null); } @@ -217,8 +217,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl * Should only be used to send collapsing inner hits to nodes pre 5.5. */ public void writeToCollapseBWC(StreamOutput out) throws IOException { - assert out.getVersion().before(Version.V_5_5_0_UNRELEASED) : - "invalid output version, must be < " + Version.V_5_5_0_UNRELEASED.toString(); + assert out.getVersion().before(Version.V_5_5_0) : + "invalid output version, must be < " + Version.V_5_5_0.toString(); writeToBWC(out, new MatchAllQueryBuilder(), null, null); } @@ -227,8 +227,8 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl * Should only be used to send hasParent or hasChild inner hits to nodes pre 5.5. */ public void writeToParentChildBWC(StreamOutput out, QueryBuilder query, String parentChildPath) throws IOException { - assert(out.getVersion().before(Version.V_5_5_0_UNRELEASED)) : - "invalid output version, must be < " + Version.V_5_5_0_UNRELEASED.toString(); + assert(out.getVersion().before(Version.V_5_5_0)) : + "invalid output version, must be < " + Version.V_5_5_0.toString(); writeToBWC(out, query, null, parentChildPath); } diff --git a/core/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java index a62b95337f9..ae092443f49 100644 --- a/core/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java @@ -103,7 +103,7 @@ public class NestedQueryBuilder extends AbstractQueryBuilder out.writeString(path); out.writeVInt(scoreMode.ordinal()); out.writeNamedWriteable(query); - if (out.getVersion().before(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().before(Version.V_5_5_0)) { final boolean hasInnerHit = innerHitBuilder != null; out.writeBoolean(hasInnerHit); if (hasInnerHit) { diff --git a/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncAction.java b/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncAction.java index a55b920bb27..7baed972fcb 100644 --- a/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncAction.java +++ b/core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncAction.java @@ -86,7 +86,7 @@ public class GlobalCheckpointSyncAction extends TransportReplicationAction< final ConcreteReplicaRequest replicaRequest, final DiscoveryNode node, final ActionListener listener) { - if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { super.sendReplicaRequest(replicaRequest, node, listener); } else { listener.onResponse(new ReplicaResponse(replicaRequest.getTargetAllocationID(), SequenceNumbersService.UNASSIGNED_SEQ_NO)); diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 557b5996668..35ab1db1418 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1092,7 +1092,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl private boolean assertMaxUnsafeAutoIdInCommit() throws IOException { final Map userData = SegmentInfos.readLatestCommit(store.directory()).getUserData(); - if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_5_0_UNRELEASED) && + if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_5_0) && // TODO: LOCAL_SHARDS need to transfer this information recoveryState().getRecoverySource().getType() != RecoverySource.Type.LOCAL_SHARDS) { // as of 5.5.0, the engine stores the maxUnsafeAutoIdTimestamp in the commit point. diff --git a/core/src/main/java/org/elasticsearch/index/store/StoreStats.java b/core/src/main/java/org/elasticsearch/index/store/StoreStats.java index 422508d8237..1ed7d6d01e8 100644 --- a/core/src/main/java/org/elasticsearch/index/store/StoreStats.java +++ b/core/src/main/java/org/elasticsearch/index/store/StoreStats.java @@ -68,7 +68,7 @@ public class StoreStats implements Streamable, ToXContent { @Override public void readFrom(StreamInput in) throws IOException { sizeInBytes = in.readVLong(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { in.readVLong(); // throttleTimeInNanos } } @@ -76,7 +76,7 @@ public class StoreStats implements Streamable, ToXContent { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVLong(sizeInBytes); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeVLong(0L); // throttleTimeInNanos } } diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index 147a952507a..d230785a23e 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -591,7 +591,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple final DiscoveryNodes nodes) { return shardRoutings .stream() - .filter(sr -> nodes.get(sr.currentNodeId()).getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) + .filter(sr -> nodes.get(sr.currentNodeId()).getVersion().onOrAfter(Version.V_6_0_0_alpha1)) .map(ShardRouting::allocationId) .map(AllocationId::getId) .collect(Collectors.toSet()); diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java index eaace661077..2bdf45fede2 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java @@ -60,7 +60,7 @@ public class RecoveryFinalizeRecoveryRequest extends TransportRequest { super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { globalCheckpoint = in.readZLong(); } else { globalCheckpoint = SequenceNumbersService.UNASSIGNED_SEQ_NO; @@ -72,7 +72,7 @@ public class RecoveryFinalizeRecoveryRequest extends TransportRequest { super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeZLong(globalCheckpoint); } } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java index 155aa53e71a..61cd986a1ae 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java @@ -61,7 +61,7 @@ public class RecoveryPrepareForTranslogOperationsRequest extends TransportReques recoveryId = in.readLong(); shardId = ShardId.readShardId(in); totalTranslogOps = in.readVInt(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { in.readLong(); // maxUnsafeAutoIdTimestamp } } @@ -72,7 +72,7 @@ public class RecoveryPrepareForTranslogOperationsRequest extends TransportReques out.writeLong(recoveryId); shardId.writeTo(out); out.writeVInt(totalTranslogOps); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeLong(IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP); // maxUnsafeAutoIdTimestamp } } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsResponse.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsResponse.java index 7427e631fb0..731eb28ed92 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsResponse.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsResponse.java @@ -44,7 +44,7 @@ public class RecoveryTranslogOperationsResponse extends TransportResponse { @Override public void writeTo(final StreamOutput out) throws IOException { // before 6.0.0 we responded with an empty response so we have to maintain that - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeZLong(localCheckpoint); } } @@ -52,7 +52,7 @@ public class RecoveryTranslogOperationsResponse extends TransportResponse { @Override public void readFrom(final StreamInput in) throws IOException { // before 6.0.0 we received an empty response so we have to maintain that - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { localCheckpoint = in.readZLong(); } else { diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java b/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java index a2a578cc722..825fa8306ba 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java @@ -119,7 +119,7 @@ public class StartRecoveryRequest extends TransportRequest { targetNode = new DiscoveryNode(in); metadataSnapshot = new Store.MetadataSnapshot(in); primaryRelocation = in.readBoolean(); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { startingSeqNo = in.readLong(); } else { startingSeqNo = SequenceNumbersService.UNASSIGNED_SEQ_NO; @@ -136,7 +136,7 @@ public class StartRecoveryRequest extends TransportRequest { targetNode.writeTo(out); metadataSnapshot.writeTo(out); out.writeBoolean(primaryRelocation); - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeLong(startingSeqNo); } } diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java index 6f5e9a52b4f..f2538365a71 100644 --- a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java @@ -70,7 +70,7 @@ public class FsInfo implements Iterable, Writeable, ToXContent { total = in.readLong(); free = in.readLong(); available = in.readLong(); - if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().before(Version.V_6_0_0_alpha1)) { in.readOptionalBoolean(); } } @@ -83,7 +83,7 @@ public class FsInfo implements Iterable, Writeable, ToXContent { out.writeLong(total); out.writeLong(free); out.writeLong(available); - if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeOptionalBoolean(null); } } @@ -455,7 +455,7 @@ public class FsInfo implements Iterable, Writeable, ToXContent { paths[i] = new Path(in); } this.total = total(); - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { this.leastDiskEstimate = in.readOptionalWriteable(DiskUsage::new); this.mostDiskEstimate = in.readOptionalWriteable(DiskUsage::new); } else { @@ -472,7 +472,7 @@ public class FsInfo implements Iterable, Writeable, ToXContent { for (Path path : paths) { path.writeTo(out); } - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { out.writeOptionalWriteable(this.leastDiskEstimate); out.writeOptionalWriteable(this.mostDiskEstimate); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java index e81c0b1890b..31594e28041 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java @@ -430,7 +430,7 @@ public class InternalOrder extends BucketOrder { * @throws IOException on error reading from the stream. */ public static BucketOrder readHistogramOrder(StreamInput in, boolean bwcOrderFlag) throws IOException { - if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha2_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha2)) { return Streams.readOrder(in); } else { // backwards compat logic if (bwcOrderFlag == false || in.readBoolean()) { @@ -486,7 +486,7 @@ public class InternalOrder extends BucketOrder { * @throws IOException on error writing to the stream. */ public static void writeHistogramOrder(BucketOrder order, StreamOutput out, boolean bwcOrderFlag) throws IOException { - if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha2_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha2)) { order.writeTo(out); } else { // backwards compat logic if(bwcOrderFlag) { // need to add flag that determines if order exists diff --git a/core/src/main/java/org/elasticsearch/search/collapse/CollapseBuilder.java b/core/src/main/java/org/elasticsearch/search/collapse/CollapseBuilder.java index df8808f4473..93f4b8bf41c 100644 --- a/core/src/main/java/org/elasticsearch/search/collapse/CollapseBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/collapse/CollapseBuilder.java @@ -95,7 +95,7 @@ public class CollapseBuilder implements Writeable, ToXContentObject { public CollapseBuilder(StreamInput in) throws IOException { this.field = in.readString(); this.maxConcurrentGroupRequests = in.readVInt(); - if (in.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_5_5_0)) { this.innerHits = in.readList(InnerHitBuilder::new); } else { InnerHitBuilder innerHitBuilder = in.readOptionalWriteable(InnerHitBuilder::new); @@ -111,7 +111,7 @@ public class CollapseBuilder implements Writeable, ToXContentObject { public void writeTo(StreamOutput out) throws IOException { out.writeString(field); out.writeVInt(maxConcurrentGroupRequests); - if (out.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_5_5_0)) { out.writeList(innerHits); } else { boolean hasInnerHit = innerHits.isEmpty() == false; diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java index 37cce0ac601..a54e72159f8 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java @@ -70,7 +70,7 @@ public final class SnapshotInfo implements Comparable, ToXContent, private static final String SUCCESSFUL_SHARDS = "successful_shards"; private static final Version VERSION_INCOMPATIBLE_INTRODUCED = Version.V_5_2_0; - public static final Version VERBOSE_INTRODUCED = Version.V_5_5_0_UNRELEASED; + public static final Version VERBOSE_INTRODUCED = Version.V_5_5_0; private static final Comparator COMPARATOR = Comparator.comparing(SnapshotInfo::startTime).thenComparing(SnapshotInfo::snapshotId); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 7b0c4eb752b..b61da9c27f1 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -612,7 +612,7 @@ public class ThreadPool extends AbstractComponent implements Closeable { public void writeTo(StreamOutput out) throws IOException { out.writeString(name); if (type == ThreadPoolType.FIXED_AUTO_QUEUE_SIZE && - out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { + out.getVersion().before(Version.V_6_0_0_alpha1)) { // 5.x doesn't know about the "fixed_auto_queue_size" thread pool type, just write fixed. out.writeString(ThreadPoolType.FIXED.getType()); } else { diff --git a/core/src/test/java/org/elasticsearch/VersionTests.java b/core/src/test/java/org/elasticsearch/VersionTests.java index 27782511de7..3bdec114729 100644 --- a/core/src/test/java/org/elasticsearch/VersionTests.java +++ b/core/src/test/java/org/elasticsearch/VersionTests.java @@ -34,7 +34,7 @@ import java.util.Map; import java.util.Set; import static org.elasticsearch.Version.V_5_3_0; -import static org.elasticsearch.Version.V_6_0_0_alpha2_UNRELEASED; +import static org.elasticsearch.Version.V_6_0_0_alpha2; import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.containsString; @@ -46,30 +46,30 @@ import static org.hamcrest.Matchers.sameInstance; public class VersionTests extends ESTestCase { public void testVersionComparison() throws Exception { - assertThat(V_5_3_0.before(V_6_0_0_alpha2_UNRELEASED), is(true)); + assertThat(V_5_3_0.before(V_6_0_0_alpha2), is(true)); assertThat(V_5_3_0.before(V_5_3_0), is(false)); - assertThat(V_6_0_0_alpha2_UNRELEASED.before(V_5_3_0), is(false)); + assertThat(V_6_0_0_alpha2.before(V_5_3_0), is(false)); - assertThat(V_5_3_0.onOrBefore(V_6_0_0_alpha2_UNRELEASED), is(true)); + assertThat(V_5_3_0.onOrBefore(V_6_0_0_alpha2), is(true)); assertThat(V_5_3_0.onOrBefore(V_5_3_0), is(true)); - assertThat(V_6_0_0_alpha2_UNRELEASED.onOrBefore(V_5_3_0), is(false)); + assertThat(V_6_0_0_alpha2.onOrBefore(V_5_3_0), is(false)); - assertThat(V_5_3_0.after(V_6_0_0_alpha2_UNRELEASED), is(false)); + assertThat(V_5_3_0.after(V_6_0_0_alpha2), is(false)); assertThat(V_5_3_0.after(V_5_3_0), is(false)); - assertThat(V_6_0_0_alpha2_UNRELEASED.after(V_5_3_0), is(true)); + assertThat(V_6_0_0_alpha2.after(V_5_3_0), is(true)); - assertThat(V_5_3_0.onOrAfter(V_6_0_0_alpha2_UNRELEASED), is(false)); + assertThat(V_5_3_0.onOrAfter(V_6_0_0_alpha2), is(false)); assertThat(V_5_3_0.onOrAfter(V_5_3_0), is(true)); - assertThat(V_6_0_0_alpha2_UNRELEASED.onOrAfter(V_5_3_0), is(true)); + assertThat(V_6_0_0_alpha2.onOrAfter(V_5_3_0), is(true)); assertTrue(Version.fromString("5.0.0-alpha2").onOrAfter(Version.fromString("5.0.0-alpha1"))); assertTrue(Version.fromString("5.0.0").onOrAfter(Version.fromString("5.0.0-beta2"))); assertTrue(Version.fromString("5.0.0-rc1").onOrAfter(Version.fromString("5.0.0-beta24"))); assertTrue(Version.fromString("5.0.0-alpha24").before(Version.fromString("5.0.0-beta0"))); - assertThat(V_5_3_0, is(lessThan(V_6_0_0_alpha2_UNRELEASED))); + assertThat(V_5_3_0, is(lessThan(V_6_0_0_alpha2))); assertThat(V_5_3_0.compareTo(V_5_3_0), is(0)); - assertThat(V_6_0_0_alpha2_UNRELEASED, is(greaterThan(V_5_3_0))); + assertThat(V_6_0_0_alpha2, is(greaterThan(V_5_3_0))); } public void testMin() { @@ -97,7 +97,7 @@ public class VersionTests extends ESTestCase { } public void testMinimumIndexCompatibilityVersion() { - assertEquals(Version.V_5_0_0, Version.V_6_0_0_alpha2_UNRELEASED.minimumIndexCompatibilityVersion()); + assertEquals(Version.V_5_0_0, Version.V_6_0_0_alpha2.minimumIndexCompatibilityVersion()); assertEquals(Version.fromId(2000099), Version.V_5_0_0.minimumIndexCompatibilityVersion()); assertEquals(Version.fromId(2000099), Version.V_5_1_1.minimumIndexCompatibilityVersion()); @@ -157,7 +157,7 @@ public class VersionTests extends ESTestCase { public void testIndexCreatedVersion() { // an actual index has a IndexMetaData.SETTING_INDEX_UUID final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_2, - Version.V_5_2_0, Version.V_6_0_0_alpha2_UNRELEASED); + Version.V_5_2_0, Version.V_6_0_0_alpha2); assertEquals(version, Version.indexCreated(Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, "foo").put(IndexMetaData.SETTING_VERSION_CREATED, version).build())); } @@ -170,11 +170,11 @@ public class VersionTests extends ESTestCase { assertThat(Version.fromString("2.3.0").minimumCompatibilityVersion(), equalTo(major)); // from 6.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() - Version lastVersion = VersionUtils.getPreviousVersion(Version.V_6_0_0_alpha2_UNRELEASED); - assertEquals(lastVersion.major, Version.V_6_0_0_alpha2_UNRELEASED.minimumCompatibilityVersion().major); + Version lastVersion = VersionUtils.getPreviousVersion(Version.V_6_0_0_alpha1); + assertEquals(lastVersion.major, Version.V_6_0_0_alpha2.minimumCompatibilityVersion().major); assertEquals("did you miss to bump the minor in Version#minimumCompatibilityVersion()", - lastVersion.minor, Version.V_6_0_0_alpha2_UNRELEASED.minimumCompatibilityVersion().minor); - assertEquals(0, Version.V_6_0_0_alpha2_UNRELEASED.minimumCompatibilityVersion().revision); + lastVersion.minor, Version.V_6_0_0_alpha2.minimumCompatibilityVersion().minor); + assertEquals(0, Version.V_6_0_0_alpha2.minimumCompatibilityVersion().revision); } public void testToString() { @@ -325,8 +325,8 @@ public class VersionTests extends ESTestCase { public void testIsCompatible() { assertTrue(isCompatible(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())); - assertTrue(isCompatible(Version.V_5_5_0_UNRELEASED, Version.V_6_0_0_alpha2_UNRELEASED)); - assertFalse(isCompatible(Version.fromId(2000099), Version.V_6_0_0_alpha2_UNRELEASED)); + assertTrue(isCompatible(Version.V_5_5_0, Version.V_6_0_0_alpha2)); + assertFalse(isCompatible(Version.fromId(2000099), Version.V_6_0_0_alpha2)); assertFalse(isCompatible(Version.fromId(2000099), Version.V_5_0_0)); assertTrue(isCompatible(Version.fromString("6.0.0"), Version.fromString("7.0.0"))); if (Version.CURRENT.isRelease()) { diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java index 6eec34a90e9..80ca8cc275a 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java @@ -155,7 +155,7 @@ public class SettingsTests extends ESTestCase { // time to say goodbye? assertTrue( "It's time to implement #22298. Please delete this test and Settings#getAsBooleanLenientForPreEs6Indices().", - Version.CURRENT.minimumCompatibilityVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)); + Version.CURRENT.minimumCompatibilityVersion().before(Version.V_6_0_0_alpha1)); String falsy = randomFrom("false", "off", "no", "0"); diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 9f4a33ada6e..8bf948240b5 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2578,7 +2578,7 @@ public class InternalEngineTests extends ESTestCase { for (int i = 0; i < numExtraDocs; i++) { ParsedDocument doc = testParsedDocument("extra" + Integer.toString(i), null, testDocument(), new BytesArray("{}"), null); Term uid; - if (indexMetaData.getCreationVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (indexMetaData.getCreationVersion().onOrAfter(Version.V_6_0_0_alpha1)) { uid = new Term(IdFieldMapper.NAME, doc.id()); } else { uid = new Term(UidFieldMapper.NAME, Uid.createUid(doc.type(), doc.id())); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java index ffc921d013a..7ed6efe516a 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java @@ -56,7 +56,7 @@ public class DynamicTemplateTests extends ESTestCase { templateDef2.put("mapping", Collections.singletonMap("store", true)); // if a wrong match type is specified, we ignore the template IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> DynamicTemplate.parse("my_template", templateDef2, Version.V_6_0_0_alpha1_UNRELEASED)); + () -> DynamicTemplate.parse("my_template", templateDef2, Version.V_6_0_0_alpha1)); assertEquals("No field type matched on [text], possible values are [object, string, long, double, boolean, date, binary]", e.getMessage()); } diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java index 6981ebdae4d..58c2fa6277c 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java @@ -71,7 +71,7 @@ public class StartRecoveryRequestTests extends ESTestCase { assertThat(outRequest.metadataSnapshot().asMap(), equalTo(inRequest.metadataSnapshot().asMap())); assertThat(outRequest.isPrimaryRelocation(), equalTo(inRequest.isPrimaryRelocation())); assertThat(outRequest.recoveryId(), equalTo(inRequest.recoveryId())); - if (targetNodeVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) { + if (targetNodeVersion.onOrAfter(Version.V_6_0_0_alpha1)) { assertThat(outRequest.startingSeqNo(), equalTo(inRequest.startingSeqNo())); } else { assertThat(SequenceNumbersService.UNASSIGNED_SEQ_NO, equalTo(inRequest.startingSeqNo())); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/InternalOrderTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/InternalOrderTests.java index 43d10af99fb..d26eeca3871 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/InternalOrderTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/InternalOrderTests.java @@ -110,7 +110,7 @@ public class InternalOrderTests extends AbstractSerializingTestCase for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) { BucketOrder order = createTestInstance(); Version bwcVersion = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), - VersionUtils.getPreviousVersion(Version.V_6_0_0_alpha2_UNRELEASED)); + VersionUtils.getPreviousVersion(Version.V_6_0_0_alpha2)); boolean bwcOrderFlag = randomBoolean(); try (BytesStreamOutput out = new BytesStreamOutput()) { out.setVersion(bwcVersion); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java index fceb6fb98d9..bd294db6d29 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java @@ -112,7 +112,7 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - if (in.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (in.getVersion().onOrAfter(Version.V_5_5_0)) { maxConcurrentSearchRequests = in.readVInt(); } requests = in.readStreamableList(SearchTemplateRequest::new); @@ -121,7 +121,7 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_5_5_0_UNRELEASED)) { + if (out.getVersion().onOrAfter(Version.V_5_5_0)) { out.writeVInt(maxConcurrentSearchRequests); } out.writeStreamableList(requests); diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java index 50fb925de68..f574236b351 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java @@ -126,7 +126,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder, List> resolveReleasedVersions(Version current, Class versionClass) { + Field[] fields = versionClass.getFields(); + List versions = new ArrayList<>(fields.length); + for (final Field field : fields) { + final int mod = field.getModifiers(); + if (false == Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { + continue; + } + if (field.getType() != Version.class) { + continue; + } + assert field.getName().matches("(V(_\\d+)+(_(alpha|beta|rc)\\d+)?|CURRENT)") : field.getName(); + if ("CURRENT".equals(field.getName())) { + continue; + } + try { + versions.add(((Version) field.get(null))); + } catch (final IllegalAccessException e) { + throw new RuntimeException(e); + } + } + Collections.sort(versions); + assert versions.get(versions.size() - 1).equals(current) : "The highest version must be the current one " + + "but was [" + versions.get(versions.size() - 1) + "] and current was [" + current + "]"; + + if (current.revision != 0) { + /* If we are in a stable branch there should be no unreleased version constants + * because we don't expect to release any new versions in older branches. If there + * are extra constants then gradle will yell about it. */ + return new Tuple<>(unmodifiableList(versions), emptyList()); + } + + /* If we are on a patch release then we know that at least the version before the + * current one is unreleased. If it is released then gradle would be complaining. */ + int unreleasedIndex = versions.size() - 2; + while (true) { + if (unreleasedIndex < 0) { + throw new IllegalArgumentException("Couldn't find first non-alpha release"); + } + /* Technically we don't support backwards compatiblity for alphas, betas, + * and rcs. But the testing infrastructure requires that we act as though we + * do. This is a difference between the gradle and Java logic but should be + * fairly safe as it is errs on us being more compatible rather than less.... + * Anyway, the upshot is that we never declare alphas as unreleased, no + * matter where they are in the list. */ + if (versions.get(unreleasedIndex).isRelease()) { + break; + } + unreleasedIndex--; + } + + Version unreleased = versions.remove(unreleasedIndex); + if (unreleased.revision == 0) { + /* If the last unreleased version is itself a patch release then gradle enforces + * that there is yet another unreleased version before that. */ + unreleasedIndex--; + Version earlierUnreleased = versions.remove(unreleasedIndex); + return new Tuple<>(unmodifiableList(versions), unmodifiableList(Arrays.asList(earlierUnreleased, unreleased))); + } + return new Tuple<>(unmodifiableList(versions), singletonList(unreleased)); + } private static final List RELEASED_VERSIONS; private static final List UNRELEASED_VERSIONS; static { - final Field[] declaredFields = Version.class.getFields(); - final Set releasedIdsSet = new HashSet<>(); - final Set unreleasedIdsSet = new HashSet<>(); - for (final Field field : declaredFields) { - final int mod = field.getModifiers(); - if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { - if (field.getType() == Version.class) { - final int id; - try { - id = ((Version) field.get(null)).id; - } catch (final IllegalAccessException e) { - throw new RuntimeException(e); - } - assert field.getName().matches("(V(_\\d+)+(_(alpha|beta|rc)\\d+)?(_UNRELEASED)?|CURRENT)") : field.getName(); - // note that below we remove CURRENT and add it to released; we do it this way because there are two constants that - // correspond to CURRENT, CURRENT itself and the actual version that CURRENT points to - if (field.getName().equals("CURRENT") || field.getName().endsWith("UNRELEASED")) { - unreleasedIdsSet.add(id); - } else { - releasedIdsSet.add(id); - } - } - } - } - - // treat CURRENT as released for BWC testing - unreleasedIdsSet.remove(Version.CURRENT.id); - releasedIdsSet.add(Version.CURRENT.id); - - // unreleasedIdsSet and releasedIdsSet should be disjoint - assert unreleasedIdsSet.stream().filter(releasedIdsSet::contains).collect(Collectors.toSet()).isEmpty(); - - RELEASED_VERSIONS = - Collections.unmodifiableList(releasedIdsSet.stream().sorted().map(Version::fromId).collect(Collectors.toList())); - UNRELEASED_VERSIONS = - Collections.unmodifiableList(unreleasedIdsSet.stream().sorted().map(Version::fromId).collect(Collectors.toList())); + Tuple, List> versions = resolveReleasedVersions(Version.CURRENT, Version.class); + RELEASED_VERSIONS = versions.v1(); + UNRELEASED_VERSIONS = versions.v2(); } /** diff --git a/test/framework/src/test/java/org/elasticsearch/test/VersionUtilsTests.java b/test/framework/src/test/java/org/elasticsearch/test/VersionUtilsTests.java new file mode 100644 index 00000000000..4b59abc0a31 --- /dev/null +++ b/test/framework/src/test/java/org/elasticsearch/test/VersionUtilsTests.java @@ -0,0 +1,162 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.test; + +import org.elasticsearch.Version; +import org.elasticsearch.common.collect.Tuple; + +import java.util.Arrays; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +public class VersionUtilsTests extends ESTestCase { + + public void testAllVersionsSorted() { + List allVersions = VersionUtils.allReleasedVersions(); + for (int i = 0, j = 1; j < allVersions.size(); ++i, ++j) { + assertTrue(allVersions.get(i).before(allVersions.get(j))); + } + } + + public void testRandomVersionBetween() { + // full range + Version got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), null, Version.CURRENT); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), null); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + + // sub range + got = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, + Version.V_6_0_0_alpha2); + assertTrue(got.onOrAfter(Version.V_5_0_0)); + assertTrue(got.onOrBefore(Version.V_6_0_0_alpha2)); + + // unbounded lower + got = VersionUtils.randomVersionBetween(random(), null, Version.V_6_0_0_alpha2); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.V_6_0_0_alpha2)); + got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.allReleasedVersions().get(0)); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(VersionUtils.allReleasedVersions().get(0))); + + // unbounded upper + got = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, null); + assertTrue(got.onOrAfter(Version.V_5_0_0)); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getPreviousVersion(), null); + assertTrue(got.onOrAfter(VersionUtils.getPreviousVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + + // range of one + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getFirstVersion()); + assertEquals(got, VersionUtils.getFirstVersion()); + got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, Version.CURRENT); + assertEquals(got, Version.CURRENT); + got = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0_alpha2, + Version.V_6_0_0_alpha2); + assertEquals(got, Version.V_6_0_0_alpha2); + + // implicit range of one + got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.getFirstVersion()); + assertEquals(got, VersionUtils.getFirstVersion()); + got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, null); + assertEquals(got, Version.CURRENT); + } + + static class TestReleaseBranch { + public static final Version V_5_3_0 = Version.fromString("5.3.0"); + public static final Version V_5_3_1 = Version.fromString("5.3.1"); + public static final Version V_5_3_2 = Version.fromString("5.3.2"); + public static final Version V_5_4_0 = Version.fromString("5.4.0"); + public static final Version V_5_4_1 = Version.fromString("5.4.1"); + public static final Version CURRENT = V_5_4_1; + } + public void testResolveReleasedVersionsForReleaseBranch() { + Tuple, List> t = VersionUtils.resolveReleasedVersions(TestReleaseBranch.CURRENT, TestReleaseBranch.class); + List released = t.v1(); + List unreleased = t.v2(); + assertEquals(Arrays.asList(TestReleaseBranch.V_5_3_0, TestReleaseBranch.V_5_3_1, TestReleaseBranch.V_5_3_2, + TestReleaseBranch.V_5_4_0, TestReleaseBranch.V_5_4_1), released); + assertEquals(emptyList(), unreleased); + } + + static class TestStableBranch { + public static final Version V_5_3_0 = Version.fromString("5.3.0"); + public static final Version V_5_3_1 = Version.fromString("5.3.1"); + public static final Version V_5_3_2 = Version.fromString("5.3.2"); + public static final Version V_5_4_0 = Version.fromString("5.4.0"); + public static final Version CURRENT = V_5_4_0; + } + public void testResolveReleasedVersionsForUnreleasedStableBranch() { + Tuple, List> t = VersionUtils.resolveReleasedVersions(TestStableBranch.CURRENT, + TestStableBranch.class); + List released = t.v1(); + List unreleased = t.v2(); + assertEquals( + Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1, TestStableBranch.V_5_4_0), + released); + assertEquals(singletonList(TestStableBranch.V_5_3_2), unreleased); + } + + static class TestStableBranchBehindStableBranch { + public static final Version V_5_3_0 = Version.fromString("5.3.0"); + public static final Version V_5_3_1 = Version.fromString("5.3.1"); + public static final Version V_5_3_2 = Version.fromString("5.3.2"); + public static final Version V_5_4_0 = Version.fromString("5.4.0"); + public static final Version V_5_5_0 = Version.fromString("5.5.0"); + public static final Version CURRENT = V_5_5_0; + } + public void testResolveReleasedVersionsForStableBtranchBehindStableBranch() { + Tuple, List> t = VersionUtils.resolveReleasedVersions(TestStableBranchBehindStableBranch.CURRENT, + TestStableBranchBehindStableBranch.class); + List released = t.v1(); + List unreleased = t.v2(); + assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1, + TestStableBranchBehindStableBranch.V_5_5_0), released); + assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, Version.V_5_4_0), unreleased); + } + + static class TestUnstableBranch { + public static final Version V_5_3_0 = Version.fromString("5.3.0"); + public static final Version V_5_3_1 = Version.fromString("5.3.1"); + public static final Version V_5_3_2 = Version.fromString("5.3.2"); + public static final Version V_5_4_0 = Version.fromString("5.4.0"); + public static final Version V_6_0_0_alpha1 = Version.fromString("6.0.0-alpha1"); + public static final Version V_6_0_0_alpha2 = Version.fromString("6.0.0-alpha2"); + public static final Version CURRENT = V_6_0_0_alpha2; + } + public void testResolveReleasedVersionsForUnstableBranch() { + Tuple, List> t = VersionUtils.resolveReleasedVersions(TestUnstableBranch.CURRENT, + TestUnstableBranch.class); + List released = t.v1(); + List unreleased = t.v2(); + assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_0, TestUnstableBranch.V_5_3_1, + TestUnstableBranch.V_6_0_0_alpha1, TestUnstableBranch.V_6_0_0_alpha2), released); + assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0), unreleased); + } + + // TODO add a test that compares gradle and VersionUtils.java in a followup +} diff --git a/test/framework/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java b/test/framework/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java deleted file mode 100644 index 5641917bc45..00000000000 --- a/test/framework/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.test.test; - -import org.elasticsearch.Version; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.VersionUtils; - -import java.util.List; - -public class VersionUtilsTests extends ESTestCase { - - public void testAllVersionsSorted() { - List allVersions = VersionUtils.allReleasedVersions(); - for (int i = 0, j = 1; j < allVersions.size(); ++i, ++j) { - assertTrue(allVersions.get(i).before(allVersions.get(j))); - } - } - - public void testRandomVersionBetween() { - // full range - Version got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT); - assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); - assertTrue(got.onOrBefore(Version.CURRENT)); - got = VersionUtils.randomVersionBetween(random(), null, Version.CURRENT); - assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); - assertTrue(got.onOrBefore(Version.CURRENT)); - got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), null); - assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); - assertTrue(got.onOrBefore(Version.CURRENT)); - - // sub range - got = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, - Version.V_6_0_0_alpha2_UNRELEASED); - assertTrue(got.onOrAfter(Version.V_5_0_0)); - assertTrue(got.onOrBefore(Version.V_6_0_0_alpha2_UNRELEASED)); - - // unbounded lower - got = VersionUtils.randomVersionBetween(random(), null, Version.V_6_0_0_alpha2_UNRELEASED); - assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); - assertTrue(got.onOrBefore(Version.V_6_0_0_alpha2_UNRELEASED)); - got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.allReleasedVersions().get(0)); - assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); - assertTrue(got.onOrBefore(VersionUtils.allReleasedVersions().get(0))); - - // unbounded upper - got = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, null); - assertTrue(got.onOrAfter(Version.V_5_0_0)); - assertTrue(got.onOrBefore(Version.CURRENT)); - got = VersionUtils.randomVersionBetween(random(), VersionUtils.getPreviousVersion(), null); - assertTrue(got.onOrAfter(VersionUtils.getPreviousVersion())); - assertTrue(got.onOrBefore(Version.CURRENT)); - - // range of one - got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getFirstVersion()); - assertEquals(got, VersionUtils.getFirstVersion()); - got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, Version.CURRENT); - assertEquals(got, Version.CURRENT); - got = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0_alpha2_UNRELEASED, - Version.V_6_0_0_alpha2_UNRELEASED); - assertEquals(got, Version.V_6_0_0_alpha2_UNRELEASED); - - // implicit range of one - got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.getFirstVersion()); - assertEquals(got, VersionUtils.getFirstVersion()); - got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, null); - assertEquals(got, Version.CURRENT); - } -}