aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2023-01-04 11:13:34 +0100
committersonartech <sonartech@sonarsource.com>2023-01-05 20:02:56 +0000
commit0611f1bd4d4e7132434d144a94996fe47a32e062 (patch)
tree25c66272a4a5498ad08c89a5e222653caa615637 /server/sonar-main
parentc0511e62e7e50def346785d1b6de6cd74059cbb4 (diff)
downloadsonarqube-0611f1bd4d4e7132434d144a94996fe47a32e062.tar.gz
sonarqube-0611f1bd4d4e7132434d144a94996fe47a32e062.zip
SONAR-17781 Allow overwriting path for 'es_hs_err_pid%p.log'
Diffstat (limited to 'server/sonar-main')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java8
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java31
2 files changed, 24 insertions, 15 deletions
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 19ab60e9164..89d289724a0 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
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
@@ -43,7 +44,7 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
// with some changes to fit running bundled in SQ
private static Map<String, String> mandatoryOptions(File tmpDir, Props props) {
Map<String, String> res = new LinkedHashMap<>(30);
- fromJvmDotOptionsFile(tmpDir, res);
+ fromJvmDotOptionsFile(tmpDir, res, props);
fromSystemJvmOptionsClass(tmpDir, res);
boolean defaultDisableBootstrapChecks = props.value("sonar.jdbc.url", "").contains("jdbc:h2");
@@ -54,7 +55,7 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
return res;
}
- private static void fromJvmDotOptionsFile(File tmpDir, Map<String, String> res) {
+ private static void fromJvmDotOptionsFile(File tmpDir, Map<String, String> res, Props props) {
// GC configuration
res.put("-XX:+UseG1GC", "");
@@ -70,7 +71,8 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
// has sufficient space
// res.put("-XX:HeapDumpPath", "data");
// specify an alternative path for JVM fatal error logs (ES 6.6.1 default is "logs/hs_err_pid%p.log")
- res.put("-XX:ErrorFile=", "../logs/es_hs_err_pid%p.log");
+ var path = Paths.get(props.value("sonar.path.logs", "logs"), "es_hs_err_pid%p.log");
+ res.put("-XX:ErrorFile=", path.toAbsolutePath().toString());
}
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 1c2b634cb0a..2de7f134905 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
@@ -22,7 +22,9 @@ package org.sonar.application.command;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Paths;
import java.util.Properties;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -36,9 +38,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
@RunWith(DataProviderRunner.class)
public class EsJvmOptionsTest {
@Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
- private Properties properties = new Properties();
+ private final Properties properties = new Properties();
+
+ @Before
+ public void before() {
+ properties.put("sonar.path.logs", "path_to_logs");
+ }
@Test
public void constructor_sets_mandatory_JVM_options() throws IOException {
@@ -49,7 +56,7 @@ public class EsJvmOptionsTest {
.containsExactlyInAnyOrder(
"-XX:+UseG1GC",
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
- "-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
+ "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath(),
"-Des.networkaddress.cache.ttl=60",
"-Des.networkaddress.cache.negative.ttl=10",
"-XX:+AlwaysPreTouch",
@@ -121,8 +128,8 @@ public class EsJvmOptionsTest {
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .doesNotContain("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .doesNotContain("-Des.enforce.bootstrap.checks=true");
}
@Test
@@ -134,8 +141,8 @@ public class EsJvmOptionsTest {
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .contains("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .contains("-Des.enforce.bootstrap.checks=true");
}
@Test
@@ -147,8 +154,8 @@ public class EsJvmOptionsTest {
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .doesNotContain("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .doesNotContain("-Des.enforce.bootstrap.checks=true");
}
@Test
@@ -160,8 +167,8 @@ public class EsJvmOptionsTest {
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .contains("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .contains("-Des.enforce.bootstrap.checks=true");
}
/**
@@ -185,7 +192,7 @@ public class EsJvmOptionsTest {
"\n" +
"-XX:+UseG1GC\n" +
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
- "-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" +
+ "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath() + "\n" +
"-Des.networkaddress.cache.ttl=60\n" +
"-Des.networkaddress.cache.negative.ttl=10\n" +
"-XX:+AlwaysPreTouch\n" +