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();
}
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();
}
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();
}
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());
}
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");
}
Aggregations