From ef537776c5716fd5e6754eb6a9ee790f3c3b393c Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Tue, 3 Dec 2024 11:58:19 +0900 Subject: [PATCH 1/4] Clean up snippets in quickstart.md --- docs/quickstart.md | 139 +++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 406c366ec..ad8230780 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -22,49 +22,66 @@ It copies the following, necessary files to current directory: ```shell #!/usr/bin/env sh +# Set the version for the Gateway Jar VERSION=12 -# Copy necessary files to current directory - -# Check and get the Gateway Jar -if [[ -f "gateway-ha.jar" ]]; then - echo "Found gateway-har.jar file in current directory." -else - echo "Failed to find gateway-ha.jar in current directory. Fetching version $VERSION from Maven Central repository." - curl https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha/${VERSION}/gateway-ha-${VERSION}-jar-with-dependencies.jar -o ./gateway-ha.jar -fi - -# Check and get the Config.yaml -if [[ -f "quickstart-config.yaml" ]]; then - echo "Found quickstart-config.yaml file in current directory." -else - cp ../docs/quickstart-config.yaml ./quickstart-config.yaml -fi - -# Check and get the postgres.sql -if [[ -f "gateway-ha-persistence-postgres.sql" ]]; then - echo "Found gateway-ha-persistence-postgres.sql file in current directory." -else - cp ../gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql ./gateway-ha-persistence-postgres.sql -fi - -#Check if DB is running -if docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then - echo "PostgreSQL database container 'localhost-postgres' is already running. Only starting Trino Gateway." -else - echo "PostgreSQL database container 'localhost-postgres' is not running. Proceeding to initialize and run database server." - export PGPASSWORD=mysecretpassword - docker run -v "$(pwd)"/gateway-ha-persistence-postgres.sql:/tmp/gateway-ha-persistence-postgres.sql --name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest - #Make sure the DB has time to initialize - sleep 5 - - #Initialize the DB - docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway' - docker exec local-postgres psql -U postgres -h localhost -d gateway -f /tmp/gateway-ha-persistence-postgres.sql -fi - - -#Start Trino Gateway server. +# Function to copy necessary files to the current directory +copy_files() { + # Check and get the Gateway Jar + if [[ -f "gateway-ha.jar" ]]; then + echo "Found gateway-ha.jar file in current directory." + else + echo "Fetching gateway-ha.jar version $VERSION from Maven Central repository." + curl -O "https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha/${VERSION}/gateway-ha-${VERSION}-jar-with-dependencies.jar" + mv "gateway-ha-${VERSION}-jar-with-dependencies.jar" ./gateway-ha.jar + fi + + # Check and get the Config.yaml + if [[ -f "quickstart-config.yaml" ]]; then + echo "Found quickstart-config.yaml file in current directory." + else + cp ../docs/quickstart-config.yaml ./quickstart-config.yaml + fi + + # Check and get the postgres.sql + if [[ -f "gateway-ha-persistence-postgres.sql" ]]; then + echo "Found gateway-ha-persistence-postgres.sql file in current directory." + else + cp ../gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql ./gateway-ha-persistence-postgres.sql + fi +} + +# Function to check if PostgreSQL database is running and start it if not +start_postgres_db() { + if docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then + echo "PostgreSQL database container 'local-postgres' is already running. Only starting Trino Gateway." + else + echo "Starting PostgreSQL database container 'local-postgres'." + + # Set the password for PostgreSQL + export PGPASSWORD=mysecretpassword + + # Run PostgreSQL container with necessary configurations + docker run -v "$(pwd)"/gateway-ha-persistence-postgres.sql:/tmp/gateway-ha-persistence-postgres.sql \ + --name local-postgres -p 5432:5432 \ + -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest + + # Wait for the database to initialize + sleep 5 + + # Initialize the database and load the SQL script + docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway' + docker exec local-postgres psql -U postgres -h localhost -d gateway \ + -f /tmp/gateway-ha-persistence-postgres.sql + fi +} + +# Main execution flow +copy_files # Copy necessary files to current directory +start_postgres_db # Start PostgreSQL database if not running + +# Start Trino Gateway server. +echo "Starting Trino Gateway server..." java -Xmx1g -jar ./gateway-ha.jar ./quickstart-config.yaml ``` @@ -84,21 +101,31 @@ to the Trino Gateway server started by the preceding script. ```shell #!/usr/bin/env sh -#Start a pair of trino servers on different ports -docker run --name trino1 -d -p 8081:8080 -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino -docker run --name trino2 -d -p 8082:8080 -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino - -#Add the trino servers as Gateway backends -curl -H "Content-Type: application/json" -X POST localhost:8080/gateway/backend/modify/add -d '{"name": "trino1", - "proxyTo": "http://localhost:8081", - "active": true, - "routingGroup": "adhoc" - }' -curl -H "Content-Type: application/json" -X POST localhost:8080/gateway/backend/modify/add -d '{"name": "trino2", - "proxyTo": "http://localhost:8082", - "active": true, - "routingGroup": "adhoc" - }' +# Start a pair of Trino servers on different ports +docker run --name trino1 -d -p 8081:8080 \ + -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino + +docker run --name trino2 -d -p 8082:8080 \ + -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino + +# Add the Trino servers as Gateway backends +add_backend() { + local name=$1 + local proxy_to=$2 + + curl -H "Content-Type: application/json" -X POST \ + localhost:8080/gateway/backend/modify/add \ + -d "{ + \"name\": \"$name\", + \"proxyTo\": \"$proxy_to\", + \"active\": true, + \"routingGroup\": \"adhoc\" + }" +} + +# Adding Trino servers as backends +add_backend "trino1" "http://localhost:8081" +add_backend "trino2" "http://localhost:8082" }' ``` You can clean up by running From d6208167cb26e1d65ff6d94c20d64c3744988d61 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Fri, 6 Dec 2024 11:26:39 +0900 Subject: [PATCH 2/4] Apply feedbacks --- docs/quickstart.md | 60 +++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index b759a5b79..ac4ff65db 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -22,65 +22,39 @@ It copies the following, necessary files to current directory: ```shell #!/usr/bin/env sh -# Set the version for the Gateway Jar VERSION=13 +BASE_URL="https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha" -# Function to copy necessary files to the current directory +# Copy necessary files copy_files() { - # Check and get the Gateway Jar - if [[ -f "gateway-ha.jar" ]]; then - echo "Found gateway-ha.jar file in current directory." - else - echo "Fetching gateway-ha.jar version $VERSION from Maven Central repository." - curl -O "https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha/${VERSION}/gateway-ha-${VERSION}-jar-with-dependencies.jar" - mv "gateway-ha-${VERSION}-jar-with-dependencies.jar" ./gateway-ha.jar + if [[ ! -f "gateway-ha.jar" ]]; then + echo "Fetching gateway-ha.jar version $VERSION" + curl -O "$BASE_URL/$VERSION/gateway-ha-$VERSION-jar-with-dependencies.jar" + mv "gateway-ha-$VERSION-jar-with-dependencies.jar" gateway-ha.jar fi - # Check and get the Config.yaml - if [[ -f "quickstart-config.yaml" ]]; then - echo "Found quickstart-config.yaml file in current directory." - else - cp ../docs/quickstart-config.yaml ./quickstart-config.yaml - fi - - # Check and get the postgres.sql - if [[ -f "gateway-ha-persistence-postgres.sql" ]]; then - echo "Found gateway-ha-persistence-postgres.sql file in current directory." - else - cp ../gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql ./gateway-ha-persistence-postgres.sql - fi + [[ ! -f "quickstart-config.yaml" ]] && cp ../docs/quickstart-config.yaml . + [[ ! -f "gateway-ha-persistence-postgres.sql" ]] && cp ../gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql . } -# Function to check if PostgreSQL database is running and start it if not +# Start PostgreSQL database if not running start_postgres_db() { - if docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then - echo "PostgreSQL database container 'local-postgres' is already running. Only starting Trino Gateway." - else - echo "Starting PostgreSQL database container 'local-postgres'." - - # Set the password for PostgreSQL - export PGPASSWORD=mysecretpassword - - # Run PostgreSQL container with necessary configurations + if ! docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then + echo "Starting PostgreSQL database container" + PGPASSWORD=mysecretpassword docker run -v "$(pwd)"/gateway-ha-persistence-postgres.sql:/tmp/gateway-ha-persistence-postgres.sql \ - --name local-postgres -p 5432:5432 \ - -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest - - # Wait for the database to initialize + --name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest sleep 5 - - # Initialize the database and load the SQL script docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway' - docker exec local-postgres psql -U postgres -h localhost -d gateway \ - -f /tmp/gateway-ha-persistence-postgres.sql + docker exec local-postgres psql -U postgres -h localhost -d gateway -f /tmp/gateway-ha-persistence-postgres.sql fi } # Main execution flow -copy_files # Copy necessary files to current directory -start_postgres_db # Start PostgreSQL database if not running +copy_files +start_postgres_db -# Start Trino Gateway server. +# Start Trino Gateway server echo "Starting Trino Gateway server..." java -Xmx1g -jar ./gateway-ha.jar ./quickstart-config.yaml ``` From a70c51a9e6b6ef9ff607ec17147027007b421b32 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Fri, 6 Dec 2024 11:32:36 +0900 Subject: [PATCH 3/4] Apply feedbacks --- docs/quickstart.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index ac4ff65db..54084e3cf 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -24,17 +24,21 @@ It copies the following, necessary files to current directory: VERSION=13 BASE_URL="https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha" +POSTGRES_SQL="gateway-ha-persistence-postgres.sql" +JAR_FILE="gateway-ha-$VERSION-jar-with-dependencies.jar" +GATEWAY_JAR="gateway-ha.jar" +CONFIG_YAML="quickstart-config.yaml" # Copy necessary files copy_files() { - if [[ ! -f "gateway-ha.jar" ]]; then - echo "Fetching gateway-ha.jar version $VERSION" - curl -O "$BASE_URL/$VERSION/gateway-ha-$VERSION-jar-with-dependencies.jar" - mv "gateway-ha-$VERSION-jar-with-dependencies.jar" gateway-ha.jar + if [[ ! -f "$GATEWAY_JAR" ]]; then + echo "Fetching $GATEWAY_JAR version $VERSION" + curl -O "$BASE_URL/$VERSION/$JAR_FILE" + mv "$JAR_FILE" "$GATEWAY_JAR" fi - [[ ! -f "quickstart-config.yaml" ]] && cp ../docs/quickstart-config.yaml . - [[ ! -f "gateway-ha-persistence-postgres.sql" ]] && cp ../gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql . + [[ ! -f "$CONFIG_YAML" ]] && cp ../docs/$CONFIG_YAML . + [[ ! -f "$POSTGRES_SQL" ]] && cp ../gateway-ha/src/main/resources/$POSTGRES_SQL . } # Start PostgreSQL database if not running @@ -42,11 +46,11 @@ start_postgres_db() { if ! docker ps --format '{{.Names}}' | grep -q '^local-postgres$'; then echo "Starting PostgreSQL database container" PGPASSWORD=mysecretpassword - docker run -v "$(pwd)"/gateway-ha-persistence-postgres.sql:/tmp/gateway-ha-persistence-postgres.sql \ - --name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres:latest + docker run -v "$PWD/$POSTGRES_SQL:/tmp/$POSTGRES_SQL" \ + --name local-postgres -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d postgres sleep 5 docker exec local-postgres psql -U postgres -h localhost -c 'CREATE DATABASE gateway' - docker exec local-postgres psql -U postgres -h localhost -d gateway -f /tmp/gateway-ha-persistence-postgres.sql + docker exec local-postgres psql -U postgres -h localhost -d gateway -f /tmp/$POSTGRES_SQL fi } @@ -56,7 +60,7 @@ start_postgres_db # Start Trino Gateway server echo "Starting Trino Gateway server..." -java -Xmx1g -jar ./gateway-ha.jar ./quickstart-config.yaml +java -Xmx1g -jar ./$GATEWAY_JAR ./$CONFIG_YAML ``` You can clean up by running From ec5a675fa8080da16d09a32254d969ada4d895f1 Mon Sep 17 00:00:00 2001 From: Sangmin Yoon Date: Fri, 6 Dec 2024 11:34:33 +0900 Subject: [PATCH 4/4] Apply feedbacks --- docs/quickstart.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 54084e3cf..52acf14cc 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -79,31 +79,30 @@ to the Trino Gateway server started by the preceding script. ```shell #!/usr/bin/env sh -# Start a pair of Trino servers on different ports -docker run --name trino1 -d -p 8081:8080 \ - -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino +TRINO_IMAGE="trinodb/trino" +JAVA_OPTS="-Dhttp-server.process-forwarded=true" -docker run --name trino2 -d -p 8082:8080 \ - -e JAVA_TOOL_OPTIONS="-Dhttp-server.process-forwarded=true" trinodb/trino +# Start Trino servers +for i in 1 2; do + docker run --name trino$i -d -p 808$i:8080 \ + -e JAVA_TOOL_OPTIONS="$JAVA_OPTS" $TRINO_IMAGE +done -# Add the Trino servers as Gateway backends +# Add Trino servers as Gateway backends add_backend() { - local name=$1 - local proxy_to=$2 - curl -H "Content-Type: application/json" -X POST \ localhost:8080/gateway/backend/modify/add \ -d "{ - \"name\": \"$name\", - \"proxyTo\": \"$proxy_to\", + \"name\": \"$1\", + \"proxyTo\": \"http://localhost:808$2\", \"active\": true, \"routingGroup\": \"adhoc\" }" } -# Adding Trino servers as backends -add_backend "trino1" "http://localhost:8081" -add_backend "trino2" "http://localhost:8082" }' +for i in 1 2; do + add_backend "trino$i" "$i" +done }' ``` You can clean up by running