Removed plugin specific version classes

Now that the versions are aligned with ES version, we can just use the es `Version` class. Version compatibility is applied by the `PluginService`.

Closes elastic/elasticsearch#439

Original commit: elastic/x-pack-elasticsearch@32f305abb8
This commit is contained in:
uboness 2015-08-13 17:54:38 +02:00
parent c4e213fc92
commit c8b83daf44
16 changed files with 20 additions and 879 deletions

View File

@ -1,204 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.license.plugin.LicenseVersion;
import java.io.IOException;
import java.io.Serializable;
public class MarvelVersion implements Serializable {
// The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is Beta/RC indicator
// AA values below 50 are beta builds, and below 99 are RC builds, with 99 indicating a release
// the (internal) format of the id is there so we can easily do after/before checks on the id
public static final int V_2_0_0_ID = /*00*/2000099;
public static final MarvelVersion V_2_0_0 = new MarvelVersion(V_2_0_0_ID, true, Version.V_2_0_0, LicenseVersion.V_1_0_0);
public static final MarvelVersion CURRENT = V_2_0_0;
public static MarvelVersion readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
}
public static MarvelVersion fromId(int id) {
switch (id) {
case V_2_0_0_ID:
return V_2_0_0;
default:
return new MarvelVersion(id, null, Version.CURRENT, LicenseVersion.CURRENT);
}
}
public static void writeVersion(MarvelVersion version, StreamOutput out) throws IOException {
out.writeVInt(version.id);
}
/**
* Returns the smallest version between the 2.
*/
public static MarvelVersion smallest(MarvelVersion version1, MarvelVersion version2) {
return version1.id < version2.id ? version1 : version2;
}
/**
* Returns the version given its string representation, current version if the argument is null or empty
*/
public static MarvelVersion fromString(String version) {
if (!Strings.hasLength(version)) {
return MarvelVersion.CURRENT;
}
String[] parts = version.split("[\\.-]");
if (parts.length < 3 || parts.length > 4) {
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build");
}
try {
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
int major = Integer.parseInt(parts[0]) * 1000000;
int minor = Integer.parseInt(parts[1]) * 10000;
int revision = Integer.parseInt(parts[2]) * 100;
int build = 99;
if (parts.length == 4) {
String buildStr = parts[3];
if (buildStr.startsWith("beta")) {
build = Integer.parseInt(buildStr.substring(4));
}
if (buildStr.startsWith("rc")) {
build = Integer.parseInt(buildStr.substring(2)) + 50;
}
}
return fromId(major + minor + revision + build);
} catch(NumberFormatException e) {
throw new IllegalArgumentException("unable to parse version " + version, e);
}
}
public final int id;
public final byte major;
public final byte minor;
public final byte revision;
public final byte build;
public final Boolean snapshot;
public final Version minEsCompatibilityVersion;
public final LicenseVersion minLicenseCompatibilityVersion;
MarvelVersion(int id, @Nullable Boolean snapshot, Version minEsCompatibilityVersion, LicenseVersion minLicenseCompatibilityVersion) {
this.id = id;
this.major = (byte) ((id / 1000000) % 100);
this.minor = (byte) ((id / 10000) % 100);
this.revision = (byte) ((id / 100) % 100);
this.build = (byte) (id % 100);
this.snapshot = snapshot;
this.minEsCompatibilityVersion = minEsCompatibilityVersion;
this.minLicenseCompatibilityVersion = minLicenseCompatibilityVersion;
}
public boolean snapshot() {
return snapshot != null && snapshot;
}
public boolean after(MarvelVersion version) {
return version.id < id;
}
public boolean onOrAfter(MarvelVersion version) {
return version.id <= id;
}
public boolean before(MarvelVersion version) {
return version.id > id;
}
public boolean onOrBefore(MarvelVersion version) {
return version.id >= id;
}
public boolean compatibleWith(MarvelVersion version) {
return version.onOrAfter(minimumCompatibilityVersion());
}
public boolean compatibleWith(Version esVersion) {
return esVersion.onOrAfter(minEsCompatibilityVersion);
}
/**
* Returns the minimum compatible version based on the current
* version. Ie a node needs to have at least the return version in order
* to communicate with a node running the current version. The returned version
* is in most of the cases the smallest major version release unless the current version
* is a beta or RC release then the version itself is returned.
*/
public MarvelVersion minimumCompatibilityVersion() {
return MarvelVersion.smallest(this, fromId(major * 1000000 + 99));
}
/**
* @return The minimum elasticsearch version this marvel version is compatible with.
*/
public Version minimumEsCompatiblityVersion() {
return minEsCompatibilityVersion;
}
/**
* @return The minimum license plugin version this marvel version is compatible with.
*/
public LicenseVersion minimumLicenseCompatibilityVersion() {
return minLicenseCompatibilityVersion;
}
/**
* Just the version number (without -SNAPSHOT if snapshot).
*/
public String number() {
StringBuilder sb = new StringBuilder();
sb.append(major).append('.').append(minor).append('.').append(revision);
if (build < 50) {
sb.append("-beta").append(build);
} else if (build < 99) {
sb.append("-rc").append(build - 50);
}
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(number());
if (snapshot()) {
sb.append("-SNAPSHOT");
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MarvelVersion that = (MarvelVersion) o;
if (id != that.id) return false;
return true;
}
@Override
public int hashCode() {
return id;
}
}

