Committed by
Gerrit Code Review
Changed default borrow behaviour to simply get current cell definition if a rese…
…rvation exists already. Change-Id: I365233a78be6033d176e33c3c3b3ad33f791d85e
Showing
3 changed files
with
8 additions
and
5 deletions
... | @@ -113,7 +113,7 @@ function cell { | ... | @@ -113,7 +113,7 @@ function cell { |
113 | case "$cell" in | 113 | case "$cell" in |
114 | "borrow") | 114 | "borrow") |
115 | aux="/tmp/cell-$$" | 115 | aux="/tmp/cell-$$" |
116 | - curl -sS -X POST "http://$CELL_WARDEN:4321/?user=$(id -un)&duration=${2:-60}" \ | 116 | + curl -sS -X POST "http://$CELL_WARDEN:4321/?user=$(id -un)&duration=${2:-0}" \ |
117 | -d "$(cat ~/.ssh/id_rsa.pub)" > $aux | 117 | -d "$(cat ~/.ssh/id_rsa.pub)" > $aux |
118 | . $aux | 118 | . $aux |
119 | rm -f $aux | 119 | rm -f $aux | ... | ... |
... | @@ -49,12 +49,13 @@ class Warden { | ... | @@ -49,12 +49,13 @@ class Warden { |
49 | private static final String USER_NOT_NULL = "User name cannot be null"; | 49 | private static final String USER_NOT_NULL = "User name cannot be null"; |
50 | private static final String KEY_NOT_NULL = "User key cannot be null"; | 50 | private static final String KEY_NOT_NULL = "User key cannot be null"; |
51 | private static final String UTF_8 = "UTF-8"; | 51 | private static final String UTF_8 = "UTF-8"; |
52 | - private static final long TIMEOUT = 3; | ||
53 | 52 | ||
54 | private static final String AUTHORIZED_KEYS = "authorized_keys"; | 53 | private static final String AUTHORIZED_KEYS = "authorized_keys"; |
55 | 54 | ||
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 | ||
... | @@ -153,7 +154,6 @@ class Warden { | ... | @@ -153,7 +154,6 @@ class Warden { |
153 | synchronized String borrowCell(String userName, String sshKey, int minutes) { | 154 | synchronized String borrowCell(String userName, String sshKey, int minutes) { |
154 | checkNotNull(userName, USER_NOT_NULL); | 155 | checkNotNull(userName, USER_NOT_NULL); |
155 | checkNotNull(sshKey, KEY_NOT_NULL); | 156 | checkNotNull(sshKey, KEY_NOT_NULL); |
156 | - checkArgument(minutes > 0, "Number of minutes must be positive"); | ||
157 | checkArgument(minutes < MAX_MINUTES, "Number of minutes must be less than %d", MAX_MINUTES); | 157 | checkArgument(minutes < MAX_MINUTES, "Number of minutes must be less than %d", MAX_MINUTES); |
158 | long now = System.currentTimeMillis(); | 158 | long now = System.currentTimeMillis(); |
159 | Reservation reservation = currentUserReservation(userName); | 159 | Reservation reservation = currentUserReservation(userName); |
... | @@ -161,7 +161,10 @@ class Warden { | ... | @@ -161,7 +161,10 @@ class Warden { |
161 | Set<String> cells = getAvailableCells(); | 161 | Set<String> cells = getAvailableCells(); |
162 | checkState(!cells.isEmpty(), "No cells are presently available"); | 162 | checkState(!cells.isEmpty(), "No cells are presently available"); |
163 | String cellName = ImmutableList.copyOf(cells).get(random.nextInt(cells.size())); | 163 | String cellName = ImmutableList.copyOf(cells).get(random.nextInt(cells.size())); |
164 | - reservation = new Reservation(cellName, userName, now, minutes); | 164 | + reservation = new Reservation(cellName, userName, now, minutes == 0 ? DEFAULT_MINUTES : minutes); |
165 | + } else if (minutes == 0) { | ||
166 | + // If minutes are 0, simply return the cell definition | ||
167 | + return getCellDefinition(reservation.cellName); | ||
165 | } else { | 168 | } else { |
166 | reservation = new Reservation(reservation.cellName, userName, now, minutes); | 169 | reservation = new Reservation(reservation.cellName, userName, now, minutes); |
167 | } | 170 | } | ... | ... |
... | @@ -70,7 +70,7 @@ public class WardenServlet extends HttpServlet { | ... | @@ -70,7 +70,7 @@ public class WardenServlet extends HttpServlet { |
70 | String sshKey = new String(ByteStreams.toByteArray(req.getInputStream()), "UTF-8"); | 70 | String sshKey = new String(ByteStreams.toByteArray(req.getInputStream()), "UTF-8"); |
71 | String userName = req.getParameter("user"); | 71 | String userName = req.getParameter("user"); |
72 | String sd = req.getParameter("duration"); | 72 | String sd = req.getParameter("duration"); |
73 | - int duration = isNullOrEmpty(sd) ? 60 : Integer.parseInt(sd); | 73 | + int duration = isNullOrEmpty(sd) ? 0 : Integer.parseInt(sd); |
74 | String cellDefinition = warden.borrowCell(userName, sshKey, duration); | 74 | String cellDefinition = warden.borrowCell(userName, sshKey, duration); |
75 | out.println(cellDefinition); | 75 | out.println(cellDefinition); |
76 | } catch (Exception e) { | 76 | } catch (Exception e) { | ... | ... |
-
Please register or login to post a comment