Skip to content

Commit e0a678f

Browse files
authored
Remove version.qualified from MainResponse (#35412)
The fully qualified version will be returned as `version.number`
1 parent afd42df commit e0a678f

File tree

12 files changed

+51
-23
lines changed

12 files changed

+51
-23
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/PingAndInfoIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testInfo() throws IOException {
5252
assertEquals(versionMap.get("build_hash"), info.getBuild().shortHash());
5353
assertEquals(versionMap.get("build_date"), info.getBuild().date());
5454
assertEquals(versionMap.get("build_snapshot"), info.getBuild().isSnapshot());
55-
assertEquals(versionMap.get("number"), info.getVersion().toString());
55+
assertTrue(versionMap.get("number").toString().startsWith(info.getVersion().toString()));
5656
assertEquals(versionMap.get("lucene_version"), info.getVersion().luceneVersion.toString());
5757
}
5858

docs/plugins/discovery-azure-classic.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,12 @@ This command should give you a JSON result:
371371
"cluster_name" : "elasticsearch",
372372
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
373373
"version" : {
374-
"number" : "{version}",
374+
"number" : "{version_qualified}",
375375
"build_flavor" : "{build_flavor}",
376376
"build_type" : "zip",
377377
"build_hash" : "f27399d",
378378
"build_date" : "2016-03-30T09:51:41.449Z",
379379
"build_snapshot" : false,
380-
"qualified" : "{version_qualified}",
381380
"lucene_version" : "{lucene_version}",
382381
"minimum_wire_compatibility_version" : "1.2.3",
383382
"minimum_index_compatibility_version" : "1.2.3"

docs/reference/setup/install/check-running.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ which should give you a response something like this:
1818
"cluster_name" : "elasticsearch",
1919
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
2020
"version" : {
21-
"number" : "{version}",
21+
"number" : "{version_qualified}",
2222
"build_flavor" : "{build_flavor}",
2323
"build_type" : "zip",
2424
"build_hash" : "f27399d",
2525
"build_date" : "2016-03-30T09:51:41.449Z",
2626
"build_snapshot" : false,
27-
"qualified" : "{version_qualified}",
2827
"lucene_version" : "{lucene_version}",
2928
"minimum_wire_compatibility_version" : "1.2.3",
3029
"minimum_index_compatibility_version" : "1.2.3"

modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ public void setCausedBy(Throwable causedBy) {
268268
"/", true, a -> (Version) a[0]);
269269
static {
270270
ConstructingObjectParser<Version, XContentType> versionParser = new ConstructingObjectParser<>(
271-
"version", true, a -> Version.fromString((String) a[0]));
271+
"version", true, a -> Version.fromString(
272+
((String) a[0])
273+
.replace("-SNAPSHOT", "")
274+
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
275+
));
272276
versionParser.declareString(constructorArg(), new ParseField("number"));
273277
MAIN_ACTION_PARSER.declareObject(constructorArg(), versionParser, new ParseField("version"));
274278
}

modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSourceTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ public void testLookupRemoteVersion() throws Exception {
150150
assertTrue(called.get());
151151
called.set(false);
152152
sourceWithMockedRemoteCall(false, ContentType.APPLICATION_JSON, "main/5_0_0_alpha_3.json").lookupRemoteVersion(v -> {
153-
// V_5_0_0_alpha3
154-
assertEquals(Version.fromId(5000003), v);
153+
// assert for V_5_0_0 (no qualifier) since we no longer consider qualifier in Version since 7
154+
assertEquals(Version.fromId(5000099), v);
155155
called.set(true);
156156
});
157157
assertTrue(called.get());
158158
called.set(false);
159159
sourceWithMockedRemoteCall(false, ContentType.APPLICATION_JSON, "main/with_unknown_fields.json").lookupRemoteVersion(v -> {
160-
// V_5_0_0_alpha3
161-
assertEquals(Version.fromId(5000003), v);
160+
// V_5_0_0 since we no longer consider qualifier in Version
161+
assertEquals(Version.fromId(5000099), v);
162162
called.set(true);
163163
});
164164
assertTrue(called.get());

qa/vagrant/src/test/resources/packaging/utils/utils.bash

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,19 @@ wait_for_elasticsearch_status() {
516516
# $1 - expected version
517517
check_elasticsearch_version() {
518518
local version=$1
519-
local versionToCheck=$(echo $version | sed -e 's/-SNAPSHOT//' | sed -e 's/-\(alpha\|beta\|rc\)[0-9]//')
519+
local versionToCheck
520+
local major=$(echo ${version} | cut -d. -f1 )
521+
if [ $major -ge 7 ] ; then
522+
versionToCheck=$version
523+
else
524+
versionToCheck=$(echo ${version} | sed -e 's/-SNAPSHOT//')
525+
fi
520526

521527
run curl -s localhost:9200
522528
[ "$status" -eq 0 ]
523529

524530
echo $output | grep \"number\"\ :\ \"$versionToCheck\" || {
525-
echo "Installed an unexpected version:"
531+
echo "Expected $versionToCheck but installed an unexpected version:"
526532
curl -s localhost:9200
527533
false
528534
}

server/src/main/java/org/elasticsearch/Build.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static Type fromDisplayName(final String displayName) {
139139
// not running from the official elasticsearch jar file (unit tests, IDE, uber client jar, shadiness)
140140
shortHash = "Unknown";
141141
date = "Unknown";
142-
version = "Unknown";
142+
version = Version.CURRENT.toString();
143143
final String buildSnapshot = System.getProperty("build.snapshot");
144144
if (buildSnapshot != null) {
145145
try {

server/src/main/java/org/elasticsearch/Version.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ public static Version fromString(String version) {
253253
if (rawMajor >= 5 && snapshot) { // we don't support snapshot as part of the version here anymore
254254
throw new IllegalArgumentException("illegal version format - snapshots are only supported until version 2.x");
255255
}
256+
if (rawMajor >=7 && parts.length == 4) { // we don't support qualifier as part of the version anymore
257+
throw new IllegalArgumentException("illegal version format - qualifiers are only supported until version 6.x");
258+
}
256259
final int betaOffset = rawMajor < 5 ? 0 : 25;
257260
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
258261
final int major = rawMajor * 1000000;

server/src/main/java/org/elasticsearch/action/main/MainResponse.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
107107
builder.field("cluster_name", clusterName.value());
108108
builder.field("cluster_uuid", clusterUuid);
109109
builder.startObject("version")
110-
.field("number", version.toString())
110+
.field("number", build.getQualifiedVersion())
111111
.field("build_flavor", build.flavor().displayName())
112112
.field("build_type", build.type().displayName())
113113
.field("build_hash", build.shortHash())
114114
.field("build_date", build.date())
115115
.field("build_snapshot", build.isSnapshot())
116-
.field("qualified", build.getQualifiedVersion())
117116
.field("lucene_version", version.luceneVersion.toString())
118117
.field("minimum_wire_compatibility_version", version.minimumCompatibilityVersion().toString())
119118
.field("minimum_index_compatibility_version", version.minimumIndexCompatibilityVersion().toString())
@@ -141,9 +140,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
141140
(String) value.get("build_hash"),
142141
(String) value.get("build_date"),
143142
(boolean) value.get("build_snapshot"),
144-
(String) value.get("qualified")
143+
(String) value.get("number")
145144
);
146-
response.version = Version.fromString((String) value.get("number"));
145+
response.version = Version.fromString(
146+
((String) value.get("number"))
147+
.replace("-SNAPSHOT", "")
148+
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
149+
);
147150
}, (parser, context) -> parser.map(), new ParseField("version"));
148151
}
149152

@@ -171,4 +174,15 @@ public boolean equals(Object o) {
171174
public int hashCode() {
172175
return Objects.hash(nodeName, version, clusterUuid, build, clusterName);
173176
}
177+
178+
@Override
179+
public String toString() {
180+
return "MainResponse{" +
181+
"nodeName='" + nodeName + '\'' +
182+
", version=" + version +
183+
", clusterName=" + clusterName +
184+
", clusterUuid='" + clusterUuid + '\'' +
185+
", build=" + build +
186+
'}';
187+
}
174188
}

server/src/test/java/org/elasticsearch/BuildTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void testEqualsAndHashCode() {
111111
assertNotEquals(build, differentSnapshot);
112112

113113
Build differentVersion = new Build(
114-
build.flavor(), build.type(), build.shortHash(), build.date(), build.isSnapshot(), "7.0.0"
114+
build.flavor(), build.type(), build.shortHash(), build.date(), build.isSnapshot(), "1.2.3"
115115
);
116116
assertNotEquals(build, differentVersion);
117117
}

server/src/test/java/org/elasticsearch/action/main/MainResponseTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ protected MainResponse createTestInstance() {
4141
ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
4242
String nodeName = randomAlphaOfLength(10);
4343
final String date = new Date(randomNonNegativeLong()).toString();
44+
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_1, Version.CURRENT);
4445
Build build = new Build(
4546
Build.Flavor.UNKNOWN, Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(),
46-
randomAlphaOfLength(12)
47+
version.toString()
4748
);
48-
Version version = VersionUtils.randomVersion(random());
4949
return new MainResponse(nodeName, version, clusterName, clusterUuid , build);
5050
}
5151

@@ -75,13 +75,12 @@ public void testToXContent() throws IOException {
7575
+ "\"cluster_name\":\"clusterName\","
7676
+ "\"cluster_uuid\":\"" + clusterUUID + "\","
7777
+ "\"version\":{"
78-
+ "\"number\":\"" + version.toString() + "\","
78+
+ "\"number\":\"" + build.getQualifiedVersion() + "\","
7979
+ "\"build_flavor\":\"" + current.flavor().displayName() + "\","
8080
+ "\"build_type\":\"" + current.type().displayName() + "\","
8181
+ "\"build_hash\":\"" + current.shortHash() + "\","
8282
+ "\"build_date\":\"" + current.date() + "\","
8383
+ "\"build_snapshot\":" + current.isSnapshot() + ","
84-
+ "\"qualified\":\"" + current.getQualifiedVersion() + "\","
8584
+ "\"lucene_version\":\"" + version.luceneVersion.toString() + "\","
8685
+ "\"minimum_wire_compatibility_version\":\"" + version.minimumCompatibilityVersion().toString() + "\","
8786
+ "\"minimum_index_compatibility_version\":\"" + version.minimumIndexCompatibilityVersion().toString() + "\"},"

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/VersionHttpResource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ private boolean validateVersion(final Response response) throws IOException {
9696
// the response should be filtered to just '{"version":{"number":"xyz"}}', so this is cheap and guaranteed
9797
@SuppressWarnings("unchecked")
9898
final String versionNumber = (String) ((Map<String, Object>) map.get("version")).get("number");
99-
final Version version = Version.fromString(versionNumber);
99+
final Version version = Version.fromString(
100+
versionNumber
101+
.replace("-SNAPSHOT", "")
102+
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
103+
);
100104

101105
if (version.onOrAfter(minimumVersion)) {
102106
logger.debug("version [{}] >= [{}] and supported for [{}]", version, minimumVersion, resourceOwnerName);

0 commit comments

Comments
 (0)