Search in sources :

Example 1 with EsScriptCommand

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

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

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

the class ProcessLauncherImplTest method do_not_fail_if_outdated_es_directory_does_not_exist.

@Test
public void do_not_fail_if_outdated_es_directory_does_not_exist() throws Exception {
    File tempDir = temp.newFolder();
    File homeDir = temp.newFolder();
    File dataDir = temp.newFolder();
    File logDir = temp.newFolder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, TestProcessBuilder::new);
    EsScriptCommand command = createEsScriptCommand(tempDir, homeDir, dataDir, logDir);
    File outdatedEsDir = new File(dataDir, "es");
    assertThat(outdatedEsDir).doesNotExist();
    underTest.launch(command);
    assertThat(outdatedEsDir).doesNotExist();
}
Also used : EsScriptCommand(org.sonar.application.command.EsScriptCommand) File(java.io.File) Test(org.junit.Test)

Example 4 with EsScriptCommand

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

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

the class ProcessLauncherImplTest method clean_up_old_es_data.

@Test
public void clean_up_old_es_data() throws Exception {
    File tempDir = temp.newFolder();
    File homeDir = temp.newFolder();
    File dataDir = temp.newFolder();
    File logDir = temp.newFolder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, TestProcessBuilder::new);
    EsScriptCommand command = createEsScriptCommand(tempDir, homeDir, dataDir, logDir);
    File outdatedEsDir = new File(dataDir, "es");
    assertThat(outdatedEsDir.mkdir()).isTrue();
    assertThat(outdatedEsDir).exists();
    underTest.launch(command);
    assertThat(outdatedEsDir).doesNotExist();
}
Also used : EsScriptCommand(org.sonar.application.command.EsScriptCommand) File(java.io.File) Test(org.junit.Test)

Aggregations

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