Skip to content

Commit

Permalink
Add usage indicators for the bundled JDK (#40616)
Browse files Browse the repository at this point in the history
This commit adds indications whether or not a distribution is from the
bundled JDK, and whether or not we are using the bundled JDK.
  • Loading branch information
jasontedor committed Mar 29, 2019
1 parent 9ee474a commit 1122411
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 34 deletions.
4 changes: 2 additions & 2 deletions distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
into('config') {
dirMode 0750
fileMode 0660
with configFiles(distributionType, oss)
with configFiles(distributionType, oss, jdk)
}
into('bin') {
with binFiles(distributionType, oss)
with binFiles(distributionType, oss, jdk)
}
if (jdk) {
into('jdk') {
Expand Down
16 changes: 10 additions & 6 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
from project(':distribution').buildTransportModules
}

configFiles = { distributionType, oss ->
configFiles = { distributionType, oss, jdk ->
copySpec {
with copySpec {
// main config files, processed with distribution specific substitutions
from '../src/config'
exclude 'log4j2.properties' // this is handled separately below
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss))
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss, jdk))
}
if (oss) {
from project(':distribution').buildOssLog4jConfig
Expand All @@ -339,23 +339,23 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}

binFiles = { distributionType, oss ->
binFiles = { distributionType, oss, jdk ->
copySpec {
// non-windows files, for all distributions
with copySpec {
from '../src/bin'
exclude '*.exe'
exclude '*.bat'
eachFile { it.setMode(0755) }
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss))
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss, jdk))
}
// windows files, only for zip
if (distributionType == 'zip') {
with copySpec {
from '../src/bin'
include '*.bat'
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss))
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, oss, jdk))
}
with copySpec {
from '../src/bin'
Expand Down Expand Up @@ -452,7 +452,7 @@ task run(type: RunTask) {
* </dl>
*/
subprojects {
ext.expansionsForDistribution = { distributionType, oss ->
ext.expansionsForDistribution = { distributionType, oss, jdk ->
final String defaultHeapSize = "1g"
final String packagingPathData = "path.data: /var/lib/elasticsearch"
final String pathLogs = "/var/log/elasticsearch"
Expand Down Expand Up @@ -545,6 +545,10 @@ subprojects {
'zip': 'zip'
],

'es.bundled_jdk': [
'def': jdk ? 'true' : 'false'
],

'license.name': [
'deb': oss ? 'ASL-2.0' : 'Elastic-License'
],
Expand Down
32 changes: 18 additions & 14 deletions distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ buildscript {
}
}

void addProcessFilesTask(String type, boolean oss) {
String packagingFiles = "build/packaging/${ oss ? 'oss-' : ''}${type}"
void addProcessFilesTask(String type, boolean oss, boolean jdk) {
String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"

String taskName = "process${oss ? 'Oss' : ''}${type.capitalize()}Files"
String taskName = "process${oss ? 'Oss' : ''}${jdk ? '' : 'NoJdk'}${type.capitalize()}Files"
task(taskName, type: Copy) {
into packagingFiles

with copySpec {
from 'src/common'
from "src/${type}"
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss))
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss, jdk))
}

into('etc/elasticsearch') {
with configFiles(type, oss)
with configFiles(type, oss, jdk)
}
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss))
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss, jdk))

doLast {
// create empty dirs, we set the permissions when configuring the packages
Expand All @@ -91,17 +91,21 @@ void addProcessFilesTask(String type, boolean oss) {
}
}
}
addProcessFilesTask('deb', true)
addProcessFilesTask('deb', false)
addProcessFilesTask('rpm', true)
addProcessFilesTask('rpm', false)
addProcessFilesTask('deb', true, true)
addProcessFilesTask('deb', true, false)
addProcessFilesTask('deb', false, true)
addProcessFilesTask('deb', false, false)
addProcessFilesTask('rpm', true, true)
addProcessFilesTask('rpm', true, false)
addProcessFilesTask('rpm', false, true)
addProcessFilesTask('rpm', false, false)

