Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove version.qualified from MainResponse #35412

Merged
merged 18 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testInfo() throws IOException {
assertEquals(versionMap.get("build_hash"), info.getBuild().shortHash());
assertEquals(versionMap.get("build_date"), info.getBuild().date());
assertEquals(versionMap.get("build_snapshot"), info.getBuild().isSnapshot());
assertEquals(versionMap.get("number"), info.getVersion().toString());
assertTrue(versionMap.get("number").toString().startsWith(info.getVersion().toString()));
assertEquals(versionMap.get("lucene_version"), info.getVersion().luceneVersion.toString());
}

Expand Down
3 changes: 1 addition & 2 deletions docs/plugins/discovery-azure-classic.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,12 @@ This command should give you a JSON result:
"cluster_name" : "elasticsearch",
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
"version" : {
"number" : "{version}",
"number" : "{version_qualified}",
"build_flavor" : "{build_flavor}",
"build_type" : "zip",
"build_hash" : "f27399d",
"build_date" : "2016-03-30T09:51:41.449Z",
"build_snapshot" : false,
"qualified" : "{version_qualified}",
"lucene_version" : "{lucene_version}",
"minimum_wire_compatibility_version" : "1.2.3",
"minimum_index_compatibility_version" : "1.2.3"
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/setup/install/check-running.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ which should give you a response something like this:
"cluster_name" : "elasticsearch",
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
"version" : {
"number" : "{version}",
"number" : "{version_qualified}",
"build_flavor" : "{build_flavor}",
"build_type" : "zip",
"build_hash" : "f27399d",
"build_date" : "2016-03-30T09:51:41.449Z",
"build_snapshot" : false,
"qualified" : "{version_qualified}",
"lucene_version" : "{lucene_version}",
"minimum_wire_compatibility_version" : "1.2.3",
"minimum_index_compatibility_version" : "1.2.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ public void setCausedBy(Throwable causedBy) {
"/", true, a -> (Version) a[0]);
static {
ConstructingObjectParser<Version, XContentType> versionParser = new ConstructingObjectParser<>(
"version", true, a -> Version.fromString((String) a[0]));
"version", true, a -> Version.fromString(
((String) a[0])
.replace("-SNAPSHOT", "")
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
));
versionParser.declareString(constructorArg(), new ParseField("number"));
MAIN_ACTION_PARSER.declareObject(constructorArg(), versionParser, new ParseField("version"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ public void testLookupRemoteVersion() throws Exception {
assertTrue(called.get());
called.set(false);
sourceWithMockedRemoteCall(false, ContentType.APPLICATION_JSON, "main/5_0_0_alpha_3.json").lookupRemoteVersion(v -> {
// V_5_0_0_alpha3
assertEquals(Version.fromId(5000003), v);
// assert for V_5_0_0 (no qualifier) since we no longer consider qualifier in Version since 7
assertEquals(Version.fromId(5000099), v);
called.set(true);
});
assertTrue(called.get());
called.set(false);
sourceWithMockedRemoteCall(false, ContentType.APPLICATION_JSON, "main/with_unknown_fields.json").lookupRemoteVersion(v -> {
// V_5_0_0_alpha3
assertEquals(Version.fromId(5000003), v);
// V_5_0_0 since we no longer consider qualifier in Version
assertEquals(Version.fromId(5000099), v);
called.set(true);
});
assertTrue(called.get());
Expand Down
10 changes: 8 additions & 2 deletions qa/vagrant/src/test/resources/packaging/utils/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,19 @@ wait_for_elasticsearch_status() {
# $1 - expected version
check_elasticsearch_version() {
local version=$1
local versionToCheck=$(echo $version | sed -e 's/-SNAPSHOT//' | sed -e 's/-\(alpha\|beta\|rc\)[0-9]//')
local versionToCheck
local major=$(echo ${version} | cut -d. -f1 )
if [ $major -ge 7 ] ; then
versionToCheck=$version
else
versionToCheck=$(echo ${version} | sed -e 's/-SNAPSHOT//')
fi

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

echo $output | grep \"number\"\ :\ \"$versionToCheck\" || {
echo "Installed an unexpected version:"
echo "Expected $versionToCheck but installed an unexpected version:"
curl -s localhost:9200
false
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static Type fromDisplayName(final String displayName) {
// not running from the official elasticsearch jar file (unit tests, IDE, uber client jar, shadiness)
shortHash = "Unknown";
date = "Unknown";
version = "Unknown";
version = Version.CURRENT.toString();
final String buildSnapshot = System.getProperty("build.snapshot");
if (buildSnapshot != null) {
try {
Expand Down
3 changes: 3 additions & 0 deletions server/src/main/java/org/elasticsearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public static Version fromString(String version) {
if (rawMajor >= 5 && snapshot) { // we don't support snapshot as part of the version here anymore
throw new IllegalArgumentException("illegal version format - snapshots are only supported until version 2.x");
}
if (rawMajor >=7 && parts.length == 4) { // we don't support qualifier as part of the version anymore
throw new IllegalArgumentException("illegal version format - qualifiers are only supported until version 6.x");
}
final int betaOffset = rawMajor < 5 ? 0 : 25;
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
final int major = rawMajor * 1000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("cluster_name", clusterName.value());
builder.field("cluster_uuid", clusterUuid);
builder.startObject("version")
.field("number", version.toString())
.field("number", build.getQualifiedVersion())
.field("build_flavor", build.flavor().displayName())
.field("build_type", build.type().displayName())
.field("build_hash", build.shortHash())
.field("build_date", build.date())
.field("build_snapshot", build.isSnapshot())
.field("qualified", build.getQualifiedVersion())
.field("lucene_version", version.luceneVersion.toString())
.field("minimum_wire_compatibility_version", version.minimumCompatibilityVersion().toString())
.field("minimum_index_compatibility_version", version.minimumIndexCompatibilityVersion().toString())
Expand Down Expand Up @@ -141,9 +140,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
(String) value.get("build_hash"),
(String) value.get("build_date"),
(boolean) value.get("build_snapshot"),
(String) value.get("qualified")
(String) value.get("number")
);
response.version = Version.fromString((String) value.get("number"));
response.version = Version.fromString(
((String) value.get("number"))
.replace("-SNAPSHOT", "")
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
);
}, (parser, context) -> parser.map(), new ParseField("version"));
}

Expand Down Expand Up @@ -171,4 +174,15 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(nodeName, version, clusterUuid, build, clusterName);
}

@Override
public String toString() {
return "MainResponse{" +
"nodeName='" + nodeName + '\'' +
", version=" + version +
", clusterName=" + clusterName +
", clusterUuid='" + clusterUuid + '\'' +
", build=" + build +
'}';
}
}
2 changes: 1 addition & 1 deletion server/src/test/java/org/elasticsearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testEqualsAndHashCode() {
assertNotEquals(build, differentSnapshot);

Build differentVersion = new Build(
build.flavor(), build.type(), build.shortHash(), build.date(), build.isSnapshot(), "7.0.0"
build.flavor(), build.type(), build.shortHash(), build.date(), build.isSnapshot(), "1.2.3"
);
assertNotEquals(build, differentVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ protected MainResponse createTestInstance() {
ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_1, Version.CURRENT);
Build build = new Build(
Build.Flavor.UNKNOWN, Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(),
randomAlphaOfLength(12)
version.toString()
);
Version version = VersionUtils.randomVersion(random());
return new MainResponse(nodeName, version, clusterName, clusterUuid , build);
}

Expand Down Expand Up @@ -75,13 +75,12 @@ public void testToXContent() throws IOException {
+ "\"cluster_name\":\"clusterName\","
+ "\"cluster_uuid\":\"" + clusterUUID + "\","
+ "\"version\":{"
+ "\"number\":\"" + version.toString() + "\","
+ "\"number\":\"" + build.getQualifiedVersion() + "\","
+ "\"build_flavor\":\"" + current.flavor().displayName() + "\","
+ "\"build_type\":\"" + current.type().displayName() + "\","
+ "\"build_hash\":\"" + current.shortHash() + "\","
+ "\"build_date\":\"" + current.date() + "\","
+ "\"build_snapshot\":" + current.isSnapshot() + ","
+ "\"qualified\":\"" + current.getQualifiedVersion() + "\","
+ "\"lucene_version\":\"" + version.luceneVersion.toString() + "\","
+ "\"minimum_wire_compatibility_version\":\"" + version.minimumCompatibilityVersion().toString() + "\","
+ "\"minimum_index_compatibility_version\":\"" + version.minimumIndexCompatibilityVersion().toString() + "\"},"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ private boolean validateVersion(final Response response) throws IOException {
// the response should be filtered to just '{"version":{"number":"xyz"}}', so this is cheap and guaranteed
@SuppressWarnings("unchecked")
final String versionNumber = (String) ((Map<String, Object>) map.get("version")).get("number");
final Version version = Version.fromString(versionNumber);
final Version version = Version.fromString(
versionNumber
.replace("-SNAPSHOT", "")
.replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "")
);

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