Add Git build info when we build a distribution

closes #3370
This commit is contained in:
Shay Banon 2013-07-24 20:24:23 +02:00
parent 646ab22e3a
commit 70bbcb4c48
6 changed files with 144 additions and 35 deletions

56
pom.xml
View File

@ -45,7 +45,7 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId> <artifactId>hamcrest-all</artifactId>
<version>1.3</version> <version>1.3</version>
@ -285,6 +285,7 @@
<includes> <includes>
<include>**/*.*</include> <include>**/*.*</include>
</includes> </includes>
<filtering>true</filtering>
</resource> </resource>
</resources> </resources>
@ -331,26 +332,27 @@
<jvmOutputAction>pipe,warn</jvmOutputAction> <jvmOutputAction>pipe,warn</jvmOutputAction>
<leaveTemporary>true</leaveTemporary> <leaveTemporary>true</leaveTemporary>
<listeners> <listeners>
<report-ant-xml mavenExtensions="true" dir="${project.build.directory}/surefire-reports" /> <report-ant-xml mavenExtensions="true"
<report-text dir="${project.build.directory}/surefire-reports"/>
showThrowable="true" <report-text
showStackTraces="true" showThrowable="true"
showOutput="onerror" showStackTraces="true"
showStatusOk="false" showOutput="onerror"
showStatusError="true" showStatusOk="false"
showStatusFailure="true" showStatusError="true"
showStatusIgnored="true" showStatusFailure="true"
showSuiteSummary="true" showStatusIgnored="true"
timestamps="false" /> showSuiteSummary="true"
<report-execution-times file="${basedir}/.local-execution-hints.log"/> timestamps="false"/>
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
</listeners> </listeners>
<assertions> <assertions>
<enable /> <enable/>
</assertions> </assertions>
<parallelism>${tests.jvms}</parallelism> <parallelism>${tests.jvms}</parallelism>
<balancers> <balancers>
<execution-times> <execution-times>
<fileset dir="${basedir}" includes=".local-execution-hints.log" /> <fileset dir="${basedir}" includes=".local-execution-hints.log"/>
</execution-times> </execution-times>
</balancers> </balancers>
<includes> <includes>
@ -380,7 +382,8 @@
<tests.slow>${tests.slow}</tests.slow> <tests.slow>${tests.slow}</tests.slow>
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local> <es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
<es.transport.tcp.compress>${env.ES_TEST_COMPRESS}</es.transport.tcp.compress> <es.transport.tcp.compress>${env.ES_TEST_COMPRESS}</es.transport.tcp.compress>
<es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}</es.action.wait_on_mapping_change> <es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}
</es.action.wait_on_mapping_change>
<java.awt.headless>true</java.awt.headless> <java.awt.headless>true</java.awt.headless>
</systemProperties> </systemProperties>
</configuration> </configuration>
@ -391,9 +394,9 @@
<!-- we skip surefire to work with randomized testing above --> <!-- we skip surefire to work with randomized testing above -->
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version> <version>2.15</version>
<configuration> <configuration>
<skipTests>true</skipTests> <skipTests>true</skipTests>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -532,6 +535,23 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin> <plugin>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<executions> <executions>

View File

@ -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;
}
}

View File

@ -295,7 +295,7 @@ public class Version implements Serializable {
} }
public static void main(String[] args) { 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 @Override

View File

@ -19,6 +19,7 @@
package org.elasticsearch.node.internal; package org.elasticsearch.node.internal;
import org.elasticsearch.Build;
import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionModule; import org.elasticsearch.action.ActionModule;
@ -119,7 +120,9 @@ public final class InternalNode implements Node {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings); Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name")); 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()) { if (logger.isDebugEnabled()) {
Environment env = tuple.v2(); Environment env = tuple.v2();
@ -170,7 +173,7 @@ public final class InternalNode implements Node {
client = injector.getInstance(Client.class); client = injector.getInstance(Client.class);
logger.info("{{}}[{}]: initialized", Version.CURRENT, JvmInfo.jvmInfo().pid()); logger.info("initialized");
} }
@Override @Override
@ -189,7 +192,7 @@ public final class InternalNode implements Node {
} }
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); 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...) // hack around dependency injection problem (for now...)
injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class)); injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class));
@ -219,7 +222,7 @@ public final class InternalNode implements Node {
} }
injector.getInstance(BulkUdpService.class).start(); injector.getInstance(BulkUdpService.class).start();
logger.info("{{}}[{}]: started", Version.CURRENT, JvmInfo.jvmInfo().pid()); logger.info("started");
return this; return this;
} }
@ -230,7 +233,7 @@ public final class InternalNode implements Node {
return this; return this;
} }
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); 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(); injector.getInstance(BulkUdpService.class).stop();
if (settings.getAsBoolean("http.enabled", true)) { if (settings.getAsBoolean("http.enabled", true)) {
@ -264,7 +267,7 @@ public final class InternalNode implements Node {
injector.getInstance(plugin).stop(); injector.getInstance(plugin).stop();
} }
logger.info("{{}}[{}]: stopped", Version.CURRENT, JvmInfo.jvmInfo().pid()); logger.info("stopped");
return this; return this;
} }
@ -278,7 +281,7 @@ public final class InternalNode implements Node {
} }
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); 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 stopWatch = new StopWatch("node_close");
stopWatch.start("bulk.udp"); stopWatch.start("bulk.udp");
@ -357,7 +360,7 @@ public final class InternalNode implements Node {
CachedStreams.clear(); CachedStreams.clear();
ThreadLocals.clearReferencesThreadLocals(); ThreadLocals.clearReferencesThreadLocals();
logger.info("{{}}[{}]: closed", Version.CURRENT, JvmInfo.jvmInfo().pid()); logger.info("closed");
} }
@Override @Override

View File

@ -20,6 +20,7 @@
package org.elasticsearch.rest.action.main; package org.elasticsearch.rest.action.main;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
import org.elasticsearch.Build;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -77,14 +78,16 @@ public class RestMainAction extends BaseRestHandler {
builder.field("name", settings.get("name")); builder.field("name", settings.get("name"));
} }
builder.startObject("version") builder.startObject("version")
.field("number", Version.CURRENT.number()) .field("number", Version.CURRENT.number())
.field("snapshot_build", Version.CURRENT.snapshot) .field("build_hash", Build.CURRENT.hash())
// We use the lucene version from lucene constants since .field("build_timestamp", Build.CURRENT.timestamp())
// this includes bugfix release version as well and is already in .field("build_snapshot", Version.CURRENT.snapshot)
// the right format. We can also be sure that the format is maitained // We use the lucene version from lucene constants since
// since this is also recorded in lucene segments and has BW compat // this includes bugfix release version as well and is already in
.field("lucene_version", Constants.LUCENE_MAIN_VERSION) // the right format. We can also be sure that the format is maitained
.endObject(); // 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.field("tagline", "You Know, for Search");
builder.endObject(); builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder)); channel.sendResponse(new XContentRestResponse(request, status, builder));

View File

@ -0,0 +1,3 @@
version=${project.version}
hash=${buildNumber}
timestamp=${timestamp}