Skip to content

Commit

Permalink
Merge pull request #492 from gokulprathin8/database-migration-pg-sql
Browse files Browse the repository at this point in the history
Support for MySQL and PostgreSQL - Production grade DB
  • Loading branch information
gokulprathin8 authored May 5, 2024
2 parents fbfa73a + 9ddf5ba commit 0ae752a
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 150 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/commit_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,107 @@ jobs:
with:
name: geoweaver-jacoco-coverage-report
path: target/site/jacoco
test-mysql:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:latest
env:
MYSQL_ROOT_PASSWORD: geoweaver
MYSQL_DATABASE: geoweaver
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping -h localhost" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
architecture: x64

- name: Create geoweaver directory and application.properties
run: |
mkdir -p ~/geoweaver
echo "spring.datasource.url=jdbc:mysql://localhost:3306/geoweaver" >> ~/geoweaver/application.properties
echo "spring.datasource.username=root" >> ~/geoweaver/application.properties
echo "spring.datasource.password=geoweaver" >> ~/geoweaver/application.properties
echo "spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver" >> ~/geoweaver/application.properties
echo "spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect" >> ~/geoweaver/application.properties
- name: Run Tests
run: |
mvn test jacoco:report
working-directory: ${{ github.workspace }}

- name: Check If All Tests Pass
run: |
if [ $? -eq 0 ]; then
echo "All tests passed successfully."
else
echo "Tests failed."
exit 1 # Exit with an error code to stop the workflow
fi
- name: Save Geoweaver JaCoCo HTML Report
uses: actions/upload-artifact@v2
with:
name: geoweaver-jacoco-coverage-report
path: target/site/jacoco

test-postgresql:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_PASSWORD: geoweaver
POSTGRES_DB: geoweaver
ports:
- 5432:5432
options: --health-cmd="pg_isready -U postgres" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
architecture: x64

- name: Create geoweaver directory and application.properties
run: |
mkdir -p ~/geoweaver
echo "spring.datasource.url=jdbc:postgresql://localhost:5432/geoweaver" >> ~/geoweaver/application.properties
echo "spring.datasource.username=postgres" >> ~/geoweaver/application.properties
echo "spring.datasource.password=geoweaver" >> ~/geoweaver/application.properties
echo "spring.datasource.driver-class-name=org.postgresql.Driver" >> ~/geoweaver/application.properties
echo "spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect" >> ~/geoweaver/application.properties
- name: Run Tests
run: |
mvn test jacoco:report
working-directory: ${{ github.workspace }}

- name: Check If All Tests Pass
run: |
if [ $? -eq 0 ]; then
echo "All tests passed successfully."
else
echo "Tests failed."
exit 1 # Exit with an error code to stop the workflow
fi
- name: Save Geoweaver JaCoCo HTML Report
uses: actions/upload-artifact@v2
with:
name: geoweaver-jacoco-coverage-report
path: target/site/jacoco

13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@
</dependency>


<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.8</version>
</dependency>

<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/CheckpointRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

import javax.transaction.Transactional;

@Transactional
public interface CheckpointRepository extends JpaRepository<Checkpoint, UUID> {
List<Checkpoint> findByWorkflowId(String workflowId);

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/gw/database/EnvironmentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;

/**
* The EnvironmentRepository interface provides methods for querying environment configurations from
* a database. It extends the CrudRepository interface to handle database operations for the
* Environment entity.
*/
@Transactional
public interface EnvironmentRepository extends CrudRepository<Environment, String> {

/**
Expand All @@ -22,13 +25,8 @@ public interface EnvironmentRepository extends CrudRepository<Environment, Strin
* @param basedir The base directory.
* @return A collection of environment configurations matching the specified criteria.
*/
@Query(
value =
"select * from environment where hostid = ?1 and bin = ?2 and pyenv = ?3 and basedir ="
+ " ?4",
nativeQuery = true)
Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
String hostid, String bin, String pyenv, String basedir);
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid AND e.bin = :bin AND e.pyenv = :pyenv AND e.basedir = :basedir")
Collection<Environment> findEnvByID_BIN_ENV_BaseDir(String hostid, String bin, String pyenv, String basedir);

/**
* Find environment configurations based on the provided host ID and binary path.
Expand All @@ -37,7 +35,7 @@ Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
* @param bin The binary path.
* @return A collection of environment configurations matching the specified host and binary path.
*/
@Query(value = "select * from environment where hostid = ?1 and bin = ?2", nativeQuery = true)
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid AND e.bin = :bin")
Collection<Environment> findEnvByID_BIN(String hostid, String bin);

/**
Expand All @@ -46,6 +44,7 @@ Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
* @param hostid The ID of the host.
* @return A collection of environment configurations associated with the specified host.
*/
@Query(value = "select * from environment where hostid = ?1", nativeQuery = true)
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid")
Collection<Environment> findEnvByHost(String hostid);

}
97 changes: 27 additions & 70 deletions src/main/java/com/gw/database/HistoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
* The HistoryRepository interface provides methods for querying historical execution data (history)
* from a database. It extends the JpaRepository interface to handle database operations.
*/
@Transactional
public interface HistoryRepository extends JpaRepository<History, String> {

/**
Expand All @@ -19,91 +22,65 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param limit The maximum number of history records to retrieve.
* @return A collection of recent history records for the host.
*/
@Query(
value = "select * from history where host_id = ?1 ORDER BY history_begin_time DESC limit ?2",
nativeQuery = true)
Collection<History> findRecentHistory(String hostid, int limit);
@Query(value = "SELECT * FROM history WHERE host_id = ?1 ORDER BY history_begin_time DESC LIMIT ?2", nativeQuery = true)
List<History> findRecentHistory(String hostid, int limit);

/**
* Find all running history records.
*
* @return A list of all running history records.
*/
@Query(
value = "select * from history where indicator='Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findAllRunningResource();

/**
* Find all running workflows.
*
* @return A list of all running workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findRunningWorkflow();

/**
* Find all failed workflows.
*
* @return A list of all failed workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Failed' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Failed' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findFailedWorkflow();

/**
* Find all successfully completed workflows.
*
* @return A list of all successful workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Done' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Done' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findSuccessWorkflow();

/**
* Find all running processes.
*
* @return A list of all running process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findRunningProcess();


/**
* Find all failed processes.
*
* @return A list of all failed process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Failed' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Failed' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findFailedProcess();


/**
* Find all successfully completed processes.
*
* @return A list of all successful process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Done' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Done' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findSuccessProcess();

/**
Expand All @@ -112,38 +89,28 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param pid The ID of the process.
* @return A list of history records associated with the specified process ID.
*/
@Query(
value =
"select * from history where history.history_process = ?1 ORDER BY history_begin_time"
+ " DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByProcessId(String pid);


/**
* Find history records by process ID, excluding 'Skipped' indicator.
*
* @param pid The ID of the process.
* @return A list of history records associated with the specified process ID, excluding 'Skipped'
* records.
*/
@Query(
value =
"select * from history where history.history_process = ?1 and history.history_input !="
+ " 'No code saved' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 AND history_input != 'No code saved' ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByProcessIdIgnoreUnknown(String pid);


/**
* Find history records by workflow ID.
*
* @param wid The ID of the workflow.
* @return A list of history records associated with the specified workflow ID.
*/
@Query(
value =
"select * from history where history.history_process = ?1 ORDER BY history_begin_time"
+ " DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByWorkflowId(String wid);

/**
Expand All @@ -152,42 +119,32 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param limit The maximum number of recent workflow records to retrieve.
* @return A list of recent workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where workflow.id = history.history_process ORDER BY"
+ " history_begin_time DESC limit ?1",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE workflow.id = history.history_process ORDER BY history_begin_time DESC LIMIT ?1", nativeQuery = true)
List<Object[]> findRecentWorkflow(int limit);


/**
* Find recent process records, limited by the specified count.
*
* @param limit The maximum number of recent process records to retrieve.
* @return A list of recent process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where gwprocess.id = history.history_process ORDER BY"
+ " history_begin_time DESC limit ?1",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE gwprocess.id = history.history_process ORDER BY history_begin_time DESC LIMIT ?1", nativeQuery = true)
List<Object[]> findRecentProcess(int limit);


/**
* Find a history record associated with a specific history ID.
*
* @param history_id The ID of the history record.
* @return A list containing a history record and additional information about the associated
* process.
*/
@Query(
value = "select * from history where history.history_id = ?1 and history.history_process=?2",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_id = ?1 AND history_process = ?2", nativeQuery = true)
List<History> findHistoryWithExecutionId(String history_id, String workflowId);

@Query(
value =
"select * from history, gwprocess where history.history_id = ?1 and"
+ " history.history_process=gwprocess.id",
nativeQuery = true)

@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_id = ?1 AND history.history_process = gwprocess.id", nativeQuery = true)
List<Object[]> findOneHistoryofProcess(String history_id);

}
Loading

0 comments on commit 0ae752a

Please sign in to comment.