Skip to content

Commit f06d988

Browse files
committed
Improve quickstart guide scripts
1 parent 4f77442 commit f06d988

File tree

2 files changed

+63
-51
lines changed

2 files changed

+63
-51
lines changed

docs/quickstart-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
serverConfig:
22
node.environment: test
33
http-server.http.port: 8080
4-
log.levels-file: gateway-ha/etc/log.properties
54

65
dataStore:
76
#This stores the URLs of backend Trino servers and query history

docs/quickstart.md

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,44 @@ It copies the following, necessary files to current directory:
2222
#!/usr/bin/env sh
2323

2424
VERSION=13
25-
26-
# Copy necessary files to current directory
27-
28-
# Check and get the Gateway Jar
29-
if [[ -f "gateway-ha.jar" ]]; then
30-
echo "Found gateway-har.jar file in current directory."
31-
else
32-
echo "Failed to find gateway-ha.jar in current directory. Fetching version $VERSION from Maven Central repository."
33-
curl https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha/${VERSION}/gateway-ha-${VERSION}-jar-with-dependencies.jar -o ./gateway-ha.jar
34-
fi
35-
36-
# Check and get the Config.yaml
37-
if [[ -f "quickstart-config.yaml" ]]; then
38-
echo "Found quickstart-config.yaml file in current directory."
39-
else
40-
cp ../docs/quickstart-config.yaml ./quickstart-config.yaml
41-
fi
42-
43-
#Check if DB is running
44-
if docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then
45-
echo "PostgreSQL database container 'localhost-postgres' is already running. Only starting Trino Gateway."
46-
else
47-
echo "PostgreSQL database container 'localhost-postgres' is not running. Proceeding to initialize and run database server."
48-
export PGPASSWORD=mysecretpassword
49-
docker run --name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest
50-
#Make sure the DB has time to initialize
51-
sleep 5
52-
53-
#Initialize the DB
54-
docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway'
55-
fi
56-
57-
58-
#Start Trino Gateway server.
59-
java -Xmx1g -jar ./gateway-ha.jar ./quickstart-config.yaml
25+
BASE_URL="https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha"
26+
POSTGRES_SQL="gateway-ha-persistence-postgres.sql"
27+
JAR_FILE="gateway-ha-$VERSION-jar-with-dependencies.jar"
28+
GATEWAY_JAR="gateway-ha.jar"
29+
CONFIG_YAML="quickstart-config.yaml"
30+
31+
# Copy necessary files
32+
copy_files() {
33+
if [[ ! -f "$GATEWAY_JAR" ]]; then
34+
echo "Fetching $GATEWAY_JAR version $VERSION"
35+
curl -O "$BASE_URL/$VERSION/$JAR_FILE"
36+
mv "$JAR_FILE" "$GATEWAY_JAR"
37+
fi
38+
39+
[[ ! -f "$CONFIG_YAML" ]] && cp ../docs/$CONFIG_YAML .
40+
[[ ! -f "$POSTGRES_SQL" ]] && cp ../gateway-ha/src/main/resources/$POSTGRES_SQL .
41+
}
42+
43+
# Start PostgreSQL database if not running
44+
start_postgres_db() {
45+
if ! docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then
46+
echo "Starting PostgreSQL database container"
47+
PGPASSWORD=mysecretpassword
48+
docker run -v "$PWD/$POSTGRES_SQL:/tmp/$POSTGRES_SQL" \
49+
--name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres
50+
sleep 5
51+
docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway'
52+
docker exec local-postgres psql -U postgres -h localhost -d gateway -f /tmp/$POSTGRES_SQL
53+
fi
54+
}
55+
56+
# Main execution flow
57+
copy_files
58+
start_postgres_db
59+
60+
# Start Trino Gateway server
61+
echo "Starting Trino Gateway server..."
62+
java -Xmx1g -jar ./$GATEWAY_JAR ./$CONFIG_YAML
6063
```
6164

6265
You can clean up by running
@@ -75,21 +78,31 @@ to the Trino Gateway server started by the preceding script.
7578
```shell
7679
#!/usr/bin/env sh
7780

78-
#Start a pair of trino servers on different ports
79-
docker run --name trino1 -d -p 8081:8080 -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino
80-
docker run --name trino2 -d -p 8082:8080 -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino
81-
82-
#Add the trino servers as Gateway backends
83-
curl -H "Content-Type: application/json" -X POST localhost:8080/gateway/backend/modify/add -d '{"name": "trino1",
84-
"proxyTo": "http://localhost:8081",
85-
"active": true,
86-
"routingGroup": "adhoc"
87-
}'
88-
curl -H "Content-Type: application/json" -X POST localhost:8080/gateway/backend/modify/add -d '{"name": "trino2",
89-
"proxyTo": "http://localhost:8082",
90-
"active": true,
91-
"routingGroup": "adhoc"
92-
}'
81+
TRINO_IMAGE="trinodb/trino"
82+
JAVA_OPTS="-Dhttp-server.process-forwarded=true"
83+
84+
# Start Trino servers
85+
for i in 1 2; do
86+
docker run --name trino$i -d -p 808$i:8080 \
87+
-e JAVA_TOOL_OPTIONS="$JAVA_OPTS" $TRINO_IMAGE
88+
done
89+
90+
# Add Trino servers as Gateway backends
91+
add_backend() {
92+
curl -H "Content-Type: application/json" -X POST \
93+
localhost:8080/gateway/backend/modify/add \
94+
-d "{
95+
\"name\": \"$1\",
96+
\"proxyTo\": \"http://localhost:808$2\",
97+
\"active\": true,
98+
\"routingGroup\": \"adhoc\"
99+
}"
100+
}
101+
102+
# Adding Trino servers as backends
103+
for i in 1 2; do
104+
add_backend "trino$i" "$i"
105+
done
93106
```
94107

95108
You can clean up by running

0 commit comments

Comments
 (0)