Skip to content

Commit

Permalink
Add waiting jobs to counters
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Mar 18, 2024
1 parent f381bcd commit 640ff6f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/cloudgene/mapred/database/JobDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,31 @@ public List<AbstractJob> 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);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/cloudgene/mapred/database/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,28 @@ public List<User> 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<User> findByQuery(String query) {

Expand Down

0 comments on commit 640ff6f

Please sign in to comment.