Wrap settings at 140 columns

and remove the checkstyle suppressions.
This commit is contained in:
Nik Everett 2016-04-27 17:48:56 -04:00
parent 6cccd4462c
commit 1df4efccd5
9 changed files with 87 additions and 64 deletions

View File

@ -344,12 +344,6 @@
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]network[/\\]NetworkService.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]network[/\\]NetworkService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]recycler[/\\]Recyclers.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]recycler[/\\]Recyclers.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]rounding[/\\]Rounding.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]rounding[/\\]Rounding.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]AbstractScopedSettings.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]ClusterSettings.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]IndexScopedSettings.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]Setting.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]Settings.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]loader[/\\]XContentSettingsLoader.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]ByteSizeValue.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]ByteSizeValue.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]TimeValue.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]TimeValue.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]BigArrays.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]BigArrays.java" checks="LineLength" />
@ -943,8 +937,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]lucene[/\\]uid[/\\]VersionsTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]lucene[/\\]uid[/\\]VersionsTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]network[/\\]CidrsTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]network[/\\]CidrsTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]rounding[/\\]TimeZoneRoundingTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]rounding[/\\]TimeZoneRoundingTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]ScopedSettingsTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]SettingTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]DistanceUnitTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]DistanceUnitTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]FuzzinessTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]unit[/\\]FuzzinessTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]BigArraysTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]util[/\\]BigArraysTests.java" checks="LineLength" />
@ -1462,12 +1454,10 @@
<suppress files="test[/\\]framework[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]test[/\\]test[/\\]InternalTestClusterTests.java" checks="LineLength" /> <suppress files="test[/\\]framework[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]test[/\\]test[/\\]InternalTestClusterTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]cli[/\\]CliTool.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]cli[/\\]CliTool.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]SettingsModule.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]rest[/\\]action[/\\]admin[/\\]indices[/\\]settings[/\\]RestGetSettingsAction.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]rest[/\\]action[/\\]admin[/\\]indices[/\\]settings[/\\]RestGetSettingsAction.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeService.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeService.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]sort[/\\]GeoDistanceSortBuilderIT.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]sort[/\\]GeoDistanceSortBuilderIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]rest[/\\]CorsNotSetIT.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]rest[/\\]CorsNotSetIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]settings[/\\]SettingsModuleTests.java" checks="LineLength" />
<suppress files="plugins[/\\]store-smb[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]store[/\\]SmbDirectoryWrapper.java" checks="LineLength" /> <suppress files="plugins[/\\]store-smb[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]store[/\\]SmbDirectoryWrapper.java" checks="LineLength" />
<suppress files="test[/\\]framework[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]inject[/\\]ModuleTestCase.java" checks="LineLength" /> <suppress files="test[/\\]framework[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]common[/\\]inject[/\\]ModuleTestCase.java" checks="LineLength" />
</suppressions> </suppressions>

View File

