Merge pull request #14564 from jasontedor/restore-build-properties

Restore build properties
This commit is contained in:
Jason Tedor 2015-11-05 21:34:07 -05:00
commit 54d2b5f3b6
12 changed files with 45 additions and 62 deletions

View File

@ -19,81 +19,67 @@
package org.elasticsearch; package org.elasticsearch;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.util.jar.JarFile;
import java.util.Properties; import java.util.jar.Manifest;
/** /**
*/ */
@SuppressForbidden(reason = "needs JarFile to read the manifest")
public class Build { public class Build {
public static final Build CURRENT; public static final Build CURRENT;
static { static {
String hash = "NA"; String shortHash = "Unknown";
String hashShort = "NA"; String date = "Unknown";
String timestamp = "NA";
try (InputStream is = Build.class.getResourceAsStream("/es-build.properties")){ String path = Build.class.getProtectionDomain().getCodeSource().getLocation().getPath();
Properties props = new Properties(); try {
props.load(is); JarFile jar = new JarFile(path);
hash = props.getProperty("hash", hash); Manifest manifest = jar.getManifest();
if (!hash.equals("NA")) { shortHash = manifest.getMainAttributes().getValue("Change");
hashShort = hash.substring(0, 7); date = manifest.getMainAttributes().getValue("Build-Date");
} } catch (IOException e) {
String gitTimestampRaw = props.getProperty("timestamp");
if (gitTimestampRaw != null) {
timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw));
}
} catch (Exception e) {
// just ignore... // just ignore...
} }
CURRENT = new Build(hash, hashShort, timestamp); CURRENT = new Build(shortHash, date);
} }
private String hash; private String shortHash;
private String hashShort; private String date;
private String timestamp;
Build(String hash, String hashShort, String timestamp) { Build(String shortHash, String date) {
this.hash = hash; this.shortHash = shortHash;
this.hashShort = hashShort; this.date = date;
this.timestamp = timestamp;
} }
public String hash() { public String shortHash() {
return hash; return shortHash;
} }
public String hashShort() { public String date() {
return hashShort; return date;
}
public String timestamp() {
return timestamp;
} }
public static Build readBuild(StreamInput in) throws IOException { public static Build readBuild(StreamInput in) throws IOException {
String hash = in.readString(); String hash = in.readString();
String hashShort = in.readString(); String date = in.readString();
String timestamp = in.readString(); return new Build(hash, date);
return new Build(hash, hashShort, timestamp);
} }
public static void writeBuild(Build build, StreamOutput out) throws IOException { public static void writeBuild(Build build, StreamOutput out) throws IOException {
out.writeString(build.hash()); out.writeString(build.shortHash());
out.writeString(build.hashShort()); out.writeString(build.date());
out.writeString(build.timestamp());
} }
@Override @Override
public String toString() { public String toString() {
return "[" + hash + "][" + timestamp + "]"; return "[" + shortHash + "][" + date + "]";
} }
} }

View File

@ -661,7 +661,7 @@ public class Version {
@SuppressForbidden(reason = "System.out.*") @SuppressForbidden(reason = "System.out.*")
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp() + ", JVM: " + JvmInfo.jvmInfo().version()); System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.shortHash() + "/" + Build.CURRENT.date() + ", JVM: " + JvmInfo.jvmInfo().version());
} }
@Override @Override

View File

@ -77,7 +77,7 @@ public class NodesInfoResponse extends BaseNodesResponse<NodeInfo> implements To
builder.field("ip", nodeInfo.getNode().getHostAddress(), XContentBuilder.FieldCaseConversion.NONE); builder.field("ip", nodeInfo.getNode().getHostAddress(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("version", nodeInfo.getVersion()); builder.field("version", nodeInfo.getVersion());
builder.field("build", nodeInfo.getBuild().hashShort()); builder.field("build_hash", nodeInfo.getBuild().shortHash());
if (nodeInfo.getServiceAttributes() != null) { if (nodeInfo.getServiceAttributes() != null) {
for (Map.Entry<String, String> nodeAttribute : nodeInfo.getServiceAttributes().entrySet()) { for (Map.Entry<String, String> nodeAttribute : nodeInfo.getServiceAttributes().entrySet()) {

View File

@ -81,7 +81,7 @@ final class BootstrapCLIParser extends CliTool {
@Override @Override
public ExitStatus execute(Settings settings, Environment env) throws Exception { public ExitStatus execute(Settings settings, Environment env) throws Exception {
terminal.println("Version: %s, Build: %s/%s, JVM: %s", org.elasticsearch.Version.CURRENT, Build.CURRENT.hashShort(), Build.CURRENT.timestamp(), JvmInfo.jvmInfo().version()); terminal.println("Version: %s, Build: %s/%s, JVM: %s", org.elasticsearch.Version.CURRENT, Build.CURRENT.shortHash(), Build.CURRENT.date(), JvmInfo.jvmInfo().version());
return ExitStatus.OK_AND_EXIT; return ExitStatus.OK_AND_EXIT;
} }
} }

View File

@ -358,7 +358,7 @@ public class HttpDownloadHelper {
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
} }
connection.setRequestProperty("ES-Version", Version.CURRENT.toString()); connection.setRequestProperty("ES-Version", Version.CURRENT.toString());
connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort()); connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.shortHash());
connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager"); connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager");
// connect to the remote site (may take some time) // connect to the remote site (may take some time)

View File

@ -135,7 +135,7 @@ public class Node implements Releasable {
Settings tmpSettings = TribeService.processSettings(tmpEnv.settings()); Settings tmpSettings = TribeService.processSettings(tmpEnv.settings());
ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name")); ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name"));
logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp()); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.shortHash(), Build.CURRENT.date());
logger.info("initializing ..."); logger.info("initializing ...");

