Add no-jdk distributions (#39882)

This commit adds a variant for every official distribution that omits
the bundled jdk. The "no-jdk" naming is conveyed through the package
classifier, alongside the platform. Package tests are also added for
each new distribution.
This commit is contained in:
Ryan Ernst 2019-03-15 00:55:15 -07:00
parent a323132503
commit 8f09c77777
38 changed files with 523 additions and 130 deletions

View File

@ -504,8 +504,8 @@ sudo bash $PACKAGING_TESTS/run-tests.sh
# run specific test cases # run specific test cases
sudo bash $PACKAGING_TESTS/run-tests.sh \ sudo bash $PACKAGING_TESTS/run-tests.sh \
org.elasticsearch.packaging.test.DefaultZipTests \ org.elasticsearch.packaging.test.DefaultWindowsZipTests \
org.elasticsearch.packaging.test.OssZipTests org.elasticsearch.packaging.test.OssWindowsZipTests
-------------------------------------------- --------------------------------------------
or on Windows, from a terminal running as Administrator or on Windows, from a terminal running as Administrator
@ -516,8 +516,8 @@ powershell -File $Env:PACKAGING_TESTS/run-tests.ps1
# run specific test cases # run specific test cases
powershell -File $Env:PACKAGING_TESTS/run-tests.ps1 ` powershell -File $Env:PACKAGING_TESTS/run-tests.ps1 `
org.elasticsearch.packaging.test.DefaultZipTests ` org.elasticsearch.packaging.test.DefaultWindowsZipTests `
org.elasticsearch.packaging.test.OssZipTests org.elasticsearch.packaging.test.OssWindowsZipTests
-------------------------------------------- --------------------------------------------
Note that on Windows boxes when running from inside the GUI, you may have to log out and Note that on Windows boxes when running from inside the GUI, you may have to log out and

View File

@ -60,7 +60,15 @@ class VagrantTestPlugin implements Plugin<Project> {
'packages:rpm', 'packages:rpm',
'packages:oss-rpm', 'packages:oss-rpm',
'packages:deb', 'packages:deb',
'packages:oss-deb' 'packages:oss-deb',
'archives:no-jdk-linux-tar',
'archives:oss-no-jdk-linux-tar',
'archives:no-jdk-windows-zip',
'archives:oss-no-jdk-windows-zip',
'packages:no-jdk-rpm',
'packages:oss-no-jdk-rpm',
'packages:no-jdk-deb',
'packages:oss-no-jdk-deb'
]) ])
/** Packages onboarded for upgrade tests **/ /** Packages onboarded for upgrade tests **/

View File

