Interface JpaJobRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<JobEntity,Long>, JpaBaseRepository<JobEntity>, org.springframework.data.jpa.repository.JpaRepository<JobEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<JobEntity>, org.springframework.data.repository.PagingAndSortingRepository<JobEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<JobEntity>, org.springframework.data.repository.Repository<JobEntity,Long>

public interface JpaJobRepository extends JpaBaseRepository<JobEntity>
Job repository.
  • Field Details

    • FIND_OLD_JOBS_QUERY

      static final String FIND_OLD_JOBS_QUERY
      The query used to find batches of jobs before a certain time.
      See Also:
  • Method Details

    • getTotalMemoryUsedOnHost

      @Query("SELECT COALESCE(SUM(j.memoryUsed), 0) FROM JobEntity j WHERE j.agentHostname = :agentHostname AND j.status IN (:statuses)") long getTotalMemoryUsedOnHost(@Param("agentHostname") String agentHostname, @Param("statuses") Set<String> statuses)
      Given the hostname that agents are running on return the total memory their jobs are currently using.
      Parameters:
      agentHostname - The agent hostname
      statuses - The job statuses to filter by e.g. JobStatus.getActiveStatuses()
      Returns:
      The total memory used in MB
    • getHostJobInfo

      @Query(value="SELECT (SELECT COALESCE(SUM(j.memory_used), 0) FROM jobs j WHERE j.agent_hostname = :agentHostname and j.status IN (:activeStatuses)) as totalMemoryAllocated, (SELECT COALESCE(SUM(j.memory_used), 0) FROM jobs j WHERE j.agent_hostname = :agentHostname and j.status IN (:usedStatuses)) as totalMemoryUsed, (SELECT COUNT(*) FROM jobs j WHERE j.agent_hostname = :agentHostname and j.status IN (:activeStatuses)) as numberOfActiveJobs", nativeQuery=true) JobInfoAggregate getHostJobInfo(@Param("agentHostname") String agentHostname, @Param("activeStatuses") Set<String> activeStatuses, @Param("usedStatuses") Set<String> usedStatuses)
      In a single query get aggregate information for the amount of memory used and count of active jobs on a given host.
      Parameters:
      agentHostname - The hostname where the agent is running the job
      activeStatuses - The set of statuses to use in order to consider a job "active"
      usedStatuses - The set of statuses to use in order to consider a job to actively be using memory
      Returns:
      A JobInfoAggregate instance with the requested information
    • countJobsByUserAndStatusIn

      Long countJobsByUserAndStatusIn(@NotBlank @NotBlank String user, @NotEmpty @NotEmpty Set<String> statuses)
      Count all jobs that belong to a given user and are in any of the given states.
      Parameters:
      user - the user name
      statuses - the set of statuses
      Returns:
      the count of jobs matching the search criteria
    • findJobsCreatedBefore

      @Query(value="SELECT id FROM jobs WHERE created < :createdThreshold AND status NOT IN (:excludedStatuses) LIMIT :batchSize", nativeQuery=true) Set<Long> findJobsCreatedBefore(@Param("createdThreshold") Instant createdThreshold, @Param("excludedStatuses") Set<String> excludeStatuses, @Param("batchSize") int limit)
      Find a batch of jobs that were created before the given time.
      Parameters:
      createdThreshold - The time before which the jobs were submitted. Exclusive
      excludeStatuses - The set of statuses which should be excluded from the results
      limit - The maximum number of jobs to to find
      Returns:
      The number of deleted jobs
    • getUserJobResourcesAggregates

      @Query("SELECT j.user AS user, COUNT(j) as runningJobsCount, COALESCE(SUM(j.memoryUsed), 0) as usedMemory FROM JobEntity j WHERE j.status IN (:statuses) AND j.api = :isApi GROUP BY j.user") Set<UserJobResourcesAggregate> getUserJobResourcesAggregates(@Param("statuses") Set<String> statuses, @Param("isApi") boolean api)
      Returns resources usage for each user that has a running job. Only jobs running on Genie servers are considered (i.e. no Agent jobs)
      Parameters:
      statuses - The set of statuses a job has to be in to be considered
      api - Whether the job was submitted through the api (true) or agent cli (false)
      Returns:
      The user resource aggregates
    • getJobIdsWithStatusIn

      @Query("SELECT j.uniqueId FROM JobEntity j WHERE j.status IN (:statuses)") Set<String> getJobIdsWithStatusIn(@Param("statuses") @NotEmpty @NotEmpty Set<String> statuses)
      Find agent jobs in the given set of states.
      Parameters:
      statuses - the job statuses filter
      Returns:
      a set of job projections
    • getJobsWithStatusAndArchiveStatusUpdatedBefore

      @Query("SELECT j.uniqueId FROM JobEntity j WHERE j.status IN (:statuses) AND j.archiveStatus IN (:archiveStatuses) AND j.updated < :updatedThreshold") Set<String> getJobsWithStatusAndArchiveStatusUpdatedBefore(@Param("statuses") @NotEmpty @NotEmpty Set<String> statuses, @Param("archiveStatuses") @NotEmpty @NotEmpty Set<String> archiveStatuses, @Param("updatedThreshold") Instant updateThreshold)
      Find agent jobs in the given set of job and archive states that were marked finished before a given threshold.
      Parameters:
      statuses - the job statuses filter
      archiveStatuses - the job archive statuses filter
      updateThreshold - select jobs last updated before this threshold
      Returns:
      a set of job ids
    • getJobStatus

      @Query("SELECT j.status FROM JobEntity j WHERE j.uniqueId = :id") Optional<String> getJobStatus(@Param("id") String id)
      Get only the status of a job.
      Parameters:
      id - The id of the job to get the status for
      Returns:
      The job status string or Optional.empty() if no job with the given id exists
    • isAPI

      @Query("SELECT j.api FROM JobEntity j WHERE j.uniqueId = :id") Optional<Boolean> isAPI(@Param("id") String id)
      Return whether the job was submitted via the API or the Agent CLI.
      Parameters:
      id - The unique id of the job
      Returns:
      true if the job was submitted via the API. Optional.empty() if the job doesn't exist
    • getJobHostname

      @Query("SELECT j.agentHostname FROM JobEntity j WHERE j.uniqueId = :id") Optional<String> getJobHostname(@Param("id") String id)
      Get only the hostname of a job.
      Parameters:
      id - The id of the job to get the hostname for
      Returns:
      The job hostname or Optional.empty() if no job with the given id exists
    • getArchiveStatus

      @Query("SELECT COALESCE(j.archiveStatus, \'UNKNOWN\') FROM JobEntity j WHERE j.uniqueId = :id") Optional<String> getArchiveStatus(@Param("id") String id)
      Get only the archive status of a job.
      Parameters:
      id - The id of the job to get the archive status for
      Returns:
      The job archive status or Optional.empty() if no job with the given id exists
    • getRequestedLauncherExt

      @Query("SELECT j.requestedLauncherExt FROM JobEntity j WHERE j.uniqueId = :id") Optional<com.fasterxml.jackson.databind.JsonNode> getRequestedLauncherExt(@Param("id") String id)
      Get only the requested launcher ext of a job.
      Parameters:
      id - The id of the job
      Returns:
      The requested launcher ext JSON node Optional.empty() if no job with the given id exists
    • getLauncherExt

      @Query("SELECT j.launcherExt FROM JobEntity j WHERE j.uniqueId = :id") Optional<com.fasterxml.jackson.databind.JsonNode> getLauncherExt(@Param("id") String id)
      Get only the launcher ext of a job.
      Parameters:
      id - The id of the job
      Returns:
      The launcher ext JSON node Optional.empty() if no job with the given id exists
    • getV3Job

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.v3.dto.job", type=LOAD) Optional<JobProjection> getV3Job(@Param("id") String id)
      Get the data needed to create a V3 Job DTO.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobProjection data or Optional.empty() if the job doesn't exist
    • getV4JobRequest

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.v4.dto.request", type=LOAD) Optional<JobRequestProjection> getV4JobRequest(@Param("id") String id)
      Get the data needed to create a V4 Job Request DTO.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobRequestProjection data or Optional.empty() if the job doesn't exist
    • getJobSpecification

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.v4.dto.specification", type=LOAD) Optional<JobSpecificationProjection> getJobSpecification(@Param("id") String id)
      Get the data needed to create a V4 Job Specification DTO.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobSpecificationProjection data or Optional.empty() if the job doesn't exist
    • getJobApplications

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.applications", type=LOAD) Optional<JobApplicationsProjection> getJobApplications(@Param("id") String id)
      Get the applications for a job.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobApplicationsProjection data or Optional.empty() if the job doesn't exist
    • getJobCluster

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.cluster", type=LOAD) Optional<JobClusterProjection> getJobCluster(@Param("id") String id)
      Get the cluster for a job.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobClusterProjection data or Optional.empty() if the job doesn't exist
    • getJobCommand

      @Query("SELECT j FROM JobEntity j WHERE j.uniqueId = :id") @EntityGraph(value="Job.command", type=LOAD) Optional<JobCommandProjection> getJobCommand(@Param("id") String id)
      Get the command for a job.
      Parameters:
      id - The unique id of the job
      Returns:
      The JobCommandProjection data or Optional.empty() if the job doesn't exist