summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/cluster/ClusterName.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/cluster/ClusterName.java')
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/ClusterName.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java
index 3a9dd82732..daf3000d71 100644
--- a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java
+++ b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
+import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import java.io.IOException;
@@ -31,18 +32,23 @@ import java.io.IOException;
*/
public class ClusterName implements Streamable {
- public static final String SETTING = "cluster.name";
+ public static final Setting<String> CLUSTER_NAME_SETTING = new Setting<>("cluster.name", "elasticsearch", (s) -> {
+ if (s.isEmpty()) {
+ throw new IllegalArgumentException("[cluster.name] must not be empty");
+ }
+ return s;
+ }, false, Setting.Scope.CLUSTER);
- public static final ClusterName DEFAULT = new ClusterName("elasticsearch".intern());
+
+ public static final ClusterName DEFAULT = new ClusterName(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY).intern());
private String value;
public static ClusterName clusterNameFromSettings(Settings settings) {
- return new ClusterName(settings.get("cluster.name", ClusterName.DEFAULT.value()));
+ return new ClusterName(CLUSTER_NAME_SETTING.get(settings));
}
private ClusterName() {
-
}
public ClusterName(String value) {