Simon Hunt

CORD Subscriber GUI - Added a little logging.

Change-Id: I96f674008cd8e6b3d7b3f517444a5ef9fd8b761c
......@@ -29,6 +29,8 @@ import org.onosproject.cord.gui.model.SubscriberUser;
import org.onosproject.cord.gui.model.UserFactory;
import org.onosproject.cord.gui.model.XosFunction;
import org.onosproject.cord.gui.model.XosFunctionDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
......@@ -50,6 +52,8 @@ public class CordModelCache extends JsonFactory {
private int subscriberId;
private Bundle currentBundle;
private final Logger log = LoggerFactory.getLogger(getClass());
// NOTE: use a tree map to maintain sorted order by user ID
private final Map<Integer, SubscriberUser> userMap =
new TreeMap<Integer, SubscriberUser>();
......@@ -59,6 +63,7 @@ public class CordModelCache extends JsonFactory {
* initializing it with basic bundle, and fetching the list of users.
*/
CordModelCache() {
log.info("Initialize model cache");
subscriberId = XosManager.INSTANCE.initDemoSubscriber();
currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
initUsers();
......@@ -80,6 +85,7 @@ public class CordModelCache extends JsonFactory {
// memento in which to store the level.
SubscriberUser su = createUser(id, name, mac, level);
userMap.put(id, su);
log.info("..caching user {} (id:{})", name, id);
}
}
......@@ -108,6 +114,7 @@ public class CordModelCache extends JsonFactory {
* @throws IllegalArgumentException if bundle ID is unknown
*/
public void setCurrentBundle(String bundleId) {
log.info("set new bundle : {}", bundleId);
BundleDescriptor bd = BundleFactory.bundleFromId(bundleId);
currentBundle = new Bundle(bd);
// update the user mementos
......
......@@ -42,6 +42,8 @@ public class XosManager {
private static final int TEST_XOS_SERVER_PORT = 8000;
private static final String URI_RS = "/rs/";
private static final String URI_SUBSCRIBER = "/rs/subscriber/%d/";
private static final String BUNDLE_URI_FORMAT = "services/%s/%s/";
private final XosManagerRestUtils xosUtilsRs =
new XosManagerRestUtils(TEST_XOS_SERVER_ADDRESS,
......@@ -52,8 +54,6 @@ public class XosManager {
private final Logger log = LoggerFactory.getLogger(getClass());
private int demoId;
/**
* No instantiation (except via unit test).
*/
......@@ -76,7 +76,7 @@ public class XosManager {
}
ObjectNode obj = (ObjectNode) node;
demoId = obj.get("id").asInt();
int demoId = obj.get("id").asInt();
log.info("Using DEMO subscriber ID {}.", demoId);
String uri = String.format(URI_SUBSCRIBER, demoId);
......@@ -114,14 +114,15 @@ public class XosManager {
* @param bundle new bundle to set
*/
public void setNewBundle(Bundle bundle) {
log.info("\n>> Set New Bundle : " + bundle.descriptor().id());
log.info(">> Set New Bundle : {}", bundle.descriptor().id());
String uriFmt = "services/%s/%s";
Set<XosFunctionDescriptor> inBundle = bundle.descriptor().functions();
for (XosFunctionDescriptor xfd: XosFunctionDescriptor.values()) {
// only process the functions that have a real back-end on XOS
if (xfd.backend()) {
String uri = String.format(uriFmt, xfd.id(), inBundle.contains(xfd));
String uri = String.format(BUNDLE_URI_FORMAT, xfd.id(),
inBundle.contains(xfd));
log.info("XOS-URI: {}", uri);
String result = xosUtils.putRest(uri);
// TODO: convert JSON result to object and check (if we care)
}
......@@ -136,10 +137,11 @@ public class XosManager {
* @param user user (containing function state)
*/
public void apply(XosFunction func, SubscriberUser user) {
log.info("\n>> Apply : " + func + " for " + user);
log.info(">> Apply : {} for {}", func, user);
String uriPrefix = "users/" + user.id() + "/";
String uri = uriPrefix + func.xosUrlApply(user);
log.info("XOS-URI: {}", uri);
String result = xosUtils.putRest(uri);
// TODO: convert JSON result to object and check (if we care)
}
......
......@@ -27,6 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class UrlFilterFunction extends DefaultXosFunction {
private static final String LEVEL = "level";
private static final String URI_PATTERN = "%s/%s/";
/**
* Denotes the URL filtering levels available. From most restrictive
......@@ -87,6 +88,6 @@ public class UrlFilterFunction extends DefaultXosFunction {
public String xosUrlApply(SubscriberUser user) {
XosFunctionDescriptor xfd = XosFunctionDescriptor.URL_FILTER;
UrlFilterMemento memo = (UrlFilterMemento) user.getMemento(xfd);
return xfd.id() + "/" + memo.level();
return String.format(URI_PATTERN, xfd.id(), memo.level());
}
}
......