Search in sources :

Example 96 with DiscoveryNode

use of org.opensearch.cluster.node.DiscoveryNode in project OpenSearch by opensearch-project.

the class RemoteClusterServiceTests method testRemoteNodeRoles.

public void testRemoteNodeRoles() throws IOException, InterruptedException {
    final Settings settings = Settings.EMPTY;
    final List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    final Settings data = nonMasterNode();
    final Settings dedicatedMaster = masterOnlyNode();
    try (MockTransportService c1N1 = startTransport("cluster_1_node_1", knownNodes, Version.CURRENT, dedicatedMaster);
        MockTransportService c1N2 = startTransport("cluster_1_node_2", knownNodes, Version.CURRENT, data);
        MockTransportService c2N1 = startTransport("cluster_2_node_1", knownNodes, Version.CURRENT, dedicatedMaster);
        MockTransportService c2N2 = startTransport("cluster_2_node_2", knownNodes, Version.CURRENT, data)) {
        final DiscoveryNode c1N1Node = c1N1.getLocalDiscoNode();
        final DiscoveryNode c1N2Node = c1N2.getLocalDiscoNode();
        final DiscoveryNode c2N1Node = c2N1.getLocalDiscoNode();
        final DiscoveryNode c2N2Node = c2N2.getLocalDiscoNode();
        knownNodes.add(c1N1Node);
        knownNodes.add(c1N2Node);
        knownNodes.add(c2N1Node);
        knownNodes.add(c2N2Node);
        Collections.shuffle(knownNodes, random());
        try (MockTransportService transportService = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) {
            transportService.start();
            transportService.acceptIncomingRequests();
            final Settings.Builder builder = Settings.builder();
            builder.putList("cluster.remote.cluster_1.seed", c1N1Node.getAddress().toString());
            builder.putList("cluster.remote.cluster_2.seed", c2N1Node.getAddress().toString());
            try (RemoteClusterService service = new RemoteClusterService(settings, transportService)) {
                assertFalse(service.isCrossClusterSearchEnabled());
                service.initializeRemoteClusters();
                assertFalse(service.isCrossClusterSearchEnabled());
                final CountDownLatch firstLatch = new CountDownLatch(1);
                service.updateRemoteCluster("cluster_1", createSettings("cluster_1", Arrays.asList(c1N1Node.getAddress().toString(), c1N2Node.getAddress().toString())), connectionListener(firstLatch));
                firstLatch.await();
                final CountDownLatch secondLatch = new CountDownLatch(1);
                service.updateRemoteCluster("cluster_2", createSettings("cluster_2", Arrays.asList(c2N1Node.getAddress().toString(), c2N2Node.getAddress().toString())), connectionListener(secondLatch));
                secondLatch.await();
                assertTrue(service.isCrossClusterSearchEnabled());
                assertTrue(service.isRemoteClusterRegistered("cluster_1"));
                assertFalse(service.isRemoteNodeConnected("cluster_1", c1N1Node));
                assertTrue(service.isRemoteNodeConnected("cluster_1", c1N2Node));
                assertTrue(service.isRemoteClusterRegistered("cluster_2"));
                assertFalse(service.isRemoteNodeConnected("cluster_2", c2N1Node));
                assertTrue(service.isRemoteNodeConnected("cluster_2", c2N2Node));
                assertEquals(0, transportService.getConnectionManager().size());
            }
        }
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 97 with DiscoveryNode

use of org.opensearch.cluster.node.DiscoveryNode in project OpenSearch by opensearch-project.

the class RemoteClusterServiceTests method testCustomPingSchedule.

public void testCustomPingSchedule() throws IOException {
    List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    try (MockTransportService cluster1Transport = startTransport("cluster_1_node", knownNodes, Version.CURRENT);
        MockTransportService cluster2Transport = startTransport("cluster_2_node", knownNodes, Version.CURRENT)) {
        DiscoveryNode cluster1Seed = cluster1Transport.getLocalDiscoNode();
        DiscoveryNode cluster2Seed = cluster2Transport.getLocalDiscoNode();
        knownNodes.add(cluster1Transport.getLocalDiscoNode());
        knownNodes.add(cluster2Transport.getLocalDiscoNode());
        Collections.shuffle(knownNodes, random());
        Settings.Builder settingsBuilder = Settings.builder();
        if (randomBoolean()) {
            settingsBuilder.put(TransportSettings.PING_SCHEDULE.getKey(), TimeValue.timeValueSeconds(randomIntBetween(1, 10)));
        }
        Settings transportSettings = settingsBuilder.build();
        try (MockTransportService transportService = MockTransportService.createNewService(transportSettings, Version.CURRENT, threadPool, null)) {
            transportService.start();
            transportService.acceptIncomingRequests();
            Settings.Builder builder = Settings.builder();
            builder.putList("cluster.remote.cluster_1.seeds", cluster1Seed.getAddress().toString());
            builder.putList("cluster.remote.cluster_2.seeds", cluster2Seed.getAddress().toString());
            // randomBoolean() ? TimeValue.MINUS_ONE :
            TimeValue pingSchedule1 = TimeValue.timeValueSeconds(randomIntBetween(1, 10));
            builder.put("cluster.remote.cluster_1.transport.ping_schedule", pingSchedule1);
            // randomBoolean() ? TimeValue.MINUS_ONE :
            TimeValue pingSchedule2 = TimeValue.timeValueSeconds(randomIntBetween(1, 10));
            builder.put("cluster.remote.cluster_2.transport.ping_schedule", pingSchedule2);
            try (RemoteClusterService service = new RemoteClusterService(builder.build(), transportService)) {
                service.initializeRemoteClusters();
                assertTrue(service.isRemoteClusterRegistered("cluster_1"));
                RemoteClusterConnection remoteClusterConnection1 = service.getRemoteClusterConnection("cluster_1");
                assertEquals(pingSchedule1, remoteClusterConnection1.getConnectionManager().getConnectionProfile().getPingInterval());
                RemoteClusterConnection remoteClusterConnection2 = service.getRemoteClusterConnection("cluster_2");
                assertEquals(pingSchedule2, remoteClusterConnection2.getConnectionManager().getConnectionProfile().getPingInterval());
            }
        }
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 98 with DiscoveryNode

use of org.opensearch.cluster.node.DiscoveryNode in project OpenSearch by opensearch-project.

the class RemoteClusterConnectionTests method testGetConnectionInfo.

public void testGetConnectionInfo() throws Exception {
    List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    try (MockTransportService transport1 = startTransport("seed_node", knownNodes, Version.CURRENT);
        MockTransportService transport2 = startTransport("seed_node_1", knownNodes, Version.CURRENT);
        MockTransportService transport3 = startTransport("discoverable_node", knownNodes, Version.CURRENT)) {
        DiscoveryNode node1 = transport1.getLocalDiscoNode();
        DiscoveryNode node2 = transport3.getLocalDiscoNode();
        DiscoveryNode node3 = transport2.getLocalDiscoNode();
        knownNodes.add(transport1.getLocalDiscoNode());
        knownNodes.add(transport3.getLocalDiscoNode());
        knownNodes.add(transport2.getLocalDiscoNode());
        Collections.shuffle(knownNodes, random());
        List<String> seedNodes = addresses(node3, node1, node2);
        Collections.shuffle(seedNodes, random());
        try (MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
            service.start();
            service.acceptIncomingRequests();
            int maxNumConnections = randomIntBetween(1, 5);
            String clusterAlias = "test-cluster";
            Settings settings = Settings.builder().put(buildSniffSettings(clusterAlias, seedNodes)).put(SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER.getKey(), maxNumConnections).build();
            try (RemoteClusterConnection connection = new RemoteClusterConnection(settings, clusterAlias, service)) {
                // test no nodes connected
                RemoteConnectionInfo remoteConnectionInfo = assertSerialization(connection.getConnectionInfo());
                assertNotNull(remoteConnectionInfo);
                SniffConnectionStrategy.SniffModeInfo sniffInfo = (SniffConnectionStrategy.SniffModeInfo) remoteConnectionInfo.modeInfo;
                assertEquals(0, sniffInfo.numNodesConnected);
                assertEquals(3, sniffInfo.seedNodes.size());
                assertEquals(maxNumConnections, sniffInfo.maxConnectionsPerCluster);
                assertEquals(clusterAlias, remoteConnectionInfo.clusterAlias);
            }
        }
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 99 with DiscoveryNode

use of org.opensearch.cluster.node.DiscoveryNode in project OpenSearch by opensearch-project.

the class TransportServiceHandshakeTests method testIncompatibleVersions.

public void testIncompatibleVersions() {
    Settings settings = Settings.builder().put("cluster.name", "test").build();
    NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT);
    NetworkHandle handleB = startServices("TS_B", settings, VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()));
    DiscoveryNode discoveryNode = new DiscoveryNode("", handleB.discoveryNode.getAddress(), emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion());
    IllegalStateException ex = expectThrows(IllegalStateException.class, () -> {
        try (Transport.Connection connection = handleA.transportService.openConnection(discoveryNode, TestProfiles.LIGHT_PROFILE)) {
            PlainActionFuture.get(fut -> handleA.transportService.handshake(connection, timeout, ActionListener.map(fut, x -> null)));
        }
    });
    assertThat(ex.getMessage(), containsString("handshake with [" + discoveryNode + "] failed: remote node version [" + handleB.discoveryNode.getVersion() + "] is incompatible with local node version [" + Version.CURRENT + "]"));
    assertFalse(handleA.transportService.nodeConnected(discoveryNode));
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) Settings(org.opensearch.common.settings.Settings)

Example 100 with DiscoveryNode

use of org.opensearch.cluster.node.DiscoveryNode in project OpenSearch by opensearch-project.

the class TransportServiceHandshakeTests method testMismatchedClusterName.

public void testMismatchedClusterName() {
    NetworkHandle handleA = startServices("TS_A", Settings.builder().put("cluster.name", "a").build(), Version.CURRENT);
    NetworkHandle handleB = startServices("TS_B", Settings.builder().put("cluster.name", "b").build(), Version.CURRENT);
    DiscoveryNode discoveryNode = new DiscoveryNode("", handleB.discoveryNode.getAddress(), emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion());
    IllegalStateException ex = expectThrows(IllegalStateException.class, () -> {
        try (Transport.Connection connection = handleA.transportService.openConnection(discoveryNode, TestProfiles.LIGHT_PROFILE)) {
            PlainActionFuture.get(fut -> handleA.transportService.handshake(connection, timeout, ActionListener.map(fut, x -> null)));
        }
    });
    assertThat(ex.getMessage(), containsString("handshake with [" + discoveryNode + "] failed: remote cluster name [b] does not match local cluster name [a]"));
    assertFalse(handleA.transportService.nodeConnected(discoveryNode));
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockNioTransport(org.opensearch.transport.nio.MockNioTransport)

Aggregations

DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)673 ClusterState (org.opensearch.cluster.ClusterState)164 Settings (org.opensearch.common.settings.Settings)152 ArrayList (java.util.ArrayList)137 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)123 ThreadPool (org.opensearch.threadpool.ThreadPool)103 ClusterService (org.opensearch.cluster.service.ClusterService)100 CountDownLatch (java.util.concurrent.CountDownLatch)98 HashSet (java.util.HashSet)93 TransportService (org.opensearch.transport.TransportService)92 IOException (java.io.IOException)89 ActionListener (org.opensearch.action.ActionListener)88 Matchers.containsString (org.hamcrest.Matchers.containsString)84 ClusterName (org.opensearch.cluster.ClusterName)82 Version (org.opensearch.Version)80 List (java.util.List)78 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)78 HashMap (java.util.HashMap)77 TimeValue (org.opensearch.common.unit.TimeValue)77 ShardId (org.opensearch.index.shard.ShardId)76