Skip to content

Commit 96e966a

Browse files
committed
Add launcher and create tar for trino-gateway
1 parent c59bb7d commit 96e966a

23 files changed

+200
-39
lines changed

docker/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ RUN \
4343
mkdir -p /usr/lib/trino-gateway /etc/trino-gateway && \
4444
chown -R "trino:trino" /usr/lib/trino-gateway /etc/trino-gateway
4545

46-
COPY --chown=trino:trino gateway-ha /usr/lib/trino-gateway
46+
ARG TRINO_GATEWAY_VERSION
47+
COPY --chown=trino:trino trino-gateway-server-${TRINO_GATEWAY_VERSION} /usr/lib/trino-gateway
48+
COPY --chown=trino:trino default/etc /etc/trino-gateway
4749

4850
EXPOSE 8080
4951
USER trino:trino
50-
CMD java -jar /usr/lib/trino-gateway/gateway-ha-jar-with-dependencies.jar "/etc/trino-gateway/config.yaml"
52+
CMD ["/usr/lib/trino/bin/run-trino"]
5153

5254
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \
5355
CMD /usr/lib/trino-gateway/bin/health-check

docker/bin/run-trino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
launcher_opts=(--etc-dir /etc/trino-gateway --config /etc/trino-gateway/config.yaml)
6+
if ! grep -s -q 'node.id' /etc/trino/node.properties; then
7+
launcher_opts+=("-Dnode.id=${HOSTNAME}")
8+
fi
9+
10+
exec /usr/lib/trino/bin/launcher run "${launcher_opts[@]}" "$@"

