Normalize template index settings before validating

This commit is contained in:
Simon Willnauer 2016-01-18 14:38:29 +01:00
parent 3e6018fedb
commit dce29d29c0
7 changed files with 17 additions and 20 deletions

View File

@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService;
import org.elasticsearch.common.inject.Inject;
@ -72,11 +73,13 @@ public class TransportPutIndexTemplateAction extends TransportMasterNodeAction<P
if (cause.length() == 0) {
cause = "api";
}
indexScopeSettings.validate(request.settings());
final Settings.Builder templateSettingsBuilder = Settings.settingsBuilder();
templateSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX);
indexScopeSettings.validate(templateSettingsBuilder);
indexTemplateService.putTemplate(new MetaDataIndexTemplateService.PutRequest(cause, request.name())
.template(request.template())
.order(request.order())
.settings(request.settings())
.settings(templateSettingsBuilder.build())
.mappings(request.mappings())
.aliases(request.aliases())
.customs(request.customs())

View File

@ -181,7 +181,6 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
public static final String SETTING_VERSION_UPGRADED_STRING = "index.version.upgraded_string";
public static final String SETTING_VERSION_MINIMUM_COMPATIBLE = "index.version.minimum_compatible";
public static final String SETTING_CREATION_DATE = "index.creation_date";
public static final Setting<Long> INDEX_CREATION_DATE_SETTING = Setting.longSetting(SETTING_CREATION_DATE, -1, -1, false, Setting.Scope.INDEX);
public static final String SETTING_PRIORITY = "index.priority";
public static final Setting<Integer> INDEX_PRIORITY_SETTING = Setting.intSetting("index.priority", 1, 0, true, Setting.Scope.INDEX);
public static final String SETTING_CREATION_DATE_STRING = "index.creation_date_string";

View File

@ -76,7 +76,6 @@ public final class IndexScopeSettings extends AbstractScopedSettings {
IndexMetaData.INDEX_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE_SETTING,
IndexMetaData.INDEX_PRIORITY_SETTING,
IndexMetaData.INDEX_DATA_PATH_SETTING,
IndexMetaData.INDEX_CREATION_DATE_SETTING,
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING,
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING,
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING,

View File

@ -60,7 +60,7 @@ public abstract class PriorityComparator implements Comparator<ShardRouting> {
}
private long timeCreated(Settings settings) {
return IndexMetaData.INDEX_CREATION_DATE_SETTING.get(settings);
return settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1l);
}
protected abstract Settings getIndexSettings(String index);

View File

@ -52,19 +52,13 @@ import static org.hamcrest.core.IsNull.notNullValue;
@ClusterScope(scope = Scope.TEST)
public class CreateIndexIT extends ESIntegTestCase {
public void testCreationDateGiven() {
prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 4l)).get();
ClusterStateResponse response = client().admin().cluster().prepareState().get();
ClusterState state = response.getState();
assertThat(state, notNullValue());
MetaData metadata = state.getMetaData();
assertThat(metadata, notNullValue());
ImmutableOpenMap<String, IndexMetaData> indices = metadata.getIndices();
assertThat(indices, notNullValue());
assertThat(indices.size(), equalTo(1));
IndexMetaData index = indices.get("test");
assertThat(index, notNullValue());
assertThat(index.getCreationDate(), equalTo(4l));
public void testCreationDateGivenFails() {
try {
prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 4l)).get();
fail();
} catch (IllegalArgumentException ex) {
assertEquals("unknow setting [index.creation_date]", ex.getMessage());
}
}
public void testCreationDateGenerated() {

View File

@ -328,7 +328,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
.get();
fail();
} catch (IllegalArgumentException ex) {
assertEquals("unknown setting [does_not_exist]", ex.getMessage());
assertEquals("unknown setting [index.does_not_exist]", ex.getMessage());
}
response = client().admin().indices().prepareGetTemplates().get();

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.test;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.plugins.Plugin;
@ -35,10 +36,11 @@ public final class InternalSettingsPlugin extends Plugin {
private static final Setting<Integer> VERSION_CREATED = Setting.intSetting("index.version.created", 0, false, Setting.Scope.INDEX);
private static final Setting<Boolean> MERGE_ENABLED = Setting.boolSetting("index.merge.enabled", true, false, Setting.Scope.INDEX);
private static final Setting<Long> INDEX_CREATION_DATE_SETTING = Setting.longSetting(IndexMetaData.SETTING_CREATION_DATE, -1, -1, false, Setting.Scope.INDEX);
public void onModule(SettingsModule module) {
module.registerSetting(VERSION_CREATED);
module.registerSetting(MERGE_ENABLED);
module.registerSetting(INDEX_CREATION_DATE_SETTING);
}
}