diff --git a/pom.xml b/pom.xml index 7b5682686d8..421c08c5921 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ - + org.hamcrest hamcrest-all 1.3 @@ -285,6 +285,7 @@ **/*.* + true @@ -331,26 +332,27 @@ pipe,warn true - - - + + + - + ${tests.jvms} - + @@ -380,7 +382,8 @@ ${tests.slow} ${env.ES_TEST_LOCAL} ${env.ES_TEST_COMPRESS} - ${env.ES_WAIT_ON_MAPPING_CHANGE} + ${env.ES_WAIT_ON_MAPPING_CHANGE} + true @@ -391,9 +394,9 @@ org.apache.maven.plugins maven-surefire-plugin - 2.15 + 2.15 - true + true @@ -532,6 +535,23 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + 1.2 + + + validate + + create + + + + + false + false + + maven-dependency-plugin diff --git a/src/main/java/org/elasticsearch/Build.java b/src/main/java/org/elasticsearch/Build.java new file mode 100644 index 00000000000..3b8493a60bb --- /dev/null +++ b/src/main/java/org/elasticsearch/Build.java @@ -0,0 +1,80 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch; + +import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.io.Streams; +import org.joda.time.DateTimeZone; +import org.joda.time.format.ISODateTimeFormat; + +import java.util.Properties; + +/** + */ +public class Build { + + public static final Build CURRENT; + + static { + String hash = "NA"; + String hashShort = "NA"; + String timestamp = "NA"; + + try { + String properties = Streams.copyToStringFromClasspath("/es-build.properties"); + Properties props = new Properties(); + props.load(new FastStringReader(properties)); + hash = props.getProperty("hash", hash); + if (!hash.equals("NA")) { + hashShort = hash.substring(0, 7); + } + String gitTimestampRaw = props.getProperty("timestamp"); + if (gitTimestampRaw != null) { + timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw)); + } + } catch (Exception e) { + // just ignore... + } + + CURRENT = new Build(hash, hashShort, timestamp); + } + + private String hash; + private String hashShort; + private String timestamp; + + Build(String hash, String hashShort, String timestamp) { + this.hash = hash; + this.hashShort = hashShort; + this.timestamp = timestamp; + } + + public String hash() { + return hash; + } + + public String hashShort() { + return hashShort; + } + + public String timestamp() { + return timestamp; + } +} diff --git a/src/main/java/org/elasticsearch/Version.java b/src/main/java/org/elasticsearch/Version.java index 9767123330c..ea1caf3fb2f 100644 --- a/src/main/java/org/elasticsearch/Version.java +++ b/src/main/java/org/elasticsearch/Version.java @@ -295,7 +295,7 @@ public class Version implements Serializable { } public static void main(String[] args) { - System.out.println("ElasticSearch Version: " + Version.CURRENT + ", JVM: " + JvmInfo.jvmInfo().version() + "(" + JvmInfo.jvmInfo().vmVersion() + ")"); + System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp() + ", JVM: " + JvmInfo.jvmInfo().version()); } @Override diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index b75cea30b9e..08de00bf105 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -19,6 +19,7 @@ package org.elasticsearch.node.internal; +import org.elasticsearch.Build; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionModule; @@ -119,7 +120,9 @@ public final class InternalNode implements Node { Tuple tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings); ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name")); - logger.info("{{}}[{}]: initializing ...", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("version[{}], pid[{}], build[{}/{}]", Version.CURRENT, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp()); + + logger.info("initializing ..."); if (logger.isDebugEnabled()) { Environment env = tuple.v2(); @@ -170,7 +173,7 @@ public final class InternalNode implements Node { client = injector.getInstance(Client.class); - logger.info("{{}}[{}]: initialized", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("initialized"); } @Override @@ -189,7 +192,7 @@ public final class InternalNode implements Node { } ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); - logger.info("{{}}[{}]: starting ...", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("starting ..."); // hack around dependency injection problem (for now...) injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class)); @@ -219,7 +222,7 @@ public final class InternalNode implements Node { } injector.getInstance(BulkUdpService.class).start(); - logger.info("{{}}[{}]: started", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("started"); return this; } @@ -230,7 +233,7 @@ public final class InternalNode implements Node { return this; } ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); - logger.info("{{}}[{}]: stopping ...", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("stopping ..."); injector.getInstance(BulkUdpService.class).stop(); if (settings.getAsBoolean("http.enabled", true)) { @@ -264,7 +267,7 @@ public final class InternalNode implements Node { injector.getInstance(plugin).stop(); } - logger.info("{{}}[{}]: stopped", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("stopped"); return this; } @@ -278,7 +281,7 @@ public final class InternalNode implements Node { } ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); - logger.info("{{}}[{}]: closing ...", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("closing ..."); StopWatch stopWatch = new StopWatch("node_close"); stopWatch.start("bulk.udp"); @@ -357,7 +360,7 @@ public final class InternalNode implements Node { CachedStreams.clear(); ThreadLocals.clearReferencesThreadLocals(); - logger.info("{{}}[{}]: closed", Version.CURRENT, JvmInfo.jvmInfo().pid()); + logger.info("closed"); } @Override diff --git a/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index d443f868a68..d3d42740c98 100644 --- a/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -20,6 +20,7 @@ package org.elasticsearch.rest.action.main; import org.apache.lucene.util.Constants; +import org.elasticsearch.Build; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -77,14 +78,16 @@ public class RestMainAction extends BaseRestHandler { builder.field("name", settings.get("name")); } builder.startObject("version") - .field("number", Version.CURRENT.number()) - .field("snapshot_build", Version.CURRENT.snapshot) - // We use the lucene version from lucene constants since - // this includes bugfix release version as well and is already in - // the right format. We can also be sure that the format is maitained - // since this is also recorded in lucene segments and has BW compat - .field("lucene_version", Constants.LUCENE_MAIN_VERSION) - .endObject(); + .field("number", Version.CURRENT.number()) + .field("build_hash", Build.CURRENT.hash()) + .field("build_timestamp", Build.CURRENT.timestamp()) + .field("build_snapshot", Version.CURRENT.snapshot) + // We use the lucene version from lucene constants since + // this includes bugfix release version as well and is already in + // the right format. We can also be sure that the format is maitained + // since this is also recorded in lucene segments and has BW compat + .field("lucene_version", Constants.LUCENE_MAIN_VERSION) + .endObject(); builder.field("tagline", "You Know, for Search"); builder.endObject(); channel.sendResponse(new XContentRestResponse(request, status, builder)); diff --git a/src/main/resources/es-build.properties b/src/main/resources/es-build.properties new file mode 100644 index 00000000000..563ecddcaf6 --- /dev/null +++ b/src/main/resources/es-build.properties @@ -0,0 +1,3 @@ +version=${project.version} +hash=${buildNumber} +timestamp=${timestamp}