Search in sources :

Example 56 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class TransportBroadcastByNodeActionTests method setClusterState.

void setClusterState(ClusterService clusterService, String index) {
    int numberOfNodes = randomIntBetween(3, 5);
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(new Index(index, "_na_"));
    int shardIndex = -1;
    int totalIndexShards = 0;
    for (int i = 0; i < numberOfNodes; i++) {
        final DiscoveryNode node = newNode(i);
        discoBuilder = discoBuilder.add(node);
        int numberOfShards = randomIntBetween(1, 10);
        totalIndexShards += numberOfShards;
        for (int j = 0; j < numberOfShards; j++) {
            final ShardId shardId = new ShardId(index, "_na_", ++shardIndex);
            ShardRouting shard = TestShardRouting.newShardRouting(index, shardId.getId(), node.getId(), true, ShardRoutingState.STARTED);
            IndexShardRoutingTable.Builder indexShard = new IndexShardRoutingTable.Builder(shardId);
            indexShard.addShard(shard);
            indexRoutingTable.addIndexShard(indexShard.build());
        }
    }
    discoBuilder.localNodeId(newNode(0).getId());
    discoBuilder.masterNodeId(newNode(numberOfNodes - 1).getId());
    ClusterState.Builder stateBuilder = ClusterState.builder(new ClusterName(TEST_CLUSTER));
    stateBuilder.nodes(discoBuilder);
    final IndexMetaData.Builder indexMetaData = IndexMetaData.builder(index).settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)).numberOfReplicas(0).numberOfShards(totalIndexShards);
    stateBuilder.metaData(MetaData.builder().put(indexMetaData));
    stateBuilder.routingTable(RoutingTable.builder().add(indexRoutingTable.build()).build());
    ClusterState clusterState = stateBuilder.build();
    setState(clusterService, clusterState);
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardId(org.elasticsearch.index.shard.ShardId) ClusterName(org.elasticsearch.cluster.ClusterName) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 57 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class MainResponseTests method testToXContent.

public void testToXContent() throws IOException {
    Build build = new Build("buildHash", "2016-11-15".toString(), true);
    Version version = Version.V_2_4_5;
    MainResponse response = new MainResponse("nodeName", version, new ClusterName("clusterName"), "clusterUuid", build, true);
    XContentBuilder builder = XContentFactory.jsonBuilder();
    response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertEquals("{" + "\"name\":\"nodeName\"," + "\"cluster_name\":\"clusterName\"," + "\"cluster_uuid\":\"clusterUuid\"," + "\"version\":{" + "\"number\":\"2.4.5\"," + "\"build_hash\":\"buildHash\"," + "\"build_date\":\"2016-11-15\"," + "\"build_snapshot\":true," + "\"lucene_version\":\"5.5.2\"}," + "\"tagline\":\"You Know, for Search\"" + "}", builder.string());
}
Also used : Version(org.elasticsearch.Version) Build(org.elasticsearch.Build) ClusterName(org.elasticsearch.cluster.ClusterName) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 58 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class MainResponseTests method createTestItem.

public static MainResponse createTestItem() {
    String clusterUuid = randomAsciiOfLength(10);
    ClusterName clusterName = new ClusterName(randomAsciiOfLength(10));
    String nodeName = randomAsciiOfLength(10);
    Build build = new Build(randomAsciiOfLength(8), new Date(randomNonNegativeLong()).toString(), randomBoolean());
    Version version = VersionUtils.randomVersion(random());
    boolean available = randomBoolean();
    return new MainResponse(nodeName, version, clusterName, clusterUuid, build, available);
}
Also used : Version(org.elasticsearch.Version) Build(org.elasticsearch.Build) ClusterName(org.elasticsearch.cluster.ClusterName) Date(java.util.Date)

Example 59 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class TransportMultiSearchActionTests method testBatchExecute.

