Search in sources :

Example 1 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class SchedulerImplTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = temporaryFolder.newFolder();
    esScriptCommand = new EsScriptCommand(ELASTICSEARCH, tempDir);
    webLeaderCommand = new JavaCommand(WEB_SERVER, tempDir);
    webFollowerCommand = new JavaCommand(WEB_SERVER, tempDir);
    ceCommand = new JavaCommand(COMPUTE_ENGINE, tempDir);
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    initialLevel = logger.getLevel();
    logger.setLevel(Level.TRACE);
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsScriptCommand(org.sonar.application.command.EsScriptCommand) Logger(ch.qos.logback.classic.Logger) File(java.io.File) Before(org.junit.Before)

Example 2 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method throw_ISE_if_command_fails.

@Test
public void throw_ISE_if_command_fails() throws IOException {
    File tempDir = temp.newFolder();
    ProcessLauncherImpl.ProcessBuilder processBuilder = mock(ProcessLauncherImpl.ProcessBuilder.class, RETURNS_MOCKS);
    when(processBuilder.start()).thenThrow(new IOException("error"));
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand<?> javaCommand = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    assertThatThrownBy(() -> underTest.launch(javaCommand)).isInstanceOf(IllegalStateException.class).hasMessage("Fail to launch process [es]");
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 3 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class ProcessLauncherImpl method launch.

public ManagedProcess launch(AbstractCommand command) {
    EsInstallation esInstallation = command.getEsInstallation();
    if (esInstallation != null) {
        cleanupOutdatedEsData(esInstallation);
        writeConfFiles(esInstallation);
    }
    Process process;
    if (command instanceof EsScriptCommand) {
        process = launchExternal((EsScriptCommand) command);
    } else if (command instanceof JavaCommand) {
        process = launchJava((JavaCommand<?>) command);
    } else {
        throw new IllegalStateException("Unexpected type of command: " + command.getClass());
    }
    ProcessId processId = command.getProcessId();
    try {
        if (processId == ProcessId.ELASTICSEARCH) {
            checkArgument(esInstallation != null, "Incorrect configuration EsInstallation is null");
            EsConnectorImpl esConnector = new EsConnectorImpl(singleton(HostAndPort.fromParts(esInstallation.getHost(), esInstallation.getHttpPort())), esInstallation.getBootstrapPassword());
            return new EsManagedProcess(process, processId, esConnector);
        } else {
            ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex());
            return new ProcessCommandsManagedProcess(process, processId, commands);
        }
    } catch (Exception e) {
        // just in case
        if (process != null) {
            process.destroyForcibly();
        }
        throw new IllegalStateException(format("Fail to launch monitor of process [%s]", processId.getKey()), e);
    }
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsScriptCommand(org.sonar.application.command.EsScriptCommand) ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) EsManagedProcess(org.sonar.application.process.EsManagedProcess) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) ManagedProcess(org.sonar.application.process.ManagedProcess) ProcessId(org.sonar.process.ProcessId) EsConnectorImpl(org.sonar.application.es.EsConnectorImpl) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) EsManagedProcess(org.sonar.application.process.EsManagedProcess) IOException(java.io.IOException)

Example 4 with JavaCommand

use of org.sonar.application.command.JavaCommand 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 5 with JavaCommand

use of org.sonar.application.command.JavaCommand 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)

Aggregations

JavaCommand (org.sonar.application.command.JavaCommand)8 File (java.io.File)7 Test (org.junit.Test)6 EsJvmOptions (org.sonar.application.command.EsJvmOptions)5 JvmOptions (org.sonar.application.command.JvmOptions)5 ManagedProcess (org.sonar.application.process.ManagedProcess)5 EsInstallation (org.sonar.application.es.EsInstallation)4 Properties (java.util.Properties)3 Props (org.sonar.process.Props)3 IOException (java.io.IOException)2 EsScriptCommand (org.sonar.application.command.EsScriptCommand)2 Logger (ch.qos.logback.classic.Logger)1 Before (org.junit.Before)1 EsConnectorImpl (org.sonar.application.es.EsConnectorImpl)1 EsManagedProcess (org.sonar.application.process.EsManagedProcess)1 ProcessCommandsManagedProcess (org.sonar.application.process.ProcessCommandsManagedProcess)1 ProcessId (org.sonar.process.ProcessId)1 ProcessCommands (org.sonar.process.sharedmemoryfile.ProcessCommands)1