Skip to content

Commit

Permalink
Add queue size to counters
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Mar 23, 2024
1 parent fd247f7 commit 2b7b02f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/cloudgene/mapred/api/v2/server/GetCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ public class GetCounter extends BaseResource {
public Representation get() {

JSONObject jsonCounters = new JSONObject();

// complete
Map<String, Long> counters = getWorkflowEngine().getCounters(
AbstractJob.STATE_SUCCESS);
JSONObject jsonComplete = new JSONObject();
AbstractJob.STATE_SUCCESS);
JSONObject jsonComplete = new JSONObject();
for (String key : counters.keySet()) {
jsonComplete.put(key, counters.get(key));
}
jsonCounters.put("complete", jsonComplete);

// running
counters = getWorkflowEngine().getCounters(AbstractJob.STATE_RUNNING);
JSONObject jsonRunning = new JSONObject();
JSONObject jsonRunning = new JSONObject();
for (String key : counters.keySet()) {
jsonRunning.put(key, counters.get(key));
}
jsonCounters.put("running", jsonRunning);

// waiting
counters = getWorkflowEngine().getCounters(AbstractJob.STATE_WAITING);
JSONObject jsonWaiting= new JSONObject();
JSONObject jsonWaiting= new JSONObject();
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.countAll());



JSONObject queue = new JSONObject();
queue.put("size", getWorkflowEngine().getSize());
jsonCounters.put("queue", queue);

return new StringRepresentation(jsonCounters.toString());

}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cloudgene/mapred/jobs/WorkflowEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public List<AbstractJob> getAllJobsInLongTimeQueue() {
return jobs;
}

public int getSize() {
return longTimeQueue.getSize() + shortTimeQueue.getSize();
}

class SetupThread extends PriorityRunnable {

private AbstractJob job;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cloudgene/mapred/jobs/queue/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public boolean isInQueue(AbstractJob job) {
}
}

public int getSize() {
return queue.size();
}

protected class PriorityComparator implements Comparator<AbstractJob> {

@Override
Expand Down

0 comments on commit 2b7b02f

Please sign in to comment.