View File

@ -574,7 +574,7 @@ public class PluginManager {
// Elasticsearch new download service uses groupId org.elasticsearch.plugin from 2.0.0 // Elasticsearch new download service uses groupId org.elasticsearch.plugin from 2.0.0
if (user == null) { if (user == null) {
if (!Strings.isNullOrEmpty(System.getProperty(PROPERTY_SUPPORT_STAGING_URLS))) { if (!Strings.isNullOrEmpty(System.getProperty(PROPERTY_SUPPORT_STAGING_URLS))) {
addUrl(urls, String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip", version, Build.CURRENT.hashShort(), name, version, name, version)); addUrl(urls, String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip", version, Build.CURRENT.shortHash(), name, version, name, version));
} }
addUrl(urls, String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/%s/%s/%s-%s.zip", name, version, name, version)); addUrl(urls, String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/%s/%s/%s-%s.zip", name, version, name, version));
} else { } else {

View File

@ -245,7 +245,7 @@ public class RestNodesAction extends AbstractCatAction {
} }
table.addCell(node.getVersion().number()); table.addCell(node.getVersion().number());
table.addCell(info == null ? null : info.getBuild().hashShort()); table.addCell(info == null ? null : info.getBuild().shortHash());
table.addCell(jvmInfo == null ? null : jvmInfo.version()); table.addCell(jvmInfo == null ? null : jvmInfo.version());
table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable()); table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable());
table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed()); table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed());

View File

@ -77,8 +77,8 @@ public class RestMainAction extends BaseRestHandler {
builder.field("cluster_name", clusterName.value()); builder.field("cluster_name", clusterName.value());
builder.startObject("version") builder.startObject("version")
.field("number", version.number()) .field("number", version.number())
.field("build_hash", Build.CURRENT.hash()) .field("build_hash", Build.CURRENT.shortHash())
.field("build_timestamp", Build.CURRENT.timestamp()) .field("build_date", Build.CURRENT.date())
.field("build_snapshot", version.snapshot) .field("build_snapshot", version.snapshot)
.field("lucene_version", version.luceneVersion.toString()) .field("lucene_version", version.luceneVersion.toString())
.endObject(); .endObject();

View File

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

View File

@ -54,8 +54,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
assertStatus(status, OK_AND_EXIT); assertStatus(status, OK_AND_EXIT);
assertThatTerminalOutput(containsString(Version.CURRENT.toString())); assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort())); assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp())); assertThatTerminalOutput(containsString(Build.CURRENT.date()));
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version())); assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
} }
@ -65,8 +65,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
assertStatus(status, OK_AND_EXIT); assertStatus(status, OK_AND_EXIT);
assertThatTerminalOutput(containsString(Version.CURRENT.toString())); assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort())); assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp())); assertThatTerminalOutput(containsString(Build.CURRENT.date()));
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version())); assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
CaptureOutputTerminal terminal = new CaptureOutputTerminal(); CaptureOutputTerminal terminal = new CaptureOutputTerminal();
@ -75,8 +75,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
assertStatus(status, OK_AND_EXIT); assertStatus(status, OK_AND_EXIT);
assertThatTerminalOutput(containsString(Version.CURRENT.toString())); assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort())); assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp())); assertThatTerminalOutput(containsString(Build.CURRENT.date()));
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version())); assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
} }

View File

@ -78,7 +78,7 @@ public class PluginManagerUnitTests extends ESTestCase {
if (supportStagingUrls) { if (supportStagingUrls) {
String expectedStagingURL = String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip", String expectedStagingURL = String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip",
Version.CURRENT.number(), Build.CURRENT.hashShort(), pluginName, Version.CURRENT.number(), pluginName, Version.CURRENT.number()); Version.CURRENT.number(), Build.CURRENT.shortHash(), pluginName, Version.CURRENT.number(), pluginName, Version.CURRENT.number());
assertThat(iterator.next().toExternalForm(), is(expectedStagingURL)); assertThat(iterator.next().toExternalForm(), is(expectedStagingURL));
} }
@ -103,7 +103,7 @@ public class PluginManagerUnitTests extends ESTestCase {
if (supportStagingUrls) { if (supportStagingUrls) {
String expectedStagingUrl = String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip", String expectedStagingUrl = String.format(Locale.ROOT, "https://download.elastic.co/elasticsearch/staging/%s-%s/org/elasticsearch/plugin/%s/%s/%s-%s.zip",
Version.CURRENT.number(), Build.CURRENT.hashShort(), randomPluginName, Version.CURRENT.number(), randomPluginName, Version.CURRENT.number()); Version.CURRENT.number(), Build.CURRENT.shortHash(), randomPluginName, Version.CURRENT.number(), randomPluginName, Version.CURRENT.number());
assertThat(iterator.next().toExternalForm(), is(expectedStagingUrl)); assertThat(iterator.next().toExternalForm(), is(expectedStagingUrl));
} }