Search in sources :

Example 6 with EsInstallation

use of org.sonar.application.es.EsInstallation in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method enabling_es_security_should_execute_keystore_cli_if_no_cert_password_provided.

@Test
public void enabling_es_security_should_execute_keystore_cli_if_no_cert_password_provided() throws Exception {
    File tempDir = temp.newFolder();
    File certificateFile = temp.newFile("certificate.pk12");
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    EsInstallation esInstallation = createEsInstallation(new Props(new Properties()).set("sonar.cluster.enabled", "true").set("sonar.cluster.search.password", "bootstrap-password").set("sonar.cluster.es.ssl.keystore", certificateFile.getAbsolutePath()).set("sonar.cluster.es.ssl.truststore", certificateFile.getAbsolutePath()));
    JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setJvmOptions(new JvmOptions<>().add("-Dfoo=bar").add("-Dfoo2=bar2"));
    command.setEsInstallation(esInstallation);
    ManagedProcess monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "certificate.pk12")).exists();
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) ManagedProcess(org.sonar.application.process.ManagedProcess) Test(org.junit.Test)

Example 7 with EsInstallation

use of org.sonar.application.es.EsInstallation in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method enabling_es_security_should_execute_keystore_cli_if_cert_password_provided.

@Test
public void enabling_es_security_should_execute_keystore_cli_if_cert_password_provided() throws Exception {
    File tempDir = temp.newFolder();
    File certificateFile = temp.newFile("certificate.pk12");
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    EsInstallation esInstallation = createEsInstallation(new Props(new Properties()).set("sonar.cluster.enabled", "true").set("sonar.cluster.search.password", "bootstrap-password").set("sonar.cluster.es.ssl.keystore", certificateFile.getAbsolutePath()).set("sonar.cluster.es.ssl.keystorePassword", "keystore-password").set("sonar.cluster.es.ssl.truststore", certificateFile.getAbsolutePath()).set("sonar.cluster.es.ssl.truststorePassword", "truststore-password"));
    JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setJvmOptions(new JvmOptions<>().add("-Dfoo=bar").add("-Dfoo2=bar2"));
    command.setEsInstallation(esInstallation);
    ManagedProcess monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "certificate.pk12")).exists();
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) ManagedProcess(org.sonar.application.process.ManagedProcess) Test(org.junit.Test)

Example 8 with EsInstallation

use of org.sonar.application.es.EsInstallation in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method enabling_es_security_should_execute_keystore_cli_if_truststore_and_keystore_provided.

@Test
public void enabling_es_security_should_execute_keystore_cli_if_truststore_and_keystore_provided() throws Exception {
    File tempDir = temp.newFolder();
    File truststoreFile = temp.newFile("truststore.pk12");
    File keystoreFile = temp.newFile("keystore.pk12");
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    EsInstallation esInstallation = createEsInstallation(new Props(new Properties()).set("sonar.cluster.enabled", "true").set("sonar.cluster.search.password", "bootstrap-password").set("sonar.cluster.es.ssl.keystore", keystoreFile.getAbsolutePath()).set("sonar.cluster.es.ssl.keystorePassword", "keystore-password").set("sonar.cluster.es.ssl.truststore", truststoreFile.getAbsolutePath()).set("sonar.cluster.es.ssl.truststorePassword", "truststore-password"));
    JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setJvmOptions(new JvmOptions<>().add("-Dfoo=bar").add("-Dfoo2=bar2"));
    command.setEsInstallation(esInstallation);
    ManagedProcess monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "truststore.pk12")).exists();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "keystore.pk12")).exists();
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) ManagedProcess(org.sonar.application.process.ManagedProcess) Test(org.junit.Test)

Example 9 with EsInstallation

use of org.sonar.application.es.EsInstallation in project sonarqube by SonarSource.

the class CommandFactoryImplTest method createEsCommand_for_unix_returns_command_for_default_settings.