@ -391,10 +391,13 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
/** /**
* Updates a target settings builder with new, updated or deleted settings from a given settings builder. * Updates a target settings builder with new, updated or deleted settings from a given settings builder.
* <p> * <p>
* Note: This method will only allow updates to dynamic settings. if a non-dynamic setting is updated an {@link IllegalArgumentException} is thrown instead. * Note: This method will only allow updates to dynamic settings. if a non-dynamic setting is updated an
* {@link IllegalArgumentException} is thrown instead.
* </p> * </p>
*
* @param toApply the new settings to apply * @param toApply the new settings to apply
* @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be
* removed from this builder
* @param updates a settings builder that holds all updates applied to target * @param updates a settings builder that holds all updates applied to target
* @param type a free text string to allow better exceptions messages * @param type a free text string to allow better exceptions messages
* @return <code>true</code> if the target has changed otherwise <code>false</code> * @return <code>true</code> if the target has changed otherwise <code>false</code>
@ -405,8 +408,10 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
/** /**
* Updates a target settings builder with new, updated or deleted settings from a given settings builder. * Updates a target settings builder with new, updated or deleted settings from a given settings builder.
*
* @param toApply the new settings to apply * @param toApply the new settings to apply
* @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be
* removed from this builder
* @param updates a settings builder that holds all updates applied to target * @param updates a settings builder that holds all updates applied to target
* @param type a free text string to allow better exceptions messages * @param type a free text string to allow better exceptions messages
* @return <code>true</code> if the target has changed otherwise <code>false</code> * @return <code>true</code> if the target has changed otherwise <code>false</code>
@ -417,11 +422,14 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
/** /**
* Updates a target settings builder with new, updated or deleted settings from a given settings builder. * Updates a target settings builder with new, updated or deleted settings from a given settings builder.
*
* @param toApply the new settings to apply * @param toApply the new settings to apply
* @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be
* removed from this builder
* @param updates a settings builder that holds all updates applied to target * @param updates a settings builder that holds all updates applied to target
* @param type a free text string to allow better exceptions messages * @param type a free text string to allow better exceptions messages
* @param onlyDynamic if <code>false</code> all settings are updated otherwise only dynamic settings are updated. if set to <code>true</code> and a non-dynamic setting is updated an exception is thrown. * @param onlyDynamic if <code>false</code> all settings are updated otherwise only dynamic settings are updated. if set to
* <code>true</code> and a non-dynamic setting is updated an exception is thrown.
* @return <code>true</code> if the target has changed otherwise <code>false</code> * @return <code>true</code> if the target has changed otherwise <code>false</code>
*/ */
private boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type, boolean onlyDynamic) { private boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type, boolean onlyDynamic) {
@ -500,16 +508,22 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
} else { } else {
changed = true; changed = true;
logger.warn("found unknown setting: {} value: {} - archiving", entry.getKey(), entry.getValue()); logger.warn("found unknown setting: {} value: {} - archiving", entry.getKey(), entry.getValue());
// we put them back in here such that tools can check from the outside if there are any indices with broken settings. The setting can remain there /*
// but we want users to be aware that some of their setting are broken and they can research why and what they need to do to replace them. * We put them back in here such that tools can check from the outside if there are any indices with broken
* settings. The setting can remain there but we want users to be aware that some of their setting are broken and
* they can research why and what they need to do to replace them.
*/
builder.put(ARCHIVED_SETTINGS_PREFIX + entry.getKey(), entry.getValue()); builder.put(ARCHIVED_SETTINGS_PREFIX + entry.getKey(), entry.getValue());
} }
} }
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
changed = true; changed = true;
logger.warn("found invalid setting: {} value: {} - archiving",ex , entry.getKey(), entry.getValue()); logger.warn("found invalid setting: {} value: {} - archiving",ex , entry.getKey(), entry.getValue());
// we put them back in here such that tools can check from the outside if there are any indices with broken settings. The setting can remain there /*
// but we want users to be aware that some of their setting sare broken and they can research why and what they need to do to replace them. * We put them back in here such that tools can check from the outside if there are any indices with broken settings. The
* setting can remain there but we want users to be aware that some of their setting are broken and they can research why
* and what they need to do to replace them.
*/
builder.put(ARCHIVED_SETTINGS_PREFIX + entry.getKey(), entry.getValue()); builder.put(ARCHIVED_SETTINGS_PREFIX + entry.getKey(), entry.getValue());
} }
} }

View File

