Simon Hunt

CORD GUI - Added logout call, and implemented the notion of session.

Change-Id: I44fc42c909071755c73ac367bf03427cfbe6b643
...@@ -62,9 +62,11 @@ public class CordModelCache extends JsonFactory { ...@@ -62,9 +62,11 @@ public class CordModelCache extends JsonFactory {
62 private static final String BUNDLE = "bundle"; 62 private static final String BUNDLE = "bundle";
63 private static final String USERS = "users"; 63 private static final String USERS = "users";
64 private static final String LEVEL = "level"; 64 private static final String LEVEL = "level";
65 + private static final String LOGOUT = "logout";
65 66
66 private static final Map<Integer, Integer> LOOKUP = new HashMap<>(); 67 private static final Map<Integer, Integer> LOOKUP = new HashMap<>();
67 68
69 + private String email = null;
68 private int subscriberId; 70 private int subscriberId;
69 private int ssid; 71 private int ssid;
70 private Bundle currentBundle; 72 private Bundle currentBundle;
...@@ -84,8 +86,6 @@ public class CordModelCache extends JsonFactory { ...@@ -84,8 +86,6 @@ public class CordModelCache extends JsonFactory {
84 ObjectNode map = XosManager.INSTANCE.initXosSubscriberLookups(); 86 ObjectNode map = XosManager.INSTANCE.initXosSubscriberLookups();
85 initLookupMap(map); 87 initLookupMap(map);
86 log.info("{} entries in SSID->SubID lookup map", LOOKUP.size()); 88 log.info("{} entries in SSID->SubID lookup map", LOOKUP.size());
87 - // force DEMO subscriber to be installed by default
88 - init("foo@bar");
89 } 89 }
90 90
91 private void initLookupMap(ObjectNode map) { 91 private void initLookupMap(ObjectNode map) {
...@@ -122,6 +122,8 @@ public class CordModelCache extends JsonFactory { ...@@ -122,6 +122,8 @@ public class CordModelCache extends JsonFactory {
122 // defaults to the demo account 122 // defaults to the demo account
123 int ssid = DEMO_SSID; 123 int ssid = DEMO_SSID;
124 124
125 + this.email = email;
126 +
125 // obviously not scalable, but good enough for demo code... 127 // obviously not scalable, but good enough for demo code...
126 if (EMAIL_0.equals(email)) { 128 if (EMAIL_0.equals(email)) {
127 ssid = 0; 129 ssid = 0;
...@@ -144,12 +146,16 @@ public class CordModelCache extends JsonFactory { ...@@ -144,12 +146,16 @@ public class CordModelCache extends JsonFactory {
144 } 146 }
145 147
146 private void initUsers() { 148 private void initUsers() {
149 + // start with a clean slate
150 + userMap.clear();
151 +
147 ArrayNode users = XosManager.INSTANCE.getUserList(); 152 ArrayNode users = XosManager.INSTANCE.getUserList();
148 if (users == null) { 153 if (users == null) {
149 log.warn("no user list for SSID {} (subid {})", ssid, subscriberId); 154 log.warn("no user list for SSID {} (subid {})", ssid, subscriberId);
150 return; 155 return;
151 } 156 }
152 157
158 + StringBuilder sb = new StringBuilder();
153 for (JsonNode u: users) { 159 for (JsonNode u: users) {
154 ObjectNode user = (ObjectNode) u; 160 ObjectNode user = (ObjectNode) u;
155 161
...@@ -164,8 +170,10 @@ public class CordModelCache extends JsonFactory { ...@@ -164,8 +170,10 @@ public class CordModelCache extends JsonFactory {
164 // memento in which to store the level. 170 // memento in which to store the level.
165 SubscriberUser su = createUser(id, name, mac, level); 171 SubscriberUser su = createUser(id, name, mac, level);
166 userMap.put(id, su); 172 userMap.put(id, su);
167 - log.info("..caching user {} (id:{})", name, id); 173 + sb.append(String.format("\n..cache user %s [%d], %s, %s",
174 + name, id, mac, level));
168 } 175 }
176 + log.info(sb.toString());
169 } 177 }
170 178
171 private SubscriberUser createUser(int uid, String name, String mac, 179 private SubscriberUser createUser(int uid, String name, String mac,
...@@ -274,6 +282,7 @@ public class CordModelCache extends JsonFactory { ...@@ -274,6 +282,7 @@ public class CordModelCache extends JsonFactory {
274 private void addSubId(ObjectNode root) { 282 private void addSubId(ObjectNode root) {
275 root.put(SUB_ID, subscriberId); 283 root.put(SUB_ID, subscriberId);
276 root.put(SSID, ssid); 284 root.put(SSID, ssid);
285 + root.put(EMAIL, email);
277 } 286 }
278 287
279 288
...@@ -287,9 +296,9 @@ public class CordModelCache extends JsonFactory { ...@@ -287,9 +296,9 @@ public class CordModelCache extends JsonFactory {
287 * @return JSON acknowledgement 296 * @return JSON acknowledgement
288 */ 297 */
289 public String jsonLogin(String email) { 298 public String jsonLogin(String email) {
299 + log.info("jsonLogin(\"{}\")", email);
290 init(email); 300 init(email);
291 ObjectNode root = objectNode(); 301 ObjectNode root = objectNode();
292 - root.put(EMAIL, email);
293 addSubId(root); 302 addSubId(root);
294 return root.toString(); 303 return root.toString();
295 } 304 }
...@@ -300,6 +309,12 @@ public class CordModelCache extends JsonFactory { ...@@ -300,6 +309,12 @@ public class CordModelCache extends JsonFactory {
300 * @return dashboard page JSON data 309 * @return dashboard page JSON data
301 */ 310 */
302 public String jsonDashboard() { 311 public String jsonDashboard() {
312 + log.info("jsonDashboard()");
313 +
314 + if (email == null) {
315 + return jsonLogout();
316 + }
317 +
303 ObjectNode root = objectNode(); 318 ObjectNode root = objectNode();
304 root.put(BUNDLE, currentBundle.descriptor().displayName()); 319 root.put(BUNDLE, currentBundle.descriptor().displayName());
305 root.set(USERS, userJsonArray()); 320 root.set(USERS, userJsonArray());
...@@ -313,6 +328,12 @@ public class CordModelCache extends JsonFactory { ...@@ -313,6 +328,12 @@ public class CordModelCache extends JsonFactory {
313 * @return bundle page JSON data 328 * @return bundle page JSON data
314 */ 329 */
315 public String jsonBundle() { 330 public String jsonBundle() {
331 + log.info("jsonBundle()");
332 +
333 + if (email == null) {
334 + return jsonLogout();
335 + }
336 +
316 ObjectNode root = BundleFactory.toObjectNode(currentBundle); 337 ObjectNode root = BundleFactory.toObjectNode(currentBundle);
317 addSubId(root); 338 addSubId(root);
318 return root.toString(); 339 return root.toString();
...@@ -324,6 +345,12 @@ public class CordModelCache extends JsonFactory { ...@@ -324,6 +345,12 @@ public class CordModelCache extends JsonFactory {
324 * @return users page JSON data 345 * @return users page JSON data
325 */ 346 */
326 public String jsonUsers() { 347 public String jsonUsers() {
348 + log.info("jsonUsers()");
349 +
350 + if (email == null) {
351 + return jsonLogout();
352 + }
353 +
327 ObjectNode root = objectNode(); 354 ObjectNode root = objectNode();
328 root.set(USERS, userJsonArray()); 355 root.set(USERS, userJsonArray());
329 addSubId(root); 356 addSubId(root);
...@@ -331,6 +358,21 @@ public class CordModelCache extends JsonFactory { ...@@ -331,6 +358,21 @@ public class CordModelCache extends JsonFactory {
331 } 358 }
332 359
333 /** 360 /**
361 + * Returns logout acknowledgement as JSON.
362 + *
363 + * @return logout acknowledgement
364 + */
365 + public String jsonLogout() {
366 + log.info("jsonLogout()");
367 + ObjectNode root = objectNode().put(LOGOUT, true);
368 + addSubId(root);
369 +
370 + email = null; // signifies no one logged in
371 +
372 + return root.toString();
373 + }
374 +
375 + /**
334 * Singleton instance. 376 * Singleton instance.
335 */ 377 */
336 public static final CordModelCache INSTANCE = new CordModelCache(); 378 public static final CordModelCache INSTANCE = new CordModelCache();
......
...@@ -31,6 +31,13 @@ public class CordWebResource { ...@@ -31,6 +31,13 @@ public class CordWebResource {
31 31
32 @GET 32 @GET
33 @Produces(MediaType.APPLICATION_JSON) 33 @Produces(MediaType.APPLICATION_JSON)
34 + @Path("login/{email}")
35 + public Response login(@PathParam("email") String email) {
36 + return Response.ok(CordModelCache.INSTANCE.jsonLogin(email)).build();
37 + }
38 +
39 + @GET
40 + @Produces(MediaType.APPLICATION_JSON)
34 @Path("dashboard") 41 @Path("dashboard")
35 public Response dashboard() { 42 public Response dashboard() {
36 return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build(); 43 return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build();
...@@ -50,15 +57,15 @@ public class CordWebResource { ...@@ -50,15 +57,15 @@ public class CordWebResource {
50 return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build(); 57 return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
51 } 58 }
52 59
53 - // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
54 -
55 @GET 60 @GET
56 @Produces(MediaType.APPLICATION_JSON) 61 @Produces(MediaType.APPLICATION_JSON)
57 - @Path("login/{email}") 62 + @Path("logout")
58 - public Response login(@PathParam("email") String email) { 63 + public Response logout() {
59 - return Response.ok(CordModelCache.INSTANCE.jsonLogin(email)).build(); 64 + return Response.ok(CordModelCache.INSTANCE.jsonLogout()).build();
60 } 65 }
61 66
67 + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
68 +
62 @GET 69 @GET
63 @Produces(MediaType.APPLICATION_JSON) 70 @Produces(MediaType.APPLICATION_JSON)
64 @Path("bundle/{id}") 71 @Path("bundle/{id}")
......
...@@ -64,7 +64,7 @@ public class XosManagerRestUtils { ...@@ -64,7 +64,7 @@ public class XosManagerRestUtils {
64 this.xosServerAddress = xosServerAddress; 64 this.xosServerAddress = xosServerAddress;
65 this.xosServerPort = xosServerPort; 65 this.xosServerPort = xosServerPort;
66 this.baseUri = baseUri; 66 this.baseUri = baseUri;
67 - log.info("XMRU:: {}:{}/{}", xosServerAddress, xosServerPort, baseUri); 67 + log.info("XMRU:: {}:{}{}", xosServerAddress, xosServerPort, baseUri);
68 } 68 }
69 69
70 // build the base URL from the pieces we know... 70 // build the base URL from the pieces we know...
......
...@@ -9,6 +9,13 @@ export LOGDBG=-Dorg.onosproject.cord.gui.LEVEL=DEBUG ...@@ -9,6 +9,13 @@ export LOGDBG=-Dorg.onosproject.cord.gui.LEVEL=DEBUG
9 export DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n" 9 export DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
10 export LOG=cord.log 10 export LOG=cord.log
11 11
12 +DBG=""
13 +if [ "$1" = "debug" ]
14 +then
15 + shift
16 + DBG=$DEBUG
17 +fi
18 +
12 IP="$1" 19 IP="$1"
13 PORT="$2" 20 PORT="$2"
14 21
...@@ -26,8 +33,7 @@ else ...@@ -26,8 +33,7 @@ else
26 PARAM2="" 33 PARAM2=""
27 fi 34 fi
28 35
29 -java $PARAM1 $PARAM2 $LOGDBG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 & 36 +java $PARAM1 $PARAM2 $LOGDBG $DBG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 &
30 -#java $PARAM1 $PARAM2 $LOGDBG $DEBUG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 &
31 37
32 echo jetty-runner started {$PARAM1:$PARAM2} 38 echo jetty-runner started {$PARAM1:$PARAM2}
33 echo .. logging to $LOG 39 echo .. logging to $LOG
......