Search in sources :

Example 81 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class AutoCreateIndexTests method testAutoCreationPatternDisabled.

public void testAutoCreationPatternDisabled() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "-index*").build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    expectForbidden(clusterState, autoCreateIndex, "index" + randomAsciiOfLengthBetween(1, 5), "-index*");
    /* When patterns are specified, even if the are all negative, the default is can't create. So a pure negative pattern is the same
         * as false, really. */
    expectNotMatch(clusterState, autoCreateIndex, "does_not_match" + randomAsciiOfLengthBetween(1, 5));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 82 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class AutoCreateIndexTests method testDynamicMappingDisabled.

public void testDynamicMappingDisabled() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom(true, randomAsciiOfLengthBetween(1, 10))).put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false).build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(randomAsciiOfLengthBetween(1, 10), buildClusterState()));
    assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 83 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class AutoCreateIndexTests method testParseFailedMissingIndex.

public void testParseFailedMissingIndex() {
    String prefix = randomFrom("+", "-");
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), prefix).build();
    try {
        newAutoCreateIndex(settings);
        fail("initialization should have failed");
    } catch (IllegalArgumentException ex) {
        assertEquals("Can't parse [" + prefix + "] for setting [action.auto_create_index] must contain an index name after [" + prefix + "]", ex.getMessage());
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 84 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class AutoCreateIndexTests method testExistingIndex.

public void testExistingIndex() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom(true, false, randomAsciiOfLengthBetween(7, 10))).build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    assertThat(autoCreateIndex.shouldAutoCreate(randomFrom("index1", "index2", "index3"), buildClusterState("index1", "index2", "index3")), equalTo(false));
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 85 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class AutoCreateIndexTests method testAutoCreationMultiplePatternsNoWildcards.

public void testAutoCreationMultiplePatternsNoWildcards() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "+test1,-index1").build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).metaData(MetaData.builder()).build();
    assertThat(autoCreateIndex.shouldAutoCreate("test1", clusterState), equalTo(true));
    expectNotMatch(clusterState, autoCreateIndex, "index" + randomAsciiOfLengthBetween(1, 5));
    expectNotMatch(clusterState, autoCreateIndex, "test" + randomAsciiOfLengthBetween(2, 5));
    expectNotMatch(clusterState, autoCreateIndex, "does_not_match" + randomAsciiOfLengthBetween(1, 5));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)1248 Test (org.junit.Test)197 IndexSettings (org.elasticsearch.index.IndexSettings)167 IOException (java.io.IOException)133 Path (java.nio.file.Path)121 ClusterState (org.elasticsearch.cluster.ClusterState)120 ArrayList (java.util.ArrayList)108 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)106 HashMap (java.util.HashMap)105 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)98 Version (org.elasticsearch.Version)91 Matchers.containsString (org.hamcrest.Matchers.containsString)91 Environment (org.elasticsearch.env.Environment)87 Map (java.util.Map)85 List (java.util.List)79 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 Index (org.elasticsearch.index.Index)70 HashSet (java.util.HashSet)58 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)54 ThreadPool (org.elasticsearch.threadpool.ThreadPool)54