Search in sources :

Example 1 with SettingsModule

use of org.opensearch.common.settings.SettingsModule in project OpenSearch by opensearch-project.

the class GetIndexActionTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    settingsFilter = new SettingsModule(Settings.EMPTY, emptyList(), emptyList(), emptySet()).getSettingsFilter();
    threadPool = new TestThreadPool("GetIndexActionTests");
    clusterService = getInstanceFromNode(ClusterService.class);
    indicesService = getInstanceFromNode(IndicesService.class);
    CapturingTransport capturingTransport = new CapturingTransport();
    transportService = capturingTransport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    getIndexAction = new GetIndexActionTests.TestTransportGetIndexAction();
}
Also used : SettingsFilter(org.opensearch.common.settings.SettingsFilter) OpenSearchSingleNodeTestCase(org.opensearch.test.OpenSearchSingleNodeTestCase) Collections.emptySet(java.util.Collections.emptySet) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Index(org.opensearch.index.Index) Collections.emptyList(java.util.Collections.emptyList) ThreadPool(org.opensearch.threadpool.ThreadPool) IndicesService(org.opensearch.indices.IndicesService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) TransportService(org.opensearch.transport.TransportService) ClusterStateCreationUtils(org.opensearch.action.support.replication.ClusterStateCreationUtils) TimeUnit(java.util.concurrent.TimeUnit) IndicesRequest(org.opensearch.action.IndicesRequest) ActionFilters(org.opensearch.action.support.ActionFilters) SettingsModule(org.opensearch.common.settings.SettingsModule) ClusterState(org.opensearch.cluster.ClusterState) After(org.junit.After) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) CapturingTransport(org.opensearch.test.transport.CapturingTransport) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before) ClusterService(org.opensearch.cluster.service.ClusterService) CapturingTransport(org.opensearch.test.transport.CapturingTransport) SettingsModule(org.opensearch.common.settings.SettingsModule) IndicesService(org.opensearch.indices.IndicesService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 2 with SettingsModule

use of org.opensearch.common.settings.SettingsModule in project OpenSearch by opensearch-project.

the class GetSettingsActionTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    settingsFilter = new SettingsModule(Settings.EMPTY, emptyList(), emptyList(), emptySet()).getSettingsFilter();
    threadPool = new TestThreadPool("GetSettingsActionTests");
    clusterService = createClusterService(threadPool);
    CapturingTransport capturingTransport = new CapturingTransport();
    transportService = capturingTransport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    getSettingsAction = new GetSettingsActionTests.TestTransportGetSettingsAction();
}
Also used : IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterStateCreationUtils(org.opensearch.action.support.replication.ClusterStateCreationUtils) IndicesRequest(org.opensearch.action.IndicesRequest) ClusterState(org.opensearch.cluster.ClusterState) After(org.junit.After) ActionListener(org.opensearch.action.ActionListener) Before(org.junit.Before) SettingsFilter(org.opensearch.common.settings.SettingsFilter) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) Collections.emptySet(java.util.Collections.emptySet) Index(org.opensearch.index.Index) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) TransportService(org.opensearch.transport.TransportService) TimeUnit(java.util.concurrent.TimeUnit) ActionFilters(org.opensearch.action.support.ActionFilters) SettingsModule(org.opensearch.common.settings.SettingsModule) ClusterService(org.opensearch.cluster.service.ClusterService) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) CapturingTransport(org.opensearch.test.transport.CapturingTransport) SettingsModule(org.opensearch.common.settings.SettingsModule) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 3 with SettingsModule

use of org.opensearch.common.settings.SettingsModule in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCanRegisterRestHandler.

