return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory())
.setEsInstallation(esInstallation)
.setReadsArgumentsFromFile(false)
- .setJvmOptions(new EsJvmOptions(tempDir)
- .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
- .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())
+ .setJvmOptions(esInstallation.getEsJvmOptions()
.add("-Delasticsearch")
.add("-Des.path.home=" + esInstallation.getHomeDirectory().getAbsolutePath())
.add("-Des.path.conf=" + esInstallation.getConfDirectory().getAbsolutePath()))
esInstallation
.setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory()))
- .setEsJvmOptions(new EsJvmOptions(tempDir)
+ .setEsJvmOptions(new EsJvmOptions(props, tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()))
.setEsYmlSettings(new EsYmlSettings(settingsMap))
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
+import org.sonar.process.Props;
import org.sonar.process.System2;
public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
"# DO NOT EDIT THIS FILE\n" +
"\n";
- public EsJvmOptions(File tmpDir) {
- this(System2.INSTANCE, tmpDir);
+ public EsJvmOptions(Props props, File tmpDir) {
+ this(System2.INSTANCE, props, tmpDir);
}
- EsJvmOptions(System2 system2, File tmpDir) {
- super(mandatoryOptions(system2, tmpDir));
+ EsJvmOptions(System2 system2, Props props, File tmpDir) {
+ super(mandatoryOptions(system2, props, tmpDir));
}
// this basically writes down the content of jvm.options file distributed in vanilla Elasticsearch package
// with some changes to fit running bundled in SQ
- private static Map<String, String> mandatoryOptions(System2 system2, File tmpDir) {
+ private static Map<String, String> mandatoryOptions(System2 system2, Props props, File tmpDir) {
Map<String, String> res = new LinkedHashMap<>(16);
// GC configuration
res.put("-XX:+UseConcMarkSweepGC", "");
res.put("-XX:UseAVX=", "2");
}
+ if (!props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
+ res.put("-Des.enforce.bootstrap.checks=", "true");
+ }
+
return res;
}
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.io.File;
import java.io.IOException;
+import java.util.Properties;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
+import org.sonar.process.Props;
import org.sonar.process.System2;
import org.sonar.test.ExceptionCauseMatcher;
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ private Properties properties = new Properties();
+
@Test
@UseDataProvider("java8or11")
public void constructor_sets_mandatory_JVM_options_on_Java_8_and_11(System2 system2) throws IOException {
File tmpDir = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions(system2, tmpDir);
+ EsJvmOptions underTest = new EsJvmOptions(system2, new Props(properties), tmpDir);
assertThat(underTest.getAll())
.containsExactly(
"-Dlog4j.shutdownHookEnabled=false",
"-Dlog4j2.disable.jmx=true",
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
- "-XX:ErrorFile=../logs/es_hs_err_pid%p.log");
+ "-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
+ "-Des.enforce.bootstrap.checks=true");
+ }
+
+ @Test
+ @UseDataProvider("java8or11")
+ public void constructor_does_not_force_boostrap_checks_if_sonarqube_property_is_true(System2 system2) throws IOException {
+ properties.put("sonar.es.bootstrap.checks.disable", "true");
+ File tmpDir = temporaryFolder.newFolder();
+ EsJvmOptions underTest = new EsJvmOptions(system2, new Props(properties), tmpDir);
+
+ assertThat(underTest.getAll())
+ .doesNotContain("-Des.enforce.bootstrap.checks=true");
}
@DataProvider
when(java9.isJava10()).thenReturn(false);
File tmpDir = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions(java9, tmpDir);
+ EsJvmOptions underTest = new EsJvmOptions(java9, new Props(properties), tmpDir);
assertThat(underTest.getAll())
.containsExactly(
"-Dlog4j2.disable.jmx=true",
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
"-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
- "-Djava.locale.providers=COMPAT");
+ "-Djava.locale.providers=COMPAT",
+ "-Des.enforce.bootstrap.checks=true");
}
@Test
when(java10.isJava10()).thenReturn(true);
File tmpDir = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions(java10, tmpDir);
+ EsJvmOptions underTest = new EsJvmOptions(java10, new Props(properties), tmpDir);
assertThat(underTest.getAll())
.containsExactly(
"-Dlog4j2.disable.jmx=true",
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
"-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
- "-XX:UseAVX=2");
+ "-XX:UseAVX=2",
+ "-Des.enforce.bootstrap.checks=true");
}
/**
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(tmpDir)
+ EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir)
.add("-foo")
.add("-bar");
"-Dlog4j2.disable.jmx=true\n" +
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
"-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" +
+ "-Des.enforce.bootstrap.checks=true\n" +
"-foo\n" +
"-bar");
@Test
public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException {
File notAFile = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions(temporaryFolder.newFolder());
+ EsJvmOptions underTest = new EsJvmOptions(new Props(properties), temporaryFolder.newFolder());
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cannot write Elasticsearch jvm options file");