diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java index b11319edff..66ac059d7d 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java @@ -30,9 +30,7 @@ import org.opencb.opencga.catalog.auth.authorization.AuthorizationManager; import org.opencb.opencga.catalog.db.DBAdaptorFactory; import org.opencb.opencga.catalog.db.api.*; -import org.opencb.opencga.catalog.exceptions.CatalogAuthorizationException; -import org.opencb.opencga.catalog.exceptions.CatalogException; -import org.opencb.opencga.catalog.exceptions.CatalogIOException; +import org.opencb.opencga.catalog.exceptions.*; import org.opencb.opencga.catalog.io.IOManager; import org.opencb.opencga.catalog.io.IOManagerFactory; import org.opencb.opencga.catalog.models.InternalGetDataResult; @@ -623,6 +621,13 @@ public OpenCGAResult getExecutionTimeByMonth(String organizationI } private void checkExecutionLimitQuota(String organizationId) throws CatalogException { + if (exceedsExecutionLimitQuota(organizationId)) { + throw new CatalogException("The organization '" + organizationId + "' has reached the maximum quota of execution hours (" + + configuration.getQuota().getMaxNumJobHours() + ") for the current month."); + } + } + + public boolean exceedsExecutionLimitQuota(String organizationId) throws CatalogException { // Get current year/month String time = TimeUtils.getTime(TimeUtils.getDate(), TimeUtils.yyyyMM); Query query = new Query(JobDBAdaptor.QueryParams.MODIFICATION_DATE.key(), time); @@ -630,10 +635,10 @@ private void checkExecutionLimitQuota(String organizationId) throws CatalogExcep if (result.getNumResults() > 0) { ExecutionTime executionTime = result.first(); if (executionTime.getTime().getHours() >= configuration.getQuota().getMaxNumJobHours()) { - throw new CatalogException("The organization '" + organizationId + "' has reached the maximum quota of execution hours (" - + configuration.getQuota().getMaxNumJobHours() + ") for the current month."); + return true; } } + return false; } /** diff --git a/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java b/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java index 01c02bde4a..07131ab1a8 100644 --- a/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java +++ b/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java @@ -500,8 +500,15 @@ protected void checkPendingJobs(List organizationIds) { for (String organizationId : organizationIds) { try (DBIterator iterator = jobManager.iteratorInOrganization(organizationId, pendingJobsQuery, queryOptions, token)) { + boolean exceeds = jobManager.exceedsExecutionLimitQuota(organizationId); while (iterator.hasNext()) { - pendingJobs.add(iterator.next()); + if (exceeds) { + abortJob(iterator.next(), "The organization '" + organizationId + "' has reached the maximum limit quota of" + + " execution hours (" + catalogManager.getConfiguration().getQuota().getMaxNumJobHours() + + ") for the current month."); + } else { + pendingJobs.add(iterator.next()); + } } } catch (Exception e) { logger.error("Error listing pending jobs from organization {}", organizationId, e);