use of org.sonar.application.command.JvmOptions 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.command.JvmOptions 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.command.JvmOptions in project sonarqube by SonarSource.
the class ProcessLauncherImplTest method launch_forks_a_new_process.
@Test
public void launch_forks_a_new_process() throws Exception {
File tempDir = temp.newFolder();
TestProcessBuilder processBuilder = new TestProcessBuilder();
ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
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(createEsInstallation());
ManagedProcess monitor = underTest.launch(command);
assertThat(monitor).isNotNull();
assertThat(processBuilder.started).isTrue();
assertThat(processBuilder.commands.get(0)).endsWith("java");
assertThat(processBuilder.commands).containsSubsequence("-Dfoo=bar", "-Dfoo2=bar2", "-cp", "lib/*.class" + System.getProperty("path.separator") + "lib/*.jar", "org.sonarqube.Main");
assertThat(processBuilder.dir).isEqualTo(command.getWorkDir());
assertThat(processBuilder.redirectErrorStream).isTrue();
assertThat(processBuilder.environment).contains(entry("VAR1", "valueOfVar1")).containsAllEntriesOf(command.getEnvVariables());
}
use of org.sonar.application.command.JvmOptions in project sonarqube by SonarSource.
the class ProcessLauncherImplTest method properties_are_passed_to_command_via_a_temporary_properties_file.
@Test
public void properties_are_passed_to_command_via_a_temporary_properties_file() throws Exception {
File tempDir = temp.newFolder();
TestProcessBuilder processBuilder = new TestProcessBuilder();
ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
long gracefulStopTimeoutMs = 1 + new Random().nextInt(10_000);
JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.WEB_SERVER, temp.newFolder()).setReadsArgumentsFromFile(true).setArgument("foo", "bar").setArgument("baz", "woo").setJvmOptions(new JvmOptions<>()).setGracefulStopTimeoutMs(gracefulStopTimeoutMs);
underTest.launch(command);
String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1);
File file = new File(propsFilePath);
assertThat(file).exists().isFile();
try (FileReader reader = new FileReader(file)) {
Properties props = new Properties();
props.load(reader);
assertThat(props).containsOnly(entry("foo", "bar"), entry("baz", "woo"), entry("process.gracefulStopTimeout", gracefulStopTimeoutMs + ""), entry("process.key", ProcessId.WEB_SERVER.getKey()), entry("process.index", String.valueOf(ProcessId.WEB_SERVER.getIpcIndex())), entry("process.sharedDir", tempDir.getAbsolutePath()));
}
}
use of org.sonar.application.command.JvmOptions 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();
}
Aggregations