diff --git a/src/main/html/webapp/components/core/job/detail/detail.js b/src/main/html/webapp/components/core/job/detail/detail.js index 5ef45138..147973c7 100644 --- a/src/main/html/webapp/components/core/job/detail/detail.js +++ b/src/main/html/webapp/components/core/job/detail/detail.js @@ -76,7 +76,7 @@ export default Control.extend({ '#delete-btn click': function(el, ev) { var that = this; - bootbox.confirm("Are you sure you want to delete " + that.job.attr('id') + "?", function(result) { + bootbox.confirm("Are you sure you want to delete " + that.job.attr('name') + "?", function(result) { if (result) { var okButton = $("button[data-bb-handler='confirm']"); @@ -106,7 +106,7 @@ export default Control.extend({ '#cancel-btn click': function(el, ev) { var that = this; - bootbox.confirm("Are you sure you want to cancel " + that.job.attr('id') + "?", function(result) { + bootbox.confirm("Are you sure you want to cancel " + that.job.attr('name') + "?", function(result) { if (result) { var okButton = $("button[data-bb-handler='confirm']"); @@ -136,7 +136,7 @@ export default Control.extend({ '#restart-btn click': function(el, ev) { var that = this; - bootbox.confirm("Are you sure you want to restart " + that.job.attr('id') + "?", function(result) { + bootbox.confirm("Are you sure you want to restart " + that.job.attr('name') + "?", function(result) { if (result) { var okButton = $("button[data-bb-handler='confirm']"); diff --git a/src/main/html/webapp/components/core/job/list/list.js b/src/main/html/webapp/components/core/job/list/list.js index d78b4f0d..63f886bf 100644 --- a/src/main/html/webapp/components/core/job/list/list.js +++ b/src/main/html/webapp/components/core/job/list/list.js @@ -48,7 +48,7 @@ export default Control.extend({ var card = $(el).closest('.card'); var job = domData.get.call(card[0], 'job'); - bootbox.confirm("Are you sure you want to delete " + job.attr('id') + "?", function(result) { + bootbox.confirm("Are you sure you want to delete " + job.attr('name') + "?", function(result) { if (result) { var okButton = $("button[data-bb-handler='confirm']"); @@ -78,7 +78,7 @@ export default Control.extend({ var card = $(el).closest('.card'); var job = domData.get.call(card[0], 'job'); - bootbox.confirm("Are you sure you want to cancel " + job.attr('id') + "?", function(result) { + bootbox.confirm("Are you sure you want to cancel " + job.attr('name') + "?", function(result) { if (result) { var okButton = $("button[data-bb-handler='confirm']"); diff --git a/src/main/java/cloudgene/mapred/api/v2/admin/ArchiveJob.java b/src/main/java/cloudgene/mapred/api/v2/admin/ArchiveJob.java index 02f76320..e97c6f30 100644 --- a/src/main/java/cloudgene/mapred/api/v2/admin/ArchiveJob.java +++ b/src/main/java/cloudgene/mapred/api/v2/admin/ArchiveJob.java @@ -83,9 +83,6 @@ public Representation get() { job.setState(AbstractJob.STATE_RETIRED); dao.update(job); - ParameterDao parameterDao = new ParameterDao(getDatabase()); - parameterDao.deleteAllByJob(job); - if (externalWorkspace != null) { try { externalWorkspace.delete(job.getId()); diff --git a/src/main/java/cloudgene/mapred/api/v2/jobs/GetJobDetails.java b/src/main/java/cloudgene/mapred/api/v2/jobs/GetJobDetails.java index 520ec3bb..da456e1b 100644 --- a/src/main/java/cloudgene/mapred/api/v2/jobs/GetJobDetails.java +++ b/src/main/java/cloudgene/mapred/api/v2/jobs/GetJobDetails.java @@ -149,9 +149,6 @@ public Representation deleteJob(Representation entity) { job.setState(AbstractJob.STATE_DELETED); dao.update(job); - ParameterDao parameterDao = new ParameterDao(getDatabase()); - parameterDao.deleteAllByJob(job); - Settings settings = getSettings(); IExternalWorkspace externalWorkspace = null; diff --git a/src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java b/src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java index 7656aaaa..bccf597b 100644 --- a/src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java +++ b/src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java @@ -2,6 +2,7 @@ import java.util.Map; +import cloudgene.mapred.database.JobDao; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.restlet.resource.Get; @@ -41,10 +42,13 @@ public Representation get() { for (String key : counters.keySet()) { jsonWaiting.put(key, counters.get(key)); } + JobDao jobDao = new JobDao(getDatabase()); + int waitingJobs = jobDao.findAllByState(AbstractJob.STATE_WAITING).size(); + jsonWaiting.put("runs", waitingJobs); jsonCounters.put("waiting", jsonWaiting); - UserDao dao = new UserDao(getDatabase()); - jsonCounters.put("users", dao.findAll().size()); + UserDao dao = new UserDao(getDatabase()); + jsonCounters.put("users", dao.countAll()); return new StringRepresentation(jsonCounters.toString()); diff --git a/src/main/java/cloudgene/mapred/cron/CleanUpTasks.java b/src/main/java/cloudgene/mapred/cron/CleanUpTasks.java index f3cb97e3..cdc10cf2 100644 --- a/src/main/java/cloudgene/mapred/cron/CleanUpTasks.java +++ b/src/main/java/cloudgene/mapred/cron/CleanUpTasks.java @@ -26,8 +26,6 @@ public class CleanUpTasks { public static int executeRetire(Database database, Settings settings) { JobDao dao = new JobDao(database); - ParameterDao parameterDao = new ParameterDao(database); - List oldJobs = dao.findAllNotifiedJobs(); int deleted = 0; @@ -57,8 +55,6 @@ public static int executeRetire(Database database, Settings settings) { dao.update(job); - parameterDao.deleteAllByJob(job); - log.info("Job " + job.getId() + " retired."); deleted++; diff --git a/src/main/java/cloudgene/mapred/database/JobDao.java b/src/main/java/cloudgene/mapred/database/JobDao.java index ac65f39f..78723a05 100644 --- a/src/main/java/cloudgene/mapred/database/JobDao.java +++ b/src/main/java/cloudgene/mapred/database/JobDao.java @@ -412,6 +412,31 @@ public List findAllByState(int state) { } } + @SuppressWarnings("unchecked") + public int countAllByState(int state) { + + StringBuilder sql = new StringBuilder(); + sql.append("select count(*) "); + sql.append("from job "); + sql.append("where state = ? "); + + Object[] params = new Object[1]; + params[0] = state; + + int result = 0; + + try { + result = (Integer) queryForObject(sql.toString(), params, new IntegerMapper()); + log.debug("count all old jobs successful. results: " + result); + + return result; + } catch (SQLException e) { + log.error("count all old jobs failed", e); + return 0; + } + } + + public AbstractJob findById(String id) { return findById(id, true); diff --git a/src/main/java/cloudgene/mapred/database/ParameterDao.java b/src/main/java/cloudgene/mapred/database/ParameterDao.java index 6028b8b8..e6251463 100644 --- a/src/main/java/cloudgene/mapred/database/ParameterDao.java +++ b/src/main/java/cloudgene/mapred/database/ParameterDao.java @@ -183,29 +183,6 @@ public CloudgeneParameterOutput findById(int id) { } } - public boolean deleteAllByJob(AbstractJob job) { - try { - - StringBuilder sql = new StringBuilder(); - sql.append("delete "); - sql.append("from parameter "); - sql.append("where job_id = ?"); - - Object[] params = new Object[1]; - params[0] = job.getId(); - - update(sql.toString(), params); - - log.debug("delete all parameters by job_id '" + job.getId() + "' successful."); - - return true; - - } catch (SQLException e) { - log.error("delete all parameters by job_id '" + job.getId() + "' failed.", e); - return false; - } - } - class ParameterInputMapper implements IRowMapper { @Override diff --git a/src/main/java/cloudgene/mapred/database/UserDao.java b/src/main/java/cloudgene/mapred/database/UserDao.java index 37af8957..fd831317 100644 --- a/src/main/java/cloudgene/mapred/database/UserDao.java +++ b/src/main/java/cloudgene/mapred/database/UserDao.java @@ -208,7 +208,28 @@ public List findAll() { } return result; } - + + @SuppressWarnings("unchecked") + public int countAll() { + + StringBuilder sql = new StringBuilder(); + sql.append("select count(*) "); + sql.append("from `user` "); + + int result = 0; + + try { + result = (Integer) queryForObject(sql.toString(), new IntegerMapper()); + log.debug("count all users successful. results: " + result); + + return result; + } catch (SQLException e) { + log.error("count all users failed", e); + return 0; + } + } + + @SuppressWarnings("unchecked") public List findByQuery(String query) {