|
@@ -12,12 +12,12 @@ import org.apache.logging.log4j.Level;
|
|
|
import org.apache.lucene.util.SetOnce;
|
|
|
import org.elasticsearch.ElasticsearchGenerationException;
|
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
|
-import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.Diff;
|
|
|
import org.elasticsearch.cluster.Diffable;
|
|
|
import org.elasticsearch.cluster.DiffableUtils;
|
|
|
import org.elasticsearch.common.Numbers;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.VersionId;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
@@ -63,6 +63,7 @@ import java.util.Set;
|
|
|
import java.util.TreeMap;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.function.IntFunction;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.function.UnaryOperator;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -522,13 +523,20 @@ public final class Settings implements ToXContentFragment, Writeable, Diffable<S
|
|
|
/**
|
|
|
* Returns a parsed version.
|
|
|
*/
|
|
|
- public Version getAsVersion(String setting, Version defaultVersion) throws SettingsException {
|
|
|
+ public <T extends VersionId> T getAsVersionId(String setting, IntFunction<T> parseVersion) throws SettingsException {
|
|
|
+ return getAsVersionId(setting, parseVersion, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns a parsed version.
|
|
|
+ */
|
|
|
+ public <T extends VersionId> T getAsVersionId(String setting, IntFunction<T> parseVersion, T defaultVersion) throws SettingsException {
|
|
|
String sValue = get(setting);
|
|
|
if (sValue == null) {
|
|
|
return defaultVersion;
|
|
|
}
|
|
|
try {
|
|
|
- return Version.fromId(Integer.parseInt(sValue));
|
|
|
+ return parseVersion.apply(Integer.parseInt(sValue));
|
|
|
} catch (Exception e) {
|
|
|
throw new SettingsException("Failed to parse version setting [" + setting + "] with value [" + sValue + "]", e);
|
|
|
}
|
|
@@ -1028,8 +1036,15 @@ public final class Settings implements ToXContentFragment, Writeable, Diffable<S
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder put(String setting, Version version) {
|
|
|
- put(setting, version.id);
|
|
|
+ /**
|
|
|
+ * Sets the setting with the provided setting key and the {@code VersionId} value.
|
|
|
+ *
|
|
|
+ * @param setting The setting key
|
|
|
+ * @param version The version value
|
|
|
+ * @return The builder
|
|
|
+ */
|
|
|
+ public Builder put(String setting, VersionId version) {
|
|
|
+ put(setting, version.id());
|
|
|
return this;
|
|
|
}
|
|
|
|