View File

@ -5,10 +5,7 @@
*/
package org.elasticsearch.marvel.license;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.license.plugin.LicenseVersion;
import org.elasticsearch.marvel.MarvelVersion;
public class LicenseModule extends AbstractModule {
@ -27,11 +24,5 @@ public class LicenseModule extends AbstractModule {
} catch (ClassNotFoundException cnfe) {
throw new IllegalStateException("marvel plugin requires the license plugin to be installed");
}
if (LicenseVersion.CURRENT.before(MarvelVersion.CURRENT.minLicenseCompatibilityVersion)) {
throw new ElasticsearchException("marvel [" + MarvelVersion.CURRENT +
"] requires minimum license plugin version [" + MarvelVersion.CURRENT.minLicenseCompatibilityVersion +
"], but installed license plugin version is [" + LicenseVersion.CURRENT + "]");
}
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel;
import org.elasticsearch.test.ESTestCase;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
public class MarvelVersionTests extends ESTestCase {
@Test
public void testVersionFromString() {
assertThat(MarvelVersion.fromString("2.0.0"), equalTo(MarvelVersion.V_2_0_0));
}
@Test
public void testVersionNumber() {
assertThat(MarvelVersion.V_2_0_0.number(), equalTo("2.0.0"));
}
}

View File

@ -1,239 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.shield;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.license.plugin.LicenseVersion;
import java.io.IOException;
import java.io.Serializable;
/**
*/
@SuppressWarnings("deprecation")
public class ShieldVersion implements Serializable {
// The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is Beta/RC indicator
// AA values below 50 are beta builds, and below 99 are RC builds, with 99 indicating a release
// the (internal) format of the id is there so we can easily do after/before checks on the id
public static final int V_1_0_0_ID = /*00*/1000099;
public static final ShieldVersion V_1_0_0 = new ShieldVersion(V_1_0_0_ID, false, Version.V_1_4_2, LicenseVersion.V_1_0_0);
public static final int V_1_0_1_ID = /*00*/1000199;
public static final ShieldVersion V_1_0_1 = new ShieldVersion(V_1_0_1_ID, false, Version.V_1_4_2, LicenseVersion.V_1_0_0);
public static final int V_1_0_2_ID = /*00*/1000299;
public static final ShieldVersion V_1_0_2 = new ShieldVersion(V_1_0_2_ID, false, Version.V_1_4_2, LicenseVersion.V_1_0_0);
public static final int V_1_1_0_ID = /*00*/1010099;
public static final ShieldVersion V_1_1_0 = new ShieldVersion(V_1_1_0_ID, false, Version.V_1_4_2, LicenseVersion.V_1_0_0);
public static final int V_1_1_1_ID = /*00*/1010199;
public static final ShieldVersion V_1_1_1 = new ShieldVersion(V_1_1_1_ID, false, Version.V_1_4_2, LicenseVersion.V_1_0_0);
public static final int V_1_2_0_ID = /*00*/1020099;
public static final ShieldVersion V_1_2_0 = new ShieldVersion(V_1_2_0_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_2_1_ID = /*00*/1020199;
public static final ShieldVersion V_1_2_1 = new ShieldVersion(V_1_2_1_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_2_2_ID = /*00*/1020299;
public static final ShieldVersion V_1_2_2 = new ShieldVersion(V_1_2_2_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_2_3_ID = /*00*/1020399;
public static final ShieldVersion V_1_2_3 = new ShieldVersion(V_1_2_3_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_3_0_ID = /*00*/1030099;
public static final ShieldVersion V_1_3_0 = new ShieldVersion(V_1_3_0_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_3_1_ID = /*00*/1030199;
public static final ShieldVersion V_1_3_1 = new ShieldVersion(V_1_3_1_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_2_0_0_ID = /*00*/2000099;
public static final ShieldVersion V_2_0_0 = new ShieldVersion(V_2_0_0_ID, true, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final ShieldVersion CURRENT = V_2_0_0;
public static ShieldVersion readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
}
public static ShieldVersion fromId(int id) {
switch (id) {
case V_1_0_0_ID: return V_1_0_0;
case V_1_0_1_ID: return V_1_0_1;
case V_1_0_2_ID: return V_1_0_2;
case V_1_1_0_ID: return V_1_1_0;
case V_1_1_1_ID: return V_1_1_1;
case V_1_2_0_ID: return V_1_2_0;
case V_1_2_1_ID: return V_1_2_1;
case V_1_2_2_ID: return V_1_2_2;
case V_1_2_3_ID: return V_1_2_3;
case V_1_3_0_ID: return V_1_3_0;
case V_1_3_1_ID: return V_1_3_1;
case V_2_0_0_ID: return V_2_0_0;
default:
return new ShieldVersion(id, null, Version.CURRENT, LicenseVersion.CURRENT);
}
}
public static void writeVersion(ShieldVersion version, StreamOutput out) throws IOException {
out.writeVInt(version.id);
}
/**
* Returns the smallest version between the 2.
*/
public static ShieldVersion smallest(ShieldVersion version1, ShieldVersion version2) {
return version1.id < version2.id ? version1 : version2;
}
/**
* Returns the version given its string representation, current version if the argument is null or empty
*/
public static ShieldVersion fromString(String version) {
if (!Strings.hasLength(version)) {
return ShieldVersion.CURRENT;
}
String[] parts = version.split("\\.|\\-");
if (parts.length < 3 || parts.length > 4) {
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build");
}
try {
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
int major = Integer.parseInt(parts[0]) * 1000000;
int minor = Integer.parseInt(parts[1]) * 10000;
int revision = Integer.parseInt(parts[2]) * 100;
int build = 99;
if (parts.length == 4) {
String buildStr = parts[3];
if (buildStr.startsWith("beta")) {
build = Integer.parseInt(buildStr.substring(4));
}
if (buildStr.startsWith("rc")) {
build = Integer.parseInt(buildStr.substring(2)) + 50;
}
}
return fromId(major + minor + revision + build);
} catch(NumberFormatException e) {
throw new IllegalArgumentException("unable to parse version " + version, e);
}
}
public final int id;
public final byte major;
public final byte minor;
public final byte revision;
public final byte build;
public final Boolean snapshot;
public final Version minEsCompatibilityVersion;
public final LicenseVersion minLicenseCompatibilityVersion;
ShieldVersion(int id, @Nullable Boolean snapshot, Version minEsCompatibilityVersion, LicenseVersion minLicenseCompatibilityVersion) {
this.id = id;
this.major = (byte) ((id / 1000000) % 100);
this.minor = (byte) ((id / 10000) % 100);
this.revision = (byte) ((id / 100) % 100);
this.build = (byte) (id % 100);
this.snapshot = snapshot;
this.minEsCompatibilityVersion = minEsCompatibilityVersion;
this.minLicenseCompatibilityVersion = minLicenseCompatibilityVersion;
}
public boolean snapshot() {
return snapshot != null && snapshot;
}
public boolean after(ShieldVersion version) {
return version.id < id;
}
public boolean onOrAfter(ShieldVersion version) {
return version.id <= id;
}
public boolean before(ShieldVersion version) {
return version.id > id;
}
public boolean onOrBefore(ShieldVersion version) {
return version.id >= id;
}
public boolean compatibleWith(ShieldVersion version) {
return version.onOrAfter(minimumCompatibilityVersion());
}
public boolean compatibleWith(Version esVersion) {
return esVersion.onOrAfter(minEsCompatibilityVersion);
}
/**
* Returns the minimum compatible version based on the current
* version. Ie a node needs to have at least the return version in order
* to communicate with a node running the current version. The returned version
* is in most of the cases the smallest major version release unless the current version
* is a beta or RC release then the version itself is returned.
*/
public ShieldVersion minimumCompatibilityVersion() {
return ShieldVersion.smallest(this, fromId(major * 1000000 + 99));
}
/**
* @return The minimum elasticsearch version this shield version is compatible with.
*/
public Version minimumEsCompatiblityVersion() {
return minEsCompatibilityVersion;
}
/**
* @return The minimum license plugin version this shield version is compatible with.
*/
public LicenseVersion minimumLicenseCompatibilityVersion() {
return minLicenseCompatibilityVersion;
}
/**
* Just the version number (without -SNAPSHOT if snapshot).
*/
public String number() {
StringBuilder sb = new StringBuilder();
sb.append(major).append('.').append(minor).append('.').append(revision);
if (build < 50) {
sb.append("-beta").append(build);
} else if (build < 99) {
sb.append("-rc").append(build - 50);
}
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(number());
if (snapshot()) {
sb.append("-SNAPSHOT");
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ShieldVersion that = (ShieldVersion) o;
if (id != that.id) return false;
return true;
}
@Override
public int hashCode() {
return id;
}
}

View File

@ -6,8 +6,6 @@
package org.elasticsearch.shield.license;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.LicenseVersion;
import org.elasticsearch.shield.ShieldVersion;
import org.elasticsearch.shield.support.AbstractShieldModule;
/**
@ -32,12 +30,6 @@ public class LicenseModule extends AbstractShieldModule.Node {
} catch (ClassNotFoundException cnfe) {
throw new IllegalStateException("shield plugin requires the license plugin to be installed");
}
if (LicenseVersion.CURRENT.before(ShieldVersion.CURRENT.minLicenseCompatibilityVersion)) {
throw new IllegalStateException("shield [" + ShieldVersion.CURRENT +
"] requires minumum license plugin version [" + ShieldVersion.CURRENT.minLicenseCompatibilityVersion +
"], but installed license plugin version is [" + LicenseVersion.CURRENT + "]");
}
}
}

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.shield.rest.action;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.inject.Inject;
@ -14,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.shield.ShieldBuild;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.ShieldVersion;
import org.elasticsearch.shield.license.LicenseService;
import static org.elasticsearch.rest.RestRequest.Method.GET;
@ -58,12 +58,12 @@ public class RestShieldInfoAction extends BaseRestHandler {
}
builder.field("cluster_name", clusterName.value());
builder.startObject("version")
.field("number", ShieldVersion.CURRENT.number())
.field("number", Version.CURRENT.number())
.field("build_hash", ShieldBuild.CURRENT.hash())
.field("build_timestamp", ShieldBuild.CURRENT.timestamp())
.field("build_snapshot", ShieldVersion.CURRENT.snapshot)
.field("build_snapshot", Version.CURRENT.snapshot)
.endObject();
builder.field("tagline", "You know, for security");
builder.field("tagline", "You Know, for Security");
builder.endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));

View File

@ -1,55 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.shield;
import org.elasticsearch.test.ESTestCase;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
/**
*
*/
public class ShieldVersionTests extends ESTestCase {
@Test
public void testStrings() throws Exception {
for (int i = 0; i < 100; i++) {
boolean beta = randomBoolean();
int buildNumber = beta ? randomIntBetween(0, 49) : randomIntBetween(0, 48);
int major = randomIntBetween(0, 20);
int minor = randomIntBetween(0, 20);
int revision = randomIntBetween(0, 20);
String build = buildNumber == 0 ? "" :
beta ? "-beta" + buildNumber : "-rc" + buildNumber;
String versionName = new StringBuilder()
.append(major)
.append(".").append(minor)
.append(".").append(revision)
.append(build).toString();
ShieldVersion version = ShieldVersion.fromString(versionName);
logger.info("version: {}", versionName);
assertThat(version.major, is((byte) major));
assertThat(version.minor, is((byte) minor));
assertThat(version.revision, is((byte) revision));
if (buildNumber == 0) {
assertThat(version.build, is((byte) 99));
} else if (beta) {
assertThat(version.build, is((byte) buildNumber));
} else {
assertThat(version.build, is((byte) (buildNumber + 50)));
}
assertThat(version.number(), equalTo(versionName));
}
}
}

View File

@ -1,223 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.license.plugin.LicenseVersion;
import java.io.IOException;
import java.io.Serializable;
/**
*/
@SuppressWarnings("deprecation")
public class WatcherVersion implements Serializable {
// The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is Beta/RC indicator
// AA values below 50 are beta builds, and below 99 are RC builds, with 99 indicating a release
// the (internal) format of the id is there so we can easily do after/before checks on the id
public static final int V_1_0_0_Beta1_ID = /*00*/1000001;
public static final WatcherVersion V_1_0_0_Beta1 = new WatcherVersion(V_1_0_0_Beta1_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_0_0_Beta2_ID = /*00*/1000002;
public static final WatcherVersion V_1_0_0_Beta2 = new WatcherVersion(V_1_0_0_Beta2_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_0_0_RC1_ID = /*00*/1000051;
public static final WatcherVersion V_1_0_0_RC1 = new WatcherVersion(V_1_0_0_RC1_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_1_0_0_ID = /*00*/1000099;
public static final WatcherVersion V_1_0_0 = new WatcherVersion(V_1_0_0_ID, false, Version.V_1_5_0, LicenseVersion.V_1_0_0);
public static final int V_2_0_0_ID = /*00*/2000099;
public static final WatcherVersion V_2_0_0 = new WatcherVersion(V_2_0_0_ID, true, Version.V_1_5_0, LicenseVersion.V_2_0_0);
public static final WatcherVersion CURRENT = V_2_0_0;
public static WatcherVersion readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
}
public static WatcherVersion fromId(int id) {
switch (id) {
case V_1_0_0_Beta1_ID:
return V_1_0_0_Beta1;
case V_1_0_0_Beta2_ID:
return V_1_0_0_Beta2;
case V_1_0_0_RC1_ID:
return V_1_0_0_RC1;
case V_1_0_0_ID:
return V_1_0_0;
case V_2_0_0_ID:
return V_2_0_0;
default:
return new WatcherVersion(id, null, Version.CURRENT, LicenseVersion.CURRENT);
}
}
public static void writeVersion(WatcherVersion version, StreamOutput out) throws IOException {
out.writeVInt(version.id);
}
/**
* Returns the smallest version between the 2.
*/
public static WatcherVersion smallest(WatcherVersion version1, WatcherVersion version2) {
return version1.id < version2.id ? version1 : version2;
}
/**
* Returns the version given its string representation, current version if the argument is null or empty
*/
public static WatcherVersion fromString(String version) {
if (!Strings.hasLength(version)) {
return WatcherVersion.CURRENT;
}
String[] parts = version.split("\\.|\\-");
if (parts.length < 3 || parts.length > 4) {
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build");
}
try {
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
int major = Integer.parseInt(parts[0]) * 1000000;
int minor = Integer.parseInt(parts[1]) * 10000;
int revision = Integer.parseInt(parts[2]) * 100;
int build = 99;
if (parts.length == 4) {
String buildStr = parts[3];
if (buildStr.startsWith("beta")) {
build = Integer.parseInt(buildStr.substring(4));
}
if (buildStr.startsWith("rc")) {
build = Integer.parseInt(buildStr.substring(2)) + 50;
}
}
return fromId(major + minor + revision + build);
} catch(NumberFormatException e) {
throw new IllegalArgumentException("unable to parse version " + version, e);
}
}
public final int id;
public final byte major;
public final byte minor;
public final byte revision;
public final byte build;
public final Boolean snapshot;
public final Version minEsCompatibilityVersion;
public final LicenseVersion minLicenseCompatibilityVersion;
WatcherVersion(int id, @Nullable Boolean snapshot, Version minEsCompatibilityVersion, LicenseVersion minLicenseCompatibilityVersion) {
this.id = id;
this.major = (byte) ((id / 1000000) % 100);
this.minor = (byte) ((id / 10000) % 100);
this.revision = (byte) ((id / 100) % 100);
this.build = (byte) (id % 100);
this.snapshot = snapshot;
this.minEsCompatibilityVersion = minEsCompatibilityVersion;
this.minLicenseCompatibilityVersion = minLicenseCompatibilityVersion;
}
public boolean snapshot() {
return snapshot != null && snapshot;
}
public boolean after(WatcherVersion version) {
return version.id < id;
}
public boolean onOrAfter(WatcherVersion version) {
return version.id <= id;
}
public boolean before(WatcherVersion version) {
return version.id > id;
}
public boolean onOrBefore(WatcherVersion version) {
return version.id >= id;
}
public boolean compatibleWith(WatcherVersion version) {
return version.onOrAfter(minimumCompatibilityVersion());
}
public boolean compatibleWith(Version esVersion) {
return esVersion.onOrAfter(minEsCompatibilityVersion);
}
/**
* Returns the minimum compatible version based on the current
* version. Ie a node needs to have at least the return version in order
* to communicate with a node running the current version. The returned version
* is in most of the cases the smallest major version release unless the current version
* is a beta or RC release then the version itself is returned.
*/
public WatcherVersion minimumCompatibilityVersion() {
return WatcherVersion.smallest(this, fromId(major * 1000000 + 99));
}
/**
* @return The minimum elasticsearch version this watcher version is compatible with.
*/
public Version minimumEsCompatiblityVersion() {
return minEsCompatibilityVersion;
}
/**
* @return The minimum license plugin version this watcher version is compatible with.
*/
public LicenseVersion minimumLicenseCompatibilityVersion() {
return minLicenseCompatibilityVersion;
}
/**
* Just the version number (without -SNAPSHOT if snapshot).
*/
public String number() {
StringBuilder sb = new StringBuilder();
sb.append(major).append('.').append(minor).append('.').append(revision);
if (build < 50) {
sb.append("-beta").append(build);
} else if (build < 99) {
sb.append("-rc").append(build - 50);
}
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(number());
if (snapshot()) {
sb.append("-SNAPSHOT");
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WatcherVersion that = (WatcherVersion) o;
if (id != that.id) return false;
return true;
}
@Override
public int hashCode() {
return id;
}
}

View File

@ -6,8 +6,6 @@
package org.elasticsearch.watcher.license;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.license.plugin.LicenseVersion;
import org.elasticsearch.watcher.WatcherVersion;
/**
*
@ -29,11 +27,5 @@ public class LicenseModule extends AbstractModule {
} catch (ClassNotFoundException cnfe) {
throw new IllegalStateException("watcher plugin requires the license plugin to be installed");
}
if (LicenseVersion.CURRENT.before(WatcherVersion.CURRENT.minLicenseCompatibilityVersion)) {
throw new IllegalStateException("watcher [" + WatcherVersion.CURRENT +
"] requires minimum license plugin version [" + WatcherVersion.CURRENT.minLicenseCompatibilityVersion +
"], but installed license plugin version is [" + LicenseVersion.CURRENT + "]");
}
}
}

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.watcher.rest.action;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -32,15 +33,15 @@ public class RestWatcherInfoAction extends WatcherRestHandler {
client.watcherStats(new WatcherStatsRequest(), new RestBuilderListener<WatcherStatsResponse>(restChannel) {
@Override
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
builder.startObject();
builder.startObject("version")
.field("name", watcherStatsResponse.getBuild().versionName())
.field("number", watcherStatsResponse.getVersion().number())
.field("build_hash", watcherStatsResponse.getBuild().hash())
.field("build_timestamp", watcherStatsResponse.getBuild().timestamp())
.field("build_snapshot", watcherStatsResponse.getVersion().snapshot)
.endObject().endObject();
builder.startObject()
.startObject("version")
.field("number", Version.CURRENT.number())
.field("build_hash", watcherStatsResponse.getBuild().hash())
.field("build_timestamp", watcherStatsResponse.getBuild().timestamp())
.field("build_snapshot", Version.CURRENT.snapshot)
.endObject()
.field("tagline", "You Know, for Alerts & Automation")
.endObject();
return new BytesRestResponse(OK, builder);
}

View File

@ -11,10 +11,8 @@ import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.ShieldSettingsFilter;
import org.elasticsearch.shield.ShieldVersion;
import org.elasticsearch.shield.authc.AuthenticationService;
import org.elasticsearch.transport.TransportMessage;
import org.elasticsearch.watcher.WatcherVersion;
import java.io.IOException;
@ -55,21 +53,8 @@ public class ShieldIntegration {
static boolean installed() {
try {
Class clazz = ShieldIntegration.class.getClassLoader().loadClass("org.elasticsearch.shield.ShieldPlugin");
if (clazz == null) {
return false;
}
// lets check min compatibility
ShieldVersion minShieldVersion = ShieldVersion.fromId(MIN_SHIELD_VERSION);
if (!ShieldVersion.CURRENT.onOrAfter(minShieldVersion)) {
throw new IllegalStateException("watcher [" + WatcherVersion.CURRENT + "] requires " +
"minimum shield plugin version [" + minShieldVersion + "], but installed shield plugin version is " +
"[" + ShieldVersion.CURRENT + "]");
}
ShieldIntegration.class.getClassLoader().loadClass("org.elasticsearch.shield.ShieldPlugin");
return true;
} catch (ClassNotFoundException e) {
return false;
}

View File

@ -17,10 +17,9 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.watcher.*;
import org.elasticsearch.watcher.WatcherBuild;
import org.elasticsearch.watcher.WatcherLifeCycleService;
import org.elasticsearch.watcher.WatcherService;
import org.elasticsearch.watcher.WatcherVersion;
import org.elasticsearch.watcher.execution.ExecutionService;
import org.elasticsearch.watcher.license.LicenseService;
import org.elasticsearch.watcher.transport.actions.WatcherTransportAction;
@ -62,7 +61,6 @@ public class TransportWatcherStatsAction extends WatcherTransportAction<WatcherS
statsResponse.setThreadPoolQueueSize(executionService.executionThreadPoolQueueSize());
statsResponse.setWatchesCount(watcherService.watchesCount());
statsResponse.setThreadPoolMaxSize(executionService.executionThreadPoolMaxSize());
statsResponse.setVersion(WatcherVersion.CURRENT);
statsResponse.setBuild(WatcherBuild.CURRENT);
statsResponse.setWatcherMetaData(lifeCycleService.watcherMetaData());

View File

@ -7,14 +7,13 @@ package org.elasticsearch.watcher.transport.actions.stats;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.watcher.WatcherBuild;
import org.elasticsearch.watcher.WatcherMetaData;
import org.elasticsearch.watcher.WatcherState;
import org.elasticsearch.watcher.WatcherVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.watcher.execution.QueuedWatch;
import org.elasticsearch.watcher.execution.WatchExecutionSnapshot;
@ -25,7 +24,6 @@ import java.util.Locale;
public class WatcherStatsResponse extends ActionResponse implements ToXContent {
private WatcherVersion version;
private WatcherBuild build;
private long watchesCount;
private WatcherState watcherState;
@ -83,17 +81,6 @@ public class WatcherStatsResponse extends ActionResponse implements ToXContent {
this.watcherState = watcherServiceState;
}
/**
* @return The watcher plugin version.
*/
public WatcherVersion getVersion() {
return version;
}
void setVersion(WatcherVersion version) {
this.version = version;
}
/**
* @return The watcher plugin build information.
*/
@ -138,7 +125,6 @@ public class WatcherStatsResponse extends ActionResponse implements ToXContent {
threadPoolQueueSize = in.readLong();
threadPoolMaxSize = in.readLong();
watcherState = WatcherState.fromId(in.readByte());
version = WatcherVersion.readVersion(in);
build = WatcherBuild.readBuild(in);
if (in.readBoolean()) {
@ -165,7 +151,6 @@ public class WatcherStatsResponse extends ActionResponse implements ToXContent {
out.writeLong(threadPoolQueueSize);
out.writeLong(threadPoolMaxSize);
out.writeByte(watcherState.getId());
WatcherVersion.writeVersion(version, out);
WatcherBuild.writeBuild(build, out);
if (snapshots != null) {

View File

@ -1,55 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher;
import org.elasticsearch.test.ESTestCase;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
/**
*
*/
public class WatcherVersionTests extends ESTestCase {
@Test
public void testStrings() throws Exception {
for (int i = 0; i < 100; i++) {
boolean beta = randomBoolean();
int buildNumber = beta ? randomIntBetween(0, 49) : randomIntBetween(0, 48);
int major = randomIntBetween(0, 20);
int minor = randomIntBetween(0, 20);
int revision = randomIntBetween(0, 20);
String build = buildNumber == 0 ? "" :
beta ? "-beta" + buildNumber : "-rc" + buildNumber;
String versionName = new StringBuilder()
.append(major)
.append(".").append(minor)
.append(".").append(revision)
.append(build).toString();
WatcherVersion version = WatcherVersion.fromString(versionName);
logger.info("version: {}", versionName);
assertThat(version.major, is((byte) major));
assertThat(version.minor, is((byte) minor));
assertThat(version.revision, is((byte) revision));
if (buildNumber == 0) {
assertThat(version.build, is((byte) 99));
} else if (beta) {
assertThat(version.build, is((byte) buildNumber));
} else {
assertThat(version.build, is((byte) (buildNumber + 50)));
}
assertThat(version.number(), equalTo(versionName));
}
}
}

View File

@ -20,7 +20,6 @@ import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.watcher.WatcherVersion;
import org.elasticsearch.watcher.actions.ActionStatus;
import org.elasticsearch.watcher.history.HistoryStore;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
@ -104,7 +103,7 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
assertThat(watcherClient().prepareDeleteWatch(watchName).get().isFound(), is(true));
// watcher stats API should work
assertThat(watcherClient().prepareWatcherStats().get().getVersion(), is(WatcherVersion.CURRENT));
assertThat(watcherClient().prepareWatcherStats().get().getWatchesCount(), is(0L));
// watcher service API should work
WatcherServiceResponse serviceResponse = watcherClient().prepareWatchService().restart().get();
@ -261,7 +260,7 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
assertThat(watcherClient().prepareDeleteWatch(watchName).get().isFound(), is(true));
// watcher stats API should work
assertThat(watcherClient().prepareWatcherStats().get().getVersion(), is(WatcherVersion.CURRENT));
assertThat(watcherClient().prepareWatcherStats().get().getWatchesCount(), is(0L));
// watcher service API should work
assertThat(watcherClient().prepareWatchService().stop().get().isAcknowledged(), is(true));

View File

@ -11,7 +11,6 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.watcher.WatcherBuild;
import org.elasticsearch.watcher.WatcherState;
import org.elasticsearch.watcher.WatcherVersion;
import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.condition.ConditionBuilders;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
@ -50,7 +49,6 @@ public class WatcherStatsTests extends AbstractWatcherIntegrationTests {
assertThat(response.getThreadPoolQueueSize(), is(0L));
assertThat(response.getWatchesCount(), is(0L));
assertThat(response.getThreadPoolMaxSize(), is(timeWarped() ? 1L : 0L));
assertThat(response.getVersion(), is(WatcherVersion.CURRENT));
assertThat(response.getBuild(), is(WatcherBuild.CURRENT));
}