Search in sources :

Example 56 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class RemoteClusterServiceTests method testBuiltRemoteClustersSeeds.

public void testBuiltRemoteClustersSeeds() throws Exception {
    Map<String, List<DiscoveryNode>> map = RemoteClusterService.buildRemoteClustersSeeds(Settings.builder().put("search.remote.foo.seeds", "192.168.0.1:8080").put("search.remote.bar.seeds", "[::1]:9090").build());
    assertEquals(2, map.size());
    assertTrue(map.containsKey("foo"));
    assertTrue(map.containsKey("bar"));
    assertEquals(1, map.get("foo").size());
    assertEquals(1, map.get("bar").size());
    DiscoveryNode foo = map.get("foo").get(0);
    assertEquals(foo.getAddress(), new TransportAddress(new InetSocketAddress(InetAddress.getByName("192.168.0.1"), 8080)));
    assertEquals(foo.getId(), "foo#192.168.0.1:8080");
    assertEquals(foo.getVersion(), Version.CURRENT.minimumCompatibilityVersion());
    DiscoveryNode bar = map.get("bar").get(0);
    assertEquals(bar.getAddress(), new TransportAddress(new InetSocketAddress(InetAddress.getByName("[::1]"), 9090)));
    assertEquals(bar.getId(), "bar#[::1]:9090");
    assertEquals(bar.getVersion(), Version.CURRENT.minimumCompatibilityVersion());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 57 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class RemoteClusterServiceTests method testGroupClusterIndices.

public void testGroupClusterIndices() throws IOException {
    List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    try (MockTransportService seedTransport = startTransport("cluster_1_node", knownNodes, Version.CURRENT);
        MockTransportService otherSeedTransport = startTransport("cluster_2_node", knownNodes, Version.CURRENT)) {
        DiscoveryNode seedNode = seedTransport.getLocalDiscoNode();
        DiscoveryNode otherSeedNode = otherSeedTransport.getLocalDiscoNode();
        knownNodes.add(seedTransport.getLocalDiscoNode());
        knownNodes.add(otherSeedTransport.getLocalDiscoNode());
        Collections.shuffle(knownNodes, random());
        try (MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
            transportService.start();
            transportService.acceptIncomingRequests();
            Settings.Builder builder = Settings.builder();
            builder.putArray("search.remote.cluster_1.seeds", seedNode.getAddress().toString());
            builder.putArray("search.remote.cluster_2.seeds", otherSeedNode.getAddress().toString());
            try (RemoteClusterService service = new RemoteClusterService(builder.build(), transportService)) {
                assertFalse(service.isCrossClusterSearchEnabled());
                service.initializeRemoteClusters();
                assertTrue(service.isCrossClusterSearchEnabled());
                assertTrue(service.isRemoteClusterRegistered("cluster_1"));
                assertTrue(service.isRemoteClusterRegistered("cluster_2"));
                assertFalse(service.isRemoteClusterRegistered("foo"));
                Map<String, List<String>> perClusterIndices = service.groupClusterIndices(new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }, i -> false);
                String[] localIndices = perClusterIndices.computeIfAbsent(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, k -> Collections.emptyList()).toArray(new String[0]);
                assertNotNull(perClusterIndices.remove(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY));
                assertArrayEquals(new String[] { "foo:bar", "foo" }, localIndices);
                assertEquals(2, perClusterIndices.size());
                assertEquals(Arrays.asList("bar", "test"), perClusterIndices.get("cluster_1"));
                assertEquals(Arrays.asList("foo:bar", "foo*"), perClusterIndices.get("cluster_2"));
                IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> service.groupClusterIndices(new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }, i -> "cluster_1:bar".equals(i)));
                assertEquals("Can not filter indices; index cluster_1:bar exists but there is also a remote cluster named:" + " cluster_1", iae.getMessage());
            }
        }
    }
}
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) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 58 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class RemoteClusterServiceTests method testIncrementallyAddClusters.

