Search in sources :

Example 31 with TransportService

use of org.elasticsearch.transport.TransportService in project elasticsearch by elastic.

the class UnicastZenPingTests method testResolveTimeout.

public void testResolveTimeout() throws InterruptedException {
    final Logger logger = mock(Logger.class);
    final NetworkService networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    final CountDownLatch latch = new CountDownLatch(1);
    final Transport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, Version.CURRENT) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(InetAddress.getLoopbackAddress(), 9500) }, new TransportAddress(InetAddress.getLoopbackAddress(), 9500));
        }

        @Override
        public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
            if ("hostname1".equals(address)) {
                return new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) };
            } else if ("hostname2".equals(address)) {
                try {
                    latch.await();
                    return new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) };
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                throw new UnknownHostException(address);
            }
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    closeables.push(transportService);
    final TimeValue resolveTimeout = TimeValue.timeValueSeconds(randomIntBetween(1, 3));
    try {
        final List<DiscoveryNode> discoveryNodes = TestUnicastZenPing.resolveHostsLists(executorService, logger, Arrays.asList("hostname1", "hostname2"), 1, transportService, "test+", resolveTimeout);
        assertThat(discoveryNodes, hasSize(1));
        verify(logger).trace("resolved host [{}] to {}", "hostname1", new TransportAddress[] { new TransportAddress(TransportAddress.META_ADDRESS, 9300) });
        verify(logger).warn("timed out after [{}] resolving host [{}]", resolveTimeout, "hostname2");
        verifyNoMoreInteractions(logger);
    } finally {
        latch.countDown();
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) UnknownHostException(java.net.UnknownHostException) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Logger(org.apache.logging.log4j.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) TimeValue(org.elasticsearch.common.unit.TimeValue) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 32 with TransportService

use of org.elasticsearch.transport.TransportService in project elasticsearch by elastic.

the class IndicesClusterStateServiceRandomUpdatesTests method createIndicesClusterStateService.

private IndicesClusterStateService createIndicesClusterStateService(DiscoveryNode discoveryNode, final Supplier<MockIndicesService> indicesServiceSupplier) {
    final ThreadPool threadPool = mock(ThreadPool.class);
    when(threadPool.generic()).thenReturn(mock(ExecutorService.class));
    final MockIndicesService indicesService = indicesServiceSupplier.get();
    final Settings settings = Settings.builder().put("node.name", discoveryNode.getName()).build();
    final TransportService transportService = new TransportService(settings, null, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(settings, boundAddress.publishAddress(), UUIDs.randomBase64UUID()), null);
    final ClusterService clusterService = mock(ClusterService.class);
    final RepositoriesService repositoriesService = new RepositoriesService(settings, clusterService, transportService, null);
    final PeerRecoveryTargetService recoveryTargetService = new PeerRecoveryTargetService(settings, threadPool, transportService, null, clusterService);
    final ShardStateAction shardStateAction = mock(ShardStateAction.class);
    return new IndicesClusterStateService(settings, indicesService, clusterService, threadPool, recoveryTargetService, shardStateAction, null, repositoriesService, null, null, null, null, shardId -> {
    });
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ExecutorService(java.util.concurrent.ExecutorService) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) Settings(org.elasticsearch.common.settings.Settings)

Example 33 with TransportService

use of org.elasticsearch.transport.TransportService in project elasticsearch by elastic.

the class NodeDisconnectIT method testNotifyOnDisconnectInSniffer.

public void testNotifyOnDisconnectInSniffer() throws IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    final Set<DiscoveryNode> disconnectedNodes = Collections.synchronizedSet(new HashSet<>());
    try (TransportClient client = new MockTransportClient(Settings.builder().put("cluster.name", internalCluster().getClusterName()).build(), Collections.emptySet(), (n, e) -> disconnectedNodes.add(n))) {
        int numNodes = 0;
        for (TransportService service : internalCluster().getInstances(TransportService.class)) {
            numNodes++;
            client.addTransportAddress(service.boundAddress().publishAddress());
        }
        Set<TransportAddress> discoveryNodes = client.connectedNodes().stream().map(n -> n.getAddress()).collect(Collectors.toSet());
        assertEquals(numNodes, discoveryNodes.size());
        assertEquals(0, disconnectedNodes.size());
        internalCluster().stopRandomDataNode();
        client.getNodesService().doSample();
        assertEquals(1, disconnectedNodes.size());
        assertTrue(discoveryNodes.contains(disconnectedNodes.stream().findAny().get().getAddress()));
    }
    assertEquals(1, disconnectedNodes.size());
}
Also used : HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) Settings(org.elasticsearch.common.settings.Settings) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL(org.elasticsearch.client.transport.TransportClient.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL) Set(java.util.Set) IOException(java.io.IOException) TransportService(org.elasticsearch.transport.TransportService) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportService(org.elasticsearch.transport.TransportService) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MockTransportClient(org.elasticsearch.transport.MockTransportClient)