@ -58,7 +58,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
public static final Predicate<String> INDEX_SETTINGS_KEY_PREDICATE = (s) -> s.startsWith(IndexMetaData.INDEX_SETTING_PREFIX); public static final Predicate<String> INDEX_SETTINGS_KEY_PREDICATE = (s) -> s.startsWith(IndexMetaData.INDEX_SETTING_PREFIX);
public static Set<Setting<?>> BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( public static final Set<Setting<?>> BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
IndexSettings.INDEX_TTL_DISABLE_PURGE_SETTING, IndexSettings.INDEX_TTL_DISABLE_PURGE_SETTING,
IndexStore.INDEX_STORE_THROTTLE_TYPE_SETTING, IndexStore.INDEX_STORE_THROTTLE_TYPE_SETTING,
IndexStore.INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING, IndexStore.INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING,
@ -143,7 +143,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
Map<String, Settings> groups = s.getAsGroups(); Map<String, Settings> groups = s.getAsGroups();
for (String key : SimilarityService.BUILT_IN.keySet()) { for (String key : SimilarityService.BUILT_IN.keySet()) {
if (groups.containsKey(key)) { if (groups.containsKey(key)) {
throw new IllegalArgumentException("illegal value for [index.similarity."+ key + "] cannot redefine built-in similarity"); throw new IllegalArgumentException("illegal value for [index.similarity." + key +
"] cannot redefine built-in similarity");
} }
} }
}, Property.IndexScope), // this allows similarity settings to be passed }, Property.IndexScope), // this allows similarity settings to be passed
@ -151,7 +152,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
))); )));
public static final IndexScopedSettings DEFAULT_SCOPED_SETTINGS = new IndexScopedSettings(Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); public static final IndexScopedSettings DEFAULT_SCOPED_SETTINGS = new IndexScopedSettings(Settings.EMPTY,
BUILT_IN_INDEX_SETTINGS);
public IndexScopedSettings(Settings settings, Set<Setting<?>> settingsSet) { public IndexScopedSettings(Settings settings, Set<Setting<?>> settingsSet) {
super(settings, settingsSet, Property.IndexScope); super(settings, settingsSet, Property.IndexScope);

View File

@ -248,9 +248,9 @@ public class Setting<T> extends ToXContentToBytes {
} }
/** /**
* Returns <code>true</code> iff this setting is a group setting. Group settings represent a set of settings * Returns <code>true</code> iff this setting is a group setting. Group settings represent a set of settings rather than a single value.
* rather than a single value. The key, see {@link #getKey()}, in contrast to non-group settings is a prefix like <tt>cluster.store.</tt> * The key, see {@link #getKey()}, in contrast to non-group settings is a prefix like <tt>cluster.store.</tt> that matches all settings
* that matches all settings with this prefix. * with this prefix.
*/ */
boolean isGroupSetting() { boolean isGroupSetting() {
return false; return false;
@ -356,7 +356,8 @@ public class Setting<T> extends ToXContentToBytes {
} }
public Setting<T> getConcreteSetting(String key) { public Setting<T> getConcreteSetting(String key) {
assert key.startsWith(this.getKey()) : "was " + key + " expected: " + getKey(); // we use startsWith here since the key might be foo.bar.0 if it's an array // we use startsWith here since the key might be foo.bar.0 if it's an array
assert key.startsWith(this.getKey()) : "was " + key + " expected: " + getKey();
return this; return this;
} }
@ -380,10 +381,11 @@ public class Setting<T> extends ToXContentToBytes {
} }
/** /**
* this is used for settings that depend on each other... see {@link org.elasticsearch.common.settings.AbstractScopedSettings#addSettingsUpdateConsumer(Setting, Setting, BiConsumer)} and it's * Updates settings that depend on eachother. See {@link AbstractScopedSettings#addSettingsUpdateConsumer(Setting, Setting, BiConsumer)}
* usage for details. * and its usage for details.
*/ */
static <A, B> AbstractScopedSettings.SettingUpdater<Tuple<A, B>> compoundUpdater(final BiConsumer<A,B> consumer, final Setting<A> aSetting, final Setting<B> bSetting, ESLogger logger) { static <A, B> AbstractScopedSettings.SettingUpdater<Tuple<A, B>> compoundUpdater(final BiConsumer<A, B> consumer,
final Setting<A> aSetting, final Setting<B> bSetting, ESLogger logger) {
final AbstractScopedSettings.SettingUpdater<A> aSettingUpdater = aSetting.newUpdater(null, logger); final AbstractScopedSettings.SettingUpdater<A> aSettingUpdater = aSetting.newUpdater(null, logger);
final AbstractScopedSettings.SettingUpdater<B> bSettingUpdater = bSetting.newUpdater(null, logger); final AbstractScopedSettings.SettingUpdater<B> bSettingUpdater = bSetting.newUpdater(null, logger);
return new AbstractScopedSettings.SettingUpdater<Tuple<A, B>>() { return new AbstractScopedSettings.SettingUpdater<Tuple<A, B>>() {
@ -444,7 +446,8 @@ public class Setting<T> extends ToXContentToBytes {
try { try {
accept.accept(inst); accept.accept(inst);
} catch (Exception | AssertionError e) { } catch (Exception | AssertionError e) {
throw new IllegalArgumentException("illegal value can't update [" + key + "] from [" + value + "] to [" + newValue + "]", e); throw new IllegalArgumentException("illegal value can't update [" + key + "] from [" + value + "] to [" + newValue + "]",
e);
} }
return inst; return inst;
} }
@ -552,8 +555,8 @@ public class Setting<T> extends ToXContentToBytes {
return new Setting<>(key, defaultValue, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties); return new Setting<>(key, defaultValue, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties);
} }
public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue defaultValue, ByteSizeValue minValue, ByteSizeValue maxValue, public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue defaultValue, ByteSizeValue minValue,
Property... properties) { ByteSizeValue maxValue, Property... properties) {
return byteSizeSetting(key, (s) -> defaultValue.toString(), minValue, maxValue, properties); return byteSizeSetting(key, (s) -> defaultValue.toString(), minValue, maxValue, properties);
} }
@ -685,7 +688,8 @@ public class Setting<T> extends ToXContentToBytes {
} }
@Override @Override
public AbstractScopedSettings.SettingUpdater<Settings> newUpdater(Consumer<Settings> consumer, ESLogger logger, Consumer<Settings> validator) { public AbstractScopedSettings.SettingUpdater<Settings> newUpdater(Consumer<Settings> consumer, ESLogger logger,
Consumer<Settings> validator) {
if (isDynamic() == false) { if (isDynamic() == false) {
throw new IllegalStateException("setting [" + getKey() + "] is not dynamic"); throw new IllegalStateException("setting [" + getKey() + "] is not dynamic");
} }
@ -706,7 +710,8 @@ public class Setting<T> extends ToXContentToBytes {
try { try {
validator.accept(currentSettings); validator.accept(currentSettings);
} catch (Exception | AssertionError e) { } catch (Exception | AssertionError e) {
throw new IllegalArgumentException("illegal value can't update [" + key + "] from [" + previousSettings.getAsMap() + "] to [" + currentSettings.getAsMap() + "]", e); throw new IllegalArgumentException("illegal value can't update [" + key + "] from ["
+ previousSettings.getAsMap() + "] to [" + currentSettings.getAsMap() + "]", e);
} }
return currentSettings; return currentSettings;
} }

View File

@ -62,8 +62,6 @@ import java.util.function.Predicate;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.unit.ByteSizeValue.parseBytesSizeValue; import static org.elasticsearch.common.unit.ByteSizeValue.parseBytesSizeValue;
import static org.elasticsearch.common.unit.SizeValue.parseSizeValue; import static org.elasticsearch.common.unit.SizeValue.parseSizeValue;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
@ -456,7 +454,8 @@ public final class Settings implements ToXContent {
if (ignoreNonGrouped) { if (ignoreNonGrouped) {
continue; continue;
} }
throw new SettingsException("Failed to get setting group for [" + settingPrefix + "] setting prefix and setting [" + setting + "] because of a missing '.'"); throw new SettingsException("Failed to get setting group for [" + settingPrefix + "] setting prefix and setting ["
+ setting + "] because of a missing '.'");
} }
String name = nameValue.substring(0, dotIndex); String name = nameValue.substring(0, dotIndex);
String value = nameValue.substring(dotIndex + 1); String value = nameValue.substring(dotIndex + 1);
@ -638,7 +637,8 @@ public final class Settings implements ToXContent {
} }
} }
if ((settings.length % 2) != 0) { if ((settings.length % 2) != 0) {
throw new IllegalArgumentException("array settings of key + value order doesn't hold correct number of arguments (" + settings.length + ")"); throw new IllegalArgumentException(
"array settings of key + value order doesn't hold correct number of arguments (" + settings.length + ")");
} }
for (int i = 0; i < settings.length; i++) { for (int i = 0; i < settings.length; i++) {
put(settings[i++].toString(), settings[i].toString()); put(settings[i++].toString(), settings[i].toString());
@ -904,7 +904,8 @@ public final class Settings implements ToXContent {
for (String s : values) { for (String s : values) {
int index = s.indexOf('='); int index = s.indexOf('=');
if (index == -1) { if (index == -1) {
throw new IllegalArgumentException("value [" + s + "] for settings loaded with delimiter [" + delimiter + "] is malformed, missing ="); throw new IllegalArgumentException(
"value [" + s + "] for settings loaded with delimiter [" + delimiter + "] is malformed, missing =");
} }
map.put(s.substring(0, index), s.substring(index + 1)); map.put(s.substring(0, index), s.substring(index + 1));
} }
@ -945,7 +946,8 @@ public final class Settings implements ToXContent {
public Builder loadFromStream(String resourceName, InputStream is) throws SettingsException { public Builder loadFromStream(String resourceName, InputStream is) throws SettingsException {
SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName);
try { try {
Map<String, String> loadedSettings = settingsLoader.load(Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8))); Map<String, String> loadedSettings = settingsLoader
.load(Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8)));
put(loadedSettings); put(loadedSettings);
} catch (Exception e) { } catch (Exception e) {
throw new SettingsException("Failed to load settings from [" + resourceName + "]", e); throw new SettingsException("Failed to load settings from [" + resourceName + "]", e);

View File

@ -77,24 +77,22 @@ public abstract class XContentSettingsLoader implements SettingsLoader {
while (!jp.isClosed() && (lastToken = jp.nextToken()) == null); while (!jp.isClosed() && (lastToken = jp.nextToken()) == null);
} catch (Exception e) { } catch (Exception e) {
throw new ElasticsearchParseException( throw new ElasticsearchParseException(
"malformed, expected end of settings but encountered additional content starting at line number: [{}], column number: [{}]", "malformed, expected end of settings but encountered additional content starting at line number: [{}], "
e, + "column number: [{}]",
jp.getTokenLocation().lineNumber, e, jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
jp.getTokenLocation().columnNumber
);
} }
if (lastToken != null) { if (lastToken != null) {
throw new ElasticsearchParseException( throw new ElasticsearchParseException(
"malformed, expected end of settings but encountered additional content starting at line number: [{}], column number: [{}]", "malformed, expected end of settings but encountered additional content starting at line number: [{}], "
jp.getTokenLocation().lineNumber, + "column number: [{}]",
jp.getTokenLocation().columnNumber jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
);
} }
return settings; return settings;
} }
private void serializeObject(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser, String objFieldName) throws IOException { private void serializeObject(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser,
String objFieldName) throws IOException {
if (objFieldName != null) { if (objFieldName != null) {
path.add(objFieldName); path.add(objFieldName);
} }
@ -121,7 +119,8 @@ public abstract class XContentSettingsLoader implements SettingsLoader {
} }
} }
private void serializeArray(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser, String fieldName) throws IOException { private void serializeArray(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser, String fieldName)
throws IOException {
XContentParser.Token token; XContentParser.Token token;
int counter = 0; int counter = 0;
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
@ -140,7 +139,8 @@ public abstract class XContentSettingsLoader implements SettingsLoader {
} }
} }
private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser, String fieldName, boolean isNull) throws IOException { private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, XContentParser parser, String fieldName,
boolean isNull) throws IOException {
sb.setLength(0); sb.setLength(0);
for (String pathEle : path) { for (String pathEle : path) {
sb.append(pathEle).append('.'); sb.append(pathEle).append('.');

View File

@ -170,7 +170,8 @@ public class ScopedSettingsTests extends ESTestCase {
ClusterSettings settings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); ClusterSettings settings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
AtomicReference<List<String>> ref = new AtomicReference<>(); AtomicReference<List<String>> ref = new AtomicReference<>();
settings.addSettingsUpdateConsumer(TransportService.TRACE_LOG_INCLUDE_SETTING, ref::set); settings.addSettingsUpdateConsumer(TransportService.TRACE_LOG_INCLUDE_SETTING, ref::set);
settings.applySettings(Settings.builder().putArray("transport.tracer.include", "internal:index/shard/recovery/*", "internal:gateway/local*").build()); settings.applySettings(Settings.builder()
.putArray("transport.tracer.include", "internal:index/shard/recovery/*", "internal:gateway/local*").build());
assertNotNull(ref.get().size()); assertNotNull(ref.get().size());
assertEquals(ref.get().size(), 2); assertEquals(ref.get().size(), 2);
assertTrue(ref.get().contains("internal:index/shard/recovery/*")); assertTrue(ref.get().contains("internal:index/shard/recovery/*"));
@ -181,7 +182,8 @@ public class ScopedSettingsTests extends ESTestCase {
IndexScopedSettings settings = new IndexScopedSettings( IndexScopedSettings settings = new IndexScopedSettings(
Settings.EMPTY, Settings.EMPTY,
IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
IndexScopedSettings copy = settings.copy(Settings.builder().put("index.store.type", "boom").build(), newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 3).build())); IndexScopedSettings copy = settings.copy(Settings.builder().put("index.store.type", "boom").build(),
newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 3).build()));
assertEquals(3, copy.get(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING).intValue()); assertEquals(3, copy.get(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING).intValue());
assertEquals(1, copy.get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING).intValue()); assertEquals(1, copy.get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING).intValue());
assertEquals("boom", copy.get(IndexModule.INDEX_STORE_TYPE_SETTING)); // test fallback to node settings assertEquals("boom", copy.get(IndexModule.INDEX_STORE_TYPE_SETTING)); // test fallback to node settings
@ -331,7 +333,8 @@ public class ScopedSettingsTests extends ESTestCase {
public void testFallbackToLoggerLevel() { public void testFallbackToLoggerLevel() {
final String level = ESLoggerFactory.getRootLogger().getLevel(); final String level = ESLoggerFactory.getRootLogger().getLevel();
try { try {
ClusterSettings settings = new ClusterSettings(Settings.builder().put("logger.level", "ERROR").build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); ClusterSettings settings = new ClusterSettings(Settings.builder().put("logger.level", "ERROR").build(),
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
assertEquals(level, ESLoggerFactory.getRootLogger().getLevel()); assertEquals(level, ESLoggerFactory.getRootLogger().getLevel());
settings.applySettings(Settings.builder().put("logger._root", "TRACE").build()); settings.applySettings(Settings.builder().put("logger._root", "TRACE").build());
assertEquals("TRACE", ESLoggerFactory.getRootLogger().getLevel()); assertEquals("TRACE", ESLoggerFactory.getRootLogger().getLevel());

View File

@ -35,8 +35,6 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
public class SettingTests extends ESTestCase { public class SettingTests extends ESTestCase {
public void testGet() { public void testGet() {
Setting<Boolean> booleanSetting = Setting.boolSetting("foo.bar", false, Property.Dynamic, Property.NodeScope); Setting<Boolean> booleanSetting = Setting.boolSetting("foo.bar", false, Property.Dynamic, Property.NodeScope);
assertFalse(booleanSetting.get(Settings.EMPTY)); assertFalse(booleanSetting.get(Settings.EMPTY));
@ -62,7 +60,8 @@ public class SettingTests extends ESTestCase {
settingUpdater.apply(Settings.builder().put("a.byte.size", 12).build(), Settings.EMPTY); settingUpdater.apply(Settings.builder().put("a.byte.size", 12).build(), Settings.EMPTY);
fail("no unit"); fail("no unit");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals("failed to parse setting [a.byte.size] with value [12] as a size in bytes: unit is missing or unrecognized", ex.getMessage()); assertEquals("failed to parse setting [a.byte.size] with value [12] as a size in bytes: unit is missing or unrecognized",
ex.getMessage());
} }
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12b").build(), Settings.EMPTY)); assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12b").build(), Settings.EMPTY));
@ -86,7 +85,8 @@ public class SettingTests extends ESTestCase {
settingUpdater.apply(build, Settings.EMPTY); settingUpdater.apply(build, Settings.EMPTY);
fail("not a boolean"); fail("not a boolean");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals("Failed to parse value [I am not a boolean] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]", ex.getMessage()); assertEquals("Failed to parse value [I am not a boolean] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]",
ex.getMessage());
} }
} }
@ -184,7 +184,10 @@ public class SettingTests extends ESTestCase {
assertTrue(setting.isGroupSetting()); assertTrue(setting.isGroupSetting());
ClusterSettings.SettingUpdater<Settings> settingUpdater = setting.newUpdater(ref::set, logger); ClusterSettings.SettingUpdater<Settings> settingUpdater = setting.newUpdater(ref::set, logger);
Settings currentInput = Settings.builder().put("foo.bar.1.value", "1").put("foo.bar.2.value", "2").put("foo.bar.3.value", "3").build(); Settings currentInput = Settings.builder()
.put("foo.bar.1.value", "1")
.put("foo.bar.2.value", "2")
.put("foo.bar.3.value", "3").build();
Settings previousInput = Settings.EMPTY; Settings previousInput = Settings.EMPTY;
assertTrue(settingUpdater.apply(currentInput, previousInput)); assertTrue(settingUpdater.apply(currentInput, previousInput));
assertNotNull(ref.get()); assertNotNull(ref.get());
@ -228,7 +231,8 @@ public class SettingTests extends ESTestCase {
ClusterSettings.SettingUpdater<Settings> predicateSettingUpdater = setting.newUpdater(ref::set, logger,(s) -> assertFalse(true)); ClusterSettings.SettingUpdater<Settings> predicateSettingUpdater = setting.newUpdater(ref::set, logger,(s) -> assertFalse(true));
try { try {
predicateSettingUpdater.apply(Settings.builder().put("foo.bar.1.value", "1").put("foo.bar.2.value", "2").build(), Settings.EMPTY); predicateSettingUpdater.apply(Settings.builder().put("foo.bar.1.value", "1").put("foo.bar.2.value", "2").build(),
Settings.EMPTY);
fail("not accepted"); fail("not accepted");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "illegal value can't update [foo.bar.] from [{}] to [{1.value=1, 2.value=2}]"); assertEquals(ex.getMessage(), "illegal value can't update [foo.bar.] from [{}] to [{1.value=1, 2.value=2}]");

View File

@ -101,7 +101,9 @@ public class SettingsModuleTests extends ModuleTestCase {
assertInstanceBinding(module, Settings.class, (s) -> s == settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings);
fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals("tribe.t1 validation failed: Failed to parse value [[2.0]] for setting [cluster.routing.allocation.balance.shard]", ex.getMessage()); assertEquals(
"tribe.t1 validation failed: Failed to parse value [[2.0]] for setting [cluster.routing.allocation.balance.shard]",
ex.getMessage());
} }
} }
} }
@ -119,7 +121,8 @@ public class SettingsModuleTests extends ModuleTestCase {
assertInstanceBinding(module, Settings.class, (s) -> s == settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings);
fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals("Failed to parse value [BOOM] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]", ex.getMessage()); assertEquals("Failed to parse value [BOOM] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]",
ex.getMessage());
} }
} }
{ {