]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11264 enforce ES boostrap checks on all editions
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 20 May 2019 14:39:42 +0000 (16:39 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 23 May 2019 18:21:09 +0000 (20:21 +0200)
server/sonar-db-core/src/test/java/org/sonar/db/CreateDb.java
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/test/java/org/sonar/application/command/EsJvmOptionsTest.java
server/sonar-main/src/test/java/org/sonar/application/process/ProcessLauncherImplTest.java

index 0106b571634ff856ab83661e8a7d6a4a86579b86..b81ea66aa01b67ff0a1c1560b37f480022fc7698 100644 (file)
@@ -26,6 +26,7 @@ import com.sonar.orchestrator.locator.Location;
 import org.apache.commons.lang.StringUtils;
 
 import java.io.File;
+import org.sonar.api.utils.log.Loggers;
 
 import static com.sonar.orchestrator.container.Edition.COMMUNITY;
 
@@ -42,6 +43,7 @@ public class CreateDb {
       builder.setSonarVersion(version);
     }
     builder.setOrchestratorProperty("orchestrator.workspaceDir", "build/it");
+    builder.setServerProperty("sonar.es.bootstrap.checks.disable", areEsBootStrapChecksDisabled() ? "true" : "false");
 
     Orchestrator orchestrator = builder.build();
     try {
@@ -50,4 +52,12 @@ public class CreateDb {
       orchestrator.stop();
     }
   }
+
+  private static boolean areEsBootStrapChecksDisabled() {
+    boolean flag = "true".equalsIgnoreCase(System.getenv("CIRRUS_CI"));
+    if (flag) {
+      Loggers.get(CreateDb.class).info("Running on Cirrus: ES Bootstrap checks are disabled");
+    }
+    return flag;
+  }
 }
index 738cabf841d044d5a693e626423da2ade61590b5..7a17300a1ed497a9d22d60102599d9d71dfc16d8 100644 (file)
@@ -114,9 +114,7 @@ public class CommandFactoryImpl implements CommandFactory {
     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()))
@@ -137,7 +135,7 @@ public class CommandFactoryImpl implements CommandFactory {
 
     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))
index 0b24606e27aee5411d21ce2533547d253cd7a980..75dc84ef5b3f7e460f5babe776d88fb4cd13bcfa 100644 (file)
@@ -26,6 +26,7 @@ import java.nio.file.Files;
 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> {
@@ -35,17 +36,17 @@ 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", "");
@@ -125,6 +126,10 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
       res.put("-XX:UseAVX=", "2");
     }
 
+    if (!props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
+      res.put("-Des.enforce.bootstrap.checks=", "true");
+    }
+
     return res;
   }
 
index a90973c8d34c553b33fa4c6d32e6f4f168731b9c..5c0d30e29876df1b7b6b7380924740f910f64e77 100644 (file)
@@ -24,11 +24,13 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 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;
 
@@ -43,11 +45,13 @@ public class EsJvmOptionsTest {
   @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(
@@ -68,7 +72,19 @@ public class EsJvmOptionsTest {
         "-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
@@ -92,7 +108,7 @@ public class EsJvmOptionsTest {
     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(
@@ -114,7 +130,8 @@ public class EsJvmOptionsTest {
         "-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
@@ -124,7 +141,7 @@ public class EsJvmOptionsTest {
     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(
@@ -146,7 +163,8 @@ public class EsJvmOptionsTest {
         "-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");
   }
 
   /**
@@ -156,7 +174,7 @@ public class EsJvmOptionsTest {
   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");
 
@@ -186,6 +204,7 @@ public class EsJvmOptionsTest {
         "-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");
 
@@ -194,7 +213,7 @@ public class EsJvmOptionsTest {
   @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");
index 37d2d1df54f1feb64bf839e9eb3533495debeef0..dea816602258d973f348e7f1a1e3e48b849c154a 100644 (file)
@@ -212,7 +212,7 @@ public class ProcessLauncherImplTest {
       .setPort(9001)
       .setHost("localhost")
       .setEsYmlSettings(new EsYmlSettings(new HashMap<>()))
-      .setEsJvmOptions(new EsJvmOptions(tempFolder))
+      .setEsJvmOptions(new EsJvmOptions(new Props(new Properties()), tempFolder))
       .setLog4j2Properties(new Properties());
   }