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

Be lenient when parsing build flavor and type on the wire #40734

Merged
merged 7 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
29 changes: 21 additions & 8 deletions server/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String displayName() {
return displayName;
}

public static Flavor fromDisplayName(final String displayName) {
public static Flavor fromDisplayName(final String displayName, final boolean strict) {
switch (displayName) {
case "default":
return Flavor.DEFAULT;
Expand All @@ -66,7 +66,12 @@ public static Flavor fromDisplayName(final String displayName) {
case "unknown":
return Flavor.UNKNOWN;
default:
throw new IllegalStateException("unexpected distribution flavor [" + displayName + "]; your distribution is broken");
if (strict) {
final String message = "unexpected distribution flavor [" + displayName + "]; your distribution is broken";
throw new IllegalStateException(message);
} else {
return Flavor.UNKNOWN;
}
}
}

Expand All @@ -91,7 +96,7 @@ public String displayName() {
this.displayName = displayName;
}

public static Type fromDisplayName(final String displayName) {
public static Type fromDisplayName(final String displayName, final boolean strict) {
switch (displayName) {
case "deb":
return Type.DEB;
Expand All @@ -106,9 +111,14 @@ public static Type fromDisplayName(final String displayName) {
case "unknown":
return Type.UNKNOWN;
default:
throw new IllegalStateException("unexpected distribution type [" + displayName + "]; your distribution is broken");
if (strict) {
throw new IllegalStateException("unexpected distribution type [" + displayName + "]; your distribution is broken");
} else {
return Type.UNKNOWN;
}
}
}

}

static {
Expand All @@ -119,8 +129,9 @@ public static Type fromDisplayName(final String displayName) {
final boolean isSnapshot;
final String version;

flavor = Flavor.fromDisplayName(System.getProperty("es.distribution.flavor", "unknown"));
type = Type.fromDisplayName(System.getProperty("es.distribution.type", "unknown"));
// these are parsed at startup, and we require that we are able to recognize the values passed in by the startup scripts
flavor = Flavor.fromDisplayName(System.getProperty("es.distribution.flavor", "unknown"), true);
type = Type.fromDisplayName(System.getProperty("es.distribution.type", "unknown"), true);

final String esPrefix = "elasticsearch-" + Version.CURRENT;
final URL url = getElasticsearchCodeSourceLocation();
Expand Down Expand Up @@ -214,12 +225,14 @@ public static Build readBuild(StreamInput in) throws IOException {
final Flavor flavor;
final Type type;
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
flavor = Flavor.fromDisplayName(in.readString());
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
flavor = Flavor.fromDisplayName(in.readString(), false);
} else {
flavor = Flavor.OSS;
}
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
type = Type.fromDisplayName(in.readString());
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
type = Type.fromDisplayName(in.readString(), false);
} else {
type = Type.UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
final String buildType = (String) value.get("build_type");
response.build =
new Build(
buildFlavor == null ? Build.Flavor.UNKNOWN : Build.Flavor.fromDisplayName(buildFlavor),
buildType == null ? Build.Type.UNKNOWN : Build.Type.fromDisplayName(buildType),
/*
* Be lenient when reading on the wire, the enumeration values from other versions might be different than what
* we know.
*/
buildFlavor == null ? Build.Flavor.UNKNOWN : Build.Flavor.fromDisplayName(buildFlavor, false),
buildType == null ? Build.Type.UNKNOWN : Build.Type.fromDisplayName(buildType, false),
(String) value.get("build_hash"),
(String) value.get("build_date"),
(boolean) value.get("build_snapshot"),
Expand Down