mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-22 21:01:00 +02:00
CORD GUI - Added logout call, and implemented the notion of session.
Change-Id: I44fc42c909071755c73ac367bf03427cfbe6b643
This commit is contained in:
parent
f34c989166
commit
c296d2c5dc
@ -62,9 +62,11 @@ public class CordModelCache extends JsonFactory {
|
|||||||
private static final String BUNDLE = "bundle";
|
private static final String BUNDLE = "bundle";
|
||||||
private static final String USERS = "users";
|
private static final String USERS = "users";
|
||||||
private static final String LEVEL = "level";
|
private static final String LEVEL = "level";
|
||||||
|
private static final String LOGOUT = "logout";
|
||||||
|
|
||||||
private static final Map<Integer, Integer> LOOKUP = new HashMap<>();
|
private static final Map<Integer, Integer> LOOKUP = new HashMap<>();
|
||||||
|
|
||||||
|
private String email = null;
|
||||||
private int subscriberId;
|
private int subscriberId;
|
||||||
private int ssid;
|
private int ssid;
|
||||||
private Bundle currentBundle;
|
private Bundle currentBundle;
|
||||||
@ -84,8 +86,6 @@ public class CordModelCache extends JsonFactory {
|
|||||||
ObjectNode map = XosManager.INSTANCE.initXosSubscriberLookups();
|
ObjectNode map = XosManager.INSTANCE.initXosSubscriberLookups();
|
||||||
initLookupMap(map);
|
initLookupMap(map);
|
||||||
log.info("{} entries in SSID->SubID lookup map", LOOKUP.size());
|
log.info("{} entries in SSID->SubID lookup map", LOOKUP.size());
|
||||||
// force DEMO subscriber to be installed by default
|
|
||||||
init("foo@bar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLookupMap(ObjectNode map) {
|
private void initLookupMap(ObjectNode map) {
|
||||||
@ -122,6 +122,8 @@ public class CordModelCache extends JsonFactory {
|
|||||||
// defaults to the demo account
|
// defaults to the demo account
|
||||||
int ssid = DEMO_SSID;
|
int ssid = DEMO_SSID;
|
||||||
|
|
||||||
|
this.email = email;
|
||||||
|
|
||||||
// obviously not scalable, but good enough for demo code...
|
// obviously not scalable, but good enough for demo code...
|
||||||
if (EMAIL_0.equals(email)) {
|
if (EMAIL_0.equals(email)) {
|
||||||
ssid = 0;
|
ssid = 0;
|
||||||
@ -144,12 +146,16 @@ public class CordModelCache extends JsonFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initUsers() {
|
private void initUsers() {
|
||||||
|
// start with a clean slate
|
||||||
|
userMap.clear();
|
||||||
|
|
||||||
ArrayNode users = XosManager.INSTANCE.getUserList();
|
ArrayNode users = XosManager.INSTANCE.getUserList();
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
log.warn("no user list for SSID {} (subid {})", ssid, subscriberId);
|
log.warn("no user list for SSID {} (subid {})", ssid, subscriberId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
for (JsonNode u: users) {
|
for (JsonNode u: users) {
|
||||||
ObjectNode user = (ObjectNode) u;
|
ObjectNode user = (ObjectNode) u;
|
||||||
|
|
||||||
@ -164,8 +170,10 @@ public class CordModelCache extends JsonFactory {
|
|||||||
// memento in which to store the level.
|
// memento in which to store the level.
|
||||||
SubscriberUser su = createUser(id, name, mac, level);
|
SubscriberUser su = createUser(id, name, mac, level);
|
||||||
userMap.put(id, su);
|
userMap.put(id, su);
|
||||||
log.info("..caching user {} (id:{})", name, id);
|
sb.append(String.format("\n..cache user %s [%d], %s, %s",
|
||||||
|
name, id, mac, level));
|
||||||
}
|
}
|
||||||
|
log.info(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SubscriberUser createUser(int uid, String name, String mac,
|
private SubscriberUser createUser(int uid, String name, String mac,
|
||||||
@ -274,6 +282,7 @@ public class CordModelCache extends JsonFactory {
|
|||||||
private void addSubId(ObjectNode root) {
|
private void addSubId(ObjectNode root) {
|
||||||
root.put(SUB_ID, subscriberId);
|
root.put(SUB_ID, subscriberId);
|
||||||
root.put(SSID, ssid);
|
root.put(SSID, ssid);
|
||||||
|
root.put(EMAIL, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -287,9 +296,9 @@ public class CordModelCache extends JsonFactory {
|
|||||||
* @return JSON acknowledgement
|
* @return JSON acknowledgement
|
||||||
*/
|
*/
|
||||||
public String jsonLogin(String email) {
|
public String jsonLogin(String email) {
|
||||||
|
log.info("jsonLogin(\"{}\")", email);
|
||||||
init(email);
|
init(email);
|
||||||
ObjectNode root = objectNode();
|
ObjectNode root = objectNode();
|
||||||
root.put(EMAIL, email);
|
|
||||||
addSubId(root);
|
addSubId(root);
|
||||||
return root.toString();
|
return root.toString();
|
||||||
}
|
}
|
||||||
@ -300,6 +309,12 @@ public class CordModelCache extends JsonFactory {
|
|||||||
* @return dashboard page JSON data
|
* @return dashboard page JSON data
|
||||||
*/
|
*/
|
||||||
public String jsonDashboard() {
|
public String jsonDashboard() {
|
||||||
|
log.info("jsonDashboard()");
|
||||||
|
|
||||||
|
if (email == null) {
|
||||||
|
return jsonLogout();
|
||||||
|
}
|
||||||
|
|
||||||
ObjectNode root = objectNode();
|
ObjectNode root = objectNode();
|
||||||
root.put(BUNDLE, currentBundle.descriptor().displayName());
|
root.put(BUNDLE, currentBundle.descriptor().displayName());
|
||||||
root.set(USERS, userJsonArray());
|
root.set(USERS, userJsonArray());
|
||||||
@ -313,6 +328,12 @@ public class CordModelCache extends JsonFactory {
|
|||||||
* @return bundle page JSON data
|
* @return bundle page JSON data
|
||||||
*/
|
*/
|
||||||
public String jsonBundle() {
|
public String jsonBundle() {
|
||||||
|
log.info("jsonBundle()");
|
||||||
|
|
||||||
|
if (email == null) {
|
||||||
|
return jsonLogout();
|
||||||
|
}
|
||||||
|
|
||||||
ObjectNode root = BundleFactory.toObjectNode(currentBundle);
|
ObjectNode root = BundleFactory.toObjectNode(currentBundle);
|
||||||
addSubId(root);
|
addSubId(root);
|
||||||
return root.toString();
|
return root.toString();
|
||||||
@ -324,12 +345,33 @@ public class CordModelCache extends JsonFactory {
|
|||||||
* @return users page JSON data
|
* @return users page JSON data
|
||||||
*/
|
*/
|
||||||
public String jsonUsers() {
|
public String jsonUsers() {
|
||||||
|
log.info("jsonUsers()");
|
||||||
|
|
||||||
|
if (email == null) {
|
||||||
|
return jsonLogout();
|
||||||
|
}
|
||||||
|
|
||||||
ObjectNode root = objectNode();
|
ObjectNode root = objectNode();
|
||||||
root.set(USERS, userJsonArray());
|
root.set(USERS, userJsonArray());
|
||||||
addSubId(root);
|
addSubId(root);
|
||||||
return root.toString();
|
return root.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns logout acknowledgement as JSON.
|
||||||
|
*
|
||||||
|
* @return logout acknowledgement
|
||||||
|
*/
|
||||||
|
public String jsonLogout() {
|
||||||
|
log.info("jsonLogout()");
|
||||||
|
ObjectNode root = objectNode().put(LOGOUT, true);
|
||||||
|
addSubId(root);
|
||||||
|
|
||||||
|
email = null; // signifies no one logged in
|
||||||
|
|
||||||
|
return root.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton instance.
|
* Singleton instance.
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +29,13 @@ import javax.ws.rs.core.Response;
|
|||||||
@Path("")
|
@Path("")
|
||||||
public class CordWebResource {
|
public class CordWebResource {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("login/{email}")
|
||||||
|
public Response login(@PathParam("email") String email) {
|
||||||
|
return Response.ok(CordModelCache.INSTANCE.jsonLogin(email)).build();
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("dashboard")
|
@Path("dashboard")
|
||||||
@ -50,15 +57,15 @@ public class CordWebResource {
|
|||||||
return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
|
return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("login/{email}")
|
@Path("logout")
|
||||||
public Response login(@PathParam("email") String email) {
|
public Response logout() {
|
||||||
return Response.ok(CordModelCache.INSTANCE.jsonLogin(email)).build();
|
return Response.ok(CordModelCache.INSTANCE.jsonLogout()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("bundle/{id}")
|
@Path("bundle/{id}")
|
||||||
|
@ -64,7 +64,7 @@ public class XosManagerRestUtils {
|
|||||||
this.xosServerAddress = xosServerAddress;
|
this.xosServerAddress = xosServerAddress;
|
||||||
this.xosServerPort = xosServerPort;
|
this.xosServerPort = xosServerPort;
|
||||||
this.baseUri = baseUri;
|
this.baseUri = baseUri;
|
||||||
log.info("XMRU:: {}:{}/{}", xosServerAddress, xosServerPort, baseUri);
|
log.info("XMRU:: {}:{}{}", xosServerAddress, xosServerPort, baseUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the base URL from the pieces we know...
|
// build the base URL from the pieces we know...
|
||||||
|
@ -9,6 +9,13 @@ export LOGDBG=-Dorg.onosproject.cord.gui.LEVEL=DEBUG
|
|||||||
export DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
|
export DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
|
||||||
export LOG=cord.log
|
export LOG=cord.log
|
||||||
|
|
||||||
|
DBG=""
|
||||||
|
if [ "$1" = "debug" ]
|
||||||
|
then
|
||||||
|
shift
|
||||||
|
DBG=$DEBUG
|
||||||
|
fi
|
||||||
|
|
||||||
IP="$1"
|
IP="$1"
|
||||||
PORT="$2"
|
PORT="$2"
|
||||||
|
|
||||||
@ -26,8 +33,7 @@ else
|
|||||||
PARAM2=""
|
PARAM2=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
java $PARAM1 $PARAM2 $LOGDBG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 &
|
java $PARAM1 $PARAM2 $LOGDBG $DBG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 &
|
||||||
#java $PARAM1 $PARAM2 $LOGDBG $DEBUG $JETTY --port $LISTENPORT $CORD >$LOG 2>&1 &
|
|
||||||
|
|
||||||
echo jetty-runner started {$PARAM1:$PARAM2}
|
echo jetty-runner started {$PARAM1:$PARAM2}
|
||||||
echo .. logging to $LOG
|
echo .. logging to $LOG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user