Committed by
Gerrit Code Review
CORD Subscriber GUI - Plumbed through to XosManager - almost ready to wire up to RestClient code.
Change-Id: I3fc2aac924934489172abe67688e7166278c68ac
Showing
6 changed files
with
115 additions
and
1 deletions
| ... | @@ -109,7 +109,7 @@ public class CordModelCache extends JsonFactory { | ... | @@ -109,7 +109,7 @@ public class CordModelCache extends JsonFactory { |
| 109 | } | 109 | } |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | - // TODO: tell XOS which functions are enabled / disabled | 112 | + XosManager.INSTANCE.setNewBundle(SUBSCRIBER_ID, currentBundle); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | 115 | ||
| ... | @@ -144,6 +144,7 @@ public class CordModelCache extends JsonFactory { | ... | @@ -144,6 +144,7 @@ public class CordModelCache extends JsonFactory { |
| 144 | checkNotNull(func, "function not part of bundle: " + funcId); | 144 | checkNotNull(func, "function not part of bundle: " + funcId); |
| 145 | 145 | ||
| 146 | func.applyParam(user, param, value); | 146 | func.applyParam(user, param, value); |
| 147 | + XosManager.INSTANCE.apply(SUBSCRIBER_ID, func, user); | ||
| 147 | } | 148 | } |
| 148 | 149 | ||
| 149 | // ============= | 150 | // ============= | ... | ... |
| ... | @@ -17,9 +17,89 @@ | ... | @@ -17,9 +17,89 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.cord.gui; | 18 | package org.onosproject.cord.gui; |
| 19 | 19 | ||
| 20 | +import org.onosproject.cord.gui.model.Bundle; | ||
| 21 | +import org.onosproject.cord.gui.model.SubscriberUser; | ||
| 22 | +import org.onosproject.cord.gui.model.XosFunction; | ||
| 23 | +import org.onosproject.cord.gui.model.XosFunctionDescriptor; | ||
| 24 | + | ||
| 25 | +import java.util.Set; | ||
| 26 | + | ||
| 20 | /** | 27 | /** |
| 21 | * Encapsulation of interactions with XOS. | 28 | * Encapsulation of interactions with XOS. |
| 22 | */ | 29 | */ |
| 23 | public class XosManager { | 30 | public class XosManager { |
| 24 | 31 | ||
| 32 | + private static final String XOS_HOST = "10.254.1.22"; | ||
| 33 | + private static final String XOS_PORT = "8000"; | ||
| 34 | + | ||
| 35 | + private static final String URL_FMT = "http://%s:%s/xoslib/rs/subscriber/"; | ||
| 36 | + | ||
| 37 | + private static final String BASE_URL = | ||
| 38 | + String.format(URL_FMT, XOS_HOST, XOS_PORT); | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * No instantiation (except via unit test). | ||
| 43 | + */ | ||
| 44 | + XosManager() {} | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Configure XOS to enable the functions that compose the given bundle, | ||
| 48 | + * and disable all the others, for the given subscriber. | ||
| 49 | + * | ||
| 50 | + * @param subscriberId subscriber identifier | ||
| 51 | + * @param bundle new bundle to set | ||
| 52 | + */ | ||
| 53 | + public void setNewBundle(int subscriberId, Bundle bundle) { | ||
| 54 | + System.out.println("\n>> Set New Bundle : " + bundle.descriptor().id()); | ||
| 55 | + | ||
| 56 | + String urlFmt = xosUrl(subscriberId) + "services/%s/%s"; | ||
| 57 | + Set<XosFunctionDescriptor> inBundle = bundle.descriptor().functions(); | ||
| 58 | + for (XosFunctionDescriptor xfd: XosFunctionDescriptor.values()) { | ||
| 59 | + xosEnableFunction(urlFmt, xfd, inBundle.contains(xfd)); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Configure XOS with new setting for given user and function, for the | ||
| 65 | + * given subscriber account. | ||
| 66 | + * | ||
| 67 | + * @param subscriberId subscriber identifier | ||
| 68 | + * @param func specific XOS function | ||
| 69 | + * @param user user (containing function state) | ||
| 70 | + */ | ||
| 71 | + public void apply(int subscriberId, XosFunction func, SubscriberUser user) { | ||
| 72 | + System.out.println("\n>> Apply : " + func + " for " + user); | ||
| 73 | + | ||
| 74 | + String urlPrefix = xosUrl(subscriberId) + "users/" + user.id() + "/"; | ||
| 75 | + String url = urlPrefix + func.xosUrlApply(user); | ||
| 76 | + restPut(url); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 81 | + | ||
| 82 | + private String xosUrl(int subscriberId) { | ||
| 83 | + return BASE_URL + String.format("%d/", subscriberId); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + private void xosEnableFunction(String urlFmt, XosFunctionDescriptor xfd, | ||
| 87 | + boolean enable) { | ||
| 88 | + String url = String.format(urlFmt, xfd.id(), enable); | ||
| 89 | + restPut(url); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 93 | + | ||
| 94 | + private void restPut(String url) { | ||
| 95 | + // TODO: wire up to Jackson client... | ||
| 96 | + System.out.println("<<PUT>> " + url); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Singleton instance. | ||
| 103 | + */ | ||
| 104 | + public static final XosManager INSTANCE = new XosManager(); | ||
| 25 | } | 105 | } | ... | ... |
| ... | @@ -55,4 +55,12 @@ public class DefaultXosFunction implements XosFunction { | ... | @@ -55,4 +55,12 @@ public class DefaultXosFunction implements XosFunction { |
| 55 | return null; | 55 | return null; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | + public String xosUrlApply(SubscriberUser user) { | ||
| 59 | + return null; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public String toString() { | ||
| 64 | + return "{XosFunction: " + xfd + "}"; | ||
| 65 | + } | ||
| 58 | } | 66 | } | ... | ... |
| ... | @@ -99,4 +99,9 @@ public class SubscriberUser { | ... | @@ -99,4 +99,9 @@ public class SubscriberUser { |
| 99 | public void clearMementos() { | 99 | public void clearMementos() { |
| 100 | mementos.clear(); | 100 | mementos.clear(); |
| 101 | } | 101 | } |
| 102 | + | ||
| 103 | + @Override | ||
| 104 | + public String toString() { | ||
| 105 | + return "{User: " + name + "}"; | ||
| 106 | + } | ||
| 102 | } | 107 | } | ... | ... |
| ... | @@ -71,5 +71,16 @@ public class UrlFilterFunction extends DefaultXosFunction { | ... | @@ -71,5 +71,16 @@ public class UrlFilterFunction extends DefaultXosFunction { |
| 71 | public void setLevel(Level level) { | 71 | public void setLevel(Level level) { |
| 72 | this.level = level; | 72 | this.level = level; |
| 73 | } | 73 | } |
| 74 | + | ||
| 75 | + public String level() { | ||
| 76 | + return level.toString(); | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public String xosUrlApply(SubscriberUser user) { | ||
| 82 | + XosFunctionDescriptor xfd = XosFunctionDescriptor.URL_FILTER; | ||
| 83 | + UrlFilterMemento memo = (UrlFilterMemento) user.getMemento(xfd); | ||
| 84 | + return xfd.id() + "/" + memo.level(); | ||
| 74 | } | 85 | } |
| 75 | } | 86 | } | ... | ... |
| ... | @@ -50,6 +50,15 @@ public interface XosFunction { | ... | @@ -50,6 +50,15 @@ public interface XosFunction { |
| 50 | Memento createMemento(); | 50 | Memento createMemento(); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | + * Create the XOS specific URL suffix for applying state change for | ||
| 54 | + * the given user. | ||
| 55 | + * | ||
| 56 | + * @param user the user | ||
| 57 | + * @return URL suffix | ||
| 58 | + */ | ||
| 59 | + String xosUrlApply(SubscriberUser user); | ||
| 60 | + | ||
| 61 | + /** | ||
| 53 | * Internal state memento. | 62 | * Internal state memento. |
| 54 | */ | 63 | */ |
| 55 | interface Memento { | 64 | interface Memento { | ... | ... |
-
Please register or login to post a comment