docker/build.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ function temurin_jdk_link() {
9595
check_environment
9696

9797
if [ -n "$TRINO_GATEWAY_VERSION" ]; then
98-
echo "🎣 Downloading Trino Gateway server artifact for release version ${TRINO_GATEWAY_VERSION}"
99-
"${SOURCE_DIR}/mvnw" -C dependency:get -Dtransitive=false -Dartifact="io.trino.gateway:gateway-ha:${TRINO_GATEWAY_VERSION}:jar:jar-with-dependencies"
98+
echo "🎣 Downloading Gateway server artifact for release version ${TRINO_GATEWAY_VERSION}"
99+
"${SOURCE_DIR}/mvnw" -C dependency:get -Dtransitive=false -Dartifact="io.trino.gateway:trino-gateway-server:${TRINO_GATEWAY_VERSION}:tar.gz"
100100
local_repo=$("${SOURCE_DIR}/mvnw" -B help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)
101-
trino_gateway_ha="$local_repo/io/trino/gateway/gateway-ha/${TRINO_GATEWAY_VERSION}/gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar"
101+
trino_gateway_ha="$local_repo/io/trino/gateway/trino-gateway-server/${TRINO_GATEWAY_VERSION}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
102102
chmod +x "$trino_gateway_ha"
103103
else
104104
TRINO_GATEWAY_VERSION=$("${SOURCE_DIR}/mvnw" -f "${SOURCE_DIR}/pom.xml" --quiet help:evaluate -Dexpression=project.version -DforceStdout)
105-
echo "🎯 Using currently built artifacts from the gateway-ha module with version ${TRINO_GATEWAY_VERSION}"
106-
trino_gateway_ha="${SOURCE_DIR}/gateway-ha/target/gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar"
105+
echo "🎯 Using currently built artifacts with version ${TRINO_GATEWAY_VERSION}"
106+
trino_gateway_ha="${SOURCE_DIR}/trino-gateway-server/target/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
107107
fi
108108

109109
echo "🧱 Preparing the image build context directory"
110110
WORK_DIR="$(mktemp -d)"
111-
GATEWAY_WORK_DIR="${WORK_DIR}/gateway-ha"
112-
mkdir "${GATEWAY_WORK_DIR}"
113-
cp "$trino_gateway_ha" "${GATEWAY_WORK_DIR}/gateway-ha-jar-with-dependencies.jar"
114-
cp -R bin "${GATEWAY_WORK_DIR}"
115-
cp "${SCRIPT_DIR}/Dockerfile" "${WORK_DIR}"
111+
cp "$trino_gateway_ha" "${WORK_DIR}/"
112+
tar -C "${WORK_DIR}" -xzf "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
113+
rm "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
114+
cp -R bin "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}"
115+
cp -R default "${WORK_DIR}/"
116116

117117
TAG_PREFIX="trino-gateway:${TRINO_GATEWAY_VERSION}"
118118
#version file is used by the Helm chart test
@@ -131,7 +131,8 @@ for arch in "${ARCHITECTURES[@]}"; do
131131
--build-arg TRINO_GATEWAY_BASE_IMAGE="${TRINO_GATEWAY_BASE_IMAGE}" \
132132
--platform "linux/$arch" \
133133
-f Dockerfile \
134-
-t "${TAG_PREFIX}-$arch"
134+
-t "${TAG_PREFIX}-$arch" \
135+
--build-arg "TRINO_GATEWAY_VERSION=${TRINO_GATEWAY_VERSION}"
135136
done
136137

137138
echo "🧹 Cleaning up the build context directory"
File renamed without changes.

docker/default/etc/jvm.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-server
2+
-XX:InitialRAMPercentage=80
3+
-XX:MaxRAMPercentage=80
4+
-XX:G1HeapRegionSize=32M
5+
-XX:+ExplicitGCInvokesConcurrent
6+
-XX:+HeapDumpOnOutOfMemoryError
7+
-XX:+ExitOnOutOfMemoryError
8+
-XX:-OmitStackTraceInFastThrow
9+
-XX:ReservedCodeCacheSize=256M
10+
-XX:PerMethodRecompilationCutoff=10000
11+
-XX:PerBytecodeRecompilationCutoff=10000
12+
-Djdk.attach.allowAttachSelf=true
13+
-Djdk.nio.maxCachedBufferSize=2000000
14+
# Reduce starvation of threads by GClocker, recommend to set about the number of cpu cores (JDK-8192647)
15+
-XX:+UnlockDiagnosticVMOptions
16+
-XX:GCLockerRetryAllocationCount=32
17+
# Allow loading dynamic agent used by JOL
18+
-XX:+EnableDynamicAgentLoading

docker/default/etc/log.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Enable verbose logging from Trino
2+
#io.trino=DEBUG

docker/default/etc/node.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node.environment=docker
2+
node.data-dir=/data/trino-gateway

docker/docker-compose.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ services:
1212
start_period: 20s
1313
ports:
1414
- "8080:8080"
15-
volumes:
16-
- target: /etc/trino-gateway/config.yaml
17-
source: ./config.yaml
18-
type: bind
1915

2016
postgres:
2117
image: ${TRINO_GATEWAY_POSTGRES_IMAGE:-postgres}

gateway-ha/src/main/java/io/trino/gateway/ha/HaGatewayLauncher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ public static void main(String[] args)
109109
throws Exception
110110
{
111111
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
112-
if (args.length != 1) {
113-
throw new IllegalArgumentException("Expected exactly one argument (path of configuration file)");
112+
String configFile = System.getProperty("config");
113+
if (configFile == null) {
114+
throw new IllegalArgumentException("Configuration file not specified. Use -Dconfig=<config-file>");
114115
}
115-
String config = Files.readString(Path.of(args[0]));
116+
String config = Files.readString(Path.of(configFile));
116117
HaGatewayConfiguration haGatewayConfiguration = objectMapper.readValue(replaceEnvironmentVariables(config), HaGatewayConfiguration.class);
117118
FlywayMigration.migrate(haGatewayConfiguration.getDataStore());
118119
List<Module> modules = addModules(haGatewayConfiguration);

gateway-ha/src/test/java/io/trino/gateway/TrinoGatewayRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public static void main(String[] args)
6060
mysql.withCopyFileToContainer(forClasspathResource("add_backends_mysql.sql"), "/docker-entrypoint-initdb.d/2-add_backends_mysql.sql");
6161
mysql.setPortBindings(List.of("3306:3306"));
6262
mysql.start();
63-
HaGatewayLauncher.main(new String[] {"gateway-ha/config.yaml"});
63+
System.setProperty("config", "gateway-ha/config.yaml");
64+
HaGatewayLauncher.main(new String[] {});
6465

6566
log.info("======== SERVER STARTED ========");
6667
}

gateway-ha/src/test/java/io/trino/gateway/ha/TestGatewayHaMultipleBackend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public MockResponse dispatch(RecordedRequest request)
120120
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");
121121

122122
// Start Gateway
123-
String[] args = {testConfigFile.getAbsolutePath()};
124-
HaGatewayLauncher.main(args);
123+
System.setProperty("config", testConfigFile.getAbsolutePath());
124+
HaGatewayLauncher.main(new String[] {});
125125
// Now populate the backend
126126
HaGatewayTestUtils.setUpBackend(
127127
"trino1", "http://localhost:" + backend1Port, "externalUrl", true, "adhoc", routerPort);

gateway-ha/src/test/java/io/trino/gateway/ha/TestGatewayHaSingleBackend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ void setup()
5858
File testConfigFile =
5959
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");
6060
// Start Gateway
61-
String[] args = {testConfigFile.getAbsolutePath()};
62-
HaGatewayLauncher.main(args);
61+
System.setProperty("config", testConfigFile.getAbsolutePath());
62+
HaGatewayLauncher.main(new String[] {});
6363
// Now populate the backend
6464
HaGatewayTestUtils.setUpBackend(
6565
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);

gateway-ha/src/test/java/io/trino/gateway/ha/TestGatewayHaWithRoutingRulesSingleBackend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void setup()
5555
File testConfigFile =
5656
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-with-routing-template.yml");
5757
// Start Gateway
58-
String[] args = {testConfigFile.getAbsolutePath()};
59-
HaGatewayLauncher.main(args);
58+
System.setProperty("config", testConfigFile.getAbsolutePath());
59+
HaGatewayLauncher.main(new String[] {});
6060
// Now populate the backend
6161
HaGatewayTestUtils.setUpBackend(
6262
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "system", routerPort);

gateway-ha/src/test/java/io/trino/gateway/ha/TestNoXForwarded.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ void setup()
5757
File testConfigFile =
5858
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-without-x-forwarded-template.yml");
5959
// Start Gateway
60-
String[] args = {testConfigFile.getAbsolutePath()};
61-
HaGatewayLauncher.main(args);
60+
System.setProperty("config", testConfigFile.getAbsolutePath());
61+
HaGatewayLauncher.main(new String[] {});
6262
// Now populate the backend
6363
HaGatewayTestUtils.setUpBackend(
6464
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);

gateway-ha/src/test/java/io/trino/gateway/ha/TestTrinoResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void setup()
7070
resourceGroupManager = new HaResourceGroupsManager(connectionManager);
7171

7272
// Start Trino Gateway so migrations are run to create tables before inserting test data
73-
String[] args = {testConfigFile.getAbsolutePath()};
74-
HaGatewayLauncher.main(args);
73+
System.setProperty("config", testConfigFile.getAbsolutePath());
74+
HaGatewayLauncher.main(new String[] {});
7575

7676
prepareData();
7777
}

gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void setup()
6363
File testConfigFile =
6464
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-with-routing-rules-api.yml");
6565
// Start Gateway
66-
String[] args = {testConfigFile.getAbsolutePath()};
67-
HaGatewayLauncher.main(args);
66+
System.setProperty("config", testConfigFile.getAbsolutePath());
67+
HaGatewayLauncher.main(new String[] {});
6868
// Now populate the backend
6969
HaGatewayTestUtils.setUpBackend(
7070
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);

gateway-ha/src/test/java/io/trino/gateway/ha/security/TestAuthorization.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void setup()
5555
{
5656
postgresql.start();
5757
File testConfigFile = HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "auth/auth-test-config.yml");
58-
String[] args = {testConfigFile.getAbsolutePath()};
59-
HaGatewayLauncher.main(args);
58+
System.setProperty("config", testConfigFile.getAbsolutePath());
59+
HaGatewayLauncher.main(new String[] {});
6060
}
6161

