aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2019-03-11 16:13:32 +0100
committerSonarTech <sonartech@sonarsource.com>2019-03-19 20:21:25 +0100
commit9fa0a0fb42129fd74b277c4e1078c171076f0c0d (patch)
treebcbab0e19735779b58b519ad86944724ed8b95fe /server/sonar-main
parent4112b9f541ac22cdc8153896ebf3213af39c1ef0 (diff)
downloadsonarqube-9fa0a0fb42129fd74b277c4e1078c171076f0c0d.tar.gz
sonarqube-9fa0a0fb42129fd74b277c4e1078c171076f0c0d.zip
SONAR-11792 define ES's JVM tmp directory to SQ's tmp directory
Diffstat (limited to 'server/sonar-main')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java4
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java7
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java2
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java8
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java12
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java11
6 files changed, 28 insertions, 16 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
index e41f0f66318..2afbc0310c9 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
@@ -112,7 +112,7 @@ public class CommandFactoryImpl implements CommandFactory {
return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory())
.setEsInstallation(esInstallation)
.setReadsArgumentsFromFile(false)
- .setJvmOptions(new EsJvmOptions()
+ .setJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())
.add("-Delasticsearch")
@@ -135,7 +135,7 @@ public class CommandFactoryImpl implements CommandFactory {
esInstallation
.setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory()))
- .setEsJvmOptions(new EsJvmOptions()
+ .setEsJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()))
.setEsYmlSettings(new EsYmlSettings(settingsMap))
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
index f71240d4fba..2c3b7bf40ad 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
@@ -34,11 +34,11 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
"# DO NOT EDIT THIS FILE\n" +
"\n";
- public EsJvmOptions() {
- super(mandatoryOptions());
+ public EsJvmOptions(File tmpDir) {
+ super(mandatoryOptions(tmpDir));
}
- private static Map<String, String> mandatoryOptions() {
+ private static Map<String, String> mandatoryOptions(File tmpDir) {
Map<String, String> res = new LinkedHashMap<>(16);
res.put("-XX:+UseConcMarkSweepGC", "");
res.put("-XX:CMSInitiatingOccupancyFraction=", "75");
@@ -46,6 +46,7 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
res.put("-XX:+AlwaysPreTouch", "");
res.put("-Xss", "1m");
res.put("-Djava.awt.headless=", "true");
+ res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
res.put("-Dfile.encoding=", "UTF-8");
res.put("-Djna.nosys=", "true");
res.put("-Djdk.io.permissionsUseCanonicalPath=", "true");
diff --git a/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java b/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
index 40bac89b82d..8b89cd98393 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
@@ -85,7 +85,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
if (command instanceof EsScriptCommand) {
process = launchExternal((EsScriptCommand) command);
} else if (command instanceof JavaCommand) {
- process = launchJava((JavaCommand) command);
+ process = launchJava((JavaCommand<?>) command);
} else {
throw new IllegalStateException("Unexpected type of command: " + command.getClass());
}
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
index a18409ab1cd..008556fc3dd 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
@@ -150,6 +150,9 @@ public class CommandFactoryImplTest {
.contains(entry("ES_JVM_OPTIONS", new File(esConfDir, "jvm.options").getAbsolutePath()))
.containsKey("JAVA_HOME");
assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
+
+ assertThat(esConfig.getEsJvmOptions().getAll())
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
}
@Test
@@ -186,6 +189,8 @@ public class CommandFactoryImplTest {
.containsKey("JAVA_HOME");
assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
+ assertThat(esConfig.getEsJvmOptions().getAll())
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
assertThat(esCommand.getJvmOptions().getAll())
.containsAll(esConfig.getEsJvmOptions().getAll())
.contains("-Delasticsearch")
@@ -210,7 +215,8 @@ public class CommandFactoryImplTest {
assertThat(esConfig.getPort()).isEqualTo(1234);
assertThat(esConfig.getEsJvmOptions().getAll())
// enforced values
- .contains("-XX:+UseConcMarkSweepGC", "-Dfile.encoding=UTF-8")
+ .contains("-XX:+UseConcMarkSweepGC", "-server", "-Dfile.encoding=UTF-8")
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath())
// user settings
.contains("-Xms10G", "-Xmx10G")
// default values disabled
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java
index 3d057470e80..1ec2e29ba11 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java
@@ -36,8 +36,9 @@ public class EsJvmOptionsTest {
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void constructor_sets_mandatory_JVM_options() {
- EsJvmOptions underTest = new EsJvmOptions();
+ public void constructor_sets_mandatory_JVM_options() throws IOException {
+ File tmpDir = temporaryFolder.newFolder();
+ EsJvmOptions underTest = new EsJvmOptions(tmpDir);
assertThat(underTest.getAll()).containsExactly(
"-XX:+UseConcMarkSweepGC",
@@ -46,6 +47,7 @@ public class EsJvmOptionsTest {
"-XX:+AlwaysPreTouch",
"-Xss1m",
"-Djava.awt.headless=true",
+ "-Djava.io.tmpdir="+ tmpDir.getAbsolutePath(),
"-Dfile.encoding=UTF-8",
"-Djna.nosys=true",
"-Djdk.io.permissionsUseCanonicalPath=true",
@@ -59,8 +61,9 @@ public class EsJvmOptionsTest {
@Test
public void writeToJvmOptionFile_writes_all_JVM_options_to_file_with_warning_header() throws IOException {
+ File tmpDir = temporaryFolder.newFolder("with space");
File file = temporaryFolder.newFile();
- EsJvmOptions underTest = new EsJvmOptions()
+ EsJvmOptions underTest = new EsJvmOptions(tmpDir)
.add("-foo")
.add("-bar");
@@ -78,6 +81,7 @@ public class EsJvmOptionsTest {
"-XX:+AlwaysPreTouch\n" +
"-Xss1m\n" +
"-Djava.awt.headless=true\n" +
+ "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
"-Dfile.encoding=UTF-8\n" +
"-Djna.nosys=true\n" +
"-Djdk.io.permissionsUseCanonicalPath=true\n" +
@@ -95,7 +99,7 @@ public class EsJvmOptionsTest {
@Test
public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException {
File notAFile = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions();
+ EsJvmOptions underTest = new EsJvmOptions(temporaryFolder.newFolder());
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cannot write Elasticsearch jvm options file");
diff --git a/server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java
index 87a83928fde..37d2d1df54f 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java
@@ -202,16 +202,17 @@ public class ProcessLauncherImplTest {
}
private EsInstallation createEsInstallation() throws IOException {
+ File tempFolder = this.temp.newFolder("temp");
return new EsInstallation(new Props(new Properties())
- .set("sonar.path.home", temp.newFolder("home").getAbsolutePath())
- .set("sonar.path.data", temp.newFolder("data").getAbsolutePath())
- .set("sonar.path.temp", temp.newFolder("temp").getAbsolutePath())
- .set("sonar.path.logs", temp.newFolder("logs").getAbsolutePath()))
+ .set("sonar.path.home", this.temp.newFolder("home").getAbsolutePath())
+ .set("sonar.path.data", this.temp.newFolder("data").getAbsolutePath())
+ .set("sonar.path.temp", tempFolder.getAbsolutePath())
+ .set("sonar.path.logs", this.temp.newFolder("logs").getAbsolutePath()))
.setClusterName("cluster")
.setPort(9001)
.setHost("localhost")
.setEsYmlSettings(new EsYmlSettings(new HashMap<>()))
- .setEsJvmOptions(new EsJvmOptions())
+ .setEsJvmOptions(new EsJvmOptions(tempFolder))
.setLog4j2Properties(new Properties());
}