Search in sources :

Example 76 with Settings

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

the class TcpTransport method buildProfileSettings.

protected Map<String, Settings> buildProfileSettings() {
    // extract default profile first and create standard bootstrap
    Map<String, Settings> profiles = TransportSettings.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups(true);
    if (!profiles.containsKey(TransportSettings.DEFAULT_PROFILE)) {
        profiles = new HashMap<>(profiles);
        profiles.put(TransportSettings.DEFAULT_PROFILE, Settings.EMPTY);
    }
    Settings defaultSettings = profiles.get(TransportSettings.DEFAULT_PROFILE);
    Map<String, Settings> result = new HashMap<>();
    // loop through all profiles and start them up, special handling for default one
    for (Map.Entry<String, Settings> entry : profiles.entrySet()) {
        Settings profileSettings = entry.getValue();
        String name = entry.getKey();
        if (!Strings.hasLength(name)) {
            logger.info("transport profile configured without a name. skipping profile with settings [{}]", profileSettings.toDelimitedString(','));
            continue;
        } else if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
            profileSettings = Settings.builder().put(profileSettings).put("port", profileSettings.get("port", TransportSettings.PORT.get(this.settings))).build();
        } else if (profileSettings.get("port") == null) {
            // if profile does not have a port, skip it
            logger.info("No port configured for profile [{}], not binding", name);
            continue;
        }
        Settings mergedSettings = Settings.builder().put(defaultSettings).put(profileSettings).build();
        result.put(name, mergedSettings);
    }
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentCollections.newConcurrentMap(org.elasticsearch.common.util.concurrent.ConcurrentCollections.newConcurrentMap) Map(java.util.Map) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) Settings(org.elasticsearch.common.settings.Settings)

Example 77 with Settings

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

the class RemoteClusterServiceTests method testRemoteClusterSeedSetting.

public void testRemoteClusterSeedSetting() {
    // simple validation
    Settings settings = Settings.builder().put("search.remote.foo.seeds", "192.168.0.1:8080").put("search.remote.bar.seed", "[::1]:9090").build();
    RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getAllConcreteSettings(settings).forEach(setting -> setting.get(settings));
    Settings brokenSettings = Settings.builder().put("search.remote.foo.seeds", "192.168.0.1").build();
    expectThrows(IllegalArgumentException.class, () -> RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getAllConcreteSettings(brokenSettings).forEach(setting -> setting.get(brokenSettings)));
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) HashMap(java.util.HashMap) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Strings(org.elasticsearch.common.Strings) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ClusterSearchShardsGroup(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOException(java.io.IOException) InetSocketAddress(java.net.InetSocketAddress) ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse) TimeUnit(java.util.concurrent.TimeUnit) AliasFilter(org.elasticsearch.search.internal.AliasFilter) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) List(java.util.List) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) Collections(java.util.Collections) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 78 with Settings

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

the class MainActionTests method testMainActionClusterAvailable.

public void testMainActionClusterAvailable() {
    final ClusterService clusterService = mock(ClusterService.class);
    final ClusterName clusterName = new ClusterName("elasticsearch");
    final Settings settings = Settings.builder().put("node.name", "my-node").build();
    final boolean available = randomBoolean();
    ClusterBlocks blocks;
    if (available) {
        if (randomBoolean()) {
            blocks = ClusterBlocks.EMPTY_CLUSTER_BLOCK;
        } else {
            blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 400", randomBoolean(), randomBoolean(), RestStatus.BAD_REQUEST, ClusterBlockLevel.ALL)).build();
        }
    } else {
        blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 503", randomBoolean(), randomBoolean(), RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL)).build();
    }
    ClusterState state = ClusterState.builder(clusterName).blocks(blocks).build();
    when(clusterService.state()).thenReturn(state);
    TransportService transportService = new TransportService(Settings.EMPTY, null, null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    TransportMainAction action = new TransportMainAction(settings, mock(ThreadPool.class), transportService, mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), clusterService);
    AtomicReference<MainResponse> responseRef = new AtomicReference<>();
    action.doExecute(new MainRequest(), new ActionListener<MainResponse>() {

        @Override
        public void onResponse(MainResponse mainResponse) {
            responseRef.set(mainResponse);
        }

        @Override
        public void onFailure(Exception e) {
            logger.error("unexpected error", e);
        }
    });
    assertNotNull(responseRef.get());
    assertEquals(available, responseRef.get().isAvailable());
    verify(clusterService, times(1)).state();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ThreadPool(org.elasticsearch.threadpool.ThreadPool) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionFilters(org.elasticsearch.action.support.ActionFilters) IOException(java.io.IOException) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings)

Example 79 with Settings

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

the class ActiveShardsObserverIT method testCreateIndexNoActiveShardsTimesOut.

public void testCreateIndexNoActiveShardsTimesOut() throws Exception {
    Settings.Builder settingsBuilder = Settings.builder().put(indexSettings()).put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5)).put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0);
    if (internalCluster().getNodeNames().length > 0) {
        String exclude = String.join(",", internalCluster().getNodeNames());
        settingsBuilder.put("index.routing.allocation.exclude._name", exclude);
    }
    Settings settings = settingsBuilder.build();
    final String indexName = "test-idx";
    assertFalse(prepareCreate(indexName).setSettings(settings).setWaitForActiveShards(randomBoolean() ? ActiveShardCount.from(1) : ActiveShardCount.ALL).setTimeout("100ms").get().isShardsAcked());
    waitForIndexCreationToComplete(indexName);
}
Also used : Settings(org.elasticsearch.common.settings.Settings)

Example 80 with Settings

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

the class ActiveShardsObserverIT method testCreateIndexWaitsForAllActiveShards.

public void testCreateIndexWaitsForAllActiveShards() throws Exception {
    // not enough data nodes, index creation times out
    final int numReplicas = internalCluster().numDataNodes() + randomInt(4);
    Settings settings = Settings.builder().put(indexSettings()).put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5)).put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), numReplicas).build();
    final String indexName = "test-idx";
    assertFalse(prepareCreate(indexName).setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).setTimeout("100ms").get().isShardsAcked());
    waitForIndexCreationToComplete(indexName);
    if (client().admin().indices().prepareExists(indexName).get().isExists()) {
        client().admin().indices().prepareDelete(indexName).get();
    }
    // enough data nodes, all shards are active
    settings = Settings.builder().put(indexSettings()).put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 7)).put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() - 1).build();
    assertAcked(prepareCreate(indexName).setSettings(settings).setWaitForActiveShards(ActiveShardCount.ALL).get());
}
Also used : 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