Changed default borrow behaviour to simply get current cell definition if a reservation exists already.

Change-Id: I365233a78be6033d176e33c3c3b3ad33f791d85e
diff --git a/tools/dev/bash_profile b/tools/dev/bash_profile
index a7aca28..b43ac32 100644
--- a/tools/dev/bash_profile
+++ b/tools/dev/bash_profile
@@ -113,7 +113,7 @@
     case "$cell" in
     "borrow")
         aux="/tmp/cell-$$"
-        curl -sS -X POST "http://$CELL_WARDEN:4321/?user=$(id -un)&duration=${2:-60}" \
+        curl -sS -X POST "http://$CELL_WARDEN:4321/?user=$(id -un)&duration=${2:-0}" \
             -d "$(cat ~/.ssh/id_rsa.pub)" > $aux
         . $aux
         rm -f $aux
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);
         }
diff --git a/utils/warden/src/main/java/org/onlab/warden/WardenServlet.java b/utils/warden/src/main/java/org/onlab/warden/WardenServlet.java
index 9f6ad33..a5f4f29 100644
--- a/utils/warden/src/main/java/org/onlab/warden/WardenServlet.java
+++ b/utils/warden/src/main/java/org/onlab/warden/WardenServlet.java
@@ -70,7 +70,7 @@
             String sshKey = new String(ByteStreams.toByteArray(req.getInputStream()), "UTF-8");
             String userName = req.getParameter("user");
             String sd = req.getParameter("duration");
-            int duration = isNullOrEmpty(sd) ? 60 : Integer.parseInt(sd);
+            int duration = isNullOrEmpty(sd) ? 0 : Integer.parseInt(sd);
             String cellDefinition = warden.borrowCell(userName, sshKey, duration);
             out.println(cellDefinition);
         } catch (Exception e) {