Search in sources :

Example 11 with TransportService

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

the class TransportMasterNodeActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(threadPool);
    transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    localNode = new DiscoveryNode("local_node", buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.singleton(DiscoveryNode.Role.MASTER), Version.CURRENT);
    remoteNode = new DiscoveryNode("remote_node", buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.singleton(DiscoveryNode.Role.MASTER), Version.CURRENT);
    allNodes = new DiscoveryNode[] { localNode, remoteNode };
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) BeforeClass(org.junit.BeforeClass) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) NotMasterException(org.elasticsearch.cluster.NotMasterException) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ActionFuture(org.elasticsearch.action.ActionFuture) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) TimeValue(org.elasticsearch.common.unit.TimeValue) After(org.junit.After) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) ClusterStateCreationUtils(org.elasticsearch.action.support.replication.ClusterStateCreationUtils) Before(org.junit.Before) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AfterClass(org.junit.AfterClass) ActionFilters(org.elasticsearch.action.support.ActionFilters) Discovery(org.elasticsearch.discovery.Discovery) ActionResponse(org.elasticsearch.action.ActionResponse) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) Set(java.util.Set) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Version(org.elasticsearch.Version) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RestStatus(org.elasticsearch.rest.RestStatus) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ThreadedActionListener(org.elasticsearch.action.support.ThreadedActionListener) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) Collections(java.util.Collections) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Before(org.junit.Before)

Example 12 with TransportService

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

the class IndexRecoveryIT method testDisconnectsWhileRecovering.

public void testDisconnectsWhileRecovering() throws Exception {
    final String indexName = "test";
    final Settings nodeSettings = Settings.builder().put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING.getKey(), "100ms").put(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT_SETTING.getKey(), "1s").put(MockFSDirectoryService.RANDOM_PREVENT_DOUBLE_WRITE_SETTING.getKey(), // restarted recoveries will delete temp files and write them again
    false).build();
    // start a master node
    internalCluster().startNode(nodeSettings);
    final String blueNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "blue").put(nodeSettings).build());
    final String redNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "red").put(nodeSettings).build());
    ClusterHealthResponse response = client().admin().cluster().prepareHealth().setWaitForNodes(">=3").get();
    assertThat(response.isTimedOut(), is(false));
    client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "color", "blue").put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)).get();
    List<IndexRequestBuilder> requests = new ArrayList<>();
    int numDocs = scaledRandomIntBetween(25, 250);
    for (int i = 0; i < numDocs; i++) {
        requests.add(client().prepareIndex(indexName, "type").setSource("{}", XContentType.JSON));
    }
    indexRandom(true, requests);
    ensureSearchable(indexName);
    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
    final String blueNodeId = internalCluster().getInstance(ClusterService.class, blueNodeName).localNode().getId();
    assertFalse(stateResponse.getState().getRoutingNodes().node(blueNodeId).isEmpty());
    SearchResponse searchResponse = client().prepareSearch(indexName).get();
    assertHitCount(searchResponse, numDocs);
    String[] recoveryActions = new String[] { PeerRecoverySourceService.Actions.START_RECOVERY, PeerRecoveryTargetService.Actions.FILES_INFO, PeerRecoveryTargetService.Actions.FILE_CHUNK, PeerRecoveryTargetService.Actions.CLEAN_FILES, //RecoveryTarget.Actions.TRANSLOG_OPS, <-- may not be sent if already flushed
    PeerRecoveryTargetService.Actions.PREPARE_TRANSLOG, PeerRecoveryTargetService.Actions.FINALIZE };
    final String recoveryActionToBlock = randomFrom(recoveryActions);
    final boolean dropRequests = randomBoolean();
    logger.info("--> will {} between blue & red on [{}]", dropRequests ? "drop requests" : "break connection", recoveryActionToBlock);
    MockTransportService blueMockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, blueNodeName);
    MockTransportService redMockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, redNodeName);
    TransportService redTransportService = internalCluster().getInstance(TransportService.class, redNodeName);
    TransportService blueTransportService = internalCluster().getInstance(TransportService.class, blueNodeName);
    final CountDownLatch requestBlocked = new CountDownLatch(1);
    blueMockTransportService.addDelegate(redTransportService, new RecoveryActionBlocker(dropRequests, recoveryActionToBlock, blueMockTransportService.original(), requestBlocked));
    redMockTransportService.addDelegate(blueTransportService, new RecoveryActionBlocker(dropRequests, recoveryActionToBlock, redMockTransportService.original(), requestBlocked));
    logger.info("--> starting recovery from blue to red");
    client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "color", "red,blue").put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)).get();
    requestBlocked.await();
    logger.info("--> stopping to block recovery");
    blueMockTransportService.clearAllRules();
    redMockTransportService.clearAllRules();
    ensureGreen();
    searchResponse = client(redNodeName).prepareSearch(indexName).setPreference("_local").get();
    assertHitCount(searchResponse, numDocs);
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) Settings(org.elasticsearch.common.settings.Settings)