public void testBatchExecute() throws Exception {
    // Initialize dependencies of TransportMultiSearchAction
    Settings settings = Settings.builder().put("node.name", TransportMultiSearchActionTests.class.getSimpleName()).build();
    ActionFilters actionFilters = mock(ActionFilters.class);
    when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
    ThreadPool threadPool = new ThreadPool(settings);
    TaskManager taskManager = mock(TaskManager.class);
    TransportService transportService = new TransportService(Settings.EMPTY, null, null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(settings, boundAddress.publishAddress(), UUIDs.randomBase64UUID()), null) {

        @Override
        public TaskManager getTaskManager() {
            return taskManager;
        }
    };
    ClusterService clusterService = mock(ClusterService.class);
    when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("test")).build());
    IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(Settings.EMPTY);
    // Keep track of the number of concurrent searches started by multi search api,
    // and if there are more searches than is allowed create an error and remember that.
    int maxAllowedConcurrentSearches = scaledRandomIntBetween(1, 16);
    AtomicInteger counter = new AtomicInteger();
    AtomicReference<AssertionError> errorHolder = new AtomicReference<>();
    // randomize whether or not requests are executed asynchronously
    final List<String> threadPoolNames = Arrays.asList(ThreadPool.Names.GENERIC, ThreadPool.Names.SAME);
    Randomness.shuffle(threadPoolNames);
    final ExecutorService commonExecutor = threadPool.executor(threadPoolNames.get(0));
    final ExecutorService rarelyExecutor = threadPool.executor(threadPoolNames.get(1));
    final Set<SearchRequest> requests = Collections.newSetFromMap(Collections.synchronizedMap(new IdentityHashMap<>()));
    TransportAction<SearchRequest, SearchResponse> searchAction = new TransportAction<SearchRequest, SearchResponse>(Settings.EMPTY, "action", threadPool, actionFilters, resolver, taskManager) {

        @Override
        protected void doExecute(SearchRequest request, ActionListener<SearchResponse> listener) {
            requests.add(request);
            int currentConcurrentSearches = counter.incrementAndGet();
            if (currentConcurrentSearches > maxAllowedConcurrentSearches) {
                errorHolder.set(new AssertionError("Current concurrent search [" + currentConcurrentSearches + "] is higher than is allowed [" + maxAllowedConcurrentSearches + "]"));
            }
            final ExecutorService executorService = rarely() ? rarelyExecutor : commonExecutor;
            executorService.execute(() -> {
                counter.decrementAndGet();
                listener.onResponse(new SearchResponse());
            });
        }
    };
    TransportMultiSearchAction action = new TransportMultiSearchAction(threadPool, actionFilters, transportService, clusterService, searchAction, resolver, 10);
    // Execute the multi search api and fail if we find an error after executing:
    try {
        /*
             * Allow for a large number of search requests in a single batch as previous implementations could stack overflow if the number
             * of requests in a single batch was large
             */
        int numSearchRequests = scaledRandomIntBetween(1, 8192);
        MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
        multiSearchRequest.maxConcurrentSearchRequests(maxAllowedConcurrentSearches);
        for (int i = 0; i < numSearchRequests; i++) {
            multiSearchRequest.add(new SearchRequest());
        }
        MultiSearchResponse response = action.execute(multiSearchRequest).actionGet();
        assertThat(response.getResponses().length, equalTo(numSearchRequests));
        assertThat(requests.size(), equalTo(numSearchRequests));
        assertThat(errorHolder.get(), nullValue());
    } finally {
        assertTrue(ESTestCase.terminate(threadPool));
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionFilters(org.elasticsearch.action.support.ActionFilters) TransportAction(org.elasticsearch.action.support.TransportAction) TaskManager(org.elasticsearch.tasks.TaskManager) ClusterService(org.elasticsearch.cluster.service.ClusterService) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 60 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class TransportMultiSearchActionTests method testDefaultMaxConcurrentSearches.

public void testDefaultMaxConcurrentSearches() {
    int numDataNodes = randomIntBetween(1, 10);
    DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
    for (int i = 0; i < numDataNodes; i++) {
        builder.add(new DiscoveryNode("_id" + i, buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.singleton(DiscoveryNode.Role.DATA), Version.CURRENT));
    }
    builder.add(new DiscoveryNode("master", buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.singleton(DiscoveryNode.Role.MASTER), Version.CURRENT));
    builder.add(new DiscoveryNode("ingest", buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.singleton(DiscoveryNode.Role.INGEST), Version.CURRENT));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).nodes(builder).build();
    int result = TransportMultiSearchAction.defaultMaxConcurrentSearches(10, state);
    assertThat(result, equalTo(10 * numDataNodes));
    state = ClusterState.builder(new ClusterName("_name")).build();
    result = TransportMultiSearchAction.defaultMaxConcurrentSearches(10, state);
    assertThat(result, equalTo(1));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8