Example 34 with TransportService

use of org.elasticsearch.transport.TransportService in project elasticsearch by elastic.

the class NodeDisconnectIT method testNotifyOnDisconnect.

public void testNotifyOnDisconnect() throws IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    final Set<DiscoveryNode> disconnectedNodes = Collections.synchronizedSet(new HashSet<>());
    try (TransportClient client = new MockTransportClient(Settings.builder().put("cluster.name", internalCluster().getClusterName()).put(CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL.getKey(), // disable sniffing for better control
    "1h").build(), Collections.emptySet(), (n, e) -> disconnectedNodes.add(n))) {
        for (TransportService service : internalCluster().getInstances(TransportService.class)) {
            client.addTransportAddress(service.boundAddress().publishAddress());
        }
        internalCluster().stopRandomDataNode();
        for (int i = 0; i < 20; i++) {
            // fire up requests such that we hit the node and pass it to the listener
            client.admin().cluster().prepareState().get();
        }
        assertEquals(1, disconnectedNodes.size());
    }
    assertEquals(1, disconnectedNodes.size());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportService(org.elasticsearch.transport.TransportService) MockTransportClient(org.elasticsearch.transport.MockTransportClient)

Example 35 with TransportService

use of org.elasticsearch.transport.TransportService in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method testClusterJoinDespiteOfPublishingIssues.

/**
     * Test cluster join with issues in cluster state publishing *
     */
public void testClusterJoinDespiteOfPublishingIssues() throws Exception {
    List<String> nodes = startCluster(2, 1);
    String masterNode = internalCluster().getMasterName();
    String nonMasterNode;
    if (masterNode.equals(nodes.get(0))) {
        nonMasterNode = nodes.get(1);
    } else {
        nonMasterNode = nodes.get(0);
    }
    DiscoveryNodes discoveryNodes = internalCluster().getInstance(ClusterService.class, nonMasterNode).state().nodes();
    TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.getMasterNode().getName());
    logger.info("blocking requests from non master [{}] to master [{}]", nonMasterNode, masterNode);
    MockTransportService nonMasterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nonMasterNode);
    nonMasterTransportService.addFailToSendNoConnectRule(masterTranspotService);
    assertNoMaster(nonMasterNode);
    logger.info("blocking cluster state publishing from master [{}] to non master [{}]", masterNode, nonMasterNode);
    MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
    TransportService localTransportService = internalCluster().getInstance(TransportService.class, discoveryNodes.getLocalNode().getName());
    if (randomBoolean()) {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublishClusterStateAction.SEND_ACTION_NAME);
    } else {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublishClusterStateAction.COMMIT_ACTION_NAME);
    }
    logger.info("allowing requests from non master [{}] to master [{}], waiting for two join request", nonMasterNode, masterNode);
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    nonMasterTransportService.addDelegate(masterTranspotService, new MockTransportService.DelegateTransport(nonMasterTransportService.original()) {

        @Override
        protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException {
            if (action.equals(MembershipAction.DISCOVERY_JOIN_ACTION_NAME)) {
                countDownLatch.countDown();
            }
            super.sendRequest(connection, requestId, action, request, options);
        }

        @Override
        public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException {
            return super.openConnection(node, profile);
        }
    });
    countDownLatch.await();
    logger.info("waiting for cluster to reform");
    masterTransportService.clearRule(localTransportService);
    nonMasterTransportService.clearRule(localTransportService);
    ensureStableCluster(2);
    // shutting down the nodes, to avoid the leakage check tripping
    // on the states associated with the commit requests we may have dropped
    internalCluster().stopRandomNonMasterNode();
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequest(org.elasticsearch.transport.TransportRequest) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Aggregations

TransportService (org.elasticsearch.transport.TransportService)42 Settings (org.elasticsearch.common.settings.Settings)25 ThreadPool (org.elasticsearch.threadpool.ThreadPool)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)19 ClusterState (org.elasticsearch.cluster.ClusterState)18 ClusterService (org.elasticsearch.cluster.service.ClusterService)17 Collections (java.util.Collections)16 IOException (java.io.IOException)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 TimeUnit (java.util.concurrent.TimeUnit)15 Before (org.junit.Before)15 ActionFilters (org.elasticsearch.action.support.ActionFilters)14 ESTestCase (org.elasticsearch.test.ESTestCase)14 MockTransportService (org.elasticsearch.test.transport.MockTransportService)14 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)14 HashSet (java.util.HashSet)13 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)13 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)12 TransportAddress (org.elasticsearch.common.transport.TransportAddress)12 After (org.junit.After)12