make get(Setting) fallback to node settings

This commit is contained in:
Simon Willnauer 2016-01-17 00:07:47 +01:00
parent cc25c4c8be
commit ef9ef0c47a
2 changed files with 26 additions and 1 deletions

View File

@ -293,7 +293,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
if (get(setting.getKey()) == null) {
throw new IllegalArgumentException("setting " + setting.getKey() + " has not been registered");
}
return setting.get(this.lastSettingsApplied);
return setting.get(this.lastSettingsApplied, settings);
}
/**

View File

@ -18,8 +18,11 @@
*/
package org.elasticsearch.common.settings;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.transport.TransportService;
@ -165,4 +168,26 @@ public class ScopedSettingsTests extends ESTestCase {
assertTrue(ref.get().contains("internal:index/shard/recovery/*"));
assertTrue(ref.get().contains("internal:gateway/local*"));
}
public void testGetSetting() {
IndexScopeSettings settings = new IndexScopeSettings(
Settings.EMPTY,
IndexScopeSettings.BUILT_IN_INDEX_SETTINGS);
IndexScopeSettings 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(1, copy.get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING).intValue());
assertEquals("boom", copy.get(IndexModule.INDEX_STORE_TYPE_SETTING)); // test fallback to node settings
}
public static IndexMetaData newIndexMeta(String name, Settings indexSettings) {
Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(indexSettings)
.build();
IndexMetaData metaData = IndexMetaData.builder(name).settings(build).build();
return metaData;
}
}