Search in sources :

Example 1 with UNICAST_HOSTS_FILE

use of org.elasticsearch.discovery.FileBasedSeedHostsProvider.UNICAST_HOSTS_FILE in project crate by crate.

the class InternalTestCluster method rebuildUnicastHostFiles.

private void rebuildUnicastHostFiles(List<NodeAndClient> newNodes) {
    // cannot be a synchronized method since it's called on other threads from within synchronized startAndPublishNodesAndClients()
    synchronized (discoveryFileMutex) {
        try {
            final Collection<NodeAndClient> currentNodes = nodes.values();
            Stream<NodeAndClient> unicastHosts = Stream.concat(currentNodes.stream(), newNodes.stream());
            List<String> discoveryFileContents = unicastHosts.map(nac -> nac.node.injector().getInstance(TransportService.class)).filter(Objects::nonNull).map(TransportService::getLocalNode).filter(Objects::nonNull).filter(DiscoveryNode::isMasterEligibleNode).map(n -> n.getAddress().toString()).distinct().collect(Collectors.toList());
            Set<Path> configPaths = Stream.concat(currentNodes.stream(), newNodes.stream()).map(nac -> nac.node.getEnvironment().configFile()).collect(Collectors.toSet());
            logger.debug("configuring discovery with {} at {}", discoveryFileContents, configPaths);
            for (final Path configPath : configPaths) {
                Files.createDirectories(configPath);
                Files.write(configPath.resolve(UNICAST_HOSTS_FILE), discoveryFileContents);
            }
        } catch (IOException e) {
            throw new AssertionError("failed to configure file-based discovery", e);
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Releasables(org.elasticsearch.common.lease.Releasables) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Matchers.not(org.hamcrest.Matchers.not) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ClusterBootstrapService(org.elasticsearch.cluster.coordination.ClusterBootstrapService) TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING) NodeValidationException(org.elasticsearch.node.NodeValidationException) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) AddVotingConfigExclusionsRequest(org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest) Future(java.util.concurrent.Future) ClusterState(org.elasticsearch.cluster.ClusterState) RandomNumbers(com.carrotsearch.randomizedtesting.generators.RandomNumbers) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) Path(java.nio.file.Path) INITIAL_MASTER_NODES_SETTING(org.elasticsearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING) RandomStrings(com.carrotsearch.randomizedtesting.generators.RandomStrings) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) INITIAL_STATE_TIMEOUT_SETTING(org.elasticsearch.node.Node.INITIAL_STATE_TIMEOUT_SETTING) Set(java.util.Set) ESTestCase.assertBusy(org.elasticsearch.test.ESTestCase.assertBusy) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) TransportSettings(org.elasticsearch.transport.TransportSettings) ZEN2_DISCOVERY_TYPE(org.elasticsearch.discovery.DiscoveryModule.ZEN2_DISCOVERY_TYPE) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) IntObjectCursor(com.carrotsearch.hppc.cursors.IntObjectCursor) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) RandomPicks(com.carrotsearch.randomizedtesting.generators.RandomPicks) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) ClusterService(org.elasticsearch.cluster.service.ClusterService) ArrayList(java.util.ArrayList) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) Nullable(javax.annotation.Nullable) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) FutureUtils(org.elasticsearch.common.util.concurrent.FutureUtils) SequenceNumbers(org.elasticsearch.index.seqno.SequenceNumbers) Files(java.nio.file.Files) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(io.crate.common.io.IOUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) SeedUtils(com.carrotsearch.randomizedtesting.SeedUtils) ExecutionException(java.util.concurrent.ExecutionException) LuceneTestCase.rarely(org.apache.lucene.util.LuceneTestCase.rarely) UNICAST_HOSTS_FILE(org.elasticsearch.discovery.FileBasedSeedHostsProvider.UNICAST_HOSTS_FILE) InternalEngine(org.elasticsearch.index.engine.InternalEngine) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) TreeMap(java.util.TreeMap) Randomness(org.elasticsearch.common.Randomness) Assert.assertEquals(org.junit.Assert.assertEquals) Builder(org.elasticsearch.common.settings.Settings.Builder) Environment(org.elasticsearch.env.Environment) Random(java.util.Random) TEST_NIGHTLY(org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY) Assert.assertThat(org.junit.Assert.assertThat) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClearVotingConfigExclusionsRequest(org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) Assert.fail(org.junit.Assert.fail) ClusterName(org.elasticsearch.cluster.ClusterName) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) AddVotingConfigExclusionsAction(org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) NavigableMap(java.util.NavigableMap) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Engine(org.elasticsearch.index.engine.Engine) Objects(java.util.Objects) ESTestCase.randomFrom(org.elasticsearch.test.ESTestCase.randomFrom) List(java.util.List) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) IntStream(java.util.stream.IntStream) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) CommitStats(org.elasticsearch.index.engine.CommitStats) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ClearVotingConfigExclusionsAction(org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction) Index(org.elasticsearch.index.Index) Strings(org.elasticsearch.common.Strings) HashSet(java.util.HashSet) Node(org.elasticsearch.node.Node) DocIdSeqNoAndSource(org.elasticsearch.index.engine.DocIdSeqNoAndSource) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ExecutorService(java.util.concurrent.ExecutorService) TimeValue.timeValueSeconds(io.crate.common.unit.TimeValue.timeValueSeconds) MockNode(org.elasticsearch.node.MockNode) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Iterator(java.util.Iterator) Plugin(org.elasticsearch.plugins.Plugin) TimeUnit(java.util.concurrent.TimeUnit) IndexShardTestCase(org.elasticsearch.index.shard.IndexShardTestCase) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) DISCOVERY_TYPE_SETTING(org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_TYPE_SETTING) Closeable(java.io.Closeable) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Path(java.nio.file.Path) Objects(java.util.Objects) IOException(java.io.IOException)

Aggregations

ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 IntObjectCursor (com.carrotsearch.hppc.cursors.IntObjectCursor)1 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 SeedUtils (com.carrotsearch.randomizedtesting.SeedUtils)1 RandomNumbers (com.carrotsearch.randomizedtesting.generators.RandomNumbers)1 RandomPicks (com.carrotsearch.randomizedtesting.generators.RandomPicks)1 RandomStrings (com.carrotsearch.randomizedtesting.generators.RandomStrings)1 IOUtils (io.crate.common.io.IOUtils)1 TimeValue (io.crate.common.unit.TimeValue)1 TimeValue.timeValueSeconds (io.crate.common.unit.TimeValue.timeValueSeconds)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1