summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord')
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java382
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java87
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/FakeUtils.java51
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java198
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManagerRestUtils.java212
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java95
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java54
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java144
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java89
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java66
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java53
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java131
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java93
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java68
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java73
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java126
-rw-r--r--framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java115
17 files changed, 0 insertions, 2037 deletions
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
deleted file mode 100644
index dd1e42b7..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.ImmutableList;
-import org.onosproject.cord.gui.model.Bundle;
-import org.onosproject.cord.gui.model.BundleDescriptor;
-import org.onosproject.cord.gui.model.BundleFactory;
-import org.onosproject.cord.gui.model.JsonFactory;
-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.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.cord.gui.model.XosFunctionDescriptor.URL_FILTER;
-
-/**
- * In memory cache of the model of the subscriber's account.
- */
-public class CordModelCache extends JsonFactory {
-
- private static final String KEY_SSID_MAP = "ssidmap";
- private static final String KEY_SSID = "service_specific_id";
- private static final String KEY_SUB_ID = "subscriber_id";
-
- private static final int DEMO_SSID = 1234;
-
- private static final String EMAIL_0 = "john@smith.org";
- private static final String EMAIL_1 = "john@doe.org";
-
- private static final String EMAIL = "email";
- private static final String SSID = "ssid";
- private static final String SUB_ID = "subId";
-
- private static final String BUNDLE = "bundle";
- private static final String USERS = "users";
- private static final String LEVEL = "level";
- private static final String LOGOUT = "logout";
-
- private static final String BUNDLE_NAME = BUNDLE + "_name";
- private static final String BUNDLE_DESC = BUNDLE + "_desc";
-
- private static final Map<Integer, Integer> LOOKUP = new HashMap<>();
-
- private String email = null;
- private int subscriberId;
- private int ssid;
- 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>();
-
- /**
- * Constructs a model cache, retrieving a mapping of SSID to XOS Subscriber
- * IDs from the XOS server.
- */
- CordModelCache() {
- log.info("Initialize model cache");
- ObjectNode map = XosManager.INSTANCE.initXosSubscriberLookups();
- initLookupMap(map);
- log.info("{} entries in SSID->SubID lookup map", LOOKUP.size());
- }
-
- private void initLookupMap(ObjectNode map) {
- ArrayNode array = (ArrayNode) map.get(KEY_SSID_MAP);
- Iterator<JsonNode> iter = array.elements();
- StringBuilder msg = new StringBuilder();
- while (iter.hasNext()) {
- ObjectNode node = (ObjectNode) iter.next();
- String ssidStr = node.get(KEY_SSID).asText();
- int ssid = Integer.valueOf(ssidStr);
- int subId = node.get(KEY_SUB_ID).asInt();
- LOOKUP.put(ssid, subId);
- msg.append(String.format("\n..binding SSID %s to sub-id %s", ssid, subId));
- }
- log.info(msg.toString());
- }
-
- private int lookupSubId(int ssid) {
- Integer subId = LOOKUP.get(ssid);
- if (subId == null) {
- log.error("Unmapped SSID: {}", ssid);
- return 0;
- }
- return subId;
- }
-
- /**
- * Initializes the model for the subscriber account associated with
- * the given email address.
- *
- * @param email the email address
- */
- void init(String email) {
- // defaults to the demo account
- int ssid = DEMO_SSID;
-
- this.email = email;
-
- // obviously not scalable, but good enough for demo code...
- if (EMAIL_0.equals(email)) {
- ssid = 0;
- } else if (EMAIL_1.equals(email)) {
- ssid = 1;
- }
-
- this.ssid = ssid;
- subscriberId = lookupSubId(ssid);
- XosManager.INSTANCE.setXosUtilsForSubscriber(subscriberId);
-
- // call the initdemo API to ensure users are populated in XOS
- XosManager.INSTANCE.initDemoSubscriber();
-
- // NOTE: I think the following should work for non-DEMO account...
- currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
- initUsers();
- }
-
- private void initUsers() {
- // start with a clean slate
- userMap.clear();
-
- ArrayNode users = XosManager.INSTANCE.getUserList();
- if (users == null) {
- log.warn("no user list for SSID {} (subid {})", ssid, subscriberId);
- return;
- }
-
- StringBuilder sb = new StringBuilder();
- for (JsonNode u: users) {
- ObjectNode user = (ObjectNode) u;
-
- int id = user.get("id").asInt();
- String name = user.get("name").asText();
- String mac = user.get("mac").asText();
- String level = user.get("level").asText();
-
- // NOTE: We are just storing the current "url-filter" level.
- // Since we are starting with the BASIC bundle, (that does
- // not include URL_FILTER), we don't yet have the URL_FILTER
- // memento in which to store the level.
- SubscriberUser su = createUser(id, name, mac, level);
- userMap.put(id, su);
- 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,
- String level) {
- SubscriberUser user = new SubscriberUser(uid, name, mac, level);
- for (XosFunction f: currentBundle.functions()) {
- user.setMemento(f.descriptor(), f.createMemento());
- }
- return user;
- }
-
- /**
- * Returns the currently selected bundle.
- *
- * @return current bundle
- */
- public Bundle getCurrentBundle() {
- return currentBundle;
- }
-
- /**
- * Sets a new bundle.
- *
- * @param bundleId bundle identifier
- * @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
- for (SubscriberUser user: userMap.values()) {
- user.clearMementos();
- for (XosFunction f: currentBundle.functions()) {
- user.setMemento(f.descriptor(), f.createMemento());
- if (f.descriptor().equals(URL_FILTER)) {
- applyUrlFilterLevel(user, user.urlFilterLevel());
- }
- }
- }
-
- XosManager.INSTANCE.setNewBundle(currentBundle);
- }
-
-
- /**
- * Returns the list of current users for this subscriber account.
- *
- * @return the list of users
- */
- public List<SubscriberUser> getUsers() {
- return ImmutableList.copyOf(userMap.values());
- }
-
- /**
- * Applies a function parameter change for a user, pushing that
- * change through to XOS.
- *
- * @param userId user identifier
- * @param funcId function identifier
- * @param param function parameter to change
- * @param value new value for function parameter
- */
- public void applyPerUserParam(String userId, String funcId,
- String param, String value) {
-
- int uid = Integer.parseInt(userId);
- SubscriberUser user = userMap.get(uid);
- checkNotNull(user, "unknown user id: " + uid);
-
- XosFunctionDescriptor xfd =
- XosFunctionDescriptor.valueOf(funcId.toUpperCase());
-
- XosFunction func = currentBundle.findFunction(xfd);
- checkNotNull(func, "function not part of bundle: " + funcId);
- applyParam(func, user, param, value, true);
- }
-
- // =============
-
- private void applyUrlFilterLevel(SubscriberUser user, String level) {
- XosFunction urlFilter = currentBundle.findFunction(URL_FILTER);
- if (urlFilter != null) {
- applyParam(urlFilter, user, LEVEL, level, false);
- }
- }
-
- private void applyParam(XosFunction func, SubscriberUser user,
- String param, String value, boolean punchThrough) {
- func.applyParam(user, param, value);
- if (punchThrough) {
- XosManager.INSTANCE.apply(func, user);
- }
- }
-
- private ArrayNode userJsonArray() {
- ArrayNode userList = arrayNode();
- for (SubscriberUser user: userMap.values()) {
- userList.add(UserFactory.toObjectNode(user));
- }
- return userList;
- }
-
- // ============= generate JSON for GUI rest calls..
-
- private void addSubId(ObjectNode root) {
- root.put(SUB_ID, subscriberId);
- root.put(SSID, ssid);
- root.put(EMAIL, email);
- }
-
-
- /**
- * Returns response JSON for login request.
- * <p>
- * Depending on which email is used, will bind the GUI to the
- * appropriate XOS Subscriber ID.
- *
- * @param email the supplied email
- * @return JSON acknowledgement
- */
- public synchronized String jsonLogin(String email) {
- log.info("jsonLogin(\"{}\")", email);
- init(email);
- ObjectNode root = objectNode();
- addSubId(root);
- return root.toString();
- }
-
- /**
- * Returns the dashboard page data as JSON.
- *
- * @return dashboard page JSON data
- */
- public synchronized String jsonDashboard() {
- log.info("jsonDashboard()");
-
- if (email == null) {
- return jsonLogout();
- }
-
- BundleDescriptor bundleDescriptor = currentBundle.descriptor();
- ObjectNode root = objectNode();
- root.put(BUNDLE_NAME, bundleDescriptor.displayName());
- root.put(BUNDLE_DESC, bundleDescriptor.description());
- root.set(USERS, userJsonArray());
- addSubId(root);
- return root.toString();
- }
-
- /**
- * Returns the bundle page data as JSON.
- *
- * @return bundle page JSON data
- */
- public synchronized String jsonBundle() {
- log.info("jsonBundle()");
-
- if (email == null) {
- return jsonLogout();
- }
-
- ObjectNode root = BundleFactory.toObjectNode(currentBundle);
- addSubId(root);
- return root.toString();
- }
-
- /**
- * Returns the users page data as JSON.
- *
- * @return users page JSON data
- */
- public synchronized String jsonUsers() {
- log.info("jsonUsers()");
-
- if (email == null) {
- return jsonLogout();
- }
-
- ObjectNode root = objectNode();
- root.set(USERS, userJsonArray());
- addSubId(root);
- return root.toString();
- }
-
- /**
- * Returns logout acknowledgement as JSON.
- *
- * @return logout acknowledgement
- */
- public synchronized 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.
- */
- public static final CordModelCache INSTANCE = new CordModelCache();
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java
deleted file mode 100644
index 7fc4afe6..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.cord.gui;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-/**
- * Web resource to use as the GUI back-end and as a proxy to XOS REST API.
- */
-@Path("")
-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
- @Produces(MediaType.APPLICATION_JSON)
- @Path("dashboard")
- public Response dashboard() {
- return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build();
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("bundle")
- public Response bundle() {
- return Response.ok(CordModelCache.INSTANCE.jsonBundle()).build();
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("users")
- public Response users() {
- return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("logout")
- public Response logout() {
- return Response.ok(CordModelCache.INSTANCE.jsonLogout()).build();
- }
-
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("bundle/{id}")
- public Response bundle(@PathParam("id") String bundleId) {
- CordModelCache.INSTANCE.setCurrentBundle(bundleId);
- return bundle();
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("users/{id}/apply/{func}/{param}/{value}")
- public Response bundle(@PathParam("id") String userId,
- @PathParam("func") String funcId,
- @PathParam("param") String param,
- @PathParam("value") String value) {
- CordModelCache.INSTANCE.applyPerUserParam(userId, funcId, param, value);
- return users();
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/FakeUtils.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/FakeUtils.java
deleted file mode 100644
index b48a2d55..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/FakeUtils.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui;
-
-import org.apache.commons.io.IOUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Provides support for fake data.
- */
-public class FakeUtils {
- private static final ClassLoader CL = FakeUtils.class.getClassLoader();
- private static final String ROOT_PATH = "/org/onosproject/cord/gui/";
- private static final String UTF_8 = "UTF-8";
-
- /**
- * Returns the contents of a local file as a string.
- *
- * @param path file path name
- * @return contents of file as a string
- */
- public static String slurp(String path) {
- String result = null;
- InputStream is = CL.getResourceAsStream(ROOT_PATH + path);
- if (is != null) {
- try {
- result = IOUtils.toString(is, UTF_8);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return result;
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java
deleted file mode 100644
index de0ae67d..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.cord.gui.model.Bundle;
-import org.onosproject.cord.gui.model.SubscriberUser;
-import org.onosproject.cord.gui.model.XosFunction;
-import org.onosproject.cord.gui.model.XosFunctionDescriptor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Set;
-
-/**
- * Encapsulation of interactions with XOS.
- */
-public class XosManager {
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- private static final String HEAD_NODE_IP = "headnodeip";
- private static final String HEAD_NODE_PORT = "headnodeport";
- private static final int PORT_MIN = 1025;
- private static final int PORT_MAX = 65535;
-
- private static final String TEST_XOS_SERVER_IP = "10.254.1.22";
- private static final String TEST_XOS_SERVER_PORT_STR = "8000";
- 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 String xosServerIp;
- private int xosServerPort;
- private XosManagerRestUtils xosUtilsRs;
- private XosManagerRestUtils xosUtils;
-
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- /**
- * No instantiation (except via unit test).
- */
- XosManager() {}
-
- private String getXosServerIp() {
- return System.getProperty(HEAD_NODE_IP, TEST_XOS_SERVER_IP);
- }
-
- private int getXosServerPort() {
- String p = System.getProperty(HEAD_NODE_PORT, TEST_XOS_SERVER_PORT_STR);
- int port;
- try {
- port = Integer.valueOf(p);
- } catch (NumberFormatException e) {
- port = TEST_XOS_SERVER_PORT;
- log.warn("Could not parse port number [{}], using {}", p, port);
- }
- if (port < PORT_MIN || port > PORT_MAX) {
- log.warn("Bad port number [{}], using {}", port, TEST_XOS_SERVER_PORT);
- port = TEST_XOS_SERVER_PORT;
- }
- return port;
- }
-
- /**
- * Queries XOS for the Subscriber ID lookup data, and returns it.
- */
- public ObjectNode initXosSubscriberLookups() {
- log.info("intDemoSubscriberLookups() called");
- xosServerIp = getXosServerIp();
- xosServerPort = getXosServerPort();
- log.info("Using XOS server at {}:{}", xosServerIp, xosServerPort);
-
- xosUtilsRs = new XosManagerRestUtils(xosServerIp, xosServerPort, URI_RS);
-
- // ask XOS for the subscriber ID lookup info
- String result = xosUtilsRs.getRest("subidlookup/");
- log.info("lookup data from XOS: {}", result);
-
- JsonNode node;
- try {
- node = MAPPER.readTree(result);
- } catch (IOException e) {
- log.error("failed to read subscriber lookup JSON data", e);
- return null;
- }
- return (ObjectNode) node;
- }
-
- /**
- * Sets a new XOS utils object to bind URL patterns for the
- * given XOS subscriber ID.
- *
- * @param xosSubId XOS subscriber ID
- */
- public void setXosUtilsForSubscriber(int xosSubId) {
- String uri = String.format(URI_SUBSCRIBER, xosSubId);
- xosUtils = new XosManagerRestUtils(xosServerIp, xosServerPort, uri);
- }
-
-
- public void initDemoSubscriber() {
- log.info("initDemoSubscriber() called");
- String result = xosUtilsRs.getRest("initdemo/");
- log.info("initdemo data from XOS: {}", result);
- }
-
- /**
- * Returns the array of users for the subscriber.
- *
- * @return list of users
- */
- public ArrayNode getUserList() {
- log.info("getUserList() called");
- String result = xosUtils.getRest("users/");
-
- JsonNode node;
- try {
- node = MAPPER.readTree(result);
- } catch (IOException e) {
- log.error("failed to read user list JSON", e);
- return null;
- }
-
- ObjectNode obj = (ObjectNode) node;
- return (ArrayNode) obj.get("users");
- }
-
-
- /**
- * Configure XOS to enable the functions that compose the given bundle,
- * and disable all the others, for the given subscriber.
- *
- * @param bundle new bundle to set
- */
- public void setNewBundle(Bundle bundle) {
- log.info(">> Set New Bundle : {}", bundle.descriptor().id());
-
- 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(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)
- }
- }
- }
-
- /**
- * Configure XOS with new setting for given user and function, for the
- * given subscriber account.
- *
- * @param func specific XOS function
- * @param user user (containing function state)
- */
- public void apply(XosFunction func, SubscriberUser 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)
- }
-
-
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- /**
- * Singleton instance.
- */
- public static final XosManager INSTANCE = new XosManager();
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManagerRestUtils.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManagerRestUtils.java
deleted file mode 100644
index 50ccde33..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManagerRestUtils.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
-import org.slf4j.Logger;
-
-import static com.google.common.net.MediaType.JSON_UTF_8;
-import static java.net.HttpURLConnection.*;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Utility RESTful methods for dealing with the XOS server.
- */
-public class XosManagerRestUtils {
- private static final String XOSLIB = "/xoslib";
- private static final String AUTH_USER = "padmin@vicci.org";
- private static final String AUTH_PASS = "letmein";
-
- private static final String UTF_8 = JSON_UTF_8.toString();
-
- private final Logger log = getLogger(getClass());
-
- private final String xosServerAddress;
- private final int xosServerPort;
- private final String baseUri;
-
-
- /**
- * Constructs a utility class, using the supplied server address and port,
- * using the given base URI.
- * <p>
- * Note that the uri should start and end with a slash; for example:
- * {@code "/volttenant/"}. This example would result in URIs of the form:
- * <pre>
- * "http://[server]:[port]/xoslib/volttenant/"
- * </pre>
- *
- * @param xosServerAddress server IP address
- * @param xosServerPort server port
- * @param baseUri base URI
- */
- public XosManagerRestUtils(String xosServerAddress, int xosServerPort,
- String baseUri) {
- this.xosServerAddress = xosServerAddress;
- this.xosServerPort = xosServerPort;
- this.baseUri = baseUri;
- log.info("XMRU:: {}:{}{}", xosServerAddress, xosServerPort, baseUri);
- }
-
- // build the base URL from the pieces we know...
- private String baseUrl() {
- return "http://" + xosServerAddress + ":" +
- Integer.toString(xosServerPort) + XOSLIB + baseUri;
- }
-
- /**
- * Gets a client web resource builder for the base XOS REST API
- * with no additional URI.
- *
- * @return web resource builder
- */
- public WebResource.Builder getClientBuilder() {
- return getClientBuilder("");
- }
-
- /**
- * Gets a client web resource builder for the base XOS REST API
- * with an optional additional URI.
- *
- * @param uri URI suffix to append to base URI
- * @return web resource builder
- */
- public WebResource.Builder getClientBuilder(String uri) {
- Client client = Client.create();
- client.addFilter(new HTTPBasicAuthFilter(AUTH_USER, AUTH_PASS));
- WebResource resource = client.resource(baseUrl() + uri);
- log.info("XOS REST CALL>> {}", resource);
- return resource.accept(UTF_8).type(UTF_8);
- }
-
- /**
- * Performs a REST GET operation on the base XOS REST URI.
- *
- * @return JSON string fetched by the GET operation
- */
- public String getRest() {
- return getRest("");
- }
-
- /**
- * Performs a REST GET operation on the base XOS REST URI with
- * an optional additional URI.
- *
- * @param uri URI suffix to append to base URI
- * @return JSON string fetched by the GET operation
- */
- public String getRest(String uri) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response = builder.get(ClientResponse.class);
-
- if (response.getStatus() != HTTP_OK) {
- log.info("REST GET request returned error code {}",
- response.getStatus());
- }
- return response.getEntity(String.class);
- }
-
- /**
- * Performs a REST PUT operation on the base XOS REST URI.
- *
- * @return JSON string returned by the PUT operation
- */
- public String putRest() {
- return putRest("");
- }
-
- /**
- * Performs a REST PUT operation on the base XOS REST URI with
- * an optional additional URI.
- *
- * @param uri URI suffix to append to base URI
- * @return JSON string returned by the PUT operation
- */
- public String putRest(String uri) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response;
-
- try {
- response = builder.put(ClientResponse.class);
- } catch (ClientHandlerException e) {
- log.warn("Unable to contact REST server: {}", e.getMessage());
- return "";
- }
-
- if (response.getStatus() != HTTP_OK) {
- log.info("REST PUT request returned error code {}",
- response.getStatus());
- }
- return response.getEntity(String.class);
- }
-
- /**
- * Performs a REST POST operation of a json string on the base
- * XOS REST URI with an optional additional URI.
- *
- * @param json JSON string to post
- */
- public void postRest(String json) {
- postRest("", json);
- }
-
- /**
- * Performs a REST POST operation of a json string on the base
- * XOS REST URI with an optional additional URI suffix.
- *
- * @param uri URI suffix to append to base URI
- * @param json JSON string to post
- */
- public void postRest(String uri, String json) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response;
-
- try {
- response = builder.post(ClientResponse.class, json);
- } catch (ClientHandlerException e) {
- log.warn("Unable to contact REST server: {}", e.getMessage());
- return;
- }
-
- if (response.getStatus() != HTTP_CREATED) {
- log.info("REST POST request returned error code {}",
- response.getStatus());
- }
- }
-
- /**
- * Performs a REST DELETE operation on the base
- * XOS REST URI with an optional additional URI.
- *
- * @param uri URI suffix to append to base URI
- */
- public void deleteRest(String uri) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response = builder.delete(ClientResponse.class);
-
- if (response.getStatus() != HTTP_NO_CONTENT) {
- log.info("REST DELETE request returned error code {}",
- response.getStatus());
- }
- }
-
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java
deleted file mode 100644
index c51cc848..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Encapsulates a bundle, including current state.
- */
-public class Bundle {
- private final BundleDescriptor bundleDescriptor;
- private final Map<XosFunctionDescriptor, XosFunction> functionMap =
- new HashMap<XosFunctionDescriptor, XosFunction>();
-
- /**
- * Constructs a new bundle instance.
- *
- * @param bundleDescriptor the descriptor
- */
- public Bundle(BundleDescriptor bundleDescriptor) {
- this.bundleDescriptor = bundleDescriptor;
- initFunctions();
- }
-
- /**
- * Returns the bundle descriptor.
- *
- * @return the descriptor
- */
- public BundleDescriptor descriptor() {
- return bundleDescriptor;
- }
-
- /**
- * Returns the set of function instances for this bundle.
- *
- * @return the functions
- */
- public Set<XosFunction> functions() {
- return ImmutableSet.copyOf(functionMap.values());
- }
-
- /**
- * Creates an initial set of function instances.
- */
- private void initFunctions() {
- for (XosFunctionDescriptor xfd: bundleDescriptor.functions()) {
- functionMap.put(xfd, createFunction(xfd));
- }
- }
-
- private XosFunction createFunction(XosFunctionDescriptor xfd) {
- XosFunction func;
- switch (xfd) {
- case URL_FILTER:
- func = new UrlFilterFunction();
- break;
-
- default:
- func = new DefaultXosFunction(xfd);
- break;
- }
- return func;
- }
-
- /**
- * Returns the function instance for the specified descriptor, or returns
- * null if function is not part of this bundle.
- *
- * @param xfd function descrriptor
- * @return function instance
- */
- public XosFunction findFunction(XosFunctionDescriptor xfd) {
- return functionMap.get(xfd);
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java
deleted file mode 100644
index 4a970543..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import java.util.Set;
-
-/**
- * Defines a bundle of {@link XosFunctionDescriptor XOS functions}.
- */
-public interface BundleDescriptor {
-
- /**
- * Bundle internal identifier.
- *
- * @return bundle identifier
- */
- String id();
-
- /**
- * Bundle display name.
- *
- * @return display name
- */
- String displayName();
-
- /**
- * Textual description of this bundle.
- *
- * @return description
- */
- String description();
-
- /**
- * The set of functions in this bundle instance.
- *
- * @return the functions
- */
- Set<XosFunctionDescriptor> functions();
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java
deleted file mode 100644
index 813ad98b..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.ImmutableList;
-
-import java.util.List;
-
-/**
- * Utility factory for creating and/or operating on bundles.
- */
-public class BundleFactory extends JsonFactory {
-
- private static final String BUNDLE = "bundle";
- private static final String BUNDLES = "bundles";
- private static final String FUNCTIONS = "functions";
-
- private static final String BASIC_ID = "basic";
- private static final String BASIC_DISPLAY_NAME = "Basic Bundle";
- private static final String BASIC_DESCRIPTION =
- "If the thing that matters most to you is high speed Internet" +
- " connectivity delivered at a great price, then the basic" +
- " bundle is right for you.\n" +
- "Starting at $30 a month for 12 months.";
-
- private static final String FAMILY_ID = "family";
- private static final String FAMILY_DISPLAY_NAME = "Family Bundle";
- private static final String FAMILY_DESCRIPTION =
- "Enjoy great entertainment, peace of mind and big savings when " +
- "you bundle high speed Internet and Firewall with" +
- " Parental Control.\n" +
- "Starting at $40 a month for 12 months.";
-
-
- // no instantiation
- private BundleFactory() {}
-
- /**
- * Designates the BASIC bundle.
- */
- public static final BundleDescriptor BASIC_BUNDLE =
- new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME,
- BASIC_DESCRIPTION,
- XosFunctionDescriptor.INTERNET,
- XosFunctionDescriptor.FIREWALL,
- XosFunctionDescriptor.CDN);
-
- /**
- * Designates the FAMILY bundle.
- */
- public static final BundleDescriptor FAMILY_BUNDLE =
- new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME,
- FAMILY_DESCRIPTION,
- XosFunctionDescriptor.INTERNET,
- XosFunctionDescriptor.FIREWALL,
- XosFunctionDescriptor.CDN,
- XosFunctionDescriptor.URL_FILTER);
-
- // all bundles, in the order they should be listed in the GUI
- private static final List<BundleDescriptor> ALL_BUNDLES = ImmutableList.of(
- BASIC_BUNDLE,
- FAMILY_BUNDLE
- );
-
- /**
- * Returns the list of available bundles.
- *
- * @return available bundles
- */
- public static List<BundleDescriptor> availableBundles() {
- return ALL_BUNDLES;
- }
-
- /**
- * Returns the bundle descriptor for the given identifier.
- *
- * @param bundleId bundle identifier
- * @return bundle descriptor
- * @throws IllegalArgumentException if bundle ID is unknown
- */
- public static BundleDescriptor bundleFromId(String bundleId) {
- for (BundleDescriptor bd : ALL_BUNDLES) {
- if (bd.id().equals(bundleId)) {
- return bd;
- }
- }
- throw new IllegalArgumentException("unknown bundle: " + bundleId);
- }
-
- /**
- * Returns an object node representation of the given bundle.
- * Note that some functions (such as CDN) are not added to the output
- * as we don't want them to appear in the GUI.
- *
- * @param bundle the bundle
- * @return object node
- */
- public static ObjectNode toObjectNode(Bundle bundle) {
- ObjectNode root = objectNode();
- BundleDescriptor descriptor = bundle.descriptor();
-
- ObjectNode bnode = objectNode()
- .put(ID, descriptor.id())
- .put(NAME, descriptor.displayName())
- .put(DESC, descriptor.description());
-
- ArrayNode funcs = arrayNode();
- for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) {
- if (xfd.visible()) {
- funcs.add(XosFunctionFactory.toObjectNode(xfd));
- }
- }
- bnode.set(FUNCTIONS, funcs);
- root.set(BUNDLE, bnode);
-
- ArrayNode bundles = arrayNode();
- for (BundleDescriptor bd: BundleFactory.availableBundles()) {
- ObjectNode bdnode = objectNode()
- .put(ID, bd.id())
- .put(NAME, bd.displayName())
- .put(DESC, bd.description());
- bundles.add(bdnode);
- }
- root.set(BUNDLES, bundles);
- return root;
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java
deleted file mode 100644
index 1c3d4abc..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.Set;
-
-
-/**
- * Base implementation of BundleDescriptor.
- */
-public class DefaultBundleDescriptor implements BundleDescriptor {
-
- private final String id;
- private final String displayName;
- private final String description;
- private final Set<XosFunctionDescriptor> functions;
-
- /**
- * Constructs a bundle descriptor.
- *
- * @param id bundle identifier
- * @param displayName bundle display name
- * @param functions functions that make up this bundle
- */
- DefaultBundleDescriptor(String id, String displayName, String description,
- XosFunctionDescriptor... functions) {
- this.id = id;
- this.displayName = displayName;
- this.description = description;
- this.functions = ImmutableSet.copyOf(functions);
- }
-
-
- public String id() {
- return id;
- }
-
- public String displayName() {
- return displayName;
- }
-
- public String description() {
- return description;
- }
-
- public Set<XosFunctionDescriptor> functions() {
- return functions;
- }
-
- @Override
- public String toString() {
- return "{BundleDescriptor: " + displayName + "}";
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- DefaultBundleDescriptor that = (DefaultBundleDescriptor) o;
- return id.equals(that.id);
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java
deleted file mode 100644
index 1ffa8ef0..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * Default XOS function implementation, that does not have any parameters
- * to tweak.
- */
-public class DefaultXosFunction implements XosFunction {
-
- protected static final ObjectMapper MAPPER = new ObjectMapper();
-
- private final XosFunctionDescriptor xfd;
-
- public DefaultXosFunction(XosFunctionDescriptor xfd) {
- this.xfd = xfd;
- }
-
- public XosFunctionDescriptor descriptor() {
- return xfd;
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * This default implementation throws an exception.
- *
- * @param user user to apply the change to
- * @param param parameter name
- * @param value new parameter value
- * @throws UnsupportedOperationException if invoked
- */
- public void applyParam(SubscriberUser user, String param, String value) {
- throw new UnsupportedOperationException();
- }
-
- public Memento createMemento() {
- return null;
- }
-
- public String xosUrlApply(SubscriberUser user) {
- return null;
- }
-
- @Override
- public String toString() {
- return "{XosFunction: " + xfd + "}";
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java
deleted file mode 100644
index 3f295994..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Base class for factories that convert objects to JSON.
- */
-public abstract class JsonFactory {
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- protected static final String ID = "id";
- protected static final String NAME = "name";
- protected static final String DESC = "desc";
- protected static final String ICON_ID = "icon_id";
-
- /**
- * Returns a freshly minted object node.
- *
- * @return empty object node
- */
- protected static ObjectNode objectNode() {
- return MAPPER.createObjectNode();
- }
-
- /**
- * Returns a freshly minted array node.
- *
- * @return empty array node
- */
- protected static ArrayNode arrayNode() {
- return MAPPER.createArrayNode();
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java
deleted file mode 100644
index 81261821..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Designates a user of a subscriber's account.
- */
-public class SubscriberUser {
- private final int id;
- private final String name;
- private final String mac;
-
- // this is "duplicated" in the URL_FILTER memento, but, oh well...
- // -- the level, as returned from XOS, when we create this user object.
- private String level;
-
- private final Map<XosFunctionDescriptor, XosFunction.Memento> mementos =
- new HashMap<XosFunctionDescriptor, XosFunction.Memento>();
-
- /**
- * Constructs a subscriber user from the given parameters.
- *
- * @param id internal identifier
- * @param name display name
- * @param mac MAC address of the associated device
- * @param level URL filter level
- */
- public SubscriberUser(int id, String name, String mac, String level) {
- this.id = id;
- this.name = name;
- this.mac = mac;
- this.level = level;
- }
-
- /**
- * Returns the internal identifier.
- *
- * @return the identifier
- */
- public int id() {
- return id;
- }
-
- /**
- * Returns the display name.
- *
- * @return display name
- */
- public String name() {
- return name;
- }
-
- /**
- * Returns the MAC address of the associated device.
- *
- * @return MAC address
- */
- public String mac() {
- return mac;
- }
-
- /**
- * Returns the URL filter level.
- *
- * @return URL filter level
- */
- public String urlFilterLevel() {
- return level;
- }
-
- /**
- * Sets the URL filter level.
- *
- * @param level URL filter level
- */
- public void setUrlFilterLevel(String level) {
- this.level = level;
- }
-
- /**
- * Stores a memento for the given XOS function.
- *
- * @param f XOS function
- * @param m memento
- */
- public void setMemento(XosFunctionDescriptor f, XosFunction.Memento m) {
- if (m != null) {
- mementos.put(f, m);
- }
- }
-
- /**
- * Returns the memento stored on this user, for the given XOS function.
- *
- * @param f XOS function
- * @return memento
- */
- public XosFunction.Memento getMemento(XosFunctionDescriptor f) {
- return mementos.get(f);
- }
-
- /**
- * Clears the memento map.
- */
- public void clearMementos() {
- mementos.clear();
- }
-
- @Override
- public String toString() {
- return "{User: " + name + "}";
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java
deleted file mode 100644
index ec1ff380..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Specialization of XosFunction for URL filtering.
- */
-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
- * to least restrictive. Note: <em>NONE</em> allows nothing;
- * <em>ALL</em> allows everything.
- */
- public enum Level { NONE, G, PG, PG_13, R, ALL }
-
- /**
- * The default URL filtering level
- */
- public static final Level DEFAULT_LEVEL = Level.G;
-
- public UrlFilterFunction() {
- super(XosFunctionDescriptor.URL_FILTER);
- }
-
- @Override
- public void applyParam(SubscriberUser user, String param, String value) {
- Memento memo = user.getMemento(descriptor());
- checkNotNull(memo, "missing memento for " + descriptor());
- UrlFilterMemento ufMemo = (UrlFilterMemento) memo;
-
- if (LEVEL.equals(param)) {
- Level newLevel = Level.valueOf(value.toUpperCase());
- ufMemo.setLevel(newLevel);
-
- // Also store the (string version) of the level
- // (not in the memento). Hackish, but that's how it is for now.
- user.setUrlFilterLevel(value);
- }
- }
-
- @Override
- public Memento createMemento() {
- return new UrlFilterMemento();
- }
-
- class UrlFilterMemento implements Memento {
- private Level level = DEFAULT_LEVEL;
-
- public ObjectNode toObjectNode() {
- ObjectNode node = MAPPER.createObjectNode();
- node.put(LEVEL, level.name());
- return node;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public String level() {
- return level.toString();
- }
- }
-
- @Override
- public String xosUrlApply(SubscriberUser user) {
- XosFunctionDescriptor xfd = XosFunctionDescriptor.URL_FILTER;
- UrlFilterMemento memo = (UrlFilterMemento) user.getMemento(xfd);
- return String.format(URI_PATTERN, xfd.id(), memo.level());
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java
deleted file mode 100644
index c843af1b..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Utility functions on users.
- */
-public class UserFactory extends JsonFactory {
-
- private static final String MAC = "mac";
- private static final String PROFILE = "profile";
-
-
- // hard-coded icons for the demo
- private static final Map<String, String> ICON_LOOKUP =
- new HashMap<String, String>();
- static {
- ICON_LOOKUP.put("Mom's PC", "mom");
- ICON_LOOKUP.put("Dad's PC", "dad");
- ICON_LOOKUP.put("Jack's Laptop", "boy2");
- ICON_LOOKUP.put("Jill's Laptop", "girl1");
- }
-
- private static final String DEFAULT_ICON_ID = "boy1";
-
- // no instantiation
- private UserFactory() {}
-
- /**
- * Returns an object node representation of the given user.
- *
- * @param user the user
- * @return object node
- */
- public static ObjectNode toObjectNode(SubscriberUser user) {
- String icon = ICON_LOOKUP.get(user.name());
- icon = icon == null ? DEFAULT_ICON_ID : icon;
-
- ObjectNode root = objectNode()
- .put(ID, user.id())
- .put(ICON_ID, icon)
- .put(NAME, user.name())
- .put(MAC, user.mac());
- root.set(PROFILE, XosFunctionFactory.profileForUser(user));
- return root;
- }
-
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java
deleted file mode 100644
index 2790dfd5..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Designates a specific instance of an XOS function.
- */
-public interface XosFunction {
-
- /**
- * Returns the descriptor for this function.
- *
- * @return function descriptor
- */
- XosFunctionDescriptor descriptor();
-
- /**
- * Applies a parameter change for the given user.
- *
- * @param user user to apply change to
- * @param param parameter name
- * @param value new parameter value
- */
- void applyParam(SubscriberUser user, String param, String value);
-
- /**
- * Create an initialized memento.
- * If the function maintains no state per user, return null.
- *
- * @return a new memento
- */
- Memento createMemento();
-
- /**
- * Create the XOS specific URL suffix for applying state change for
- * the given user.
- *
- * @param user the user
- * @return URL suffix
- */
- String xosUrlApply(SubscriberUser user);
-
- /**
- * Internal state memento.
- */
- interface Memento {
- /**
- * Returns a JSON representation of this memento.
- *
- * @return memento state as object node
- */
- ObjectNode toObjectNode();
- }
-}
-
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java
deleted file mode 100644
index efc95377..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-/**
- * Designates XOS Functions.
- */
-public enum XosFunctionDescriptor {
- /**
- * Internet function.
- */
- INTERNET("internet",
- "Internet",
- "Discover the joys of high-speed, reliable Internet" +
- " connectivity delivered seamlessly to your home.",
- false,
- true),
-
- /**
- * Firewall function.
- */
- FIREWALL("firewall",
- "Firewall",
- "Simple access control and filtering with minimal set-up.",
- true,
- true),
-
- /**
- * URL Filtering function (parental controls).
- */
- URL_FILTER("url_filter",
- "Parental Control",
- "Parental Control is peace of mind that your kids are safe" +
- " - whether you are around or away. Indicate with a " +
- "few clicks what online content is appropriate for " +
- "your children, and voila - you have control over" +
- " what your kids can and cannot view.",
- true,
- true),
-
- /**
- * Content Distribution function.
- */
- CDN("cdn",
- "CDN",
- "Content Distribution Network service.",
- true,
- false);
-
-
- private final String id;
- private final String displayName;
- private final String description;
- private final boolean backend;
- private final boolean visible;
-
- XosFunctionDescriptor(String id, String displayName, String description,
- boolean backend, boolean visible) {
- this.id = id;
- this.displayName = displayName;
- this.description = description;
- this.backend = backend;
- this.visible = visible;
- }
-
- /**
- * Returns this function's internal identifier.
- *
- * @return the identifier
- */
- public String id() {
- return id;
- }
-
- /**
- * Returns this function's display name.
- *
- * @return display name
- */
- public String displayName() {
- return displayName;
- }
-
- /**
- * Returns a short, textual description of the function.
- *
- * @return textual description
- */
- public String description() {
- return description;
- }
-
- /**
- * Returns true if this function is supported by the XOS backend.
- *
- * @return true if backend function exists
- */
- public boolean backend() {
- return backend;
- }
-
- /**
- * Returns true if this function should be shown in the GUI, in the
- * bundle listing.
- *
- * @return true if to be displayed
- */
- public boolean visible() {
- return visible;
- }
-}
diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java
deleted file mode 100644
index dffabceb..00000000
--- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.onosproject.cord.gui.model.XosFunctionDescriptor.URL_FILTER;
-
-/**
- * Utility factory for operating on XOS functions.
- */
-public class XosFunctionFactory extends JsonFactory {
-
- private static final String PARAMS = "params";
- private static final String LEVEL = "level";
- private static final String LEVELS = "levels";
-
-
- // no instantiation
- private XosFunctionFactory() {}
-
- /**
- * Produces the JSON representation of the given XOS function descriptor.
- *
- * @param xfd function descriptor
- * @return JSON encoding
- */
- public static ObjectNode toObjectNode(XosFunctionDescriptor xfd) {
- ObjectNode root = objectNode()
- .put(ID, xfd.id())
- .put(NAME, xfd.displayName())
- .put(DESC, xfd.description());
- root.set(PARAMS, paramsForXfd(xfd));
- return root;
- }
-
- private static ObjectNode paramsForXfd(XosFunctionDescriptor xfd) {
- ParamsFactory psf = PARAM_MAP.get(xfd);
- if (psf == null) {
- psf = DEF_PARAMS_FACTORY;
- }
- return psf.params();
- }
-
-
- // ==== handling different parameter structures...
- private static final Map<XosFunctionDescriptor, ParamsFactory>
- PARAM_MAP = new HashMap<XosFunctionDescriptor, ParamsFactory>();
-
- private static final ParamsFactory DEF_PARAMS_FACTORY = new ParamsFactory();
- static {
- PARAM_MAP.put(URL_FILTER, new UrlFilterParamsFactory());
- }
-
- /**
- * Creates an object node representation of the profile for the
- * specified user.
- *
- * @param user the user
- * @return object node profile
- */
- public static ObjectNode profileForUser(SubscriberUser user) {
- ObjectNode root = objectNode();
- for (XosFunctionDescriptor xfd: XosFunctionDescriptor.values()) {
- XosFunction.Memento mem = user.getMemento(xfd);
- if (mem != null) {
- root.set(xfd.id(), mem.toObjectNode());
- }
- }
- return root;
- }
-
-
- // ===================================================================
- // === factories for creating parameter structures, both default
- // and from a memento...
-
- // private parameter structure creator
- static class ParamsFactory {
- ObjectNode params() {
- return objectNode();
- }
- }
-
- static class UrlFilterParamsFactory extends ParamsFactory {
- @Override
- ObjectNode params() {
- ObjectNode result = objectNode();
- result.put(LEVEL, UrlFilterFunction.DEFAULT_LEVEL.name());
- ArrayNode levels = arrayNode();
- for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) {
- levels.add(lvl.name());
- }
- result.set(LEVELS, levels);
- return result;
- }
- }
-}