Search in sources :

Example 46 with Settings

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

the class RoutingBackwardCompatibilityTests method testBackwardCompatibility.

public void testBackwardCompatibility() throws Exception {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) {
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            if (line.startsWith("#")) {
                // comment
                continue;
            }
            String[] parts = line.split("\t");
            assertEquals(Arrays.toString(parts), 7, parts.length);
            final String index = parts[0];
            final int numberOfShards = Integer.parseInt(parts[1]);
            final String type = parts[2];
            final String id = parts[3];
            final String routing = "null".equals(parts[4]) ? null : parts[4];
            // not needed anymore - old hashing is gone
            final int pre20ExpectedShardId = Integer.parseInt(parts[5]);
            final int currentExpectedShard = Integer.parseInt(parts[6]);
            OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
            for (Version version : VersionUtils.allReleasedVersions()) {
                if (version.onOrAfter(Version.V_2_0_0) == false) {
                    // unsupported version, no need to test
                    continue;
                }
                final Settings settings = settings(version).build();
                IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build();
                MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false);
                RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
                ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
                final int shardId = operationRouting.indexShards(clusterState, index, id, routing).shardId().getId();
                assertEquals(currentExpectedShard, shardId);
            }
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) InputStreamReader(java.io.InputStreamReader) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Version(org.elasticsearch.Version) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) BufferedReader(java.io.BufferedReader) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 47 with Settings

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

the class UnassignedInfoTests method testRemainingDelayCalculation.

/**
     * Verifies that delayed allocation calculation are correct.
     */
public void testRemainingDelayCalculation() throws Exception {
    final long baseTime = System.nanoTime();
    UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "test", null, 0, baseTime, System.currentTimeMillis(), randomBoolean(), AllocationStatus.NO_ATTEMPT);
    final long totalDelayNanos = TimeValue.timeValueMillis(10).nanos();
    final Settings indexSettings = Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueNanos(totalDelayNanos)).build();
    long delay = unassignedInfo.getRemainingDelay(baseTime, indexSettings);
    assertThat(delay, equalTo(totalDelayNanos));
    long delta1 = randomIntBetween(1, (int) (totalDelayNanos - 1));
    delay = unassignedInfo.getRemainingDelay(baseTime + delta1, indexSettings);
    assertThat(delay, equalTo(totalDelayNanos - delta1));
    delay = unassignedInfo.getRemainingDelay(baseTime + totalDelayNanos, indexSettings);
    assertThat(delay, equalTo(0L));
    delay = unassignedInfo.getRemainingDelay(baseTime + totalDelayNanos + randomIntBetween(1, 20), indexSettings);
    assertThat(delay, equalTo(0L));
}
Also used : Settings(org.elasticsearch.common.settings.Settings)

Example 48 with Settings

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

the class DiscoveryNodeFiltersTests method testIpBindFilteringMatchingAnd.

public void testIpBindFilteringMatchingAnd() {
    Settings settings = shuffleSettings(Settings.builder().put("xxx.tag", "A").put("xxx." + randomFrom("_ip", "_host_ip", "_publish_ip"), "192.1.1.54").build());
    DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
    DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null);
    assertThat(filters.match(node), equalTo(true));
}
Also used : Settings(org.elasticsearch.common.settings.Settings)

Example 49 with Settings

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

the class DiscoveryNodeFiltersTests method testIdMatch.

public void testIdMatch() {
    Settings settings = Settings.builder().put("xxx._id", "id1").build();
    DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(OR, "xxx.", settings);
    DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    assertThat(filters.match(node), equalTo(true));
    node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    assertThat(filters.match(node), equalTo(false));
}
Also used : Settings(org.elasticsearch.common.settings.Settings)

Example 50 with Settings

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

the class DiscoveryNodeFiltersTests method testIpPublishFilteringNotMatchingAnd.

public void testIpPublishFilteringNotMatchingAnd() {
    Settings settings = shuffleSettings(Settings.builder().put("xxx.tag", "A").put("xxx._publish_ip", "8.8.8.8").build());
    DiscoveryNodeFilters filters = DiscoveryNodeFilters.buildFromSettings(AND, "xxx.", settings);
    DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null);
    assertThat(filters.match(node), equalTo(false));
}
Also used : Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)874 IndexSettings (org.elasticsearch.index.IndexSettings)112 Path (java.nio.file.Path)91 IOException (java.io.IOException)83 ClusterState (org.elasticsearch.cluster.ClusterState)76 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)68 HashMap (java.util.HashMap)66 ArrayList (java.util.ArrayList)65 Version (org.elasticsearch.Version)63 Environment (org.elasticsearch.env.Environment)63 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)61 Test (org.junit.Test)60 Map (java.util.Map)55 Index (org.elasticsearch.index.Index)55 Matchers.containsString (org.hamcrest.Matchers.containsString)54 List (java.util.List)45 ThreadPool (org.elasticsearch.threadpool.ThreadPool)41 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)37 MetaData (org.elasticsearch.cluster.metadata.MetaData)36