public void testPluginCanRegisterRestHandler() {
    class FakeHandler implements RestHandler {

        @Override
        public List<Route> routes() {
            return singletonList(new Route(Method.GET, "/_dummy"));
        }

        @Override
        public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
        }
    }
    ActionPlugin registersFakeHandler = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new FakeHandler());
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        UsageService usageService = new UsageService();
        ActionModule actionModule = new ActionModule(settings.getSettings(), new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(registersFakeHandler), null, null, usageService, null);
        actionModule.initRestHandlers(null);
        // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.getRestController().registerHandler(new RestHandler() {

            @Override
            public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
            }

            @Override
            public List<Route> routes() {
                return singletonList(new Route(Method.GET, "/_dummy"));
            }
        }));
        assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_dummy] for method: GET"));
    } finally {
        threadPool.shutdown();
    }
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ActionPlugin(org.opensearch.plugins.ActionPlugin) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) RestChannel(org.opensearch.rest.RestChannel) RestController(org.opensearch.rest.RestController) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.opensearch.common.settings.SettingsFilter) RestRequest(org.opensearch.rest.RestRequest) RestHandler(org.opensearch.rest.RestHandler) UsageService(org.opensearch.usage.UsageService) SettingsModule(org.opensearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 4 with SettingsModule

use of org.opensearch.common.settings.SettingsModule in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCantOverwriteBuiltinRestHandler.

public void testPluginCantOverwriteBuiltinRestHandler() throws IOException {
    ActionPlugin dupsMainAction = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new RestMainAction() {

                @Override
                public String getName() {
                    return "duplicated_" + super.getName();
                }
            });
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        UsageService usageService = new UsageService();
        ActionModule actionModule = new ActionModule(settings.getSettings(), new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(dupsMainAction), null, null, usageService, null);
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null));
        assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET"));
    } finally {
        threadPool.shutdown();
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ActionPlugin(org.opensearch.plugins.ActionPlugin) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) RestController(org.opensearch.rest.RestController) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.opensearch.common.settings.SettingsFilter) RestMainAction(org.opensearch.rest.action.RestMainAction) RestHandler(org.opensearch.rest.RestHandler) UsageService(org.opensearch.usage.UsageService) SettingsModule(org.opensearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 5 with SettingsModule

use of org.opensearch.common.settings.SettingsModule in project OpenSearch by opensearch-project.

the class ActionModuleTests method testSetupRestHandlerContainsKnownBuiltin.

public void testSetupRestHandlerContainsKnownBuiltin() {
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    UsageService usageService = new UsageService();
    ActionModule actionModule = new ActionModule(settings.getSettings(), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), null, emptyList(), null, null, usageService, null);
    actionModule.initRestHandlers(null);
    // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail
    Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.getRestController().registerHandler(new RestHandler() {

        @Override
        public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
        }

        @Override
        public List<Route> routes() {
            return singletonList(new Route(Method.GET, "/"));
        }
    }));
    assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET"));
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) UsageService(org.opensearch.usage.UsageService) RestHandler(org.opensearch.rest.RestHandler) RestRequest(org.opensearch.rest.RestRequest) SettingsModule(org.opensearch.common.settings.SettingsModule) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) RestChannel(org.opensearch.rest.RestChannel) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IOException(java.io.IOException)

Aggregations

SettingsModule (org.opensearch.common.settings.SettingsModule)7 IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)5 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)4 Settings (org.opensearch.common.settings.Settings)4 SettingsFilter (org.opensearch.common.settings.SettingsFilter)4 TestThreadPool (org.opensearch.threadpool.TestThreadPool)4 ThreadPool (org.opensearch.threadpool.ThreadPool)4 IOException (java.io.IOException)3 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)3 RestHandler (org.opensearch.rest.RestHandler)3 UsageService (org.opensearch.usage.UsageService)3 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptySet (java.util.Collections.emptySet)2 TimeUnit (java.util.concurrent.TimeUnit)2 Supplier (java.util.function.Supplier)2 After (org.junit.After)2 Before (org.junit.Before)2 ActionListener (org.opensearch.action.ActionListener)2 IndicesRequest (org.opensearch.action.IndicesRequest)2 ActionFilters (org.opensearch.action.support.ActionFilters)2