]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11792 define ES's JVM tmp directory to SQ's tmp directory
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 11 Mar 2019 15:13:32 +0000 (16:13 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:25 +0000 (20:21 +0100)
server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java
server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java

index e41f0f663182b40d259eb3fce8fc38db84f1f6be..2afbc0310c9f4562063489054ca16e2bf2947066 100644 (file)
@@ -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))
index f71240d4fba22f5d99f540cf1890fc7e41761603..2c3b7bf40ad0a76386467e0510eabb7685c4d88e 100644 (file)
@@ -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");
index 40bac89b82dd4a8d121cd581b7becb13e4b2c956..8b89cd9839306a9f2680139fe793b8bf5b8be201 100644 (file)
@@ -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());
     }
index a18409ab1cda67f70ce2506c0e12b101c3779855..008556fc3dd8981e58bfddc37025981fdb7812ea 100644 (file)
@@ -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
index 3d057470e804e59e98c60c08bd2a500b491d43e4..1ec2e29ba11d220fd42d328c3f467628c4731b41 100644 (file)
@@ -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");
index 87a83928fde4ebf3fd2dd763f4eb3e02d978fcaa..37d2d1df54f1feb64bf839e9eb3533495debeef0 100644 (file)
@@ -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());
   }