// Common configuration that is package dependent. This can't go in ospackage
// since we have different templated files that need to be consumed, but the structure
// is the same
Closure commonPackageConfig(String type, boolean oss, boolean jdk) {
return {
dependsOn "process${oss ? 'Oss' : ''}${type.capitalize()}Files"
dependsOn "process${oss ? 'Oss' : ''}${jdk ? '' : 'NoJdk'}${type.capitalize()}Files"
packageName "elasticsearch${oss ? '-oss' : ''}"
arch (type == 'deb' ? 'amd64' : 'X86_64')
// Follow elasticsearch's file naming convention
Expand All @@ -110,7 +114,7 @@ Closure commonPackageConfig(String type, boolean oss, boolean jdk) {

String prefix = "${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"
destinationDir = file("${prefix}/build/distributions")
String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${type}"
String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"

String scripts = "${packagingFiles}/scripts"
preInstall file("${scripts}/preinst")
Expand All @@ -125,7 +129,7 @@ Closure commonPackageConfig(String type, boolean oss, boolean jdk) {
// specify it again explicitly for copying common files
into('/usr/share/elasticsearch') {
into('bin') {
with binFiles(type, oss)
with binFiles(type, oss, jdk)
}
from(rootProject.projectDir) {
include 'README.textile'
Expand Down Expand Up @@ -202,7 +206,7 @@ Closure commonPackageConfig(String type, boolean oss, boolean jdk) {
createDirectoryEntry true
fileType CONFIG | NOREPLACE
}
String envFile = expansionsForDistribution(type, false)['path.env']
String envFile = expansionsForDistribution(type, oss, jdk)['path.env']
configurationFile envFile
into(new File(envFile).getParent()) {
fileType CONFIG | NOREPLACE
Expand Down
2 changes: 2 additions & 0 deletions distribution/src/bin/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null;
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-Des.bundled_jdk="$ES_BUNDLED_JDK" \
-cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch \
"$@"
Expand All @@ -40,6 +41,7 @@ else
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-Des.bundled_jdk="$ES_BUNDLED_JDK" \
-cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch \
"$@" \
Expand Down
1 change: 1 addition & 0 deletions distribution/src/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ES_PATH_CONF=`cd "$ES_PATH_CONF"; pwd`

ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
ES_DISTRIBUTION_TYPE=${es.distribution.type}
ES_BUNDLED_JDK=${es.bundled_jdk}

if [ -z "$ES_TMPDIR" ]; then
ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
Expand Down
1 change: 1 addition & 0 deletions distribution/src/bin/elasticsearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for %%I in ("%ES_PATH_CONF%..") do set ES_PATH_CONF=%%~dpfI

set ES_DISTRIBUTION_FLAVOR=${es.distribution.flavor}
set ES_DISTRIBUTION_TYPE=${es.distribution.type}
set ES_BUNDLED_JDK=${es.bundled_jdk}

if not defined ES_TMPDIR (
for /f "tokens=* usebackq" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory""`) do set ES_TMPDIR=%%a
Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch-service.bat
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ if "%JVM_SS%" == "" (
goto:eof
)

set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.path.conf="%ES_PATH_CONF%";-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%";-Des.distribution.type="%ES_DISTRIBUTION_TYPE%"
set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.path.conf="%ES_PATH_CONF%";-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%";-Des.distribution.type="%ES_DISTRIBUTION_TYPE%";-Des.bundled_jdk="%ES_BUNDLED_JDK%"

if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0
Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
exit /b 1
)

%JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
%JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" -Des.bundled_jd="%ES_BUNDLED_JDK%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!

endlocal
endlocal
Expand Down
9 changes: 6 additions & 3 deletions docs/reference/cluster/stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ Will return, for example:
"max_uptime_in_millis": 13737,
"versions": [
{
"version": "1.8.0_74",
"vm_name": "Java HotSpot(TM) 64-Bit Server VM",
"vm_version": "25.74-b02",
"version": "12",
"vm_name": "OpenJDK 64-Bit Server VM",
"vm_version": "12+33",
"vm_vendor": "Oracle Corporation",
"bundled_jdk": true,
"using_bundled_jdk": true,
"count": 1
}
],
Expand Down Expand Up @@ -200,6 +202,7 @@ Will return, for example:
// TESTRESPONSE[s/"plugins": \[[^\]]*\]/"plugins": $body.$_path/]
// TESTRESPONSE[s/"network_types": \{[^\}]*\}/"network_types": $body.$_path/]
// TESTRESPONSE[s/"discovery_types": \{[^\}]*\}/"discovery_types": $body.$_path/]
// TESTRESPONSE[s/: true|false/: $body.$_path/]
// TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
// TESTRESPONSE[s/: "[^"]*"/: $body.$_path/]
// These replacements do a few things:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ static final class Fields {
static final String VM_NAME = "vm_name";
static final String VM_VERSION = "vm_version";
static final String VM_VENDOR = "vm_vendor";
static final String BUNDLED_JDK = "bundled_jdk";
static final String USING_BUNDLED_JDK = "using_bundled_jdk";
static final String COUNT = "count";
static final String THREADS = "threads";
static final String MAX_UPTIME = "max_uptime";
Expand All @@ -524,6 +526,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params)
builder.field(Fields.VM_NAME, v.key.vmName);
builder.field(Fields.VM_VERSION, v.key.vmVersion);
builder.field(Fields.VM_VENDOR, v.key.vmVendor);
builder.field(Fields.BUNDLED_JDK, v.key.bundledJdk);
builder.field(Fields.USING_BUNDLED_JDK, v.key.usingBundledJdk);
builder.field(Fields.COUNT, v.value);
builder.endObject();
}
Expand All @@ -543,12 +547,16 @@ public static class JvmVersion {
String vmName;
String vmVersion;
String vmVendor;
boolean bundledJdk;
Boolean usingBundledJdk;

JvmVersion(JvmInfo jvmInfo) {
version = jvmInfo.version();
vmName = jvmInfo.getVmName();
vmVersion = jvmInfo.getVmVersion();
vmVendor = jvmInfo.getVmVendor();
bundledJdk = jvmInfo.getBundledJdk();
usingBundledJdk = jvmInfo.getUsingBundledJdk();
}

@Override
Expand Down
60 changes: 53 additions & 7 deletions server/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

package org.elasticsearch.monitor.jvm;

import org.elasticsearch.Version;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand Down Expand Up @@ -150,10 +154,24 @@ public class JvmInfo implements Writeable, ToXContentFragment {

}

final boolean bundledJdk = Booleans.parseBoolean(System.getProperty("es.bundled_jdk", Boolean.FALSE.toString()));
final Boolean usingBundledJdk = bundledJdk ? usingBundledJdk() : null;

INSTANCE = new JvmInfo(JvmPid.getPid(), System.getProperty("java.version"), runtimeMXBean.getVmName(), runtimeMXBean.getVmVersion(),
runtimeMXBean.getVmVendor(), runtimeMXBean.getStartTime(), configuredInitialHeapSize, configuredMaxHeapSize,
mem, inputArguments, bootClassPath, classPath, systemProperties, gcCollectors, memoryPools, onError, onOutOfMemoryError,
useCompressedOops, useG1GC, useSerialGC);
runtimeMXBean.getVmVendor(), bundledJdk, usingBundledJdk, runtimeMXBean.getStartTime(), configuredInitialHeapSize,
configuredMaxHeapSize, mem, inputArguments, bootClassPath, classPath, systemProperties, gcCollectors, memoryPools, onError,
onOutOfMemoryError, useCompressedOops, useG1GC, useSerialGC);
}

@SuppressForbidden(reason = "PathUtils#get")
private static boolean usingBundledJdk() {
/*
* We are using the bundled JDK if java.home is the jdk sub-directory of our working directory. This is because we always set
* the working directory of Elasticsearch to home, and the bundled JDK is in the jdk sub-directory there.
*/
final String javaHome = System.getProperty("java.home");
final String userDir = System.getProperty("user.dir");
return PathUtils.get(javaHome).equals(PathUtils.get(userDir).resolve("jdk").toAbsolutePath());
}

public static JvmInfo jvmInfo() {
Expand All @@ -170,6 +188,8 @@ public static JvmInfo jvmInfo() {
private final String vmName;
private final String vmVersion;
private final String vmVendor;
private final boolean bundledJdk;
private final Boolean usingBundledJdk;
private final long startTime;
private final long configuredInitialHeapSize;
private final long configuredMaxHeapSize;
Expand All @@ -186,15 +206,18 @@ public static JvmInfo jvmInfo() {
private final String useG1GC;
private final String useSerialGC;

private JvmInfo(long pid, String version, String vmName, String vmVersion, String vmVendor, long startTime,
long configuredInitialHeapSize, long configuredMaxHeapSize, Mem mem, String[] inputArguments, String bootClassPath,
String classPath, Map<String, String> systemProperties, String[] gcCollectors, String[] memoryPools, String onError,
String onOutOfMemoryError, String useCompressedOops, String useG1GC, String useSerialGC) {
private JvmInfo(long pid, String version, String vmName, String vmVersion, String vmVendor, boolean bundledJdk, Boolean usingBundledJdk,
long startTime, long configuredInitialHeapSize, long configuredMaxHeapSize, Mem mem, String[] inputArguments,
String bootClassPath, String classPath, Map<String, String> systemProperties, String[] gcCollectors,
String[] memoryPools, String onError, String onOutOfMemoryError, String useCompressedOops, String useG1GC,
String useSerialGC) {
this.pid = pid;
this.version = version;
this.vmName = vmName;
this.vmVersion = vmVersion;
this.vmVendor = vmVendor;
this.bundledJdk = bundledJdk;
this.usingBundledJdk = usingBundledJdk;
this.startTime = startTime;
this.configuredInitialHeapSize = configuredInitialHeapSize;
this.configuredMaxHeapSize = configuredMaxHeapSize;
Expand All @@ -218,6 +241,13 @@ public JvmInfo(StreamInput in) throws IOException {
vmName = in.readString();
vmVersion = in.readString();
vmVendor = in.readString();
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
bundledJdk = in.readBoolean();
usingBundledJdk = in.readOptionalBoolean();
} else {
bundledJdk = false;
usingBundledJdk = null;
}
startTime = in.readLong();
inputArguments = new String[in.readInt()];
for (int i = 0; i < inputArguments.length; i++) {
Expand Down Expand Up @@ -246,6 +276,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(vmName);
out.writeString(vmVersion);
out.writeString(vmVendor);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeBoolean(bundledJdk);
out.writeOptionalBoolean(usingBundledJdk);
}
out.writeLong(startTime);
out.writeInt(inputArguments.length);
for (String inputArgument : inputArguments) {
Expand Down Expand Up @@ -360,6 +394,14 @@ public String getVmVendor() {
return this.vmVendor;
}

public boolean getBundledJdk() {
return bundledJdk;
}

public Boolean getUsingBundledJdk() {
return usingBundledJdk;
}

public long getStartTime() {
return this.startTime;
}
Expand Down Expand Up @@ -436,6 +478,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(Fields.VM_NAME, vmName);
builder.field(Fields.VM_VERSION, vmVersion);
builder.field(Fields.VM_VENDOR, vmVendor);
builder.field(Fields.BUNDLED_JDK, bundledJdk);
builder.field(Fields.USING_BUNDLED_JDK, usingBundledJdk);
builder.timeField(Fields.START_TIME_IN_MILLIS, Fields.START_TIME, startTime);

builder.startObject(Fields.MEM);
Expand Down Expand Up @@ -464,6 +508,8 @@ static final class Fields {
static final String VM_NAME = "vm_name";
static final String VM_VERSION = "vm_version";
static final String VM_VENDOR = "vm_vendor";
static final String BUNDLED_JDK = "bundled_jdk";
static final String USING_BUNDLED_JDK = "using_bundled_jdk";
static final String START_TIME = "start_time";
static final String START_TIME_IN_MILLIS = "start_time_in_millis";

Expand Down
Loading

0 comments on commit 1122411

Please sign in to comment.