Search in sources :

Example 6 with IndexScopedSettings

use of org.elasticsearch.common.settings.IndexScopedSettings in project elasticsearch by elastic.

the class IndexSettingsModule method newIndexSettings.

public static IndexSettings newIndexSettings(Index index, Settings indexSetting, Settings nodeSettings, Setting<?>... setting) {
    Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(indexSetting).build();
    IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
    Set<Setting<?>> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
    if (setting.length > 0) {
        settingSet.addAll(Arrays.asList(setting));
    }
    return new IndexSettings(metaData, nodeSettings, new IndexScopedSettings(Settings.EMPTY, settingSet));
}
Also used : IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Setting(org.elasticsearch.common.settings.Setting) IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) HashSet(java.util.HashSet)

Example 7 with IndexScopedSettings

use of org.elasticsearch.common.settings.IndexScopedSettings in project crate by crate.

the class MetadataCreateIndexService method onlyCreateIndex.

private void onlyCreateIndex(final NodeContext nodeContext, final CreateIndexClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {
    Settings.Builder updatedSettingsBuilder = Settings.builder();
    Settings build = updatedSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build();
    // we do validate here - index setting must be consistent
    indexScopedSettings.validate(build, true);
    request.settings(build);
    clusterService.submitStateUpdateTask("create-index [" + request.index() + "], cause [" + request.cause() + "]", new IndexCreationTask(LOGGER, allocationService, request, listener, indicesService, aliasValidator, xContentRegistry, settings, this::validate, indexScopedSettings, nodeContext, indexNameExpressionResolver));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings)

Example 8 with IndexScopedSettings

use of org.elasticsearch.common.settings.IndexScopedSettings in project crate by crate.

the class IndexSettingsModule method newIndexSettings.

public static IndexSettings newIndexSettings(Index index, Settings settings, IndexScopedSettings indexScopedSettings) {
    Settings build = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(settings).build();
    IndexMetadata metadata = IndexMetadata.builder(index.getName()).settings(build).build();
    return new IndexSettings(metadata, Settings.EMPTY, indexScopedSettings);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings)

Example 9 with IndexScopedSettings

use of org.elasticsearch.common.settings.IndexScopedSettings in project crate by crate.

the class IndexSettingsTests method testArchivedSettingsValidation.

@Test
public void testArchivedSettingsValidation() {
    final Settings settings = Settings.builder().put(AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX + "foo", System.currentTimeMillis()).build();
    final IndexScopedSettings indexScopedSettings = new IndexScopedSettings(settings, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
    {
        // validation should fail since we are not ignoring archived settings
        final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexScopedSettings.validate(settings, randomBoolean()));
        assertThat(e, hasToString(containsString("unknown setting [archived.foo]")));
    }
    {
        // validation should fail since we are not ignoring archived settings
        final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexScopedSettings.validate(settings, randomBoolean(), randomBoolean(), false));
        assertThat(e, hasToString(containsString("unknown setting [archived.foo]")));
    }
    // nothing should happen since we are ignoring archived settings
    indexScopedSettings.validate(settings, randomBoolean(), randomBoolean(), true);
}
Also used : IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) AbstractScopedSettings(org.elasticsearch.common.settings.AbstractScopedSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Test(org.junit.Test)

Example 10 with IndexScopedSettings

use of org.elasticsearch.common.settings.IndexScopedSettings in project crate by crate.

the class IndexSettingsTests method testPrivateSettingsValidation.

@Test
public void testPrivateSettingsValidation() {
    final Settings settings = Settings.builder().put(IndexMetadata.SETTING_CREATION_DATE, System.currentTimeMillis()).build();
    final IndexScopedSettings indexScopedSettings = new IndexScopedSettings(settings, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
    {
        // validation should fail since we are not ignoring private settings
        final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexScopedSettings.validate(settings, randomBoolean()));
        assertThat(e, hasToString(containsString("unknown setting [index.creation_date]")));
    }
    {
        // validation should fail since we are not ignoring private settings
        final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexScopedSettings.validate(settings, randomBoolean(), false, randomBoolean()));
        assertThat(e, hasToString(containsString("unknown setting [index.creation_date]")));
    }
    // nothing should happen since we are ignoring private settings
    indexScopedSettings.validate(settings, randomBoolean(), true, randomBoolean());
}
Also used : IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) AbstractScopedSettings(org.elasticsearch.common.settings.AbstractScopedSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Test(org.junit.Test)

Aggregations

IndexScopedSettings (org.elasticsearch.common.settings.IndexScopedSettings)15 Settings (org.elasticsearch.common.settings.Settings)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 IndexSettings (org.elasticsearch.index.IndexSettings)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Supplier (java.util.function.Supplier)3 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)3 SettingsFilter (org.elasticsearch.common.settings.SettingsFilter)3 ActionPlugin (org.elasticsearch.plugins.ActionPlugin)3 RestController (org.elasticsearch.rest.RestController)3 RestHandler (org.elasticsearch.rest.RestHandler)3 ThreadPool (org.elasticsearch.threadpool.ThreadPool)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 AliasValidator (org.elasticsearch.cluster.metadata.AliasValidator)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaDataCreateIndexService (org.elasticsearch.cluster.metadata.MetaDataCreateIndexService)2 MetaDataIndexTemplateService (org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService)2