From 92a27e7b4d09b170825ada0cb2c9e971a44c2a8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 17 Aug 2017 18:17:30 +0200 Subject: [PATCH] SONAR-9590 do not write jvm.options file twice --- .../process/CommandFactoryImpl.java | 4 - .../sonar/application/process/EsCommand.java | 10 -- .../process/ProcessLauncherImpl.java | 11 +- .../org/sonar/application/process/jvm.options | 103 ------------------ 4 files changed, 3 insertions(+), 125 deletions(-) delete mode 100644 server/sonar-process-monitor/src/main/resources/org/sonar/application/process/jvm.options diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java index 35d018126c0..de2174d3e2d 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java @@ -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)); diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsCommand.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsCommand.java index 3e787eb6736..43974a5ef08 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsCommand.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsCommand.java @@ -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 { private Properties log4j2Properties; private List esOptions = new ArrayList<>(); private List jvmOptions = new ArrayList<>(); - private Path jvmOptionsFile; public EsCommand(ProcessId id) { super(id); @@ -117,12 +115,4 @@ public class EsCommand extends AbstractCommand { return this; } - public Path getJvmOptionsFile() { - return jvmOptionsFile; - } - - public EsCommand setJvmOptionsFile(Path jvmOptionsFile) { - this.jvmOptionsFile = jvmOptionsFile; - return this; - } } diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java index b2d13441f18..19b8eb6504f 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java @@ -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 index be2b6ab73a2..00000000000 --- a/server/sonar-process-monitor/src/main/resources/org/sonar/application/process/jvm.options +++ /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 -- 2.39.5