Skip to content

Commit

Permalink
add more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Oct 22, 2023
1 parent 9c3613f commit e0ac55a
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 168 deletions.
55 changes: 37 additions & 18 deletions src/main/java/com/gw/database/EnvironmentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,41 @@

import com.gw.jpa.Environment;

public interface EnvironmentRepository extends CrudRepository<Environment, String>{

// new StringBuffer("select * from environment where host = '").append(hostid)
// .append("' and bin = '").append(bin).append("' and pyenv = '")
// .append(env).append("' and basedir = '").append(basedir).append("';");
@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(value = "select * from environment where hostid = ?1 and bin = ?2",
nativeQuery = true)
Collection<Environment> findEnvByID_BIN(String hostid, String bin);


@Query(value = "select * from environment where hostid = ?1 ",
nativeQuery = true)
Collection<Environment> findEnvByHost(String hostid);

/**
* 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.
*/
public interface EnvironmentRepository extends CrudRepository<Environment, String> {

/**
* Find environment configurations based on the provided host ID, binary path, Python environment, and base directory.
*
* @param hostid The ID of the host.
* @param bin The binary path.
* @param pyenv The Python environment.
* @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);

/**
* Find environment configurations based on the provided host ID and binary path.
*
* @param hostid The ID of the host.
* @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)
Collection<Environment> findEnvByID_BIN(String hostid, String bin);

/**
* Find environment configurations based on the provided host ID.
*
* @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)
Collection<Environment> findEnvByHost(String hostid);
}

189 changes: 125 additions & 64 deletions src/main/java/com/gw/database/HistoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,129 @@

import com.gw.jpa.History;

public interface HistoryRepository extends JpaRepository<History, String>{

@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 indicator='Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
List<History> findAllRunningResource();

@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();

@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();

@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();

@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();

@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();

@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();

@Query(value="select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;",
nativeQuery = true)
List<History> findByProcessId(String pid);

@Query(value="select * from history where history.history_process = ?1 and history.indicator != 'Skipped' ORDER BY history_begin_time DESC;",
nativeQuery = true)
List<History> findByProcessIdIgnoreUnknown(String pid);

@Query(value="select * from history where history.history_process = ?1 ORDER BY history_begin_time DESC;",
nativeQuery = true)
List<History> findByWorkflowId(String wid);


@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);


@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);

@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);





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

/**
* Find recent history records for a specific host, limited by the specified count.
*
* @param hostid The ID of the host.
* @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);

/**
* 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)
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)
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)
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)
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)
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)
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)
List<Object[]> findSuccessProcess();

/**
* Find history records by process ID.
*
* @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)
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.indicator != 'Skipped' 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)
List<History> findByWorkflowId(String wid);

/**
* Find recent workflow records, limited by the specified count.
*
* @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)
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)
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, gwprocess where history.history_id = ?1 and history.history_process=gwprocess.id", nativeQuery = true)
List<Object[]> findOneHistoryofProcess(String history_id);
}
133 changes: 92 additions & 41 deletions src/main/java/com/gw/database/HostRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,97 @@

import com.gw.jpa.Host;

public interface HostRepository extends CrudRepository<Host, String>{

@Query(value="select * from host where owner = ?1 ",
nativeQuery = true)
Collection<Host> findByOwner(String owner);

@Query(value="select * from HOST where name like CONCAT('%',:keyword,'%')",
nativeQuery = true)
Collection<Host> findHostsByNameAlike(@Param("keyword") String keyword);

@Query(value="select * from HOST where type = 'ssh'",
nativeQuery = true)
Collection<Host> findSSHHosts();

@Query(value="select * from HOST where owner = ?1 ",
nativeQuery = true)
Collection<Host> findAllPublicAndPrivateByOwner(String owner);

@Query(value="select * from HOST where owner = ?1 and confidential = 'TRUE'",
nativeQuery = true)
Collection<Host> findPrivateByOwner(String owner);

@Query(value="select * from HOST where confidential = 'FALSE' ",
nativeQuery = true)
Collection<Host> findAllPublicHosts();

@Query(value="select * from HOST where type = 'jupyter'",
nativeQuery = true)
Collection<Host> findJupyterNotebookHosts();

@Query(value="select * from HOST where type = 'jupyterhub'",
nativeQuery = true)
Collection<Host> findJupyterHubHosts();

@Query(value="select * from HOST where type = 'jupyterlab'",
nativeQuery = true)
Collection<Host> findJupyterLabHosts();

@Query(value="select * from HOST where type = 'gee'",
nativeQuery = true)
Collection<Host> findGEEHosts();
/**
* The HostRepository interface provides methods for querying host-related information from the database.
* It extends the CrudRepository interface to handle basic CRUD operations.
*/
public interface HostRepository extends CrudRepository<Host, String> {

/**
* Find hosts by owner.
*
* @param owner The owner's name.
* @return A collection of hosts owned by the specified owner.
*/
@Query(value = "select * from host where owner = ?1 ", nativeQuery = true)
Collection<Host> findByOwner(String owner);
// Collection<Host> findByOwner(String owner);

/**
* Find hosts by name containing the specified keyword.
*
* @param keyword The keyword to search for in host names.
* @return A collection of hosts with names containing the keyword.
*/
@Query(value = "select * from HOST where name like CONCAT('%',:keyword,'%')", nativeQuery = true)
Collection<Host> findHostsByNameAlike(@Param("keyword") String keyword);
// Collection<Host> findByNameContaining(String keyword);

/**
* Find SSH hosts.
*
* @return A collection of SSH hosts.
*/
@Query(value = "select * from HOST where type = 'ssh'", nativeQuery = true)
Collection<Host> findSSHHosts();

/**
* Find all public and private hosts of an owner.
*
* @param owner The owner's name.
* @return A collection of all public and private hosts owned by the specified owner.
*/
@Query(value = "select * from HOST where owner = ?1 ", nativeQuery = true)
Collection<Host> findAllPublicAndPrivateByOwner(String owner);

/**
* Find private hosts of an owner.
*
* @param owner The owner's name.
* @return A collection of private hosts owned by the specified owner.
*/
@Query(value = "select * from HOST where owner = ?1 and confidential = 'TRUE'", nativeQuery = true)
Collection<Host> findPrivateByOwner(String owner);
// Collection<Host> findByOwnerAndConfidential(String owner, boolean confidential);

/**
* Find all public hosts.
*
* @return A collection of all public hosts.
*/
@Query(value = "select * from HOST where confidential = 'FALSE'", nativeQuery = true)
Collection<Host> findAllPublicHosts();

/**
* Find hosts of type 'jupyter'.
*
* @return A collection of hosts of type 'jupyter'.
*/
@Query(value = "select * from HOST where type = 'jupyter'", nativeQuery = true)
Collection<Host> findJupyterNotebookHosts();

/**
* Find hosts of type 'jupyterhub'.
*
* @return A collection of hosts of type 'jupyterhub'.
*/
@Query(value = "select * from HOST where type = 'jupyterhub'", nativeQuery = true)
Collection<Host> findJupyterHubHosts();

/**
* Find hosts of type 'jupyterlab'.
*
* @return A collection of hosts of type 'jupyterlab'.
*/
@Query(value = "select * from HOST where type = 'jupyterlab'", nativeQuery = true)
Collection<Host> findJupyterLabHosts();

/**
* Find hosts of type 'gee'.
*
* @return A collection of hosts of type 'gee'.
*/
@Query(value = "select * from HOST where type = 'gee'", nativeQuery = true)
Collection<Host> findGEEHosts();
}

Loading

0 comments on commit e0ac55a

Please sign in to comment.