public void testIncrementallyAddClusters() throws IOException {
    List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    try (MockTransportService seedTransport = startTransport("cluster_1_node", knownNodes, Version.CURRENT);
        MockTransportService otherSeedTransport = startTransport("cluster_2_node", knownNodes, Version.CURRENT)) {
        DiscoveryNode seedNode = seedTransport.getLocalDiscoNode();
        DiscoveryNode otherSeedNode = otherSeedTransport.getLocalDiscoNode();
        knownNodes.add(seedTransport.getLocalDiscoNode());
        knownNodes.add(otherSeedTransport.getLocalDiscoNode());
        Collections.shuffle(knownNodes, random());
        try (MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
            transportService.start();
            transportService.acceptIncomingRequests();
            Settings.Builder builder = Settings.builder();
            builder.putArray("search.remote.cluster_1.seeds", seedNode.getAddress().toString());
            builder.putArray("search.remote.cluster_2.seeds", otherSeedNode.getAddress().toString());
            try (RemoteClusterService service = new RemoteClusterService(Settings.EMPTY, transportService)) {
                assertFalse(service.isCrossClusterSearchEnabled());
                service.initializeRemoteClusters();
                assertFalse(service.isCrossClusterSearchEnabled());
                service.updateRemoteCluster("cluster_1", Collections.singletonList(seedNode.getAddress().address()));
                assertTrue(service.isCrossClusterSearchEnabled());
                assertTrue(service.isRemoteClusterRegistered("cluster_1"));
                service.updateRemoteCluster("cluster_2", Collections.singletonList(otherSeedNode.getAddress().address()));
                assertTrue(service.isCrossClusterSearchEnabled());
                assertTrue(service.isRemoteClusterRegistered("cluster_1"));
                assertTrue(service.isRemoteClusterRegistered("cluster_2"));
                service.updateRemoteCluster("cluster_2", Collections.emptyList());
                assertFalse(service.isRemoteClusterRegistered("cluster_2"));
                IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> service.updateRemoteCluster(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, Collections.emptyList()));
                assertEquals("remote clusters must not have the empty string as its key", iae.getMessage());
            }
        }
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 59 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class NodeConnectionsServiceTests method testReconnect.

public void testReconnect() {
    List<DiscoveryNode> nodes = generateNodes();
    NodeConnectionsService service = new NodeConnectionsService(Settings.EMPTY, threadPool, transportService);
    ClusterState current = clusterStateFromNodes(Collections.emptyList());
    ClusterChangedEvent event = new ClusterChangedEvent("test", clusterStateFromNodes(randomSubsetOf(nodes)), current);
    transport.randomConnectionExceptions = true;
    service.connectToNodes(event.state().nodes());
    for (int i = 0; i < 3; i++) {
        // simulate disconnects
        for (DiscoveryNode node : randomSubsetOf(nodes)) {
            transport.disconnectFromNode(node);
        }
        service.new ConnectionChecker().run();
    }
    // disable exceptions so things can be restored
    transport.randomConnectionExceptions = false;
    service.new ConnectionChecker().run();
    assertConnectedExactlyToNodes(event.state());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode)

Example 60 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class ClusterRerouteIT method testClusterRerouteWithBlocks.

public void testClusterRerouteWithBlocks() throws Exception {
    List<String> nodesIds = internalCluster().startNodes(2);
    logger.info("--> create an index with 1 shard and 0 replicas");
    assertAcked(prepareCreate("test-blocks").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)));
    ensureGreen("test-blocks");
    logger.info("--> check that the index has 1 shard");
    ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
    List<ShardRouting> shards = state.routingTable().allShards("test-blocks");
    assertThat(shards, hasSize(1));
    logger.info("--> check that the shard is allocated");
    ShardRouting shard = shards.get(0);
    assertThat(shard.assignedToNode(), equalTo(true));
    logger.info("--> retrieve the node where the shard is allocated");
    DiscoveryNode node = state.nodes().resolveNode(shard.currentNodeId());
    assertNotNull(node);
    // toggle is used to mve the shard from one node to another
    int toggle = nodesIds.indexOf(node.getName());
    // Rerouting shards is not blocked
    for (String blockSetting : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) {
        try {
            enableIndexBlock("test-blocks", blockSetting);
            assertAcked(client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test-blocks", 0, nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2))));
            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForYellowStatus().setWaitForNoRelocatingShards(true).execute().actionGet();
            assertThat(healthResponse.isTimedOut(), equalTo(false));
        } finally {
            disableIndexBlock("test-blocks", blockSetting);
        }
    }
    // Rerouting shards is blocked when the cluster is read only
    try {
        setClusterReadOnly(true);
        assertBlocked(client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test-blocks", 1, nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2))));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)352 ClusterState (org.elasticsearch.cluster.ClusterState)83 ArrayList (java.util.ArrayList)82 Settings (org.elasticsearch.common.settings.Settings)79 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)74 IOException (java.io.IOException)69 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)52 HashMap (java.util.HashMap)45 ShardId (org.elasticsearch.index.shard.ShardId)45 HashSet (java.util.HashSet)43 List (java.util.List)41 TransportAddress (org.elasticsearch.common.transport.TransportAddress)41 CountDownLatch (java.util.concurrent.CountDownLatch)39 MockTransportService (org.elasticsearch.test.transport.MockTransportService)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)37 Map (java.util.Map)35 ExecutionException (java.util.concurrent.ExecutionException)35 Version (org.elasticsearch.Version)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 ClusterName (org.elasticsearch.cluster.ClusterName)30