summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/env/Environment.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/env/Environment.java')
-rw-r--r--core/src/main/java/org/elasticsearch/env/Environment.java65
1 files changed, 39 insertions, 26 deletions
diff --git a/core/src/main/java/org/elasticsearch/env/Environment.java b/core/src/main/java/org/elasticsearch/env/Environment.java
index b6453a4707..65d62bd9e3 100644
--- a/core/src/main/java/org/elasticsearch/env/Environment.java
+++ b/core/src/main/java/org/elasticsearch/env/Environment.java
@@ -23,6 +23,7 @@ import org.apache.lucene.util.Constants;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
+import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import java.io.IOException;
@@ -33,6 +34,9 @@ import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Function;
import static org.elasticsearch.common.Strings.cleanPath;
@@ -43,6 +47,15 @@ import static org.elasticsearch.common.Strings.cleanPath;
// TODO: move PathUtils to be package-private here instead of
// public+forbidden api!
public class Environment {
+ public static final Setting<String> PATH_HOME_SETTING = Setting.simpleString("path.home", false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PATH_CONF_SETTING = Setting.simpleString("path.conf", false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PATH_SCRIPTS_SETTING = Setting.simpleString("path.scripts", false, Setting.Scope.CLUSTER);
+ public static final Setting<List<String>> PATH_DATA_SETTING = Setting.listSetting("path.data", Collections.emptyList(), Function.identity(), false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PATH_LOGS_SETTING = Setting.simpleString("path.logs", false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PATH_PLUGINS_SETTING = Setting.simpleString("path.plugins", false, Setting.Scope.CLUSTER);
+ public static final Setting<List<String>> PATH_REPO_SETTING = Setting.listSetting("path.repo", Collections.emptyList(), Function.identity(), false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PATH_SHARED_DATA_SETTING = Setting.simpleString("path.shared_data", false, Setting.Scope.CLUSTER);
+ public static final Setting<String> PIDFILE_SETTING = Setting.simpleString("pidfile", false, Setting.Scope.CLUSTER);
private final Settings settings;
@@ -95,64 +108,64 @@ public class Environment {
public Environment(Settings settings) {
this.settings = settings;
final Path homeFile;
- if (settings.get("path.home") != null) {
- homeFile = PathUtils.get(cleanPath(settings.get("path.home")));
+ if (PATH_HOME_SETTING.exists(settings)) {
+ homeFile = PathUtils.get(cleanPath(PATH_HOME_SETTING.get(settings)));
} else {
- throw new IllegalStateException("path.home is not configured");
+ throw new IllegalStateException(PATH_HOME_SETTING.getKey() + " is not configured");
}
- if (settings.get("path.conf") != null) {
- configFile = PathUtils.get(cleanPath(settings.get("path.conf")));
+ if (PATH_CONF_SETTING.exists(settings)) {
+ configFile = PathUtils.get(cleanPath(PATH_CONF_SETTING.get(settings)));
} else {
configFile = homeFile.resolve("config");
}
- if (settings.get("path.scripts") != null) {
- scriptsFile = PathUtils.get(cleanPath(settings.get("path.scripts")));
+ if (PATH_SCRIPTS_SETTING.exists(settings)) {
+ scriptsFile = PathUtils.get(cleanPath(PATH_SCRIPTS_SETTING.get(settings)));
} else {
scriptsFile = configFile.resolve("scripts");
}
- if (settings.get("path.plugins") != null) {
- pluginsFile = PathUtils.get(cleanPath(settings.get("path.plugins")));
+ if (PATH_PLUGINS_SETTING.exists(settings)) {
+ pluginsFile = PathUtils.get(cleanPath(PATH_PLUGINS_SETTING.get(settings)));
} else {
pluginsFile = homeFile.resolve("plugins");
}
- String[] dataPaths = settings.getAsArray("path.data");
- if (dataPaths.length > 0) {
- dataFiles = new Path[dataPaths.length];
- dataWithClusterFiles = new Path[dataPaths.length];
- for (int i = 0; i < dataPaths.length; i++) {
- dataFiles[i] = PathUtils.get(dataPaths[i]);
+ List<String> dataPaths = PATH_DATA_SETTING.get(settings);
+ if (dataPaths.isEmpty() == false) {
+ dataFiles = new Path[dataPaths.size()];
+ dataWithClusterFiles = new Path[dataPaths.size()];
+ for (int i = 0; i < dataPaths.size(); i++) {
+ dataFiles[i] = PathUtils.get(dataPaths.get(i));
dataWithClusterFiles[i] = dataFiles[i].resolve(ClusterName.clusterNameFromSettings(settings).value());
}
} else {
dataFiles = new Path[]{homeFile.resolve("data")};
dataWithClusterFiles = new Path[]{homeFile.resolve("data").resolve(ClusterName.clusterNameFromSettings(settings).value())};
}
- if (settings.get("path.shared_data") != null) {
- sharedDataFile = PathUtils.get(cleanPath(settings.get("path.shared_data")));
+ if (PATH_SHARED_DATA_SETTING.exists(settings)) {
+ sharedDataFile = PathUtils.get(cleanPath(PATH_SHARED_DATA_SETTING.get(settings)));
} else {
sharedDataFile = null;
}
- String[] repoPaths = settings.getAsArray("path.repo");
- if (repoPaths.length > 0) {
- repoFiles = new Path[repoPaths.length];
- for (int i = 0; i < repoPaths.length; i++) {
- repoFiles[i] = PathUtils.get(repoPaths[i]);
+ List<String> repoPaths = PATH_REPO_SETTING.get(settings);
+ if (repoPaths.isEmpty() == false) {
+ repoFiles = new Path[repoPaths.size()];
+ for (int i = 0; i < repoPaths.size(); i++) {
+ repoFiles[i] = PathUtils.get(repoPaths.get(i));
}
} else {
repoFiles = new Path[0];
}
- if (settings.get("path.logs") != null) {
- logsFile = PathUtils.get(cleanPath(settings.get("path.logs")));
+ if (PATH_LOGS_SETTING.exists(settings)) {
+ logsFile = PathUtils.get(cleanPath(PATH_LOGS_SETTING.get(settings)));
} else {
logsFile = homeFile.resolve("logs");
}
- if (settings.get("pidfile") != null) {
- pidFile = PathUtils.get(cleanPath(settings.get("pidfile")));
+ if (PIDFILE_SETTING.exists(settings)) {
+ pidFile = PathUtils.get(cleanPath(PIDFILE_SETTING.get(settings)));
} else {
pidFile = null;
}