mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-21 20:31:00 +02:00
CORD Subscriber GUI - Plumbed through to XosManager - almost ready to wire up to RestClient code.
Change-Id: I3fc2aac924934489172abe67688e7166278c68ac
This commit is contained in:
parent
bdd6b3be6b
commit
a00b0ceca8
@ -109,7 +109,7 @@ public class CordModelCache extends JsonFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tell XOS which functions are enabled / disabled
|
XosManager.INSTANCE.setNewBundle(SUBSCRIBER_ID, currentBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +144,7 @@ public class CordModelCache extends JsonFactory {
|
|||||||
checkNotNull(func, "function not part of bundle: " + funcId);
|
checkNotNull(func, "function not part of bundle: " + funcId);
|
||||||
|
|
||||||
func.applyParam(user, param, value);
|
func.applyParam(user, param, value);
|
||||||
|
XosManager.INSTANCE.apply(SUBSCRIBER_ID, func, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============
|
// =============
|
||||||
|
@ -17,9 +17,89 @@
|
|||||||
|
|
||||||
package org.onosproject.cord.gui;
|
package org.onosproject.cord.gui;
|
||||||
|
|
||||||
|
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 java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulation of interactions with XOS.
|
* Encapsulation of interactions with XOS.
|
||||||
*/
|
*/
|
||||||
public class XosManager {
|
public class XosManager {
|
||||||
|
|
||||||
|
private static final String XOS_HOST = "10.254.1.22";
|
||||||
|
private static final String XOS_PORT = "8000";
|
||||||
|
|
||||||
|
private static final String URL_FMT = "http://%s:%s/xoslib/rs/subscriber/";
|
||||||
|
|
||||||
|
private static final String BASE_URL =
|
||||||
|
String.format(URL_FMT, XOS_HOST, XOS_PORT);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No instantiation (except via unit test).
|
||||||
|
*/
|
||||||
|
XosManager() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure XOS to enable the functions that compose the given bundle,
|
||||||
|
* and disable all the others, for the given subscriber.
|
||||||
|
*
|
||||||
|
* @param subscriberId subscriber identifier
|
||||||
|
* @param bundle new bundle to set
|
||||||
|
*/
|
||||||
|
public void setNewBundle(int subscriberId, Bundle bundle) {
|
||||||
|
System.out.println("\n>> Set New Bundle : " + bundle.descriptor().id());
|
||||||
|
|
||||||
|
String urlFmt = xosUrl(subscriberId) + "services/%s/%s";
|
||||||
|
Set<XosFunctionDescriptor> inBundle = bundle.descriptor().functions();
|
||||||
|
for (XosFunctionDescriptor xfd: XosFunctionDescriptor.values()) {
|
||||||
|
xosEnableFunction(urlFmt, xfd, inBundle.contains(xfd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure XOS with new setting for given user and function, for the
|
||||||
|
* given subscriber account.
|
||||||
|
*
|
||||||
|
* @param subscriberId subscriber identifier
|
||||||
|
* @param func specific XOS function
|
||||||
|
* @param user user (containing function state)
|
||||||
|
*/
|
||||||
|
public void apply(int subscriberId, XosFunction func, SubscriberUser user) {
|
||||||
|
System.out.println("\n>> Apply : " + func + " for " + user);
|
||||||
|
|
||||||
|
String urlPrefix = xosUrl(subscriberId) + "users/" + user.id() + "/";
|
||||||
|
String url = urlPrefix + func.xosUrlApply(user);
|
||||||
|
restPut(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
|
private String xosUrl(int subscriberId) {
|
||||||
|
return BASE_URL + String.format("%d/", subscriberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void xosEnableFunction(String urlFmt, XosFunctionDescriptor xfd,
|
||||||
|
boolean enable) {
|
||||||
|
String url = String.format(urlFmt, xfd.id(), enable);
|
||||||
|
restPut(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
|
private void restPut(String url) {
|
||||||
|
// TODO: wire up to Jackson client...
|
||||||
|
System.out.println("<<PUT>> " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton instance.
|
||||||
|
*/
|
||||||
|
public static final XosManager INSTANCE = new XosManager();
|
||||||
}
|
}
|
||||||
|
@ -55,4 +55,12 @@ public class DefaultXosFunction implements XosFunction {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String xosUrlApply(SubscriberUser user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{XosFunction: " + xfd + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,4 +99,9 @@ public class SubscriberUser {
|
|||||||
public void clearMementos() {
|
public void clearMementos() {
|
||||||
mementos.clear();
|
mementos.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{User: " + name + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,5 +71,16 @@ public class UrlFilterFunction extends DefaultXosFunction {
|
|||||||
public void setLevel(Level level) {
|
public void setLevel(Level level) {
|
||||||
this.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 xfd.id() + "/" + memo.level();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,15 @@ public interface XosFunction {
|
|||||||
*/
|
*/
|
||||||
Memento createMemento();
|
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.
|
* Internal state memento.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user