Merge pull request #14564 from jasontedor/restore-build-properties
Restore build properties
This commit is contained in:
commit
54d2b5f3b6
|
@ -19,81 +19,67 @@
|
|||
|
||||
package org.elasticsearch;
|
||||
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
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.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
*/
|
||||
@SuppressForbidden(reason = "needs JarFile to read the manifest")
|
||||
public class Build {
|
||||
|
||||
public static final Build CURRENT;
|
||||
|
||||
static {
|
||||
String hash = "NA";
|
||||
String hashShort = "NA";
|
||||
String timestamp = "NA";
|
||||
String shortHash = "Unknown";
|
||||
String date = "Unknown";
|
||||
|
||||
try (InputStream is = Build.class.getResourceAsStream("/es-build.properties")){
|
||||
Properties props = new Properties();
|
||||
props.load(is);
|
||||
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) {
|
||||
String path = Build.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
try {
|
||||
JarFile jar = new JarFile(path);
|
||||
Manifest manifest = jar.getManifest();
|
||||
shortHash = manifest.getMainAttributes().getValue("Change");
|
||||
date = manifest.getMainAttributes().getValue("Build-Date");
|
||||
} catch (IOException e) {
|
||||
// just ignore...
|
||||
}
|
||||
|
||||
CURRENT = new Build(hash, hashShort, timestamp);
|
||||
CURRENT = new Build(shortHash, date);
|
||||
}
|
||||
|
||||
private String hash;
|
||||
private String hashShort;
|
||||
private String timestamp;
|
||||
private String shortHash;
|
||||
private String date;
|
||||
|
||||
Build(String hash, String hashShort, String timestamp) {
|
||||
this.hash = hash;
|
||||
this.hashShort = hashShort;
|
||||
this.timestamp = timestamp;
|
||||
Build(String shortHash, String date) {
|
||||
this.shortHash = shortHash;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String hash() {
|
||||
return hash;
|
||||
public String shortHash() {
|
||||
return shortHash;
|
||||
}
|
||||
|
||||
public String hashShort() {
|
||||
return hashShort;
|
||||
}
|
||||
|
||||
public String timestamp() {
|
||||
return timestamp;
|
||||
public String date() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public static Build readBuild(StreamInput in) throws IOException {
|
||||
String hash = in.readString();
|
||||
String hashShort = in.readString();
|
||||
String timestamp = in.readString();
|
||||
return new Build(hash, hashShort, timestamp);
|
||||
String date = in.readString();
|
||||
return new Build(hash, date);
|
||||
}
|
||||
|
||||
public static void writeBuild(Build build, StreamOutput out) throws IOException {
|
||||
out.writeString(build.hash());
|
||||
out.writeString(build.hashShort());
|
||||
out.writeString(build.timestamp());
|
||||
out.writeString(build.shortHash());
|
||||
out.writeString(build.date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + hash + "][" + timestamp + "]";
|
||||
return "[" + shortHash + "][" + date + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -661,7 +661,7 @@ public class Version {
|
|||
|
||||
@SuppressForbidden(reason = "System.out.*")
|
||||
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
|
||||
|
|
|
@ -77,7 +77,7 @@ public class NodesInfoResponse extends BaseNodesResponse<NodeInfo> implements To
|
|||
builder.field("ip", nodeInfo.getNode().getHostAddress(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
|
||||
builder.field("version", nodeInfo.getVersion());
|
||||
builder.field("build", nodeInfo.getBuild().hashShort());
|
||||
builder.field("build_hash", nodeInfo.getBuild().shortHash());
|
||||
|
||||
if (nodeInfo.getServiceAttributes() != null) {
|
||||
for (Map.Entry<String, String> nodeAttribute : nodeInfo.getServiceAttributes().entrySet()) {
|
||||
|
|
|
@ -81,7 +81,7 @@ final class BootstrapCLIParser extends CliTool {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,7 +358,7 @@ public class HttpDownloadHelper {
|
|||
connection.setConnectTimeout(5000);
|
||||
}
|
||||
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");
|
||||
|
||||
// connect to the remote site (may take some time)
|
||||
|
|
|
@ -135,7 +135,7 @@ public class Node implements Releasable {
|
|||
Settings tmpSettings = TribeService.processSettings(tmpEnv.settings());
|
||||
|
||||
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 ...");
|
||||
|
||||
|
|
|
@ -574,7 +574,7 @@ public class PluginManager {
|
|||
// Elasticsearch new download service uses groupId org.elasticsearch.plugin from 2.0.0
|
||||
if (user == null) {
|
||||
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));
|
||||
} else {
|
||||
|
|
|
@ -245,7 +245,7 @@ public class RestNodesAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
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(fsInfo == null ? null : fsInfo.getTotal().getAvailable());
|
||||
table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed());
|
||||
|
|
|
@ -77,8 +77,8 @@ public class RestMainAction extends BaseRestHandler {
|
|||
builder.field("cluster_name", clusterName.value());
|
||||
builder.startObject("version")
|
||||
.field("number", version.number())
|
||||
.field("build_hash", Build.CURRENT.hash())
|
||||
.field("build_timestamp", Build.CURRENT.timestamp())
|
||||
.field("build_hash", Build.CURRENT.shortHash())
|
||||
.field("build_date", Build.CURRENT.date())
|
||||
.field("build_snapshot", version.snapshot)
|
||||
.field("lucene_version", version.luceneVersion.toString())
|
||||
.endObject();
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
version=${project.version}
|
||||
hash=${buildNumber}
|
||||
timestamp=${timestamp}
|
|
@ -54,8 +54,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
|
|||
assertStatus(status, OK_AND_EXIT);
|
||||
|
||||
assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.date()));
|
||||
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
|
|||
assertStatus(status, OK_AND_EXIT);
|
||||
|
||||
assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.date()));
|
||||
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
|
||||
|
||||
CaptureOutputTerminal terminal = new CaptureOutputTerminal();
|
||||
|
@ -75,8 +75,8 @@ public class BootstrapCliParserTests extends CliToolTestCase {
|
|||
assertStatus(status, OK_AND_EXIT);
|
||||
|
||||
assertThatTerminalOutput(containsString(Version.CURRENT.toString()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.hashShort()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.timestamp()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.shortHash()));
|
||||
assertThatTerminalOutput(containsString(Build.CURRENT.date()));
|
||||
assertThatTerminalOutput(containsString(JvmInfo.jvmInfo().version()));
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public class PluginManagerUnitTests extends ESTestCase {
|
|||
|
||||
if (supportStagingUrls) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class PluginManagerUnitTests extends ESTestCase {
|
|||
|
||||
if (supportStagingUrls) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue