-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...in/kotlin/com/atlassian/performance/tools/infrastructure/api/database/PostgresDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.atlassian.performance.tools.infrastructure.api.database | ||
|
||
import com.atlassian.performance.tools.infrastructure.DockerImage | ||
import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage | ||
import com.atlassian.performance.tools.ssh.api.SshConnection | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.logging.log4j.Logger | ||
import java.net.URI | ||
import java.time.Duration | ||
|
||
class PostgresDatabase( | ||
private val source: DatasetPackage, | ||
private val maxConnections: Int | ||
) : Database { | ||
private val logger: Logger = LogManager.getLogger(this::class.java) | ||
|
||
private val image: DockerImage = DockerImage( | ||
name = "postgres:9.6.15", | ||
pullTimeout = Duration.ofMinutes(5) | ||
) | ||
|
||
constructor( | ||
source: DatasetPackage | ||
) : this( | ||
source = source, | ||
maxConnections = 200 | ||
) | ||
|
||
override fun setup(ssh: SshConnection): String { | ||
val data = source.download(ssh) | ||
val containerName = image.run( | ||
ssh = ssh, | ||
// TODO Dataset for Postgres | ||
// parameters = "-p 5432:5432 -v `realpath $data`:/", | ||
parameters = "-p 5432:5432", | ||
arguments = "-c 'listen_addresses='*'' -c 'max_connections=$maxConnections'" | ||
) | ||
Thread.sleep(Duration.ofSeconds(15).toMillis()) | ||
logger.debug("Postgres - creating jira user and database") | ||
ssh.execute("sudo docker exec -u postgres $containerName psql --command \"CREATE USER jira WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN PASSWORD 'jira';\"") | ||
ssh.execute("sudo docker exec -u postgres $containerName createdb -E UNICODE -l C -T template0 -O jira jira") | ||
return data | ||
} | ||
|
||
override fun start(jira: URI, ssh: SshConnection) { | ||
// TODO Check logs for the following entry | ||
// LOG: database system is ready to accept connections | ||
Thread.sleep(Duration.ofSeconds(15).toMillis()) | ||
} | ||
|
||
} |