Skip to content

Commit

Permalink
Revert "SONAR-11792 use dedicated temp directory for ES"
Browse files Browse the repository at this point in the history
This reverts commit 0257bd1.
  • Loading branch information
sns-seb authored and sonartech committed May 6, 2019
1 parent b5938da commit d9a9b8c
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 337 deletions.
Expand Up @@ -24,7 +24,6 @@
import java.util.Optional; import java.util.Optional;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.sonar.application.es.EsInstallation; import org.sonar.application.es.EsInstallation;
import org.sonar.application.es.EsInstallationImpl;
import org.sonar.application.es.EsLogging; import org.sonar.application.es.EsLogging;
import org.sonar.application.es.EsSettings; import org.sonar.application.es.EsSettings;
import org.sonar.application.es.EsYmlSettings; import org.sonar.application.es.EsYmlSettings;
Expand Down Expand Up @@ -113,7 +112,7 @@ private JavaCommand createEsCommandForWindows() {
return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory()) return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory())
.setEsInstallation(esInstallation) .setEsInstallation(esInstallation)
.setReadsArgumentsFromFile(false) .setReadsArgumentsFromFile(false)
.setJvmOptions(new EsJvmOptions(esInstallation) .setJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()) .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())
.add("-Delasticsearch") .add("-Delasticsearch")
Expand All @@ -128,15 +127,15 @@ private JavaCommand createEsCommandForWindows() {
} }


private EsInstallation createEsInstallation() { private EsInstallation createEsInstallation() {
EsInstallationImpl esInstallation = new EsInstallationImpl(props); EsInstallation esInstallation = new EsInstallation(props);
if (!esInstallation.getExecutable().exists()) { if (!esInstallation.getExecutable().exists()) {
throw new IllegalStateException("Cannot find elasticsearch binary"); throw new IllegalStateException("Cannot find elasticsearch binary");
} }
Map<String, String> settingsMap = new EsSettings(props, esInstallation, System2.INSTANCE).build(); Map<String, String> settingsMap = new EsSettings(props, esInstallation, System2.INSTANCE).build();


esInstallation esInstallation
.setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory())) .setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory()))
.setEsJvmOptions(new EsJvmOptions(esInstallation) .setEsJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())) .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()))
.setEsYmlSettings(new EsYmlSettings(settingsMap)) .setEsYmlSettings(new EsYmlSettings(settingsMap))
Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.sonar.application.es.EsInstallation;
import org.sonar.process.System2; import org.sonar.process.System2;