@ -45,7 +45,7 @@ task createPluginsDir(type: EmptyDirTask) {
dirMode 0755 dirMode 0755
} }
CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, boolean oss) { CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, boolean oss, boolean jdk) {
return copySpec { return copySpec {
into("elasticsearch-${version}") { into("elasticsearch-${version}") {
into('lib') { into('lib') {
@ -59,7 +59,7 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
into('bin') { into('bin') {
with binFiles(distributionType, oss) with binFiles(distributionType, oss)
} }
if (platform != null) { if (jdk) {
into('jdk') { into('jdk') {
with jdkFiles(platform) with jdkFiles(platform)
} }
@ -107,19 +107,31 @@ Closure commonZipConfig = {
task buildIntegTestZip(type: Zip) { task buildIntegTestZip(type: Zip) {
configure(commonZipConfig) configure(commonZipConfig)
with archiveFiles(transportModulesFiles, 'zip', null, true) with archiveFiles(transportModulesFiles, 'zip', null, true, false)
} }
task buildWindowsZip(type: Zip) { task buildWindowsZip(type: Zip) {
configure(commonZipConfig) configure(commonZipConfig)
archiveClassifier = 'windows-x86_64' archiveClassifier = 'windows-x86_64'
with archiveFiles(modulesFiles(false), 'zip', 'windows', false) with archiveFiles(modulesFiles(false), 'zip', 'windows', false, true)
} }
task buildOssWindowsZip(type: Zip) { task buildOssWindowsZip(type: Zip) {
configure(commonZipConfig) configure(commonZipConfig)
archiveClassifier = 'windows-x86_64' archiveClassifier = 'windows-x86_64'
with archiveFiles(modulesFiles(true), 'zip', 'windows', true) with archiveFiles(modulesFiles(true), 'zip', 'windows', true, true)
}
task buildNoJdkWindowsZip(type: Zip) {
configure(commonZipConfig)
archiveClassifier = 'no-jdk-windows-x86_64'
with archiveFiles(modulesFiles(false), 'zip', 'windows', false, false)
}
task buildOssNoJdkWindowsZip(type: Zip) {
configure(commonZipConfig)
archiveClassifier = 'no-jdk-windows-x86_64'
with archiveFiles(modulesFiles(true), 'zip', 'windows', true, false)
} }
Closure commonTarConfig = { Closure commonTarConfig = {
@ -132,25 +144,49 @@ Closure commonTarConfig = {
task buildDarwinTar(type: Tar) { task buildDarwinTar(type: Tar) {
configure(commonTarConfig) configure(commonTarConfig)
archiveClassifier = 'darwin-x86_64' archiveClassifier = 'darwin-x86_64'
with archiveFiles(modulesFiles(false), 'tar', 'darwin', false) with archiveFiles(modulesFiles(false), 'tar', 'darwin', false, true)
} }
task buildOssDarwinTar(type: Tar) { task buildOssDarwinTar(type: Tar) {
configure(commonTarConfig) configure(commonTarConfig)
archiveClassifier = 'darwin-x86_64' archiveClassifier = 'darwin-x86_64'
with archiveFiles(modulesFiles(true), 'tar', 'darwin', true) with archiveFiles(modulesFiles(true), 'tar', 'darwin', true, true)
}
task buildNoJdkDarwinTar(type: Tar) {
configure(commonTarConfig)
archiveClassifier = 'no-jdk-darwin-x86_64'
with archiveFiles(modulesFiles(false), 'tar', 'darwin', false, false)
}
task buildOssNoJdkDarwinTar(type: Tar) {
configure(commonTarConfig)
archiveClassifier = 'no-jdk-darwin-x86_64'
with archiveFiles(modulesFiles(true), 'tar', 'darwin', true, false)
} }
task buildLinuxTar(type: Tar) { task buildLinuxTar(type: Tar) {
configure(commonTarConfig) configure(commonTarConfig)
archiveClassifier = 'linux-x86_64' archiveClassifier = 'linux-x86_64'
with archiveFiles(modulesFiles(false), 'tar', 'linux', false) with archiveFiles(modulesFiles(false), 'tar', 'linux', false, true)
} }
task buildOssLinuxTar(type: Tar) { task buildOssLinuxTar(type: Tar) {
configure(commonTarConfig) configure(commonTarConfig)
archiveClassifier = 'linux-x86_64' archiveClassifier = 'linux-x86_64'
with archiveFiles(modulesFiles(true), 'tar', 'linux', true) with archiveFiles(modulesFiles(true), 'tar', 'linux', true, true)
}
task buildNoJdkLinuxTar(type: Tar) {
configure(commonTarConfig)
archiveClassifier = 'no-jdk-linux-x86_64'
with archiveFiles(modulesFiles(false), 'tar', 'linux', false, false)
}
task buildOssNoJdkLinuxTar(type: Tar) {
configure(commonTarConfig)
archiveClassifier = 'no-jdk-linux-x86_64'
with archiveFiles(modulesFiles(true), 'tar', 'linux', true, false)
} }
Closure tarExists = { it -> new File('/bin/tar').exists() || new File('/usr/bin/tar').exists() || new File('/usr/local/bin/tar').exists() } Closure tarExists = { it -> new File('/bin/tar').exists() || new File('/usr/bin/tar').exists() || new File('/usr/local/bin/tar').exists() }

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -64,7 +64,8 @@ buildscript {
void addProcessFilesTask(String type, boolean oss) { void addProcessFilesTask(String type, boolean oss) {
String packagingFiles = "build/packaging/${ oss ? 'oss-' : ''}${type}" String packagingFiles = "build/packaging/${ oss ? 'oss-' : ''}${type}"
task("process${oss ? 'Oss' : ''}${type.capitalize()}Files", type: Copy) { String taskName = "process${oss ? 'Oss' : ''}${type.capitalize()}Files"
task(taskName, type: Copy) {
into packagingFiles into packagingFiles
with copySpec { with copySpec {
@ -98,17 +99,18 @@ addProcessFilesTask('rpm', false)
// Common configuration that is package dependent. This can't go in ospackage // 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 // since we have different templated files that need to be consumed, but the structure
// is the same // is the same
Closure commonPackageConfig(String type, boolean oss) { Closure commonPackageConfig(String type, boolean oss, boolean jdk) {
return { return {
dependsOn "process${oss ? 'Oss' : ''}${type.capitalize()}Files" dependsOn "process${oss ? 'Oss' : ''}${type.capitalize()}Files"
packageName "elasticsearch${oss ? '-oss' : ''}" packageName "elasticsearch${oss ? '-oss' : ''}"
arch (type == 'deb' ? 'amd64' : 'X86_64') arch (type == 'deb' ? 'amd64' : 'X86_64')
// Follow elasticsearch's file naming convention // Follow elasticsearch's file naming convention
archiveName "${packageName}-${project.version}-${archString}.${type}" String jdkString = jdk ? "" : "no-jdk-"
archiveName "${packageName}-${project.version}-${jdkString}${archString}.${type}"
String prefix = "${oss ? 'oss-' : ''}${type}" String prefix = "${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"
destinationDir = file("${prefix}/build/distributions") destinationDir = file("${prefix}/build/distributions")
String packagingFiles = "build/packaging/${prefix}" String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${type}"
String scripts = "${packagingFiles}/scripts" String scripts = "${packagingFiles}/scripts"
preInstall file("${scripts}/preinst") preInstall file("${scripts}/preinst")
@ -135,8 +137,10 @@ Closure commonPackageConfig(String type, boolean oss) {
into('modules') { into('modules') {
with modulesFiles(oss) with modulesFiles(oss)
} }
into('jdk') { if (jdk) {
with jdkFiles('linux') into('jdk') {
with jdkFiles('linux')
}
} }
// we need to specify every intermediate directory in these paths so the package managers know they are explicitly // we need to specify every intermediate directory in these paths so the package managers know they are explicitly
// intended to manage them; otherwise they may be left behind on uninstallation. duplicate calls of the same // intended to manage them; otherwise they may be left behind on uninstallation. duplicate calls of the same
@ -289,9 +293,9 @@ ospackage {
with noticeFile with noticeFile
} }
Closure commonDebConfig(boolean oss) { Closure commonDebConfig(boolean oss, boolean jdk) {
return { return {
configure(commonPackageConfig('deb', oss)) configure(commonPackageConfig('deb', oss, jdk))
// jdeb does not provide a way to set the License control attribute, and ospackage // jdeb does not provide a way to set the License control attribute, and ospackage
// silently ignores setting it. Instead, we set the license as "custom field" // silently ignores setting it. Instead, we set the license as "custom field"
@ -314,16 +318,24 @@ Closure commonDebConfig(boolean oss) {
} }
task buildDeb(type: Deb) { task buildDeb(type: Deb) {
configure(commonDebConfig(false)) configure(commonDebConfig(false, true))
} }
task buildOssDeb(type: Deb) { task buildOssDeb(type: Deb) {
configure(commonDebConfig(true)) configure(commonDebConfig(true, true))
} }
Closure commonRpmConfig(boolean oss) { task buildNoJdkDeb(type: Deb) {
configure(commonDebConfig(false, false))
}
task buildOssNoJdkDeb(type: Deb) {
configure(commonDebConfig(true, false))
}
Closure commonRpmConfig(boolean oss, boolean jdk) {
return { return {
configure(commonPackageConfig('rpm', oss)) configure(commonPackageConfig('rpm', oss, jdk))
if (oss) { if (oss) {
license 'ASL 2.0' license 'ASL 2.0'
@ -351,11 +363,19 @@ Closure commonRpmConfig(boolean oss) {
} }
task buildRpm(type: Rpm) { task buildRpm(type: Rpm) {
configure(commonRpmConfig(false)) configure(commonRpmConfig(false, true))
} }
task buildOssRpm(type: Rpm) { task buildOssRpm(type: Rpm) {
configure(commonRpmConfig(true)) configure(commonRpmConfig(true, true))
}
task buildNoJdkRpm(type: Rpm) {
configure(commonRpmConfig(false, false))
}
task buildOssNoJdkRpm(type: Rpm) {
configure(commonRpmConfig(true, false))
} }
Closure dpkgExists = { it -> new File('/bin/dpkg-deb').exists() || new File('/usr/bin/dpkg-deb').exists() || new File('/usr/local/bin/dpkg-deb').exists() } Closure dpkgExists = { it -> new File('/bin/dpkg-deb').exists() || new File('/usr/bin/dpkg-deb').exists() || new File('/usr/local/bin/dpkg-deb').exists() }

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

View File

@ -19,11 +19,6 @@
package org.elasticsearch.example.expertscript; package org.elasticsearch.example.expertscript;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Map;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -36,6 +31,11 @@ import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptEngine;
import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Map;
/** /**
* An example script plugin that adds a {@link ScriptEngine} implementing expert scoring. * An example script plugin that adds a {@link ScriptEngine} implementing expert scoring.
*/ */

View File

@ -21,28 +21,36 @@ package org.elasticsearch.packaging;
import org.elasticsearch.packaging.test.DefaultDebBasicTests; import org.elasticsearch.packaging.test.DefaultDebBasicTests;
import org.elasticsearch.packaging.test.DefaultDebPreservationTests; import org.elasticsearch.packaging.test.DefaultDebPreservationTests;
import org.elasticsearch.packaging.test.DefaultLinuxTarTests;
import org.elasticsearch.packaging.test.DefaultNoJdkDebBasicTests;
import org.elasticsearch.packaging.test.DefaultNoJdkLinuxTarTests;
import org.elasticsearch.packaging.test.DefaultNoJdkRpmBasicTests;
import org.elasticsearch.packaging.test.DefaultNoJdkWindowsZipTests;
import org.elasticsearch.packaging.test.DefaultRpmBasicTests; import org.elasticsearch.packaging.test.DefaultRpmBasicTests;
import org.elasticsearch.packaging.test.DefaultRpmPreservationTests; import org.elasticsearch.packaging.test.DefaultRpmPreservationTests;
import org.elasticsearch.packaging.test.DefaultTarTests;
import org.elasticsearch.packaging.test.DefaultWindowsServiceTests; import org.elasticsearch.packaging.test.DefaultWindowsServiceTests;
import org.elasticsearch.packaging.test.DefaultZipTests; import org.elasticsearch.packaging.test.DefaultWindowsZipTests;
import org.elasticsearch.packaging.test.OssDebBasicTests; import org.elasticsearch.packaging.test.OssDebBasicTests;
import org.elasticsearch.packaging.test.OssDebPreservationTests; import org.elasticsearch.packaging.test.OssDebPreservationTests;
import org.elasticsearch.packaging.test.OssLinuxTarTests;
import org.elasticsearch.packaging.test.OssNoJdkDebBasicTests;
import org.elasticsearch.packaging.test.OssNoJdkLinuxTarTests;
import org.elasticsearch.packaging.test.OssNoJdkRpmBasicTests;
import org.elasticsearch.packaging.test.OssNoJdkWindowsZipTests;
import org.elasticsearch.packaging.test.OssRpmBasicTests; import org.elasticsearch.packaging.test.OssRpmBasicTests;
import org.elasticsearch.packaging.test.OssRpmPreservationTests; import org.elasticsearch.packaging.test.OssRpmPreservationTests;
import org.elasticsearch.packaging.test.OssTarTests;
import org.elasticsearch.packaging.test.OssWindowsServiceTests; import org.elasticsearch.packaging.test.OssWindowsServiceTests;
import org.elasticsearch.packaging.test.OssZipTests; import org.elasticsearch.packaging.test.OssWindowsZipTests;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ @SuiteClasses({
DefaultTarTests.class, DefaultLinuxTarTests.class,
OssTarTests.class, OssLinuxTarTests.class,
DefaultZipTests.class, DefaultWindowsZipTests.class,
OssZipTests.class, OssWindowsZipTests.class,
DefaultRpmBasicTests.class, DefaultRpmBasicTests.class,
OssRpmBasicTests.class, OssRpmBasicTests.class,
DefaultDebBasicTests.class, DefaultDebBasicTests.class,
@ -52,6 +60,14 @@ import org.junit.runners.Suite.SuiteClasses;
DefaultRpmPreservationTests.class, DefaultRpmPreservationTests.class,
OssRpmPreservationTests.class, OssRpmPreservationTests.class,
DefaultWindowsServiceTests.class, DefaultWindowsServiceTests.class,
OssWindowsServiceTests.class OssWindowsServiceTests.class,
DefaultNoJdkLinuxTarTests.class,
OssNoJdkLinuxTarTests.class,
DefaultNoJdkWindowsZipTests.class,
OssNoJdkWindowsZipTests.class,
DefaultNoJdkRpmBasicTests.class,
OssNoJdkRpmBasicTests.class,
DefaultNoJdkDebBasicTests.class,
OssNoJdkDebBasicTests.class
}) })
public class PackagingTests {} public class PackagingTests {}

View File

@ -71,7 +71,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
final Result r = sh.run(bin.elasticsearchPlugin + " list"); final Result r = sh.run(bin.elasticsearchPlugin + " list");
assertThat(r.stdout, isEmptyString()); assertThat(r.stdout, isEmptyString());
@ -81,18 +81,23 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
sh.getEnv().remove("JAVA_HOME");
final Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated"); final Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
try { try {
mv(installation.bundledJdk, relocatedJdk); if (distribution().hasJdk) {
mv(installation.bundledJdk, relocatedJdk);
}
// ask for elasticsearch version to quickly exit if java is actually found (ie test failure) // ask for elasticsearch version to quickly exit if java is actually found (ie test failure)
final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v"); final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString() + " -v");
assertThat(runResult.exitCode, is(1)); assertThat(runResult.exitCode, is(1));
assertThat(runResult.stderr, containsString("could not find java in JAVA_HOME or bundled")); assertThat(runResult.stderr, containsString("could not find java in JAVA_HOME or bundled"));
} finally { } finally {
mv(relocatedJdk, installation.bundledJdk); if (distribution().hasJdk) {
mv(relocatedJdk, installation.bundledJdk);
}
} }
} }
@ -100,7 +105,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.onLinux(() -> sh.run("sudo -u " + ARCHIVE_OWNER + " " + bin.elasticsearchKeystore + " create")); Platforms.onLinux(() -> sh.run("sudo -u " + ARCHIVE_OWNER + " " + bin.elasticsearchKeystore + " create"));
@ -135,16 +140,20 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
// cleanup from previous test // cleanup from previous test
rm(installation.config("elasticsearch.keystore")); rm(installation.config("elasticsearch.keystore"));
Archives.runElasticsearch(installation); Archives.runElasticsearch(installation, newShell());
assertTrue("gc logs exist", Files.exists(installation.logs.resolve("gc.log"))); final String gcLogName = Platforms.LINUX && distribution().hasJdk == false
? "gc.log.0.current"
: "gc.log";
assertTrue("gc logs exist", Files.exists(installation.logs.resolve(gcLogName)));
ServerUtils.runElasticsearchTests(); ServerUtils.runElasticsearchTests();
Archives.stopElasticsearch(installation); Archives.stopElasticsearch(installation);
} }
public void assertRunsWithJavaHome() throws IOException { public void assertRunsWithJavaHome() throws IOException {
Shell sh = new Shell(); Shell sh = newShell();
Platforms.onLinux(() -> { Platforms.onLinux(() -> {
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim(); String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
@ -172,6 +181,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
public void test52BundledJdkRemoved() throws IOException { public void test52BundledJdkRemoved() throws IOException {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
assumeThat(distribution().hasJdk, is(true));
Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated"); Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
try { try {
@ -188,7 +198,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assertThat(installation.config("elasticsearch.keystore"), file(File, ARCHIVE_OWNER, ARCHIVE_OWNER, p660)); assertThat(installation.config("elasticsearch.keystore"), file(File, ARCHIVE_OWNER, ARCHIVE_OWNER, p660));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.onLinux(() -> { Platforms.onLinux(() -> {
final Result result = sh.run("sudo -u " + ARCHIVE_OWNER + " " + bin.elasticsearchKeystore + " list"); final Result result = sh.run("sudo -u " + ARCHIVE_OWNER + " " + bin.elasticsearchKeystore + " list");
@ -220,7 +230,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
"-Dlog4j2.disable.jmx=true\n"; "-Dlog4j2.disable.jmx=true\n";
append(tempConf.resolve("jvm.options"), jvmOptions); append(tempConf.resolve("jvm.options"), jvmOptions);
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + tempConf)); Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + tempConf));
Platforms.onWindows(() -> sh.run( Platforms.onWindows(() -> sh.run(
"$account = New-Object System.Security.Principal.NTAccount 'vagrant'; " + "$account = New-Object System.Security.Principal.NTAccount 'vagrant'; " +
@ -233,7 +243,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
"}" "}"
)); ));
final Shell serverShell = new Shell(); final Shell serverShell = newShell();
serverShell.getEnv().put("ES_PATH_CONF", tempConf.toString()); serverShell.getEnv().put("ES_PATH_CONF", tempConf.toString());
serverShell.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops"); serverShell.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops");
@ -266,7 +276,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
append(tempConf.resolve("elasticsearch.yml"), "node.name: relative"); append(tempConf.resolve("elasticsearch.yml"), "node.name: relative");
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + temp)); Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + temp));
Platforms.onWindows(() -> sh.run( Platforms.onWindows(() -> sh.run(
"$account = New-Object System.Security.Principal.NTAccount 'vagrant'; " + "$account = New-Object System.Security.Principal.NTAccount 'vagrant'; " +
@ -279,7 +289,8 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
"}" "}"
)); ));
final Shell serverShell = new Shell(temp); final Shell serverShell = newShell();
serverShell.setWorkingDirectory(temp);
serverShell.getEnv().put("ES_PATH_CONF", "config"); serverShell.getEnv().put("ES_PATH_CONF", "config");
Archives.runElasticsearch(installation, serverShell); Archives.runElasticsearch(installation, serverShell);
@ -297,7 +308,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
if (distribution().equals(Distribution.DEFAULT_LINUX) || distribution().equals(Distribution.DEFAULT_WINDOWS)) { if (distribution().equals(Distribution.DEFAULT_LINUX) || distribution().equals(Distribution.DEFAULT_WINDOWS)) {
assertTrue(Files.exists(installation.lib.resolve("tools").resolve("security-cli"))); assertTrue(Files.exists(installation.lib.resolve("tools").resolve("security-cli")));
@ -321,7 +332,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.PlatformAction action = () -> { Platforms.PlatformAction action = () -> {
final Result result = sh.run(bin.elasticsearchShard + " help"); final Result result = sh.run(bin.elasticsearchShard + " help");
@ -338,7 +349,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Installation.Executables bin = installation.executables(); final Installation.Executables bin = installation.executables();
final Shell sh = new Shell(); final Shell sh = newShell();
Platforms.PlatformAction action = () -> { Platforms.PlatformAction action = () -> {
final Result result = sh.run(bin.elasticsearchNode + " -h"); final Result result = sh.run(bin.elasticsearchNode + " -h");

View File

@ -26,6 +26,7 @@ import org.elasticsearch.packaging.util.Shell;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -36,14 +37,12 @@ import static org.elasticsearch.packaging.util.Packages.SYSVINIT_SCRIPT;
import static org.elasticsearch.packaging.util.Packages.assertInstalled; import static org.elasticsearch.packaging.util.Packages.assertInstalled;
import static org.elasticsearch.packaging.util.Packages.assertRemoved; import static org.elasticsearch.packaging.util.Packages.assertRemoved;
import static org.elasticsearch.packaging.util.Packages.install; import static org.elasticsearch.packaging.util.Packages.install;
import static org.elasticsearch.packaging.util.Packages.remove;
import static org.elasticsearch.packaging.util.Packages.packageStatus; import static org.elasticsearch.packaging.util.Packages.packageStatus;
import static org.elasticsearch.packaging.util.Packages.remove;
import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation; import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation;
import static org.elasticsearch.packaging.util.Platforms.isDPKG; import static org.elasticsearch.packaging.util.Platforms.isDPKG;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
@ -66,11 +65,11 @@ public abstract class DebPreservationTestCase extends PackagingTestCase {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
} }
public void test10Install() { public void test10Install() throws IOException {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution()); verifyPackageInstallation(installation, distribution(), newShell());
} }
public void test20Remove() { public void test20Remove() {

View File

@ -21,7 +21,7 @@ package org.elasticsearch.packaging.test;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
public class DefaultTarTests extends ArchiveTestCase { public class DefaultLinuxTarTests extends ArchiveTestCase {
@Override @Override
protected Distribution distribution() { protected Distribution distribution() {

View File

@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class DefaultNoJdkDebBasicTests extends PackageTestCase {
@Override
protected Distribution distribution() {
return Distribution.DEFAULT_NO_JDK_DEB;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class DefaultNoJdkLinuxTarTests extends ArchiveTestCase {
@Override
protected Distribution distribution() {
return Distribution.DEFAULT_NO_JDK_LINUX;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class DefaultNoJdkRpmBasicTests extends PackageTestCase {
@Override
protected Distribution distribution() {
return Distribution.DEFAULT_NO_JDK_RPM;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class DefaultNoJdkWindowsZipTests extends ArchiveTestCase {
@Override
protected Distribution distribution() {
return Distribution.DEFAULT_NO_JDK_WINDOWS;
}
}

View File

@ -21,7 +21,7 @@ package org.elasticsearch.packaging.test;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
public class DefaultZipTests extends ArchiveTestCase { public class DefaultWindowsZipTests extends ArchiveTestCase {
@Override @Override
protected Distribution distribution() { protected Distribution distribution() {

View File

@ -21,7 +21,7 @@ package org.elasticsearch.packaging.test;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
public class OssTarTests extends ArchiveTestCase { public class OssLinuxTarTests extends ArchiveTestCase {
@Override @Override
protected Distribution distribution() { protected Distribution distribution() {

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class OssNoJdkDebBasicTests extends PackageTestCase {
@Override
protected Distribution distribution() {
return Distribution.OSS_NO_JDK_DEB;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class OssNoJdkLinuxTarTests extends ArchiveTestCase {
@Override
protected Distribution distribution() {
return Distribution.OSS_NO_JDK_LINUX;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class OssNoJdkRpmBasicTests extends PackageTestCase {
@Override
protected Distribution distribution() {
return Distribution.OSS_NO_JDK_RPM;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
public class OssNoJdkWindowsZipTests extends ArchiveTestCase {
@Override
protected Distribution distribution() {
return Distribution.OSS_NO_JDK_WINDOWS;
}
}

View File

@ -21,7 +21,7 @@ package org.elasticsearch.packaging.test;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
public class OssZipTests extends ArchiveTestCase { public class OssWindowsZipTests extends ArchiveTestCase {
@Override @Override
protected Distribution distribution() { protected Distribution distribution() {

View File

@ -61,29 +61,27 @@ public abstract class PackageTestCase extends PackagingTestCase {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
} }
public void test10InstallPackage() { public void test10InstallPackage() throws IOException {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution()); verifyPackageInstallation(installation, distribution(), newShell());
} }
public void test20PluginsCommandWhenNoPlugins() { public void test20PluginsCommandWhenNoPlugins() {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Shell sh = new Shell(); assertThat(newShell().run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString());
assertThat(sh.run(installation.bin("elasticsearch-plugin") + " list").stdout, isEmptyString());
} }
public void test30InstallDoesNotStartServer() { public void test30InstallDoesNotStartServer() {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
final Shell sh = new Shell(); assertThat(newShell().run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
} }
public void assertRunsWithJavaHome() throws IOException { public void assertRunsWithJavaHome() throws IOException {
Shell sh = new Shell(); Shell sh = newShell();
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim(); String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
byte[] originalEnvFile = Files.readAllBytes(installation.envFile); byte[] originalEnvFile = Files.readAllBytes(installation.envFile);
@ -103,12 +101,15 @@ public abstract class PackageTestCase extends PackagingTestCase {
public void test31JavaHomeOverride() throws IOException { public void test31JavaHomeOverride() throws IOException {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
// we always run with java home when no bundled jdk is included, so this test would be repetitive
assumeThat(distribution().hasJdk, is(true));
assertRunsWithJavaHome(); assertRunsWithJavaHome();
} }
public void test42BundledJdkRemoved() throws IOException { public void test42BundledJdkRemoved() throws IOException {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
assumeThat(distribution().hasJdk, is(true));
Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated"); Path relocatedJdk = installation.bundledJdk.getParent().resolve("jdk.relocated");
try { try {
@ -124,7 +125,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
startElasticsearch(); startElasticsearch();
runElasticsearchTests(); runElasticsearchTests();
verifyPackageInstallation(installation, distribution()); // check startup script didn't change permissions verifyPackageInstallation(installation, distribution(), newShell()); // check startup script didn't change permissions
} }
public void test50Remove() { public void test50Remove() {
@ -133,7 +134,7 @@ public abstract class PackageTestCase extends PackagingTestCase {
remove(distribution()); remove(distribution());
// removing must stop the service // removing must stop the service
final Shell sh = new Shell(); final Shell sh = newShell();
assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch"))); assertThat(sh.run("ps aux").stdout, not(containsString("org.elasticsearch.bootstrap.Elasticsearch")));
if (isSystemd()) { if (isSystemd()) {
@ -178,12 +179,12 @@ public abstract class PackageTestCase extends PackagingTestCase {
assertFalse(Files.exists(SYSTEMD_SERVICE)); assertFalse(Files.exists(SYSTEMD_SERVICE));
} }
public void test60Reinstall() { public void test60Reinstall() throws IOException {
assumeThat(installation, is(notNullValue())); assumeThat(installation, is(notNullValue()));
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution()); verifyPackageInstallation(installation, distribution(), newShell());
remove(distribution()); remove(distribution());
assertRemoved(distribution()); assertRemoved(distribution());

View File

@ -27,6 +27,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.Installation; import org.elasticsearch.packaging.util.Installation;
import org.elasticsearch.packaging.util.Platforms;
import org.elasticsearch.packaging.util.Shell;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -70,5 +72,19 @@ public abstract class PackagingTestCase extends Assert {
/** The {@link Distribution} that should be tested in this case */ /** The {@link Distribution} that should be tested in this case */
protected abstract Distribution distribution(); protected abstract Distribution distribution();
protected Shell newShell() {
Shell sh = new Shell();
if (distribution().hasJdk == false) {
Platforms.onLinux(() -> {
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
sh.getEnv().put("JAVA_HOME", systemJavaHome);
});
Platforms.onWindows(() -> {
final String systemJavaHome = sh.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
sh.getEnv().put("JAVA_HOME", systemJavaHome);
});
}
return sh;
}
} }

View File

@ -26,6 +26,7 @@ import org.elasticsearch.packaging.util.Shell;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -66,11 +67,11 @@ public abstract class RpmPreservationTestCase extends PackagingTestCase {
assumeTrue("only compatible distributions", distribution().packaging.compatible); assumeTrue("only compatible distributions", distribution().packaging.compatible);
} }
public void test10Install() { public void test10Install() throws IOException {
assertRemoved(distribution()); assertRemoved(distribution());
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution()); verifyPackageInstallation(installation, distribution(), newShell());
} }
public void test20Remove() { public void test20Remove() {
@ -88,12 +89,12 @@ public abstract class RpmPreservationTestCase extends PackagingTestCase {
assertFalse(Files.exists(installation.envFile)); assertFalse(Files.exists(installation.envFile));
} }
public void test30PreserveConfig() { public void test30PreserveConfig() throws IOException {
final Shell sh = new Shell(); final Shell sh = new Shell();
installation = install(distribution()); installation = install(distribution());
assertInstalled(distribution()); assertInstalled(distribution());
verifyPackageInstallation(installation, distribution()); verifyPackageInstallation(installation, distribution(), newShell());
sh.run("echo foobar | " + installation.executables().elasticsearchKeystore + " add --stdin foo.bar"); sh.run("echo foobar | " + installation.executables().elasticsearchKeystore + " add --stdin foo.bar");
Stream.of( Stream.of(

View File

@ -23,42 +23,59 @@ import java.util.Locale;
public enum Distribution { public enum Distribution {
OSS_LINUX(Packaging.TAR, Platform.LINUX, Flavor.OSS), OSS_LINUX(Packaging.TAR, Platform.LINUX, Flavor.OSS, true),
OSS_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.OSS), OSS_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.OSS, true),
OSS_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.OSS), OSS_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.OSS, true),
OSS_DEB(Packaging.DEB, Platform.LINUX, Flavor.OSS), OSS_DEB(Packaging.DEB, Platform.LINUX, Flavor.OSS, true),
OSS_RPM(Packaging.RPM, Platform.LINUX, Flavor.OSS), OSS_RPM(Packaging.RPM, Platform.LINUX, Flavor.OSS, true),
DEFAULT_LINUX(Packaging.TAR, Platform.LINUX, Flavor.DEFAULT), DEFAULT_LINUX(Packaging.TAR, Platform.LINUX, Flavor.DEFAULT, true),
DEFAULT_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.DEFAULT), DEFAULT_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.DEFAULT, true),
DEFAULT_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.DEFAULT), DEFAULT_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.DEFAULT, true),
DEFAULT_DEB(Packaging.DEB, Platform.LINUX, Flavor.DEFAULT), DEFAULT_DEB(Packaging.DEB, Platform.LINUX, Flavor.DEFAULT, true),
DEFAULT_RPM(Packaging.RPM, Platform.LINUX, Flavor.DEFAULT); DEFAULT_RPM(Packaging.RPM, Platform.LINUX, Flavor.DEFAULT, true),
OSS_NO_JDK_LINUX(Packaging.TAR, Platform.LINUX, Flavor.OSS, false),
OSS_NO_JDK_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.OSS, false),
OSS_NO_JDK_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.OSS, false),
OSS_NO_JDK_DEB(Packaging.DEB, Platform.LINUX, Flavor.OSS, false),
OSS_NO_JDK_RPM(Packaging.RPM, Platform.LINUX, Flavor.OSS, false),
DEFAULT_NO_JDK_LINUX(Packaging.TAR, Platform.LINUX, Flavor.DEFAULT, false),
DEFAULT_NO_JDK_WINDOWS(Packaging.ZIP, Platform.WINDOWS, Flavor.DEFAULT, false),
DEFAULT_NO_JDK_DARWIN(Packaging.TAR, Platform.DARWIN, Flavor.DEFAULT, false),
DEFAULT_NO_JDK_DEB(Packaging.DEB, Platform.LINUX, Flavor.DEFAULT, false),
DEFAULT_NO_JDK_RPM(Packaging.RPM, Platform.LINUX, Flavor.DEFAULT, false);
public final Packaging packaging; public final Packaging packaging;
public final Platform platform; public final Platform platform;
public final Flavor flavor; public final Flavor flavor;
public final boolean hasJdk;
Distribution(Packaging packaging, Platform platform, Flavor flavor) { Distribution(Packaging packaging, Platform platform, Flavor flavor, boolean hasJdk) {
this.packaging = packaging; this.packaging = packaging;
this.platform = platform; this.platform = platform;
this.flavor = flavor; this.flavor = flavor;
this.hasJdk = hasJdk;
} }
public String filename(String version) { public String filename(String version) {
String architecture = ""; String classifier = "";
if (version.startsWith("6.") == false) { if (version.startsWith("6.") == false) {
if (hasJdk == false) {
classifier += "-no-jdk";
}
if (packaging == Packaging.DEB) { if (packaging == Packaging.DEB) {
architecture = "-amd64"; classifier += "-amd64";
} else { } else {
if (packaging != Packaging.RPM) { if (packaging != Packaging.RPM) {
architecture = "-" + platform.toString(); classifier += "-" + platform.toString();
} }
architecture += "-x86_64"; classifier += "-x86_64";
} }
} }
return flavor.name + "-" + version + architecture + packaging.extension; return flavor.name + "-" + version + classifier + packaging.extension;
} }
public boolean isDefault() { public boolean isDefault() {

View File

@ -22,9 +22,11 @@ package org.elasticsearch.packaging.util;
import org.elasticsearch.packaging.util.Shell.Result; import org.elasticsearch.packaging.util.Shell.Result;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -88,25 +90,31 @@ public class Packages {
return result; return result;
} }
public static Installation install(Distribution distribution) { public static Installation install(Distribution distribution) throws IOException {
return install(distribution, getCurrentVersion()); return install(distribution, getCurrentVersion());
} }
public static Installation install(Distribution distribution, String version) { public static Installation install(Distribution distribution, String version) throws IOException {
final Result result = runInstallCommand(distribution, version); Shell sh = new Shell();
String systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
if (distribution.hasJdk == false) {
sh.getEnv().put("JAVA_HOME", systemJavaHome);
}
final Result result = runInstallCommand(distribution, version, sh);
if (result.exitCode != 0) { if (result.exitCode != 0) {
throw new RuntimeException("Installing distribution " + distribution + " version " + version + " failed: " + result); throw new RuntimeException("Installing distribution " + distribution + " version " + version + " failed: " + result);
} }
return Installation.ofPackage(distribution.packaging); Installation installation = Installation.ofPackage(distribution.packaging);
if (distribution.hasJdk == false) {
Files.write(installation.envFile, ("JAVA_HOME=" + systemJavaHome + "\n").getBytes(StandardCharsets.UTF_8),
StandardOpenOption.APPEND);
}
return installation;
} }
public static Result runInstallCommand(Distribution distribution) { public static Result runInstallCommand(Distribution distribution, String version, Shell sh) {
return runInstallCommand(distribution, getCurrentVersion());
}
public static Result runInstallCommand(Distribution distribution, String version) {
final Shell sh = new Shell();
final Path distributionFile = getDistributionFile(distribution, version); final Path distributionFile = getDistributionFile(distribution, version);
if (Platforms.isRPM()) { if (Platforms.isRPM()) {
@ -142,16 +150,15 @@ public class Packages {
}); });
} }
public static void verifyPackageInstallation(Installation installation, Distribution distribution) { public static void verifyPackageInstallation(Installation installation, Distribution distribution, Shell sh) {
verifyOssInstallation(installation, distribution); verifyOssInstallation(installation, distribution, sh);
if (distribution.flavor == Distribution.Flavor.DEFAULT) { if (distribution.flavor == Distribution.Flavor.DEFAULT) {
verifyDefaultInstallation(installation); verifyDefaultInstallation(installation);
} }
} }
private static void verifyOssInstallation(Installation es, Distribution distribution) { private static void verifyOssInstallation(Installation es, Distribution distribution, Shell sh) {
final Shell sh = new Shell();
sh.run("id elasticsearch"); sh.run("id elasticsearch");
sh.run("getent group elasticsearch"); sh.run("getent group elasticsearch");

View File

@ -31,37 +31,27 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
import static java.util.Collections.emptyMap;
/** /**
* Wrapper to run shell commands and collect their outputs in a less verbose way * Wrapper to run shell commands and collect their outputs in a less verbose way
*/ */
public class Shell { public class Shell {
final Map<String, String> env; final Map<String, String> env;
final Path workingDirectory; Path workingDirectory;
public Shell() { public Shell() {
this(emptyMap(), null); this.env = new HashMap<>();
} this.workingDirectory = null;
public Shell(Map<String, String> env) {
this(env, null);
}
public Shell(Path workingDirectory) {
this(emptyMap(), workingDirectory);
}
public Shell(Map<String, String> env, Path workingDirectory) {
this.env = new HashMap<>(env);
this.workingDirectory = workingDirectory;
} }
public Map<String, String> getEnv() { public Map<String, String> getEnv() {
return env; return env;
} }
public void setWorkingDirectory(Path workingDirectory) {
this.workingDirectory = workingDirectory;
}
/** /**
* Run the provided string as a shell script. On Linux the {@code bash -c [script]} syntax will be used, and on Windows * Run the provided string as a shell script. On Linux the {@code bash -c [script]} syntax will be used, and on Windows
* the {@code powershell.exe -Command [script]} syntax will be used. Throws an exception if the exit code of the script is nonzero * the {@code powershell.exe -Command [script]} syntax will be used. Throws an exception if the exit code of the script is nonzero

View File

@ -18,15 +18,25 @@ List projects = [
'distribution:archives:integ-test-zip', 'distribution:archives:integ-test-zip',
'distribution:archives:oss-windows-zip', 'distribution:archives:oss-windows-zip',
'distribution:archives:windows-zip', 'distribution:archives:windows-zip',
'distribution:archives:oss-no-jdk-windows-zip',
'distribution:archives:no-jdk-windows-zip',
'distribution:archives:oss-darwin-tar', 'distribution:archives:oss-darwin-tar',
'distribution:archives:darwin-tar', 'distribution:archives:darwin-tar',
'distribution:archives:oss-no-jdk-darwin-tar',
'distribution:archives:no-jdk-darwin-tar',
'distribution:archives:oss-linux-tar', 'distribution:archives:oss-linux-tar',
'distribution:archives:linux-tar', 'distribution:archives:linux-tar',
'distribution:archives:oss-no-jdk-linux-tar',
'distribution:archives:no-jdk-linux-tar',
'distribution:docker', 'distribution:docker',
'distribution:packages:oss-deb', 'distribution:packages:oss-deb',
'distribution:packages:deb', 'distribution:packages:deb',
'distribution:packages:oss-no-jdk-deb',
'distribution:packages:no-jdk-deb',
'distribution:packages:oss-rpm', 'distribution:packages:oss-rpm',
'distribution:packages:rpm', 'distribution:packages:rpm',
'distribution:packages:oss-no-jdk-rpm',
'distribution:packages:no-jdk-rpm',
'distribution:bwc:bugfix', 'distribution:bwc:bugfix',
'distribution:bwc:maintenance', 'distribution:bwc:maintenance',
'distribution:bwc:minor', 'distribution:bwc:minor',