Skip to content

Commit

Permalink
Add gateway runner with docker containers
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Jan 11, 2024
1 parent 89c5c5e commit 929129b
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 90 deletions.
45 changes: 11 additions & 34 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,22 @@

# Development

## How to setup a dev environment
## Build requirements

Step 1: setup mysql. Install docker with docker-compose and run the below
command when setting up first time:
* Mac OS X or Linux
* Java 17+, 64-bit
* Docker

#### Run the services - mysqldb, two instances of trino
#### Running Trino Gateway in your IDE

- This setup helps you develop and test any routing rules for the trino
- Both trino services would have a single `system` catalog
- Add the catalog properties files in ` bin/localdev/coordinator/` for
additional catalogs
The best way to run Trino Gateway for development is to run the
`TrinoGatewayRunner` class.
You need to run `io.trino.gateway.TrinoGatewayRunner.main()` method on your IDE
or execute the following command:

```sh
./mvnw test-compile exec:java -pl gateway-ha -Dexec.classpathScope=test -Dexec.mainClass="io.trino.gateway.TrinoGatewayRunner"
```
cd localdev
docker-compose up -d
```

#### Check the "Status' of the services by

`docker-compose ps`

#### Create the schema for the backends, once mysqldb becomes healthy

`docker-compose exec mysqldb sh -c "mysql -uroot -proot123 -hmysqldb -Dtrinogateway < /etc/mysql/gateway-ha-persistence.sql"`

#### Add the backends for mysqldb

`docker-compose exec mysqldb sh -c "mysql -uroot -proot123 -hmysqldb -Dtrinogateway < /etc/mysql/add_backends.sql"`

#### Create the schema for the backends, once postgres becomes healthy

`docker-compose exec postgres sh -c 'PGPASSWORD="P0stG&es" psql -h localhost -p 5432 -U trino_gateway_db_admin -d trino_gateway_db -f /etc/postgresql/gateway-ha-persistence-postgres.sql'`

#### Add the backends for postgres

`docker-compose exec postgres sh -c 'PGPASSWORD="P0stG&es" psql -h localhost -p 5432 -U trino_gateway_db_admin -d trino_gateway_db -f /etc/postgresql/add_backends_postgres.sql'`

It would add 2 trino backend records which can be used for the development and
testing

### Build and run

Expand Down
13 changes: 12 additions & 1 deletion gateway-ha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,21 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>trino</artifactId>
<version>1.19.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
64 changes: 64 additions & 0 deletions gateway-ha/src/test/java/io/trino/gateway/TrinoGatewayRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.gateway;

import io.trino.gateway.ha.HaGatewayLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.TrinoContainer;

import java.util.List;

import static org.testcontainers.utility.MountableFile.forClasspathResource;

public final class TrinoGatewayRunner
{
private TrinoGatewayRunner() {}

public static void main(String[] args)
throws Exception
{
TrinoContainer trino1 = new TrinoContainer("trinodb/trino:395");
trino1.setPortBindings(List.of("8081:8080"));
trino1.start();
TrinoContainer trino2 = new TrinoContainer("trinodb/trino:395");
trino2.setPortBindings(List.of("8082:8080"));
trino2.start();

PostgreSQLContainer<?> postgres = new PostgreSQLContainer("postgres:16");
postgres.withUsername("trino_gateway_db_admin");
postgres.withPassword("P0stG&es");
postgres.withDatabaseName("trino_gateway_db");
postgres.withCopyFileToContainer(forClasspathResource("gateway-ha-persistence-postgres.sql"), "/docker-entrypoint-initdb.d/1-gateway-ha-persistence-postgres.sql");
postgres.withCopyFileToContainer(forClasspathResource("add_backends_postgres.sql"), "/docker-entrypoint-initdb.d/2-add_backends_postgres.sql");
postgres.setPortBindings(List.of("5432:5432"));
postgres.start();

MySQLContainer<?> mysql = new MySQLContainer("mysql:5.7");
mysql.withUsername("root");
mysql.withPassword("root123");
mysql.withDatabaseName("trinogateway");
mysql.withCopyFileToContainer(forClasspathResource("gateway-ha-persistence.sql"), "/docker-entrypoint-initdb.d/1-gateway-ha-persistence.sql");
mysql.withCopyFileToContainer(forClasspathResource("add_backends.sql"), "/docker-entrypoint-initdb.d/2-add_backends.sql");
mysql.setPortBindings(List.of("3306:3306"));
mysql.start();

HaGatewayLauncher.main(new String[]{"server", "gateway-ha/gateway-ha-config.yml"});

Logger log = LoggerFactory.getLogger(TrinoGatewayRunner.class);
log.info("======== SERVER STARTED ========");
}
}
File renamed without changes.
File renamed without changes.
54 changes: 0 additions & 54 deletions localdev/docker-compose.yml

This file was deleted.

9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>1.19.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -108,7 +116,6 @@
<arg>-XDcompilePolicy=simple</arg>
<arg>
-Xplugin:ErrorProne
-Xep:MissingOverride:ERROR \
<!-- TODO: Enable DoubleBraceInitialization flag -->
-Xep:DoubleBraceInitialization:OFF
</arg>
Expand Down

0 comments on commit 929129b

Please sign in to comment.