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());
}
}
}
}
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());
}
}
}
}
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);
}
}
}
}
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));
}
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));
}
Aggregations