Search in sources :

Example 1 with EsInstallation

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

the class CommandFactoryImplTest method createEsCommand_for_windows_returns_command_for_default_settings.

@Test
public void createEsCommand_for_windows_returns_command_for_default_settings() throws Exception {
    when(system2.isOsWindows()).thenReturn(true);
    prepareEsFileSystem();
    Properties props = new Properties();
    props.setProperty("sonar.search.host", "localhost");
    AbstractCommand command = newFactory(props, system2).createEsCommand();
    assertThat(command).isInstanceOf(JavaCommand.class);
    JavaCommand<?> esCommand = (JavaCommand<?>) 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.getArguments()).isEmpty();
    assertThat(esCommand.getEnvVariables()).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());
    assertThat(esCommand.getJvmOptions().getAll()).containsAll(esConfig.getEsJvmOptions().getAll()).contains("-Delasticsearch").contains("-Des.path.home=" + new File(homeDir, "elasticsearch")).contains("-Des.path.conf=" + esConfDir.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 2 with EsInstallation

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

the class ProcessLauncherImplTest method createEsScriptCommand.

private EsScriptCommand createEsScriptCommand(File tempDir, File homeDir, File dataDir, File logDir) throws IOException {
    EsScriptCommand command = new EsScriptCommand(ProcessId.ELASTICSEARCH, temp.newFolder());
    Props props = new Props(new Properties());
    props.set("sonar.path.temp", tempDir.getAbsolutePath());
    props.set("sonar.path.home", homeDir.getAbsolutePath());
    props.set("sonar.path.data", dataDir.getAbsolutePath());
    props.set("sonar.path.logs", logDir.getAbsolutePath());
    command.setEsInstallation(new EsInstallation(props).setEsYmlSettings(mock(EsYmlSettings.class)).setEsJvmOptions(mock(EsJvmOptions.class)).setLog4j2Properties(new Properties()).setHost("localhost").setHttpPort(9001));
    return command;
}
Also used : EsScriptCommand(org.sonar.application.command.EsScriptCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsJvmOptions(org.sonar.application.command.EsJvmOptions) Props(org.sonar.process.Props) Properties(java.util.Properties)

Example 3 with EsInstallation

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

the class CommandFactoryImpl method createEsInstallation.

private EsInstallation createEsInstallation() {
    EsInstallation esInstallation = new EsInstallation(props);
    if (!esInstallation.getExecutable().exists()) {
        throw new IllegalStateException("Cannot find elasticsearch binary");
    }
    Map<String, String> settingsMap = new EsSettings(props, esInstallation, System2.INSTANCE).build();
    esInstallation.setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory())).setEsJvmOptions(new EsJvmOptions(props, tempDir).addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()).addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())).setEsYmlSettings(new EsYmlSettings(settingsMap)).setHost(settingsMap.get("http.host")).setHttpPort(Integer.parseInt(settingsMap.get("http.port")));
    return esInstallation;
}
Also used : EsInstallation(org.sonar.application.es.EsInstallation) EsSettings(org.sonar.application.es.EsSettings) EsLogging(org.sonar.application.es.EsLogging) EsYmlSettings(org.sonar.application.es.EsYmlSettings)

Example 4 with EsInstallation

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

the class ProcessLauncherImpl method create.

private ProcessBuilder create(EsScriptCommand esScriptCommand) {
    List<String> commands = new ArrayList<>();
    EsInstallation esInstallation = esScriptCommand.getEsInstallation();
    requireNonNull(esInstallation, () -> "No Elasticsearch installation configuration is available for the command of type " + esScriptCommand.getClass());
    commands.add(esInstallation.getExecutable().getAbsolutePath());
    commands.addAll(esScriptCommand.getOptions());
    return create(esScriptCommand, commands);
}
Also used : EsInstallation(org.sonar.application.es.EsInstallation) ArrayList(java.util.ArrayList)

Example 5 with EsInstallation

use of org.sonar.application.es.EsInstallation 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)

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