From 11fd20a4a3263c5d1202a06a0d2c5103af3fee1f Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Sun, 9 Feb 2025 09:56:18 +0100 Subject: [PATCH 1/2] Rename PreviewUiQueryRunner to WebUiPreviewQueryRunner This is now consistent with the wording in the rest of the codebase --- ...iewUiQueryRunner.java => WebUiPreviewQueryRunner.java} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename core/trino-main/src/test/java/io/trino/server/ui/{PreviewUiQueryRunner.java => WebUiPreviewQueryRunner.java} (87%) diff --git a/core/trino-main/src/test/java/io/trino/server/ui/PreviewUiQueryRunner.java b/core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java similarity index 87% rename from core/trino-main/src/test/java/io/trino/server/ui/PreviewUiQueryRunner.java rename to core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java index 8ec87f18d096..804a18e393de 100644 --- a/core/trino-main/src/test/java/io/trino/server/ui/PreviewUiQueryRunner.java +++ b/core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java @@ -20,18 +20,18 @@ import static io.trino.testing.TestingHandles.TEST_CATALOG_NAME; import static io.trino.testing.TestingSession.testSessionBuilder; -public class PreviewUiQueryRunner +public class WebUiPreviewQueryRunner { - private PreviewUiQueryRunner() {} + private WebUiPreviewQueryRunner() {} public static void main(String[] args) { StandaloneQueryRunner queryRunner = new StandaloneQueryRunner(testSessionBuilder() .setCatalog(TEST_CATALOG_NAME) .setSchema("tiny") - .build(), PreviewUiQueryRunner::configureTrinoServer); + .build(), WebUiPreviewQueryRunner::configureTrinoServer); - Logger log = Logger.get(PreviewUiQueryRunner.class); + Logger log = Logger.get(WebUiPreviewQueryRunner.class); log.info("======== SERVER STARTED ========"); log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); } From 97e79f9679f46aa878d252dc389c74484fa3761c Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Sun, 9 Feb 2025 10:07:57 +0100 Subject: [PATCH 2/2] Move preview UI runner to testing This allows the runner to install Tpch catalog and use spooling which is useful for rendering different kind of information on the UI. --- .../server/ui/WebUiPreviewQueryRunner.java | 46 ---------- .../testing/WebUiPreviewQueryRunner.java | 88 +++++++++++++++++++ 2 files changed, 88 insertions(+), 46 deletions(-) delete mode 100644 core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java create mode 100644 testing/trino-testing/src/main/java/io/trino/testing/WebUiPreviewQueryRunner.java diff --git a/core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java b/core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java deleted file mode 100644 index 804a18e393de..000000000000 --- a/core/trino-main/src/test/java/io/trino/server/ui/WebUiPreviewQueryRunner.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.ui; - -import io.airlift.log.Logger; -import io.trino.server.testing.TestingTrinoServer; -import io.trino.testing.StandaloneQueryRunner; - -import static io.trino.testing.TestingHandles.TEST_CATALOG_NAME; -import static io.trino.testing.TestingSession.testSessionBuilder; - -public class WebUiPreviewQueryRunner -{ - private WebUiPreviewQueryRunner() {} - - public static void main(String[] args) - { - StandaloneQueryRunner queryRunner = new StandaloneQueryRunner(testSessionBuilder() - .setCatalog(TEST_CATALOG_NAME) - .setSchema("tiny") - .build(), WebUiPreviewQueryRunner::configureTrinoServer); - - Logger log = Logger.get(WebUiPreviewQueryRunner.class); - log.info("======== SERVER STARTED ========"); - log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); - } - - private static void configureTrinoServer(TestingTrinoServer.Builder builder) - { - builder.addProperty("web-ui.preview.enabled", "true"); - builder.addProperty("http-server.http.port", "8080"); - builder.addProperty("web-ui.authentication.type", "fixed"); - builder.addProperty("web-ui.user", "webapp-preview-user"); - } -} diff --git a/testing/trino-testing/src/main/java/io/trino/testing/WebUiPreviewQueryRunner.java b/testing/trino-testing/src/main/java/io/trino/testing/WebUiPreviewQueryRunner.java new file mode 100644 index 000000000000..782c20fa87e6 --- /dev/null +++ b/testing/trino-testing/src/main/java/io/trino/testing/WebUiPreviewQueryRunner.java @@ -0,0 +1,88 @@ +/* + * 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.testing; + +import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.airlift.log.Logger; +import io.trino.plugin.tpch.TpchPlugin; + +import java.util.Map; + +import static io.trino.testing.TestingSession.testSessionBuilder; + +public class WebUiPreviewQueryRunner +{ + private WebUiPreviewQueryRunner() + {} + + public static Builder builder() + { + return new Builder(); + } + + public static final class Builder + extends DistributedQueryRunner.Builder + { + private Map connectorProperties = ImmutableMap.of(); + + private Builder() + { + super(testSessionBuilder() + .setCatalog("tpch") + .setSchema("tiny") + .build()); + } + + @CanIgnoreReturnValue + public Builder withConnectorProperties(Map connectorProperties) + { + this.connectorProperties = ImmutableMap.copyOf(connectorProperties); + return this; + } + + @Override + public DistributedQueryRunner build() + throws Exception + { + DistributedQueryRunner queryRunner = super.build(); + try { + queryRunner.installPlugin(new TpchPlugin()); + queryRunner.createCatalog("tpch", "tpch", connectorProperties); + return queryRunner; + } + catch (Exception e) { + queryRunner.close(); + throw e; + } + } + } + + public static void main(String[] args) + throws Exception + { + DistributedQueryRunner queryRunner = builder() + .addCoordinatorProperty("web-ui.preview.enabled", "true") + .addCoordinatorProperty("http-server.http.port", "8080") + .addCoordinatorProperty("web-ui.authentication.type", "fixed") + .addCoordinatorProperty("web-ui.user", "webapp-preview-user") + .withProtocolSpooling("json") + .build(); + + Logger log = Logger.get(WebUiPreviewQueryRunner.class); + log.info("======== SERVER STARTED ========"); + log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); + log.info("\n====\nPreview UI %s/ui/preview\n====", queryRunner.getCoordinator().getBaseUrl()); + } +}