@Test
public void createEsCommand_for_unix_returns_command_for_default_settings() throws Exception {
    when(system2.isOsWindows()).thenReturn(false);
    prepareEsFileSystem();
    Properties props = new Properties();
    props.setProperty("sonar.search.host", "localhost");
    AbstractCommand command = newFactory(props, system2).createEsCommand();
    assertThat(command).isInstanceOf(EsScriptCommand.class);
    EsScriptCommand esCommand = (EsScriptCommand) command;
    EsInstallation esConfig = esCommand.getEsInstallation();
    assertThat(esConfig.getHost()).isNotEmpty();
    assertThat(esConfig.getHttpPort()).isEqualTo(9001);
    assertThat(esConfig.getEsJvmOptions().getAll()).contains("-XX:+UseG1GC").contains("-Dfile.encoding=UTF-8").contains("-Xms512m", "-Xmx512m", "-XX:+HeapDumpOnOutOfMemoryError");
    assertThat(esConfig.getEsYmlSettings()).isNotNull();
    assertThat(esConfig.getLog4j2Properties()).contains(entry("appender.file_es.fileName", new File(logsDir, "es.log").getAbsolutePath()));
    File esConfDir = new File(tempDir, "conf/es");
    assertThat(esCommand.getEnvVariables()).contains(entry("ES_PATH_CONF", esConfDir.getAbsolutePath())).contains(entry("ES_JVM_OPTIONS", new File(esConfDir, "jvm.options").getAbsolutePath())).containsKey("ES_JAVA_HOME");
    assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
    assertThat(esConfig.getEsJvmOptions().getAll()).contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
}
Also used : EsInstallation(org.sonar.application.es.EsInstallation) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) File(java.io.File) Test(org.junit.Test)

Example 10 with EsInstallation

use of org.sonar.application.es.EsInstallation in project sonarqube by SonarSource.

the class CommandFactoryImplTest method createEsCommand_returns_command_for_overridden_settings.

@Test
public void createEsCommand_returns_command_for_overridden_settings() throws Exception {
    prepareEsFileSystem();
    Properties props = new Properties();
    props.setProperty("sonar.search.host", "localhost");
    props.setProperty("sonar.cluster.name", "foo");
    props.setProperty("sonar.search.port", "1234");
    props.setProperty("sonar.search.javaOpts", "-Xms10G -Xmx10G");
    AbstractCommand esCommand = newFactory(props).createEsCommand();
    EsInstallation esConfig = esCommand.getEsInstallation();
    assertThat(esConfig.getHttpPort()).isEqualTo(1234);
    assertThat(esConfig.getEsJvmOptions().getAll()).contains("-XX:+UseG1GC").contains("-Dfile.encoding=UTF-8").contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath()).contains("-Xms10G", "-Xmx10G").doesNotContain("-XX:+HeapDumpOnOutOfMemoryError");
}
Also used : EsInstallation(org.sonar.application.es.EsInstallation) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) Test(org.junit.Test)

Aggregations

EsInstallation (org.sonar.application.es.EsInstallation)10 Properties (java.util.Properties)7 Test (org.junit.Test)6 File (java.io.File)5 EsJvmOptions (org.sonar.application.command.EsJvmOptions)4 JavaCommand (org.sonar.application.command.JavaCommand)4 ManagedProcess (org.sonar.application.process.ManagedProcess)4 Props (org.sonar.process.Props)4 JvmOptions (org.sonar.application.command.JvmOptions)3 ProcessProperties (org.sonar.process.ProcessProperties)3 EsScriptCommand (org.sonar.application.command.EsScriptCommand)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EsConnectorImpl (org.sonar.application.es.EsConnectorImpl)1 EsLogging (org.sonar.application.es.EsLogging)1 EsSettings (org.sonar.application.es.EsSettings)1 EsYmlSettings (org.sonar.application.es.EsYmlSettings)1 EsManagedProcess (org.sonar.application.process.EsManagedProcess)1 ProcessCommandsManagedProcess (org.sonar.application.process.ProcessCommandsManagedProcess)1 ProcessId (org.sonar.process.ProcessId)1