From b1e718d23f747638851fd1ed0cf2aa336827deee Mon Sep 17 00:00:00 2001 From: Erik Krogen Date: Wed, 21 Aug 2024 15:18:30 -0700 Subject: [PATCH] Allow DevelopmentServer testing with internal and external plugins together Co-authored-by: Pratham Desai --- .gitignore | 4 ++ README.md | 7 ++++ .../trino-server-dev/etc/config.properties | 2 + .../trino-server-dev/etc/plugin/.gitignore | 5 +++ .../io/trino/server/DevelopmentServer.java | 4 +- .../HybridDevelopmentPluginsProvider.java | 40 +++++++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 testing/trino-server-dev/etc/plugin/.gitignore create mode 100644 testing/trino-server-dev/src/main/java/io/trino/server/HybridDevelopmentPluginsProvider.java diff --git a/.gitignore b/.gitignore index 9ab8de9022e8..5032b80a3904 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ product-test-reports **/dependency-reduced-pom.xml core/trino-web-ui/src/main/resources/webapp/dist/ .node + +# Local plugins added for testing should be excluded +testing/trino-server-dev/etc/plugin/* +!testing/trino-server-dev/etc/plugin/README.md diff --git a/README.md b/README.md index 1b0c7d0a844a..cbf06f9ae256 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,13 @@ IntelliJ, using `$MODULE_DIR$` accomplishes this automatically. If `VM options` doesn't exist in the dialog, you need to select `Modify options` and enable `Add VM options`. +To adjust which internal plugins are enabled for the development server, adjust the value of +`plugin.bundles` in `config.properties`. External plugins can also be added to the server +by copying them into the `testing/trino-server-dev/etc/plugin` directory. +Each plugin must be added as its own subdirectory containing all necessary dependencies. +If you want to expose a custom plugin as a catalog, you'll need to also add a corresponding +`.properties` file to `testing/trino-server-dev/etc/catalog`. + ### Running the CLI Start the CLI to connect to the server and run SQL queries: diff --git a/testing/trino-server-dev/etc/config.properties b/testing/trino-server-dev/etc/config.properties index 35fd47cf7a54..6e7fa409bff2 100644 --- a/testing/trino-server-dev/etc/config.properties +++ b/testing/trino-server-dev/etc/config.properties @@ -56,4 +56,6 @@ plugin.bundles=\ ../../plugin/trino-exchange-hdfs/pom.xml, \ ../../plugin/trino-mysql-event-listener/pom.xml +# This can be configured to any path, whether absolute or relative to the working directory +plugin.dir=etc/plugin node-scheduler.include-coordinator=true diff --git a/testing/trino-server-dev/etc/plugin/.gitignore b/testing/trino-server-dev/etc/plugin/.gitignore new file mode 100644 index 000000000000..b1c6eb098dc8 --- /dev/null +++ b/testing/trino-server-dev/etc/plugin/.gitignore @@ -0,0 +1,5 @@ +# Keep this placeholder directory as a place to add plugins. +# Ignore everything in this directory ... +* +# ... except this file +!.gitignore diff --git a/testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java b/testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java index 48cc83e4c9de..272c9f158c1d 100644 --- a/testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java +++ b/testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java @@ -31,7 +31,9 @@ protected Iterable getAdditionalModules() { return ImmutableList.of(binder -> { newOptionalBinder(binder, PluginsProvider.class).setBinding() - .to(DevelopmentPluginsProvider.class).in(Scopes.SINGLETON); + .to(HybridDevelopmentPluginsProvider.class).in(Scopes.SINGLETON); + binder.bind(DevelopmentPluginsProvider.class).in(Scopes.SINGLETON); + binder.bind(ServerPluginsProvider.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(DevelopmentLoaderConfig.class); }); } diff --git a/testing/trino-server-dev/src/main/java/io/trino/server/HybridDevelopmentPluginsProvider.java b/testing/trino-server-dev/src/main/java/io/trino/server/HybridDevelopmentPluginsProvider.java new file mode 100644 index 000000000000..ae3ae83dbc91 --- /dev/null +++ b/testing/trino-server-dev/src/main/java/io/trino/server/HybridDevelopmentPluginsProvider.java @@ -0,0 +1,40 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.server; + +import com.google.inject.Inject; +import io.trino.server.PluginManager.PluginsProvider; + +import static java.util.Objects.requireNonNull; + +public class HybridDevelopmentPluginsProvider + implements PluginsProvider +{ + private final DevelopmentPluginsProvider developmentPluginsProvider; + private final ServerPluginsProvider serverPluginsProvider; + + @Inject + public HybridDevelopmentPluginsProvider(DevelopmentPluginsProvider developmentPluginsProvider, ServerPluginsProvider serverPluginsProvider) + { + this.developmentPluginsProvider = requireNonNull(developmentPluginsProvider, "developmentPluginsProvider is null"); + this.serverPluginsProvider = requireNonNull(serverPluginsProvider, "serverPluginsProvider is null"); + } + + @Override + public void loadPlugins(Loader loader, ClassLoaderFactory createClassLoader) + { + developmentPluginsProvider.loadPlugins(loader, createClassLoader); + serverPluginsProvider.loadPlugins(loader, createClassLoader); + } +}