public class EsJvmOptions extends JvmOptions<EsJvmOptions> { public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
Expand All @@ -36,17 +35,17 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
"# DO NOT EDIT THIS FILE\n" + "# DO NOT EDIT THIS FILE\n" +
"\n"; "\n";


public EsJvmOptions(EsInstallation esInstallation) { public EsJvmOptions(File tmpDir) {
this(System2.INSTANCE, esInstallation); this(System2.INSTANCE, tmpDir);
} }


EsJvmOptions(System2 system2, EsInstallation esInstallation) { EsJvmOptions(System2 system2, File tmpDir) {
super(mandatoryOptions(system2, esInstallation)); super(mandatoryOptions(system2, tmpDir));
} }


// this basically writes down the content of jvm.options file distributed in vanilla Elasticsearch package // this basically writes down the content of jvm.options file distributed in vanilla Elasticsearch package
// with some changes to fit running bundled in SQ // with some changes to fit running bundled in SQ
private static Map<String, String> mandatoryOptions(System2 system2, EsInstallation esInstallation) { private static Map<String, String> mandatoryOptions(System2 system2, File tmpDir) {
Map<String, String> res = new LinkedHashMap<>(16); Map<String, String> res = new LinkedHashMap<>(16);
// GC configuration // GC configuration
res.put("-XX:+UseConcMarkSweepGC", ""); res.put("-XX:+UseConcMarkSweepGC", "");
Expand Down Expand Up @@ -92,7 +91,7 @@ private static Map<String, String> mandatoryOptions(System2 system2, EsInstallat


// (by default ES 6.6.1 uses variable ${ES_TMPDIR} which is replaced by start scripts. Since we start JAR file // (by default ES 6.6.1 uses variable ${ES_TMPDIR} which is replaced by start scripts. Since we start JAR file
// directly on windows, we specify absolute file as URL (to support space in path) instead // directly on windows, we specify absolute file as URL (to support space in path) instead
res.put("-Djava.io.tmpdir=", esInstallation.getTmpDirectory().getAbsolutePath()); res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());


// heap dumps (enable by default in ES 6.6.1, we don't enable them, no one will analyze them anyway) // heap dumps (enable by default in ES 6.6.1, we don't enable them, no one will analyze them anyway)
// generate a heap dump when an allocation from the Java heap fails // generate a heap dump when an allocation from the Java heap fails
Expand All @@ -102,7 +101,7 @@ private static Map<String, String> mandatoryOptions(System2 system2, EsInstallat
// has sufficient space // has sufficient space
// res.put("-XX:HeapDumpPath", "data"); // res.put("-XX:HeapDumpPath", "data");
// specify an alternative path for JVM fatal error logs (ES 6.6.1 default is "logs/hs_err_pid%p.log") // specify an alternative path for JVM fatal error logs (ES 6.6.1 default is "logs/hs_err_pid%p.log")
res.put("-XX:ErrorFile=", new File(esInstallation.getLogDirectory(), "es_hs_err_pid%p.log").getAbsolutePath()); res.put("-XX:ErrorFile=", "../logs/es_hs_err_pid%p.log");


// JDK 8 GC logging (by default ES 6.6.1 enables them, we don't want to do that in SQ, no one will analyze them anyway) // JDK 8 GC logging (by default ES 6.6.1 enables them, we don't want to do that in SQ, no one will analyze them anyway)
// res.put("8:-XX:+PrintGCDetails", ""); // res.put("8:-XX:+PrintGCDetails", "");
Expand Down
Expand Up @@ -20,42 +20,159 @@
package org.sonar.application.es; package org.sonar.application.es;


import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.sonar.application.command.EsJvmOptions; import org.sonar.application.command.EsJvmOptions;
import org.sonar.process.Props;


public interface EsInstallation { import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
File getHomeDirectory(); import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
import static org.sonar.process.ProcessProperties.Property.PATH_LOGS;
import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;


List<File> getOutdatedSearchDirectories(); /**

* Holds {@link File} to the various directories of ElasticSearch distribution embedded in SonarQube and provides
File getDataDirectory(); * {@link File} objects to the various files of it SonarQube cares about.

*
File getConfDirectory(); * <p>

* This class does not ensure files nor directories actually exist.
File getLogDirectory(); * </p>

*/
File getTmpDirectory(); public class EsInstallation {

private final File homeDirectory;
File getExecutable(); private final List<File> outdatedSearchDirectories;

private final File dataDirectory;
File getLog4j2PropertiesLocation(); private final File confDirectory;

private final File logDirectory;
File getElasticsearchYml(); private EsJvmOptions esJvmOptions;

private EsYmlSettings esYmlSettings;
File getJvmOptions(); private Properties log4j2Properties;

private String clusterName;
File getLibDirectory(); private String host;

private int port;
EsJvmOptions getEsJvmOptions();

public EsInstallation(Props props) {
EsYmlSettings getEsYmlSettings(); File sqHomeDir = props.nonNullValueAsFile(PATH_HOME.getKey());


Properties getLog4j2Properties(); this.homeDirectory = new File(sqHomeDir, "elasticsearch");

this.outdatedSearchDirectories = buildOutdatedSearchDirs(props);
String getClusterName(); this.dataDirectory = buildDataDir(props);

this.confDirectory = buildConfDir(props);
String getHost(); this.logDirectory = buildLogPath(props);

}
int getPort();
private static List<File> buildOutdatedSearchDirs(Props props) {
String dataPath = props.nonNullValue(PATH_DATA.getKey());
return Arrays.asList(new File(dataPath, "es"), new File(dataPath, "es5"));
}

private static File buildDataDir(Props props) {
String dataPath = props.nonNullValue(PATH_DATA.getKey());
return new File(dataPath, "es6");
}

private static File buildLogPath(Props props) {
return props.nonNullValueAsFile(PATH_LOGS.getKey());
}

private static File buildConfDir(Props props) {
File tempPath = props.nonNullValueAsFile(PATH_TEMP.getKey());
return new File(new File(tempPath, "conf"), "es");
}

public File getHomeDirectory() {
return homeDirectory;
}

public List<File> getOutdatedSearchDirectories() {
return Collections.unmodifiableList(outdatedSearchDirectories);
}

public File getDataDirectory() {
return dataDirectory;
}

public File getConfDirectory() {
return confDirectory;
}

public File getLogDirectory() {
return logDirectory;
}

public File getExecutable() {
return new File(homeDirectory, "bin/elasticsearch");
}

public File getLog4j2PropertiesLocation() {
return new File(confDirectory, "log4j2.properties");
}

public File getElasticsearchYml() {
return new File(confDirectory, "elasticsearch.yml");
}

public File getJvmOptions() {
return new File(confDirectory, "jvm.options");
}

public File getLibDirectory() {
return new File(homeDirectory, "lib");
}

public EsJvmOptions getEsJvmOptions() {
return esJvmOptions;
}

public EsInstallation setEsJvmOptions(EsJvmOptions esJvmOptions) {
this.esJvmOptions = esJvmOptions;
return this;
}

public EsYmlSettings getEsYmlSettings() {
return esYmlSettings;
}

public EsInstallation setEsYmlSettings(EsYmlSettings esYmlSettings) {
this.esYmlSettings = esYmlSettings;
return this;
}

public Properties getLog4j2Properties() {
return log4j2Properties;
}

public EsInstallation setLog4j2Properties(Properties log4j2Properties) {
this.log4j2Properties = log4j2Properties;
return this;
}

public String getClusterName() {
return clusterName;
}

public EsInstallation setClusterName(String clusterName) {
this.clusterName = clusterName;
return this;
}

public String getHost() {
return host;
}

public EsInstallation setHost(String host) {
this.host = host;
return this;
}

public int getPort() {
return port;
}

public EsInstallation setPort(int port) {
this.port = port;
return this;
}
} }

0 comments on commit d9a9b8c

Please sign in to comment.