]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9590 do not write jvm.options file twice
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 17 Aug 2017 16:17:30 +0000 (18:17 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 5 Sep 2017 12:24:12 +0000 (14:24 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java
server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsCommand.java
server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
server/sonar-process-monitor/src/main/resources/org/sonar/application/process/jvm.options [deleted file]

index 35d018126c09dc72e39408d6e457ecd13fe832b3..de2174d3e2d186429bb85b3fc24e4c05e09f8a51 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.application.process;
 
 import java.io.File;
-import java.nio.file.Path;
 import java.util.Map;
 import java.util.Optional;
 import org.sonar.application.config.AppSettings;
@@ -64,7 +63,6 @@ public class CommandFactoryImpl implements CommandFactory {
 
     File logDir = new File(settingsMap.get("path.logs"));
     File confDir = new File(settingsMap.get("path.conf"));
-    Path jvmOptionsFile = confDir.toPath().resolve("jvm.options");
     EsCommand res = new EsCommand(ProcessId.ELASTICSEARCH)
       .setWorkDir(executable.getParentFile().getParentFile())
       .setExecutable(executable)
@@ -76,8 +74,6 @@ public class CommandFactoryImpl implements CommandFactory {
       .setPort(Integer.valueOf(settingsMap.get("transport.tcp.port")))
       .addJvmOption(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS))
       .addJvmOption(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS))
-      .setJvmOptionsFile(jvmOptionsFile)
-      .setEnvVariable("ES_JVM_OPTIONS", jvmOptionsFile.toString())
       .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home"));
 
     settingsMap.forEach((key, value) -> res.addEsOption("-E" + key + "=" + value));
index 3e787eb6736edf96452a71150bffdb9b696e1af4..43974a5ef0887015278f79b0a8a1678c1cc800bf 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.application.process;
 
 import java.io.File;
-import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -35,7 +34,6 @@ public class EsCommand extends AbstractCommand<EsCommand> {
   private Properties log4j2Properties;
   private List<String> esOptions = new ArrayList<>();
   private List<String> jvmOptions = new ArrayList<>();
-  private Path jvmOptionsFile;
 
   public EsCommand(ProcessId id) {
     super(id);
@@ -117,12 +115,4 @@ public class EsCommand extends AbstractCommand<EsCommand> {
     return this;
   }
 
-  public Path getJvmOptionsFile() {
-    return jvmOptionsFile;
-  }
-
-  public EsCommand setJvmOptionsFile(Path jvmOptionsFile) {
-    this.jvmOptionsFile = jvmOptionsFile;
-    return this;
-  }
 }
index b2d13441f18aca3c3dd8c0a858383a8820271212..19b8eb6504f28b4cb2113d2432afd19d602194a1 100644 (file)
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
-import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -33,7 +32,6 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -107,7 +105,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
 
     try {
       IOUtils.copy(getClass().getResourceAsStream("elasticsearch.yml"), new FileOutputStream(new File(confDir, "elasticsearch.yml")));
-      IOUtils.copy(getClass().getResourceAsStream("jvm.options"), new FileOutputStream(new File(confDir, "jvm.options")));
+      writeJvmOptions(esCommand, new File(confDir, "jvm.options"));
       esCommand.getLog4j2Properties().store(new FileOutputStream(new File(confDir, "log4j2.properties")), "log42 properties file for ES bundled in SonarQube");
     } catch (IOException e) {
       throw new IllegalStateException("Failed to write ES configuration files", e);
@@ -141,13 +139,10 @@ public class ProcessLauncherImpl implements ProcessLauncher {
     commands.add(esCommand.getExecutable().getAbsolutePath());
     commands.addAll(esCommand.getEsOptions());
 
-    writeJvmOptions(esCommand);
-
     return create(esCommand, commands);
   }
 
-  private static void writeJvmOptions(EsCommand esCommand) {
-    Path jvmOptionsFile = esCommand.getJvmOptionsFile();
+  private static void writeJvmOptions(EsCommand esCommand, File jvmOptionsFile) {
     String jvmOptions = esCommand.getJvmOptions()
       .stream()
 
@@ -157,7 +152,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
       .collect(Collectors.joining("\n"));
     String jvmOptionsContent = ELASTICSEARCH_JVM_OPTIONS_HEADER + jvmOptions;
     try {
-      Files.write(jvmOptionsFile, jvmOptionsContent.getBytes(Charset.forName("UTF-8")));
+      Files.write(jvmOptionsFile.toPath(), jvmOptionsContent.getBytes(Charset.forName("UTF-8")));
     } catch (IOException e) {
       throw new IllegalStateException("Cannot write Elasticsearch jvm options file", e);
     }
diff --git a/server/sonar-process-monitor/src/main/resources/org/sonar/application/process/jvm.options b/server/sonar-process-monitor/src/main/resources/org/sonar/application/process/jvm.options
deleted file mode 100644 (file)
index be2b6ab..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-## JVM configuration
-
-################################################################
-## IMPORTANT: JVM heap size
-################################################################
-##
-## You should always set the min and max JVM heap
-## size to the same value. For example, to set
-## the heap to 4 GB, set:
-##
-## -Xms4g
-## -Xmx4g
-##
-## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
-## for more information
-##
-################################################################
-
-# Xms represents the initial size of total heap space
-# Xmx represents the maximum size of total heap space
-
--Xms2g
--Xmx2g
-
-################################################################
-## Expert settings
-################################################################
-##
-## All settings below this section are considered
-## expert settings. Don't tamper with them unless
-## you understand what you are doing
-##
-################################################################
-
-## GC configuration
--XX:+UseConcMarkSweepGC
--XX:CMSInitiatingOccupancyFraction=75
--XX:+UseCMSInitiatingOccupancyOnly
-
-## optimizations
-
-# disable calls to System#gc
--XX:+DisableExplicitGC
-
-# pre-touch memory pages used by the JVM during initialization
--XX:+AlwaysPreTouch
-
-## basic
-
-# force the server VM
--server
-
-# set to headless, just in case
--Djava.awt.headless=true
-
-# ensure UTF-8 encoding by default (e.g. filenames)
--Dfile.encoding=UTF-8
-
-# use our provided JNA always versus the system one
--Djna.nosys=true
-
-# use old-style file permissions on JDK9
--Djdk.io.permissionsUseCanonicalPath=true
-
-# flags to keep Netty from being unsafe
--Dio.netty.noUnsafe=true
--Dio.netty.noKeySetOptimization=true
-
-# log4j 2
--Dlog4j.shutdownHookEnabled=false
--Dlog4j2.disable.jmx=true
--Dlog4j.skipJansi=true
-
-## heap dumps
-
-# generate a heap dump when an allocation from the Java heap fails
-# heap dumps are created in the working directory of the JVM
--XX:+HeapDumpOnOutOfMemoryError
-
-# specify an alternative path for heap dumps
-# ensure the directory exists and has sufficient space
-#-XX:HeapDumpPath=${heap.dump.path}
-
-## GC logging
-
-#-XX:+PrintGCDetails
-#-XX:+PrintGCTimeStamps
-#-XX:+PrintGCDateStamps
-#-XX:+PrintClassHistogram
-#-XX:+PrintTenuringDistribution
-#-XX:+PrintGCApplicationStoppedTime
-
-# log GC status to a file with time stamps
-# ensure the directory exists
-#-Xloggc:${loggc}
-
-# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
-# If documents were already indexed with unquoted fields in a previous version
-# of Elasticsearch, some operations may throw errors.
-#
-# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided
-# only for migration purposes.
-#-Delasticsearch.json.allow_unquoted_field_names=true