mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-27 10:28:28 +00:00
associate a version with a discovery node
This commit is contained in:
parent
3d49b4ed3a
commit
3d4c31de91
@ -19,63 +19,95 @@
|
||||
|
||||
package org.elasticsearch;
|
||||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class Version {
|
||||
|
||||
private static final String number;
|
||||
private static final String date;
|
||||
private static final boolean snapshotBuild;
|
||||
// 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_0_18_0_ID = /*00*/180099;
|
||||
public static final Version V_0_18_0 = new Version(V_0_18_0_ID, true);
|
||||
|
||||
static {
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
InputStream stream = Version.class.getClassLoader().getResourceAsStream("org/elasticsearch/version.properties");
|
||||
props.load(stream);
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
public static final Version CURRENT = V_0_18_0;
|
||||
|
||||
public static Version readVersion(StreamInput in) throws IOException {
|
||||
return fromId(in.readVInt());
|
||||
}
|
||||
|
||||
private static Version fromId(int id) {
|
||||
switch (id) {
|
||||
case V_0_18_0_ID:
|
||||
return V_0_18_0;
|
||||
default:
|
||||
return new Version(id, null);
|
||||
}
|
||||
|
||||
number = props.getProperty("number", "0.0.0");
|
||||
snapshotBuild = number.contains("-SNAPSHOT");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
date = props.getProperty("date", sdf.format(new Date()));
|
||||
}
|
||||
|
||||
public static String number() {
|
||||
return number;
|
||||
public static void writeVersion(Version version, StreamOutput out) throws IOException {
|
||||
out.writeVInt(version.id);
|
||||
}
|
||||
|
||||
public static String date() {
|
||||
return date;
|
||||
public final int id;
|
||||
public final byte major;
|
||||
public final byte minor;
|
||||
public final byte revision;
|
||||
public final byte build;
|
||||
public final Boolean snapshot;
|
||||
|
||||
Version(int id, @Nullable Boolean snapshot) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static boolean snapshotBuild() {
|
||||
return snapshotBuild;
|
||||
public boolean snapshot() {
|
||||
return snapshot != null && snapshot;
|
||||
}
|
||||
|
||||
public static String full() {
|
||||
StringBuilder sb = new StringBuilder("elasticsearch/");
|
||||
sb.append(number);
|
||||
if (snapshotBuild) {
|
||||
sb.append("/").append(date);
|
||||
public boolean after(Version version) {
|
||||
return version.id > id;
|
||||
}
|
||||
|
||||
public boolean onOrAfter(Version version) {
|
||||
return version.id >= id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("ElasticSearch Version: " + number + " (" + date() + "), JVM: " + JvmInfo.jvmInfo().vmVersion());
|
||||
System.out.println("ElasticSearch Version: " + Version.CURRENT + "JVM: " + JvmInfo.jvmInfo().vmVersion());
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(number());
|
||||
if (snapshot()) {
|
||||
sb.append("-SNAPSHOT");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ public class Bootstrap {
|
||||
}
|
||||
|
||||
private static String buildErrorMessage(String stage, Throwable e) {
|
||||
StringBuilder errorMessage = new StringBuilder("{").append(Version.full()).append("}: ");
|
||||
StringBuilder errorMessage = new StringBuilder("{").append(Version.CURRENT).append("}: ");
|
||||
try {
|
||||
if (ANSI.isEnabled()) {
|
||||
errorMessage.append(attrib(ANSI.Code.FG_RED)).append(stage).append(" Failed ...").append(attrib(ANSI.Code.OFF)).append("\n");
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.elasticsearch.cluster.node;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
@ -55,6 +56,8 @@ public class DiscoveryNode implements Streamable, Serializable {
|
||||
|
||||
private ImmutableMap<String, String> attributes;
|
||||
|
||||
private Version version = Version.CURRENT;
|
||||
|
||||
private DiscoveryNode() {
|
||||
}
|
||||
|
||||
@ -191,6 +194,14 @@ public class DiscoveryNode implements Streamable, Serializable {
|
||||
return masterNode();
|
||||
}
|
||||
|
||||
public Version version() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public static DiscoveryNode readNode(StreamInput in) throws IOException {
|
||||
DiscoveryNode node = new DiscoveryNode();
|
||||
node.readFrom(in);
|
||||
@ -207,6 +218,7 @@ public class DiscoveryNode implements Streamable, Serializable {
|
||||
builder.put(in.readUTF().intern(), in.readUTF().intern());
|
||||
}
|
||||
attributes = builder.build();
|
||||
version = Version.readVersion(in);
|
||||
}
|
||||
|
||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||
@ -218,6 +230,7 @@ public class DiscoveryNode implements Streamable, Serializable {
|
||||
out.writeUTF(entry.getKey());
|
||||
out.writeUTF(entry.getValue());
|
||||
}
|
||||
Version.writeVersion(version, out);
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object obj) {
|
||||
|
@ -112,7 +112,7 @@ public final class InternalNode implements Node {
|
||||
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
|
||||
|
||||
ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
|
||||
logger.info("{{}}[{}]: initializing ...", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: initializing ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
this.pluginsService = new PluginsService(tuple.v1(), tuple.v2());
|
||||
this.settings = pluginsService.updatedSettings();
|
||||
@ -149,7 +149,7 @@ public final class InternalNode implements Node {
|
||||
|
||||
client = injector.getInstance(Client.class);
|
||||
|
||||
logger.info("{{}}[{}]: initialized", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: initialized", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
}
|
||||
|
||||
@Override public Settings settings() {
|
||||
@ -166,7 +166,7 @@ public final class InternalNode implements Node {
|
||||
}
|
||||
|
||||
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
|
||||
logger.info("{{}}[{}]: starting ...", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: starting ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
|
||||
injector.getInstance(plugin).start();
|
||||
@ -193,7 +193,7 @@ public final class InternalNode implements Node {
|
||||
}
|
||||
injector.getInstance(JmxService.class).connectAndRegister(discoService.nodeDescription(), injector.getInstance(NetworkService.class));
|
||||
|
||||
logger.info("{{}}[{}]: started", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: started", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -203,7 +203,7 @@ public final class InternalNode implements Node {
|
||||
return this;
|
||||
}
|
||||
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
|
||||
logger.info("{{}}[{}]: stopping ...", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: stopping ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
if (settings.getAsBoolean("http.enabled", true)) {
|
||||
injector.getInstance(HttpServer.class).stop();
|
||||
@ -237,7 +237,7 @@ public final class InternalNode implements Node {
|
||||
injector.getInstance(plugin).stop();
|
||||
}
|
||||
|
||||
logger.info("{{}}[{}]: stopped", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: stopped", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -251,7 +251,7 @@ public final class InternalNode implements Node {
|
||||
}
|
||||
|
||||
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
|
||||
logger.info("{{}}[{}]: closing ...", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: closing ...", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
|
||||
StopWatch stopWatch = new StopWatch("node_close");
|
||||
stopWatch.start("http");
|
||||
@ -325,7 +325,7 @@ public final class InternalNode implements Node {
|
||||
injector.getInstance(NodeEnvironment.class).close();
|
||||
Injectors.close(injector);
|
||||
|
||||
logger.info("{{}}[{}]: closed", Version.full(), JvmInfo.jvmInfo().pid());
|
||||
logger.info("{{}}[{}]: closed", Version.CURRENT, JvmInfo.jvmInfo().pid());
|
||||
}
|
||||
|
||||
@Override public boolean isClosed() {
|
||||
|
@ -65,11 +65,11 @@ public class PluginManager {
|
||||
public void downloadAndExtract(String name) throws IOException {
|
||||
HttpDownloadHelper downloadHelper = new HttpDownloadHelper();
|
||||
|
||||
File pluginFile = new File(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
|
||||
File pluginFile = new File(url + "/" + name + "/elasticsearch-" + name + "-" + Version.CURRENT.number() + ".zip");
|
||||
boolean downloaded = false;
|
||||
String filterZipName = null;
|
||||
if (!pluginFile.exists()) {
|
||||
pluginFile = new File(url + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
|
||||
pluginFile = new File(url + "/elasticsearch-" + name + "-" + Version.CURRENT.number() + ".zip");
|
||||
if (!pluginFile.exists()) {
|
||||
pluginFile = new File(environment.pluginsFile(), name + ".zip");
|
||||
if (url != null) {
|
||||
@ -107,14 +107,14 @@ public class PluginManager {
|
||||
pluginFile = new File(environment.pluginsFile(), name + ".zip");
|
||||
if (version == null) {
|
||||
// try with ES version from downloads
|
||||
URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + Version.number() + ".zip");
|
||||
URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + Version.CURRENT.number() + ".zip");
|
||||
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
|
||||
try {
|
||||
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
|
||||
downloaded = true;
|
||||
} catch (IOException e) {
|
||||
// try a tag with ES version
|
||||
pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + Version.number());
|
||||
pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + Version.CURRENT.number());
|
||||
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
|
||||
try {
|
||||
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
|
||||
@ -151,7 +151,7 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
|
||||
URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.CURRENT.number() + ".zip");
|
||||
System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
|
||||
try {
|
||||
downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
|
||||
|
@ -29,7 +29,14 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.StringRestResponse;
|
||||
import org.elasticsearch.rest.XContentRestResponse;
|
||||
import org.elasticsearch.rest.XContentThrowableRestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -79,7 +86,7 @@ public class RestMainAction extends BaseRestHandler {
|
||||
if (settings.get("name") != null) {
|
||||
builder.field("name", settings.get("name"));
|
||||
}
|
||||
builder.startObject("version").field("number", Version.number()).field("date", Version.date()).field("snapshot_build", Version.snapshotBuild()).endObject();
|
||||
builder.startObject("version").field("number", Version.CURRENT.number()).field("snapshot_build", Version.CURRENT.snapshot).endObject();
|
||||
builder.field("tagline", "You Know, for Search");
|
||||
builder.field("cover", "DON'T PANIC");
|
||||
if (rootNode != null) {
|
||||
|
@ -185,7 +185,7 @@ public class MemcachedDecoder extends FrameDecoder {
|
||||
this.request = new MemcachedRestRequest(RestRequest.Method.POST, args[1], null, Integer.parseInt(args[4]), false);
|
||||
buffer.markReaderIndex();
|
||||
} else if ("version".equals(cmd)) { // sent as a noop
|
||||
byte[] bytes = Version.full().getBytes();
|
||||
byte[] bytes = Version.CURRENT.toString().getBytes();
|
||||
ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(bytes.length);
|
||||
writeBuffer.writeBytes(bytes);
|
||||
channel.write(writeBuffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user