Thomas Vachuska
Committed by Gerrit Code Review

Fixing a small bug in warden logging.

Change-Id: I27439f1309a954738e09a2732275f769a22ace3e
...@@ -55,6 +55,7 @@ class Warden { ...@@ -55,6 +55,7 @@ class Warden {
55 private static final long TIMEOUT = 10; // 10 seconds 55 private static final long TIMEOUT = 10; // 10 seconds
56 private static final int MAX_MINUTES = 240; // 4 hours max 56 private static final int MAX_MINUTES = 240; // 4 hours max
57 private static final int MINUTE = 60_000; // 1 minute 57 private static final int MINUTE = 60_000; // 1 minute
58 + private static final int DEFAULT_MINUTES = 60;
58 59
59 private final File log = new File("warden.log"); 60 private final File log = new File("warden.log");
60 61
...@@ -157,11 +158,11 @@ class Warden { ...@@ -157,11 +158,11 @@ class Warden {
157 long now = System.currentTimeMillis(); 158 long now = System.currentTimeMillis();
158 Reservation reservation = currentUserReservation(userName); 159 Reservation reservation = currentUserReservation(userName);
159 if (reservation == null) { 160 if (reservation == null) {
160 - checkArgument(minutes > 0, "Number of minutes must be positive"); 161 + checkArgument(minutes >= 0, "Number of minutes must be non-negative");
161 Set<String> cells = getAvailableCells(); 162 Set<String> cells = getAvailableCells();
162 checkState(!cells.isEmpty(), "No cells are presently available"); 163 checkState(!cells.isEmpty(), "No cells are presently available");
163 String cellName = ImmutableList.copyOf(cells).get(random.nextInt(cells.size())); 164 String cellName = ImmutableList.copyOf(cells).get(random.nextInt(cells.size()));
164 - reservation = new Reservation(cellName, userName, now, minutes); 165 + reservation = new Reservation(cellName, userName, now, minutes == 0 ? DEFAULT_MINUTES : minutes);
165 } else if (minutes == 0) { 166 } else if (minutes == 0) {
166 // If minutes are 0, simply return the cell definition 167 // If minutes are 0, simply return the cell definition
167 return getCellDefinition(reservation.cellName); 168 return getCellDefinition(reservation.cellName);
...@@ -171,7 +172,7 @@ class Warden { ...@@ -171,7 +172,7 @@ class Warden {
171 172
172 reserveCell(reservation.cellName, reservation); 173 reserveCell(reservation.cellName, reservation);
173 installUserKeys(reservation.cellName, userName, sshKey); 174 installUserKeys(reservation.cellName, userName, sshKey);
174 - log(userName, reservation.cellName, "borrowed for " + minutes + " minutes"); 175 + log(userName, reservation.cellName, "borrowed for " + reservation.duration + " minutes");
175 return getCellDefinition(reservation.cellName); 176 return getCellDefinition(reservation.cellName);
176 } 177 }
177 178
......