6262
@Test

gateway-ha/src/test/java/io/trino/gateway/ha/security/TestOIDC.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ void setup()
146146

147147
File testConfigFile =
148148
HaGatewayTestUtils.buildGatewayConfig(gatewayBackendDatabase, ROUTER_PORT, "auth/oauth-test-config.yml");
149-
String[] args = {testConfigFile.getAbsolutePath()};
150149
System.out.println(ROUTER_PORT);
151-
HaGatewayLauncher.main(args);
150+
System.setProperty("config", testConfigFile.getAbsolutePath());
151+
HaGatewayLauncher.main(new String[] {});
152152
}
153153

154154
@Test

gateway-ha/src/test/java/io/trino/gateway/proxyserver/TestProxyRequestHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public MockResponse dispatch(RecordedRequest request)
8585

8686
File testConfigFile = buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");
8787

88-
String[] args = {testConfigFile.getAbsolutePath()};
89-
HaGatewayLauncher.main(args);
88+
System.setProperty("config", testConfigFile.getAbsolutePath());
89+
HaGatewayLauncher.main(new String[] {});
9090

9191
setUpBackend("custom", "http://localhost:" + customBackendPort, "externalUrl", true, "adhoc", routerPort);
9292
}

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<modules>
3131
<module>gateway-ha</module>
32+
<module>trino-gateway-server</module>
3233
</modules>
3334
<scm>
3435
<connection>scm:git:git://github.com/trinodb/trino-gateway.git</connection>
@@ -44,6 +45,7 @@
4445
<air.check.skip-spotbugs>true</air.check.skip-spotbugs>
4546
<air.check.skip-pmd>true</air.check.skip-pmd>
4647
<air.release.preparation-goals>clean verify -DskipTests</air.release.preparation-goals>
48+
<dep.airlift.launcher.version>304</dep.airlift.launcher.version>
4749
</properties>
4850

