Changed default borrow behaviour to simply get current cell definition if a reservation exists already.
Change-Id: I365233a78be6033d176e33c3c3b3ad33f791d85e
diff --git a/utils/warden/src/main/java/org/onlab/warden/Warden.java b/utils/warden/src/main/java/org/onlab/warden/Warden.java
index 0469a7f..b1e4c71 100644
--- a/utils/warden/src/main/java/org/onlab/warden/Warden.java
+++ b/utils/warden/src/main/java/org/onlab/warden/Warden.java
@@ -49,12 +49,13 @@
private static final String USER_NOT_NULL = "User name cannot be null";
private static final String KEY_NOT_NULL = "User key cannot be null";
private static final String UTF_8 = "UTF-8";
- private static final long TIMEOUT = 3;
private static final String AUTHORIZED_KEYS = "authorized_keys";
+ private static final long TIMEOUT = 10; // 10 seconds
private static final int MAX_MINUTES = 240; // 4 hours max
private static final int MINUTE = 60_000; // 1 minute
+ private static final int DEFAULT_MINUTES = 60;
private final File log = new File("warden.log");
@@ -153,7 +154,6 @@
synchronized String borrowCell(String userName, String sshKey, int minutes) {
checkNotNull(userName, USER_NOT_NULL);
checkNotNull(sshKey, KEY_NOT_NULL);
- checkArgument(minutes > 0, "Number of minutes must be positive");
checkArgument(minutes < MAX_MINUTES, "Number of minutes must be less than %d", MAX_MINUTES);
long now = System.currentTimeMillis();
Reservation reservation = currentUserReservation(userName);
@@ -161,7 +161,10 @@
Set<String> cells = getAvailableCells();
checkState(!cells.isEmpty(), "No cells are presently available");
String cellName = ImmutableList.copyOf(cells).get(random.nextInt(cells.size()));
- reservation = new Reservation(cellName, userName, now, minutes);
+ reservation = new Reservation(cellName, userName, now, minutes == 0 ? DEFAULT_MINUTES : minutes);
+ } else if (minutes == 0) {
+ // If minutes are 0, simply return the cell definition
+ return getCellDefinition(reservation.cellName);
} else {
reservation = new Reservation(reservation.cellName, userName, now, minutes);
}