Search in sources :

Example 26 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver 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 27 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class AutoCreateIndexTests method testUpdate.

public void testUpdate() {
    boolean value = randomBoolean();
    Settings settings;
    if (value && randomBoolean()) {
        settings = Settings.EMPTY;
    } else {
        settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), value).build();
    }
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AutoCreateIndex autoCreateIndex = new AutoCreateIndex(settings, clusterSettings, new IndexNameExpressionResolver(settings));
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(value));
    Settings newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), !value).build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(!value));
    newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "logs-*").build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(true));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().size(), equalTo(1));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().get(0).v1(), equalTo("logs-*"));
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 28 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class IndicesRequestIT method testFlush.

public void testFlush() {
    String[] indexShardActions = new String[] { TransportShardFlushAction.NAME, TransportShardFlushAction.NAME + "[r]", TransportShardFlushAction.NAME + "[p]" };
    interceptTransportActions(indexShardActions);
    FlushRequest flushRequest = new FlushRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().flush(flushRequest).actionGet();
    clearInterceptedActions();
    String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndexNames(client().admin().cluster().prepareState().get().getState(), flushRequest);
    assertIndicesSubset(Arrays.asList(indices), indexShardActions);
}
Also used : FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 29 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class IndicesRequestIT method testRefresh.

public void testRefresh() {
    String[] indexShardActions = new String[] { TransportShardRefreshAction.NAME, TransportShardRefreshAction.NAME + "[r]", TransportShardRefreshAction.NAME + "[p]" };
    interceptTransportActions(indexShardActions);
    RefreshRequest refreshRequest = new RefreshRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().refresh(refreshRequest).actionGet();
    clearInterceptedActions();
    String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndexNames(client().admin().cluster().prepareState().get().getState(), refreshRequest);
    assertIndicesSubset(Arrays.asList(indices), indexShardActions);
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 30 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class ActionModuleTests method testPluginCanRegisterAction.

public void testPluginCanRegisterAction() {
    class FakeRequest extends ActionRequest {

        @Override
        public ActionRequestValidationException validate() {
            return null;
        }
    }
    class FakeTransportAction extends TransportAction<FakeRequest, ActionResponse> {

        protected FakeTransportAction(Settings settings, String actionName, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, TaskManager taskManager) {
            super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, taskManager);
        }

        @Override
        protected void doExecute(FakeRequest request, ActionListener<ActionResponse> listener) {
        }
    }
    class FakeAction extends GenericAction<FakeRequest, ActionResponse> {

        protected FakeAction() {
            super("fake");
        }

        @Override
        public ActionResponse newResponse() {
            return null;
        }
    }
    FakeAction action = new FakeAction();
    ActionPlugin registersFakeAction = new ActionPlugin() {

        @Override
        public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
            return singletonList(new ActionHandler<>(action, FakeTransportAction.class));
        }
    };
    assertThat(ActionModule.setupActions(singletonList(registersFakeAction)), hasEntry("fake", new ActionHandler<>(action, FakeTransportAction.class)));
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ActionPlugin(org.elasticsearch.plugins.ActionPlugin) ActionFilters(org.elasticsearch.action.support.ActionFilters) TransportAction(org.elasticsearch.action.support.TransportAction) TaskManager(org.elasticsearch.tasks.TaskManager) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ActionHandler(org.elasticsearch.plugins.ActionPlugin.ActionHandler) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)32 Settings (org.elasticsearch.common.settings.Settings)15 ThreadPool (org.elasticsearch.threadpool.ThreadPool)12 ClusterState (org.elasticsearch.cluster.ClusterState)10 ActionListener (org.elasticsearch.action.ActionListener)9 ActionFilters (org.elasticsearch.action.support.ActionFilters)9 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 ClusterService (org.elasticsearch.cluster.ClusterService)7 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)5 ShardId (org.elasticsearch.index.shard.ShardId)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)4 TableIdent (io.crate.metadata.TableIdent)4 UUID (java.util.UUID)4 TransportService (org.elasticsearch.transport.TransportService)4 ShardResponse (io.crate.executor.transport.ShardResponse)3