Commit 640ff6f 1 parent f381bcd commit 640ff6f Copy full SHA for 640ff6f
File tree 3 files changed +53
-3
lines changed
src/main/java/cloudgene/mapred
3 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .Map ;
4
4
5
+ import cloudgene .mapred .database .JobDao ;
5
6
import org .restlet .representation .Representation ;
6
7
import org .restlet .representation .StringRepresentation ;
7
8
import org .restlet .resource .Get ;
@@ -41,10 +42,13 @@ public Representation get() {
41
42
for (String key : counters .keySet ()) {
42
43
jsonWaiting .put (key , counters .get (key ));
43
44
}
45
+ JobDao jobDao = new JobDao (getDatabase ());
46
+ int waitingJobs = jobDao .findAllByState (AbstractJob .STATE_WAITING ).size ();
47
+ jsonWaiting .put ("runs" , waitingJobs );
44
48
jsonCounters .put ("waiting" , jsonWaiting );
45
49
46
- UserDao dao = new UserDao (getDatabase ());
47
- jsonCounters .put ("users" , dao .findAll (). size ());
50
+ UserDao dao = new UserDao (getDatabase ());
51
+ jsonCounters .put ("users" , dao .countAll ());
48
52
49
53
50
54
return new StringRepresentation (jsonCounters .toString ());
Original file line number Diff line number Diff line change @@ -412,6 +412,31 @@ public List<AbstractJob> findAllByState(int state) {
412
412
}
413
413
}
414
414
415
+ @ SuppressWarnings ("unchecked" )
416
+ public int countAllByState (int state ) {
417
+
418
+ StringBuilder sql = new StringBuilder ();
419
+ sql .append ("select count(*) " );
420
+ sql .append ("from job " );
421
+ sql .append ("where state = ? " );
422
+
423
+ Object [] params = new Object [1 ];
424
+ params [0 ] = state ;
425
+
426
+ int result = 0 ;
427
+
428
+ try {
429
+ result = (Integer ) queryForObject (sql .toString (), params , new IntegerMapper ());
430
+ log .debug ("count all old jobs successful. results: " + result );
431
+
432
+ return result ;
433
+ } catch (SQLException e ) {
434
+ log .error ("count all old jobs failed" , e );
435
+ return 0 ;
436
+ }
437
+ }
438
+
439
+
415
440
public AbstractJob findById (String id ) {
416
441
417
442
return findById (id , true );
Original file line number Diff line number Diff line change @@ -208,7 +208,28 @@ public List<User> findAll() {
208
208
}
209
209
return result ;
210
210
}
211
-
211
+
212
+ @ SuppressWarnings ("unchecked" )
213
+ public int countAll () {
214
+
215
+ StringBuilder sql = new StringBuilder ();
216
+ sql .append ("select count(*) " );
217
+ sql .append ("from `user` " );
218
+
219
+ int result = 0 ;
220
+
221
+ try {
222
+ result = (Integer ) queryForObject (sql .toString (), new IntegerMapper ());
223
+ log .debug ("count all users successful. results: " + result );
224
+
225
+ return result ;
226
+ } catch (SQLException e ) {
227
+ log .error ("count all users failed" , e );
228
+ return 0 ;
229
+ }
230
+ }
231
+
232
+
212
233
@ SuppressWarnings ("unchecked" )
213
234
public List <User > findByQuery (String query ) {
214
235
You can’t perform that action at this time.
0 commit comments