4951
<dependencyManagement>

trino-gateway-server/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.trino.gateway</groupId>
6+
<artifactId>trino-gateway-parent</artifactId>
7+
<version>16-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>trino-gateway-server</artifactId>
11+
<packaging>provisio</packaging>
12+
<description>Trino Gateway - Server package</description>
13+
14+
<properties>
15+
<dep.takari.version>2.1.4</dep.takari.version>
16+
<server.tar.package>trino-gateway-server-${project.version}</server.tar.package>
17+
18+
<!-- Launcher properties -->
19+
<main-class>io.trino.gateway.ha.HaGatewayLauncher</main-class>
20+
<process-name>${project.artifactId}</process-name>
21+
22+
<!-- Special consideration for Takari Lifecycle -->
23+
<!-- This works as trino-server have no sources (is just provisio packaged) -->
24+
<takari.skip>false</takari.skip>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.junit.jupiter</groupId>
30+
<artifactId>junit-jupiter-api</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter-engine</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>ca.vanzyl.provisio.maven.plugins</groupId>
45+
<artifactId>provisio-maven-plugin</artifactId>
46+
<version>1.0.24</version>
47+
<extensions>true</extensions>
48+
<executions>
49+
<execution>
50+
<id>pack</id>
51+
<goals>
52+
<goal>provision</goal>
53+
</goals>
54+
<configuration>
55+
<descriptorDirectory>${project.basedir}/src/main/provisio</descriptorDirectory>
56+
<outputDirectory>${project.build.directory}/${server.tar.package}</outputDirectory>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
62+
<plugin>
63+
<groupId>io.takari.maven.plugins</groupId>
64+
<artifactId>takari-lifecycle-plugin</artifactId>
65+
<version>${dep.takari.version}</version>
66+
<configuration>
67+
<proc>none</proc>
68+
<skip>${takari.skip}</skip>
69+
</configuration>
70+
</plugin>
71+
72+
<plugin>
73+
<groupId>org.basepom.maven</groupId>
74+
<artifactId>duplicate-finder-maven-plugin</artifactId>
75+
<configuration>
76+
<ignoredResourcePatterns combine.children="append">
77+
<ignoredResourcePattern>aircompressor.*</ignoredResourcePattern>
78+
</ignoredResourcePatterns>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<runtime>
2+
<!-- Target -->
3+
<archive name="${project.artifactId}-${project.version}.tar.gz" hardLinkIncludes="**/*.jar" />
4+
5+
<!-- Launcher -->
6+
<artifactSet to="bin">
7+
<artifact id="io.airlift:launcher:tar.gz:bin:${dep.airlift.launcher.version}">
8+
<unpack />
9+
</artifact>
10+
<artifact id="io.airlift:launcher:tar.gz:properties:${dep.airlift.launcher.version}">
11+
<unpack filter="true" />
12+
</artifact>
13+
</artifactSet>
14+
15+
<!-- Gateway Server -->
16+
<artifactSet to="lib">
17+
<artifact id="${project.groupId}:gateway-ha:${project.version}" />
18+
</artifactSet>
19+
20+
</runtime>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.gateway.server;
15+
16+
import org.junit.jupiter.api.Test;
17+
18+
public class TestDummy
19+
{
20+
@Test
21+
public void buildRequiresTestToExist() {}
22+
}

0 commit comments

Comments
 (0)