Example 13 with TransportService

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

the class MainActionTests method testMainActionClusterAvailable.

public void testMainActionClusterAvailable() {
    final ClusterService clusterService = mock(ClusterService.class);
    final ClusterName clusterName = new ClusterName("elasticsearch");
    final Settings settings = Settings.builder().put("node.name", "my-node").build();
    final boolean available = randomBoolean();
    ClusterBlocks blocks;
    if (available) {
        if (randomBoolean()) {
            blocks = ClusterBlocks.EMPTY_CLUSTER_BLOCK;
        } else {
            blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 400", randomBoolean(), randomBoolean(), RestStatus.BAD_REQUEST, ClusterBlockLevel.ALL)).build();
        }
    } else {
        blocks = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(randomIntBetween(1, 16), "test global block 503", randomBoolean(), randomBoolean(), RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL)).build();
    }
    ClusterState state = ClusterState.builder(clusterName).blocks(blocks).build();
    when(clusterService.state()).thenReturn(state);
    TransportService transportService = new TransportService(Settings.EMPTY, null, null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    TransportMainAction action = new TransportMainAction(settings, mock(ThreadPool.class), transportService, mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), clusterService);
    AtomicReference<MainResponse> responseRef = new AtomicReference<>();
    action.doExecute(new MainRequest(), new ActionListener<MainResponse>() {

        @Override
        public void onResponse(MainResponse mainResponse) {
            responseRef.set(mainResponse);
        }

        @Override
        public void onFailure(Exception e) {
            logger.error("unexpected error", e);
        }
    });
    assertNotNull(responseRef.get());
    assertEquals(available, responseRef.get().isAvailable());
    verify(clusterService, times(1)).state();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ThreadPool(org.elasticsearch.threadpool.ThreadPool) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionFilters(org.elasticsearch.action.support.ActionFilters) IOException(java.io.IOException) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings)

Example 14 with TransportService

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

the class ShardStateActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.transport = new CapturingTransport();
    clusterService = createClusterService(THREAD_POOL);
    transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new TestShardStateAction(Settings.EMPTY, clusterService, transportService, null, null);
    shardStateAction.setOnBeforeWaitForNewMasterAndRetry(() -> {
    });
    shardStateAction.setOnAfterWaitForNewMasterAndRetry(() -> {
    });
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) BeforeClass(org.junit.BeforeClass) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) NotMasterException(org.elasticsearch.cluster.NotMasterException) ClusterService(org.elasticsearch.cluster.service.ClusterService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportResponse(org.elasticsearch.transport.TransportResponse) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) ClusterStateCreationUtils(org.elasticsearch.action.support.replication.ClusterStateCreationUtils) ShardsIterator(org.elasticsearch.cluster.routing.ShardsIterator) NodeDisconnectedException(org.elasticsearch.transport.NodeDisconnectedException) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AfterClass(org.junit.AfterClass) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Discovery(org.elasticsearch.discovery.Discovery) Predicate(java.util.function.Predicate) LongConsumer(java.util.function.LongConsumer) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) NodeNotConnectedException(org.elasticsearch.transport.NodeNotConnectedException) RoutingService(org.elasticsearch.cluster.routing.RoutingService) Matchers.is(org.hamcrest.Matchers.is) TransportException(org.elasticsearch.transport.TransportException) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Before(org.junit.Before)

Example 15 with TransportService

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

the class NodeConnectionsServiceTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.threadPool = new TestThreadPool(getClass().getName());
    this.transport = new MockTransport();
    transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(Settings.EMPTY, buildNewFakeTransportAddress(), UUIDs.randomBase64UUID()), null);
    transportService.start();
    transportService.acceptIncomingRequests();
}
Also used : Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) TransportServiceAdapter(org.elasticsearch.transport.TransportServiceAdapter) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) CheckedBiConsumer(org.elasticsearch.common.CheckedBiConsumer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Transport(org.elasticsearch.transport.Transport) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Lifecycle(org.elasticsearch.common.component.Lifecycle) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportException(org.elasticsearch.transport.TransportException) Collections(java.util.Collections) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

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