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