Skip to content

Commit

Permalink
Merge pull request #1407 from NASA-AMMOS/fix/add-merlin
Browse files Browse the repository at this point in the history
Add Missing `merlin` Prefix
  • Loading branch information
Mythicaeda authored Apr 17, 2024
2 parents 19ceee2 + b1257be commit 739acf3
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 21 deletions.
20 changes: 20 additions & 0 deletions db-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ jacocoTestReport {
}

task e2eTest(type: Test) {
ext.parseEnvFile = { filePath ->
file(filePath).readLines().each() {
if (!it.isEmpty() && !it.startsWith("#")) {
def (key, value) = it.tokenize('=')
if (key.startsWith("export ")) {
key = key.split("export ")[1];
}
if (System.getenv(key) == null) {
environment key, value
}
}
}
}

if(file('../e2e-tests/.env').exists()) {
parseEnvFile('../e2e-tests/.env')
} else if(file('../.env').exists()){
parseEnvFile('../.env')
}

useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;

import java.io.File;
Expand Down Expand Up @@ -34,22 +35,28 @@ public DatabaseTestHelper(String dbName, String appName) throws SQLException, IO
* Sets up the test database
*/
private HikariDataSource startDatabase() throws IOException, InterruptedException {
// Load database admin credentials from the environment
final var aerieUsername = getEnv("AERIE_USERNAME");
final var aeriePassword = getEnv("AERIE_PASSWORD");

final var postgresUsername = getEnv("POSTGRES_USER");
final var postgresPassword = getEnv("POSTGRES_PASSWORD");

// Create test database and grant privileges
{
final var pb = new ProcessBuilder("psql",
"postgresql://postgres:postgres@localhost:5432",
"postgresql://"+postgresUsername+":"+postgresPassword+"@localhost:5432/postgres",
"-v", "ON_ERROR_STOP=1",
"-c", "CREATE DATABASE " + dbName + ";",
"-c", "GRANT ALL PRIVILEGES ON DATABASE " + dbName + " TO aerie;"
"-c", "GRANT ALL PRIVILEGES ON DATABASE " + dbName + " TO "+aerieUsername+";"
);

final var proc = pb.start();

// Handle the case where we cannot connect to postgres by skipping the tests
final var errors = new String(proc.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
Assumptions.assumeFalse(
( errors.contains("Connection refused")
|| errors.contains("role \"postgres\" does not exist")));
|| errors.contains("role \""+postgresUsername+"\" does not exist")));
proc.waitFor();
proc.destroy();
}
Expand All @@ -58,9 +65,9 @@ private HikariDataSource startDatabase() throws IOException, InterruptedExceptio
// Apparently, the previous privileges are insufficient on their own
{
final var pb = new ProcessBuilder("psql",
"postgresql://aerie:aerie@localhost:5432/" + dbName,
"postgresql://"+aerieUsername+":"+aeriePassword+"@localhost:5432/" + dbName,
"-v", "ON_ERROR_STOP=1",
"-c", "ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO aerie;",
"-c", "ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO "+aerieUsername+";",
"-c", "\\ir %s".formatted(initSqlScriptFile.getAbsolutePath())
);

Expand All @@ -77,8 +84,9 @@ private HikariDataSource startDatabase() throws IOException, InterruptedExceptio
hikariConfig.addDataSourceProperty("portNumber", "5432");
hikariConfig.addDataSourceProperty("databaseName", dbName);
hikariConfig.addDataSourceProperty("applicationName", appName);
hikariConfig.setUsername("aerie");
hikariConfig.setPassword("aerie");

hikariConfig.setUsername(aerieUsername);
hikariConfig.setPassword(aeriePassword);

hikariConfig.setConnectionInitSql("set time zone 'UTC'");

Expand All @@ -92,12 +100,16 @@ public void close() throws SQLException, IOException, InterruptedException {
Assumptions.assumeTrue(connection != null);
connection.close();

// Grab postgres credentials from environment
final var postgresUsername = getEnv("POSTGRES_USER");
final var postgresPassword = getEnv("POSTGRES_PASSWORD");

// Clear out all data from the database on test conclusion
// This is done WITH (FORCE) so there aren't issues with trying
// to drop a database while there are connected sessions from
// dev tools
final var pb = new ProcessBuilder("psql",
"postgresql://postgres:postgres@localhost:5432",
"postgresql://"+postgresUsername+":"+postgresPassword+"@localhost:5432/postgres",
"-v", "ON_ERROR_STOP=1",
"-c", "DROP DATABASE IF EXISTS " + dbName + " WITH (FORCE);"
);
Expand All @@ -114,6 +126,11 @@ public Connection connection() {
return connection;
}

private static String getEnv(final String key) {
final var env = System.getenv(key);
return env == null ? Assertions.fail("Could not find envvar: "+key) : env;
}

public void clearTable(@Language(value="SQL", prefix="SELECT * FROM ") String table) throws SQLException {
try (final var statement = connection.createStatement()) {
statement.executeUpdate("TRUNCATE " + table + " CASCADE;");
Expand Down
10 changes: 5 additions & 5 deletions deployment/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ DOCKER_TAG=latest

# Provide Usernames and Passwords Below

AERIE_USERNAME=aerie
AERIE_USERNAME=aerie_service
AERIE_PASSWORD=

GATEWAY_USERNAME=gateway
GATEWAY_USERNAME=gateway_service
GATEWAY_PASSWORD=

MERLIN_USERNAME=merlin
MERLIN_USERNAME=merlin_service
MERLIN_PASSWORD=

SCHEDULER_USERNAME=scheduler
SCHEDULER_USERNAME=scheduler_service
SCHEDULER_PASSWORD=

SEQUENCING_USERNAME=sequencing
SEQUENCING_USERNAME=sequencing_service
SEQUENCING_PASSWORD=

HASURA_GRAPHQL_ADMIN_SECRET=
Expand Down
10 changes: 5 additions & 5 deletions deployment/Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See the [environment variables document](https://github.com/NASA-AMMOS/aerie-gat
| `JAVA_OPTS` | Configuration for Merlin's logging level and output file | `string` | log level: warn. output: stderr |
| `MERLIN_PORT` | Port number for the Merlin server | `number` | 27183 |
| `MERLIN_LOCAL_STORE` | Local storage for Merlin in the container | `string` | /usr/src/app/merlin_file_store |
| `MERLIN_DB_USER` | Username of the Merlin DB User | `string` | merlin |
| `MERLIN_DB_USER` | Username of the Merlin DB User | `string` | merlin_service |
| `MERLIN_DB_PASSWORD` | Password of the Merlin DB User | `string` | |
| `UNTRUE_PLAN_START` | Temporary solution to provide plan start time to models, should be set to a time that models will not fail to initialize on | `string` | |
| `ENABLE_CONTINUOUS_VALIDATION_THREAD` | Flag to enable a worker thread that continuously computes and caches activity directive validation results | `boolean` | true |
Expand All @@ -37,7 +37,7 @@ See the [environment variables document](https://github.com/NASA-AMMOS/aerie-gat
| `AERIE_DB_PORT` | The DB instance port number that Merlin will connect with | `number` | 5432 |
| `JAVA_OPTS` | Configuration for Merlin's logging level and output file | `string` | log level: warn. output: stderr |
| `MERLIN_WORKER_LOCAL_STORE` | The local storage as for the Merlin container | `string` | /usr/src/app/merlin_file_store |
| `MERLIN_DB_USER` | Username of the Merlin DB User | `string` | merlin |
| `MERLIN_DB_USER` | Username of the Merlin DB User | `string` | merlin_service |
| `MERLIN_DB_PASSWORD` | Password of the Merlin DB User | `string` | (this must the same as the Merlin container) |
| `SIMULATION_PROGRESS_POLL_PERIOD_MILLIS` | Cadence at which the worker will report simulation progress to the database. | `number` | 5000 |
| `UNTRUE_PLAN_START` | Temporary solution to provide plan start time to models, should be set to a time that models will not fail to initialize on | `string` | |
Expand All @@ -51,7 +51,7 @@ See the [environment variables document](https://github.com/NASA-AMMOS/aerie-gat
| `HASURA_GRAPHQL_ADMIN_SECRET` | The admin secret for Hasura which gives admin access if used. | `string` | |
| `JAVA_OPTS` | Configuration for the scheduler's logging level and output file | `string` | log level: warn. output: stderr |
| `MERLIN_GRAPHQL_URL` | URI of the Merlin graphql interface to call | `string` | http://hasura:8080/v1/graphql |
| `SCHEDULER_DB_USER` | Username of the Scheduler DB User | `string` | scheduler |
| `SCHEDULER_DB_USER` | Username of the Scheduler DB User | `string` | scheduler_service |
| `SCHEDULER_DB_PASSWORD` | Password of the Scheduler DB User | `string` | |
| `SCHEDULER_PORT` | Port number for the scheduler server | `number` | 27185 |

Expand All @@ -65,7 +65,7 @@ See the [environment variables document](https://github.com/NASA-AMMOS/aerie-gat
| `JAVA_OPTS` | Configuration for the scheduler's logging level and output file | `string` | log level: warn. output: stderr |
| `MERLIN_GRAPHQL_URL` | URI of the Merlin graphql interface to call | `string` | http://hasura:8080/v1/graphql |
| `MERLIN_LOCAL_STORE` | Local storage for Merlin in the container (for backdoor jar access) | `string` | /usr/src/app/merlin_file_store |
| `SCHEDULER_DB_USER` | Username of the Scheduler DB User | `string` | scheduler |
| `SCHEDULER_DB_USER` | Username of the Scheduler DB User | `string` | scheduler_service |
| `SCHEDULER_DB_PASSWORD` | Password of the Scheduler DB User | `string` | |
| `SCHEDULER_OUTPUT_MODE` | How scheduler output is sent back to Aerie | `string` | UpdateInputPlanWithNewActivities |
| `SCHEDULER_RULES_JAR` | Jar file to load scheduling rules from (until user input to database) | `string` | /usr/src/app/merlin_file_store/scheduler_rules.jar |
Expand All @@ -80,7 +80,7 @@ See the [environment variables document](https://github.com/NASA-AMMOS/aerie-gat
| `LOG_FILE` | Either an output filepath to log to, or 'console' | `string` | console |
| `LOG_LEVEL` | Logging level for filtering logs | `string` | warn |
| `MERLIN_GRAPHQL_URL` | URI of the Aerie GraphQL API | `string` | http://hasura:8080/v1/graphql |
| `SEQUENCING_DB_USER` | Username of the Sequencing DB User | `string` | sequencing |
| `SEQUENCING_DB_USER` | Username of the Sequencing DB User | `string` | sequencing_service |
| `SEQUENCING_DB_PASSWORD` | Password of the Sequencing DB User | `string` | |
| `SEQUENCING_LOCAL_STORE` | Local storage file storage in the container | `string` | /usr/src/app/sequencing_file_store |
| `SEQUENCING_SERVER_PORT` | Port the server listens on | `number` | 27184 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ResultsProtocol.OwnerRole forceAllocate(PlanId planId, String requestedBy
final var updateSimConfig = new UpdateSimulationConfigurationRevisionAction(connection)) {
updateSimConfig.apply(planId.id());
} catch (final SQLException ex) {
throw new DatabaseException("Failed to allocation simulation cell", ex);
throw new DatabaseException("Failed to allocate simulation cell", ex);
}
return allocate(planId, requestedBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/*package-local*/ final class UpdateSimulationConfigurationRevisionAction implements AutoCloseable {
private final @Language("SQL") String sql = """
update simulation
update merlin.simulation
set revision = revision
where plan_id = ?;
""";
Expand Down

0 comments on commit 739acf3

Please sign in to comment.