GUI -- Huge Refactoring of server-side message handlers (Part Two).
--- Well, it compiles, and seems to work, with the cursory testing I've done... Change-Id: I0e59657c134e109850e4770766083370dfd9fdc2
Showing
17 changed files
with
1161 additions
and
639 deletions
... | @@ -27,10 +27,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -27,10 +27,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
27 | import org.apache.felix.scr.annotations.Service; | 27 | import org.apache.felix.scr.annotations.Service; |
28 | import org.onlab.osgi.ServiceDirectory; | 28 | import org.onlab.osgi.ServiceDirectory; |
29 | import org.onosproject.intentperf.IntentPerfCollector.Sample; | 29 | import org.onosproject.intentperf.IntentPerfCollector.Sample; |
30 | +import org.onosproject.ui.RequestHandler; | ||
30 | import org.onosproject.ui.UiConnection; | 31 | import org.onosproject.ui.UiConnection; |
31 | import org.onosproject.ui.UiExtension; | 32 | import org.onosproject.ui.UiExtension; |
32 | import org.onosproject.ui.UiExtensionService; | 33 | import org.onosproject.ui.UiExtensionService; |
33 | -import org.onosproject.ui.UiMessageHandler; | 34 | +import org.onosproject.ui.UiMessageHandlerTwo; |
34 | import org.onosproject.ui.UiView; | 35 | import org.onosproject.ui.UiView; |
35 | 36 | ||
36 | import java.util.Collection; | 37 | import java.util.Collection; |
... | @@ -48,14 +49,20 @@ import static org.onosproject.ui.UiView.Category.OTHER; | ... | @@ -48,14 +49,20 @@ import static org.onosproject.ui.UiView.Category.OTHER; |
48 | @Service(value = IntentPerfUi.class) | 49 | @Service(value = IntentPerfUi.class) |
49 | public class IntentPerfUi { | 50 | public class IntentPerfUi { |
50 | 51 | ||
52 | + private static final String INTENT_PERF_START = "intentPerfStart"; | ||
53 | + private static final String INTENT_PERF_STOP = "intentPerfStop"; | ||
54 | + | ||
51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
52 | protected UiExtensionService uiExtensionService; | 56 | protected UiExtensionService uiExtensionService; |
53 | 57 | ||
54 | private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>()); | 58 | private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>()); |
55 | 59 | ||
56 | - private List<UiView> views = ImmutableList.of(new UiView(OTHER, "intentPerf", "Intent Performance")); | 60 | + private List<UiView> views = ImmutableList.of( |
57 | - private UiExtension uiExtension = new UiExtension(views, this::newHandlers, | 61 | + new UiView(OTHER, "intentPerf", "Intent Performance") |
58 | - getClass().getClassLoader()); | 62 | + ); |
63 | + | ||
64 | + private UiExtension uiExtension = | ||
65 | + new UiExtension(views, this::newHandlers, getClass().getClassLoader()); | ||
59 | 66 | ||
60 | private IntentPerfCollector collector; | 67 | private IntentPerfCollector collector; |
61 | 68 | ||
... | @@ -90,25 +97,22 @@ public class IntentPerfUi { | ... | @@ -90,25 +97,22 @@ public class IntentPerfUi { |
90 | } | 97 | } |
91 | 98 | ||
92 | // Creates and returns session specific message handler. | 99 | // Creates and returns session specific message handler. |
93 | - private Collection<UiMessageHandler> newHandlers() { | 100 | + private Collection<UiMessageHandlerTwo> newHandlers() { |
94 | return ImmutableList.of(new StreamingControl()); | 101 | return ImmutableList.of(new StreamingControl()); |
95 | } | 102 | } |
96 | 103 | ||
104 | + | ||
97 | // UI Message handlers for turning on/off reporting to a session. | 105 | // UI Message handlers for turning on/off reporting to a session. |
98 | - private class StreamingControl extends UiMessageHandler { | 106 | + private class StreamingControl extends UiMessageHandlerTwo { |
99 | 107 | ||
100 | private boolean streamingEnabled = false; | 108 | private boolean streamingEnabled = false; |
101 | 109 | ||
102 | - protected StreamingControl() { | ||
103 | - super(ImmutableSet.of("intentPerfStart", "intentPerfStop")); | ||
104 | - } | ||
105 | - | ||
106 | @Override | 110 | @Override |
107 | - public void process(ObjectNode message) { | 111 | + protected Collection<RequestHandler> getHandlers() { |
108 | - streamingEnabled = message.path("event").asText("unknown").equals("intentPerfStart"); | 112 | + return ImmutableSet.of( |
109 | - if (streamingEnabled) { | 113 | + new IntentPerfStart(), |
110 | - sendInitData(); | 114 | + new IntentPerfStop() |
111 | - } | 115 | + ); |
112 | } | 116 | } |
113 | 117 | ||
114 | @Override | 118 | @Override |
... | @@ -129,17 +133,6 @@ public class IntentPerfUi { | ... | @@ -129,17 +133,6 @@ public class IntentPerfUi { |
129 | } | 133 | } |
130 | } | 134 | } |
131 | 135 | ||
132 | - private void sendInitData() { | ||
133 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
134 | - ArrayNode an = mapper.createArrayNode(); | ||
135 | - ArrayNode sn = mapper.createArrayNode(); | ||
136 | - rootNode.set("headers", an); | ||
137 | - rootNode.set("samples", sn); | ||
138 | - | ||
139 | - collector.getSampleHeaders().forEach(an::add); | ||
140 | - collector.getSamples().forEach(s -> sn.add(sampleNode(s))); | ||
141 | - connection().sendMessage("intentPerfInit", 0, rootNode); | ||
142 | - } | ||
143 | 136 | ||
144 | private ObjectNode sampleNode(Sample sample) { | 137 | private ObjectNode sampleNode(Sample sample) { |
145 | ObjectNode sampleNode = mapper.createObjectNode(); | 138 | ObjectNode sampleNode = mapper.createObjectNode(); |
... | @@ -153,6 +146,47 @@ public class IntentPerfUi { | ... | @@ -153,6 +146,47 @@ public class IntentPerfUi { |
153 | return sampleNode; | 146 | return sampleNode; |
154 | } | 147 | } |
155 | 148 | ||
149 | + // ====================================================================== | ||
150 | + | ||
151 | + private final class IntentPerfStart extends RequestHandler { | ||
152 | + | ||
153 | + private IntentPerfStart() { | ||
154 | + super(INTENT_PERF_START); | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public void process(long sid, ObjectNode payload) { | ||
159 | + streamingEnabled = true; | ||
160 | + sendInitData(); | ||
161 | + } | ||
162 | + | ||
163 | + private void sendInitData() { | ||
164 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
165 | + ArrayNode an = MAPPER.createArrayNode(); | ||
166 | + ArrayNode sn = MAPPER.createArrayNode(); | ||
167 | + rootNode.set("headers", an); | ||
168 | + rootNode.set("samples", sn); | ||
169 | + | ||
170 | + collector.getSampleHeaders().forEach(an::add); | ||
171 | + collector.getSamples().forEach(s -> sn.add(sampleNode(s))); | ||
172 | + sendMessage("intentPerfInit", 0, rootNode); | ||
173 | + } | ||
174 | + } | ||
175 | + | ||
176 | + // ====================================================================== | ||
177 | + | ||
178 | + private final class IntentPerfStop extends RequestHandler { | ||
179 | + | ||
180 | + private IntentPerfStop() { | ||
181 | + super(INTENT_PERF_STOP); | ||
182 | + } | ||
183 | + | ||
184 | + @Override | ||
185 | + public void process(long sid, ObjectNode payload) { | ||
186 | + streamingEnabled = false; | ||
187 | + } | ||
188 | + } | ||
189 | + | ||
156 | } | 190 | } |
157 | 191 | ||
158 | } | 192 | } | ... | ... |
... | @@ -61,6 +61,17 @@ public final class JsonUtils { | ... | @@ -61,6 +61,17 @@ public final class JsonUtils { |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
64 | + * Returns the sequence identifier from the specified event, or 0 (zero) | ||
65 | + * if the "sid" property does not exist. | ||
66 | + * | ||
67 | + * @param event message event | ||
68 | + * @return extracted sequence identifier | ||
69 | + */ | ||
70 | + public static long sid(ObjectNode event) { | ||
71 | + return number(event, "sid"); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
64 | * Returns the payload from the specified event. | 75 | * Returns the payload from the specified event. |
65 | * | 76 | * |
66 | * @param event message event | 77 | * @param event message event |
... | @@ -95,7 +106,7 @@ public final class JsonUtils { | ... | @@ -95,7 +106,7 @@ public final class JsonUtils { |
95 | /** | 106 | /** |
96 | * Returns the specified node property as a string, with a default fallback. | 107 | * Returns the specified node property as a string, with a default fallback. |
97 | * | 108 | * |
98 | - * @param node message event | 109 | + * @param node object node |
99 | * @param name property name | 110 | * @param name property name |
100 | * @param defaultValue fallback value if property is absent | 111 | * @param defaultValue fallback value if property is absent |
101 | * @return property as a string | 112 | * @return property as a string |
... | @@ -104,4 +115,15 @@ public final class JsonUtils { | ... | @@ -104,4 +115,15 @@ public final class JsonUtils { |
104 | return node.path(name).asText(defaultValue); | 115 | return node.path(name).asText(defaultValue); |
105 | } | 116 | } |
106 | 117 | ||
118 | + /** | ||
119 | + * Returns the specified node property as an object node. | ||
120 | + * | ||
121 | + * @param node object node | ||
122 | + * @param name property name | ||
123 | + * @return property as a node | ||
124 | + */ | ||
125 | + public static ObjectNode node(ObjectNode node, String name) { | ||
126 | + return (ObjectNode) node.path(name); | ||
127 | + } | ||
128 | + | ||
107 | } | 129 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.ui; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of an entity that handles a specific request from the | ||
23 | + * user interface client. | ||
24 | + * | ||
25 | + * @see UiMessageHandlerTwo | ||
26 | + */ | ||
27 | +public abstract class RequestHandler { | ||
28 | + | ||
29 | + protected static final ObjectMapper MAPPER = new ObjectMapper(); | ||
30 | + | ||
31 | + private final String eventType; | ||
32 | + private UiMessageHandlerTwo parent; | ||
33 | + | ||
34 | + | ||
35 | + public RequestHandler(String eventType) { | ||
36 | + this.eventType = eventType; | ||
37 | + } | ||
38 | + | ||
39 | + // package private | ||
40 | + void setParent(UiMessageHandlerTwo parent) { | ||
41 | + this.parent = parent; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the event type that this handler handles. | ||
46 | + * | ||
47 | + * @return event type | ||
48 | + */ | ||
49 | + public String eventType() { | ||
50 | + return eventType; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Processes the incoming message payload from the client. | ||
55 | + * | ||
56 | + * @param sid message sequence identifier | ||
57 | + * @param payload request message payload | ||
58 | + */ | ||
59 | + public abstract void process(long sid, ObjectNode payload); | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + // =================================================================== | ||
64 | + // === Convenience methods... | ||
65 | + | ||
66 | + /** | ||
67 | + * Returns implementation of the specified service class. | ||
68 | + * | ||
69 | + * @param serviceClass service class | ||
70 | + * @param <T> type of service | ||
71 | + * @return implementation class | ||
72 | + * @throws org.onlab.osgi.ServiceNotFoundException if no implementation found | ||
73 | + */ | ||
74 | + protected <T> T get(Class<T> serviceClass) { | ||
75 | + return parent.directory().get(serviceClass); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Sends a message back to the client. | ||
80 | + * | ||
81 | + * @param eventType message event type | ||
82 | + * @param sid message sequence identifier | ||
83 | + * @param payload message payload | ||
84 | + */ | ||
85 | + protected void sendMessage(String eventType, long sid, ObjectNode payload) { | ||
86 | + parent.connection().sendMessage(eventType, sid, payload); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Sends a message back to the client. | ||
91 | + * Here, the message is preformatted; the assumption is it has its | ||
92 | + * eventType, sid and payload attributes already filled in. | ||
93 | + * | ||
94 | + * @param message the message to send | ||
95 | + */ | ||
96 | + protected void sendMessage(ObjectNode message) { | ||
97 | + parent.connection().sendMessage(message); | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Allows one request handler to pass the event on to another for | ||
102 | + * further processing. | ||
103 | + * Note that the message handlers must be defined in the same parent. | ||
104 | + * | ||
105 | + * @param eventType event type | ||
106 | + * @param sid sequence identifier | ||
107 | + * @param payload message payload | ||
108 | + */ | ||
109 | + protected void chain(String eventType, long sid, ObjectNode payload) { | ||
110 | + parent.exec(eventType, sid, payload); | ||
111 | + } | ||
112 | + | ||
113 | + // =================================================================== | ||
114 | + | ||
115 | + | ||
116 | + // FIXME : Javadocs | ||
117 | + protected String string(ObjectNode node, String key) { | ||
118 | + return JsonUtils.string(node, key); | ||
119 | + } | ||
120 | + | ||
121 | + protected String string(ObjectNode node, String key, String defValue) { | ||
122 | + return JsonUtils.string(node, key, defValue); | ||
123 | + } | ||
124 | + | ||
125 | +} |
... | @@ -40,6 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -40,6 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
40 | * } | 40 | * } |
41 | * </pre> | 41 | * </pre> |
42 | */ | 42 | */ |
43 | +@Deprecated | ||
43 | public abstract class UiMessageHandler { | 44 | public abstract class UiMessageHandler { |
44 | 45 | ||
45 | private final Set<String> messageTypes; | 46 | private final Set<String> messageTypes; | ... | ... |
... | @@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory { | ... | @@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory { |
28 | * | 28 | * |
29 | * @return collection of new handlers | 29 | * @return collection of new handlers |
30 | */ | 30 | */ |
31 | - Collection<UiMessageHandler> newHandlers(); | 31 | + Collection<UiMessageHandlerTwo> newHandlers(); |
32 | 32 | ||
33 | } | 33 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.ui; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | +import org.onlab.osgi.ServiceDirectory; | ||
21 | + | ||
22 | +import java.util.Collection; | ||
23 | +import java.util.Collections; | ||
24 | +import java.util.HashMap; | ||
25 | +import java.util.Map; | ||
26 | +import java.util.Set; | ||
27 | + | ||
28 | +import static com.google.common.base.Preconditions.checkArgument; | ||
29 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | + | ||
31 | +/** | ||
32 | + * Abstraction of an entity capable of processing a JSON message from the user | ||
33 | + * interface client. | ||
34 | + * <p> | ||
35 | + * The message is a JSON object with the following structure: | ||
36 | + * </p> | ||
37 | + * <pre> | ||
38 | + * { | ||
39 | + * "type": "<em>event-type</em>", | ||
40 | + * "sid": "<em>sequence-number</em>", | ||
41 | + * "payload": { | ||
42 | + * <em>arbitrary JSON object structure</em> | ||
43 | + * } | ||
44 | + * } | ||
45 | + * </pre> | ||
46 | + */ | ||
47 | +public abstract class UiMessageHandlerTwo { | ||
48 | + | ||
49 | + private final Map<String, RequestHandler> handlerMap = new HashMap<>(); | ||
50 | + | ||
51 | + private UiConnection connection; | ||
52 | + private ServiceDirectory directory; | ||
53 | + | ||
54 | + /** | ||
55 | + * Mapper for creating ObjectNodes and ArrayNodes etc. | ||
56 | + */ | ||
57 | + protected final ObjectMapper mapper = new ObjectMapper(); | ||
58 | + | ||
59 | + /** | ||
60 | + * Binds the handlers returned from {@link #getHandlers()} to this | ||
61 | + * instance. | ||
62 | + */ | ||
63 | + void bindHandlers() { | ||
64 | + Collection<RequestHandler> handlers = getHandlers(); | ||
65 | + checkNotNull(handlers, "Handlers cannot be null"); | ||
66 | + checkArgument(!handlers.isEmpty(), "Handlers cannot be empty"); | ||
67 | + | ||
68 | + for (RequestHandler h : handlers) { | ||
69 | + h.setParent(this); | ||
70 | + handlerMap.put(h.eventType(), h); | ||
71 | + } | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Subclasses must return the collection of handlers for the | ||
76 | + * message types they handle. | ||
77 | + * | ||
78 | + * @return the message handler instances | ||
79 | + */ | ||
80 | + protected abstract Collection<RequestHandler> getHandlers(); | ||
81 | + | ||
82 | + /** | ||
83 | + * Returns the set of message types which this handler is capable of | ||
84 | + * processing. | ||
85 | + * | ||
86 | + * @return set of message types | ||
87 | + */ | ||
88 | + public Set<String> messageTypes() { | ||
89 | + return Collections.unmodifiableSet(handlerMap.keySet()); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Processes a JSON message from the user interface client. | ||
94 | + * | ||
95 | + * @param message JSON message | ||
96 | + */ | ||
97 | + public void process(ObjectNode message) { | ||
98 | + String type = JsonUtils.eventType(message); | ||
99 | + long sid = JsonUtils.sid(message); | ||
100 | + ObjectNode payload = JsonUtils.payload(message); | ||
101 | + exec(type, sid, payload); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Finds the appropriate handler and executes the process method. | ||
106 | + * | ||
107 | + * @param eventType event type | ||
108 | + * @param sid sequence identifier | ||
109 | + * @param payload message payload | ||
110 | + */ | ||
111 | + void exec(String eventType, long sid, ObjectNode payload) { | ||
112 | + RequestHandler handler = handlerMap.get(eventType); | ||
113 | + if (handler != null) { | ||
114 | + handler.process(sid, payload); | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Initializes the handler with the user interface connection and | ||
120 | + * service directory context. | ||
121 | + * | ||
122 | + * @param connection user interface connection | ||
123 | + * @param directory service directory | ||
124 | + */ | ||
125 | + public void init(UiConnection connection, ServiceDirectory directory) { | ||
126 | + this.connection = connection; | ||
127 | + this.directory = directory; | ||
128 | + bindHandlers(); | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Destroys the message handler context. | ||
133 | + */ | ||
134 | + public void destroy() { | ||
135 | + this.connection = null; | ||
136 | + this.directory = null; | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Returns the user interface connection with which this handler was primed. | ||
141 | + * | ||
142 | + * @return user interface connection | ||
143 | + */ | ||
144 | + public UiConnection connection() { | ||
145 | + return connection; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Returns the user interface connection with which this handler was primed. | ||
150 | + * | ||
151 | + * @return user interface connection | ||
152 | + */ | ||
153 | + public ServiceDirectory directory() { | ||
154 | + return directory; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Returns implementation of the specified service class. | ||
159 | + * | ||
160 | + * @param serviceClass service class | ||
161 | + * @param <T> type of service | ||
162 | + * @return implementation class | ||
163 | + * @throws org.onlab.osgi.ServiceNotFoundException if no implementation found | ||
164 | + */ | ||
165 | + protected <T> T get(Class<T> serviceClass) { | ||
166 | + return directory.get(serviceClass); | ||
167 | + } | ||
168 | + | ||
169 | +} |
... | @@ -73,4 +73,19 @@ public abstract class AbstractTableRow implements TableRow { | ... | @@ -73,4 +73,19 @@ public abstract class AbstractTableRow implements TableRow { |
73 | protected void add(String id, Object value) { | 73 | protected void add(String id, Object value) { |
74 | cells.put(id, value.toString()); | 74 | cells.put(id, value.toString()); |
75 | } | 75 | } |
76 | + | ||
77 | + /** | ||
78 | + * Concatenates an arbitrary number of objects, using their | ||
79 | + * toString() methods. | ||
80 | + * | ||
81 | + * @param items the items to concatenate | ||
82 | + * @return a concatenated string | ||
83 | + */ | ||
84 | + protected static String concat(Object... items) { | ||
85 | + StringBuilder sb = new StringBuilder(); | ||
86 | + for (Object o : items) { | ||
87 | + sb.append(o); | ||
88 | + } | ||
89 | + return sb.toString(); | ||
90 | + } | ||
76 | } | 91 | } | ... | ... |
... | @@ -22,13 +22,15 @@ import org.onosproject.app.ApplicationService; | ... | @@ -22,13 +22,15 @@ import org.onosproject.app.ApplicationService; |
22 | import org.onosproject.app.ApplicationState; | 22 | import org.onosproject.app.ApplicationState; |
23 | import org.onosproject.core.Application; | 23 | import org.onosproject.core.Application; |
24 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
25 | -import org.onosproject.ui.UiMessageHandler; | 25 | +import org.onosproject.ui.RequestHandler; |
26 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
26 | import org.onosproject.ui.table.AbstractTableRow; | 27 | import org.onosproject.ui.table.AbstractTableRow; |
27 | import org.onosproject.ui.table.RowComparator; | 28 | import org.onosproject.ui.table.RowComparator; |
28 | import org.onosproject.ui.table.TableRow; | 29 | import org.onosproject.ui.table.TableRow; |
29 | import org.onosproject.ui.table.TableUtils; | 30 | import org.onosproject.ui.table.TableUtils; |
30 | 31 | ||
31 | import java.util.Arrays; | 32 | import java.util.Arrays; |
33 | +import java.util.Collection; | ||
32 | import java.util.List; | 34 | import java.util.List; |
33 | import java.util.stream.Collectors; | 35 | import java.util.stream.Collectors; |
34 | 36 | ||
... | @@ -37,62 +39,74 @@ import static org.onosproject.app.ApplicationState.ACTIVE; | ... | @@ -37,62 +39,74 @@ import static org.onosproject.app.ApplicationState.ACTIVE; |
37 | /** | 39 | /** |
38 | * Message handler for application view related messages. | 40 | * Message handler for application view related messages. |
39 | */ | 41 | */ |
40 | -public class ApplicationViewMessageHandler extends UiMessageHandler { | 42 | +public class ApplicationViewMessageHandler extends UiMessageHandlerTwo { |
41 | 43 | ||
42 | - /** | 44 | + private static final String APP_DATA_REQ = "appDataRequest"; |
43 | - * Creates a new message handler for the application messages. | 45 | + private static final String APP_MGMT_REQ = "appManagementRequest"; |
44 | - */ | ||
45 | - protected ApplicationViewMessageHandler() { | ||
46 | - super(ImmutableSet.of("appDataRequest", "appManagementRequest")); | ||
47 | - } | ||
48 | 46 | ||
49 | @Override | 47 | @Override |
50 | - public void process(ObjectNode message) { | 48 | + protected Collection<RequestHandler> getHandlers() { |
51 | - String type = eventType(message); | 49 | + return ImmutableSet.of( |
52 | - if (type.equals("appDataRequest")) { | 50 | + new AppDataRequest(), |
53 | - sendAppList(message); | 51 | + new AppMgmtRequest() |
54 | - } else if (type.equals("appManagementRequest")) { | 52 | + ); |
55 | - processManagementCommand(message); | ||
56 | - } | ||
57 | } | 53 | } |
58 | 54 | ||
59 | - private void sendAppList(ObjectNode message) { | 55 | + // ====================================================================== |
60 | - ObjectNode payload = payload(message); | ||
61 | - RowComparator rc = TableUtils.createRowComparator(payload); | ||
62 | 56 | ||
63 | - ApplicationService service = get(ApplicationService.class); | 57 | + private final class AppDataRequest extends RequestHandler { |
64 | - TableRow[] rows = generateTableRows(service); | ||
65 | - Arrays.sort(rows, rc); | ||
66 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
67 | - rootNode.set("apps", TableUtils.generateArrayNode(rows)); | ||
68 | 58 | ||
69 | - connection().sendMessage("appDataResponse", 0, rootNode); | 59 | + private AppDataRequest() { |
70 | - } | 60 | + super(APP_DATA_REQ); |
61 | + } | ||
71 | 62 | ||
72 | - private void processManagementCommand(ObjectNode message) { | 63 | + @Override |
73 | - ObjectNode payload = payload(message); | 64 | + public void process(long sid, ObjectNode payload) { |
74 | - String action = string(payload, "action"); | 65 | + RowComparator rc = TableUtils.createRowComparator(payload); |
75 | - String name = string(payload, "name"); | 66 | + |
76 | - if (action != null && name != null) { | 67 | + ApplicationService service = get(ApplicationService.class); |
77 | - ApplicationAdminService service = get(ApplicationAdminService.class); | 68 | + TableRow[] rows = generateTableRows(service); |
78 | - ApplicationId appId = service.getId(name); | 69 | + Arrays.sort(rows, rc); |
79 | - if (action.equals("activate")) { | 70 | + ObjectNode rootNode = MAPPER.createObjectNode(); |
80 | - service.activate(appId); | 71 | + rootNode.set("apps", TableUtils.generateArrayNode(rows)); |
81 | - } else if (action.equals("deactivate")) { | 72 | + |
82 | - service.deactivate(appId); | 73 | + sendMessage("appDataResponse", 0, rootNode); |
83 | - } else if (action.equals("uninstall")) { | 74 | + } |
84 | - service.uninstall(appId); | 75 | + |
85 | - } | 76 | + private TableRow[] generateTableRows(ApplicationService service) { |
86 | - sendAppList(message); | 77 | + List<TableRow> list = service.getApplications().stream() |
78 | + .map(application -> new ApplicationTableRow(service, application)) | ||
79 | + .collect(Collectors.toList()); | ||
80 | + return list.toArray(new TableRow[list.size()]); | ||
87 | } | 81 | } |
88 | } | 82 | } |
83 | + // ====================================================================== | ||
89 | 84 | ||
90 | - private TableRow[] generateTableRows(ApplicationService service) { | 85 | + private final class AppMgmtRequest extends RequestHandler { |
91 | - List<TableRow> list = service.getApplications().stream() | 86 | + |
92 | - .map(application -> new ApplicationTableRow(service, application)) | 87 | + private AppMgmtRequest() { |
93 | - .collect(Collectors.toList()); | 88 | + super(APP_MGMT_REQ); |
94 | - return list.toArray(new TableRow[list.size()]); | 89 | + } |
90 | + | ||
91 | + @Override | ||
92 | + public void process(long sid, ObjectNode payload) { | ||
93 | + String action = string(payload, "action"); | ||
94 | + String name = string(payload, "name"); | ||
95 | + if (action != null && name != null) { | ||
96 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
97 | + ApplicationId appId = service.getId(name); | ||
98 | + if (action.equals("activate")) { | ||
99 | + service.activate(appId); | ||
100 | + } else if (action.equals("deactivate")) { | ||
101 | + service.deactivate(appId); | ||
102 | + } else if (action.equals("uninstall")) { | ||
103 | + service.uninstall(appId); | ||
104 | + } | ||
105 | + chain(APP_DATA_REQ, sid, payload); | ||
106 | + } | ||
107 | + } | ||
95 | } | 108 | } |
109 | + // ====================================================================== | ||
96 | 110 | ||
97 | /** | 111 | /** |
98 | * TableRow implementation for | 112 | * TableRow implementation for | ... | ... |
... | @@ -23,58 +23,62 @@ import org.joda.time.format.DateTimeFormat; | ... | @@ -23,58 +23,62 @@ import org.joda.time.format.DateTimeFormat; |
23 | import org.onosproject.cluster.ClusterService; | 23 | import org.onosproject.cluster.ClusterService; |
24 | import org.onosproject.cluster.ControllerNode; | 24 | import org.onosproject.cluster.ControllerNode; |
25 | import org.onosproject.cluster.NodeId; | 25 | import org.onosproject.cluster.NodeId; |
26 | -import org.onosproject.ui.UiMessageHandler; | 26 | +import org.onosproject.ui.RequestHandler; |
27 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
27 | import org.onosproject.ui.table.AbstractTableRow; | 28 | import org.onosproject.ui.table.AbstractTableRow; |
28 | import org.onosproject.ui.table.RowComparator; | 29 | import org.onosproject.ui.table.RowComparator; |
29 | import org.onosproject.ui.table.TableRow; | 30 | import org.onosproject.ui.table.TableRow; |
30 | import org.onosproject.ui.table.TableUtils; | 31 | import org.onosproject.ui.table.TableUtils; |
31 | 32 | ||
32 | -import java.util.ArrayList; | ||
33 | import java.util.Arrays; | 33 | import java.util.Arrays; |
34 | +import java.util.Collection; | ||
34 | import java.util.List; | 35 | import java.util.List; |
36 | +import java.util.stream.Collectors; | ||
35 | 37 | ||
36 | 38 | ||
37 | /** | 39 | /** |
38 | * Message handler for cluster view related messages. | 40 | * Message handler for cluster view related messages. |
39 | */ | 41 | */ |
40 | -public class ClusterViewMessageHandler extends UiMessageHandler { | 42 | +public class ClusterViewMessageHandler extends UiMessageHandlerTwo { |
41 | 43 | ||
42 | - /** | 44 | + private static final String CLUSTER_DATA_REQ = "clusterDataRequest"; |
43 | - * Creates a new message handler for the cluster messages. | ||
44 | - */ | ||
45 | - protected ClusterViewMessageHandler() { | ||
46 | - super(ImmutableSet.of("clusterDataRequest")); | ||
47 | - } | ||
48 | 45 | ||
49 | @Override | 46 | @Override |
50 | - public void process(ObjectNode message) { | 47 | + protected Collection<RequestHandler> getHandlers() { |
51 | - String type = eventType(message); | 48 | + return ImmutableSet.of(new ClusterDataRequest()); |
52 | - if (type.equals("clusterDataRequest")) { | ||
53 | - sendClusterList(message); | ||
54 | - } | ||
55 | } | 49 | } |
56 | 50 | ||
57 | - private void sendClusterList(ObjectNode message) { | 51 | + // ====================================================================== |
58 | - ObjectNode payload = payload(message); | ||
59 | - RowComparator rc = TableUtils.createRowComparator(payload); | ||
60 | 52 | ||
61 | - ClusterService service = get(ClusterService.class); | 53 | + private final class ClusterDataRequest extends RequestHandler { |
62 | - TableRow[] rows = generateTableRows(service); | ||
63 | - Arrays.sort(rows, rc); | ||
64 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
65 | - rootNode.set("clusters", TableUtils.generateArrayNode(rows)); | ||
66 | 54 | ||
67 | - connection().sendMessage("clusterDataResponse", 0, rootNode); | 55 | + private ClusterDataRequest() { |
68 | - } | 56 | + super(CLUSTER_DATA_REQ); |
57 | + } | ||
69 | 58 | ||
70 | - private TableRow[] generateTableRows(ClusterService service) { | 59 | + @Override |
71 | - List<TableRow> list = new ArrayList<>(); | 60 | + public void process(long sid, ObjectNode payload) { |
72 | - for (ControllerNode node : service.getNodes()) { | 61 | + RowComparator rc = TableUtils.createRowComparator(payload); |
73 | - list.add(new ControllerNodeTableRow(service, node)); | 62 | + |
63 | + ClusterService service = get(ClusterService.class); | ||
64 | + TableRow[] rows = generateTableRows(service); | ||
65 | + Arrays.sort(rows, rc); | ||
66 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
67 | + rootNode.set("clusters", TableUtils.generateArrayNode(rows)); | ||
68 | + | ||
69 | + sendMessage("clusterDataResponse", 0, rootNode); | ||
70 | + } | ||
71 | + | ||
72 | + private TableRow[] generateTableRows(ClusterService service) { | ||
73 | + List<TableRow> list = service.getNodes().stream() | ||
74 | + .map(node -> new ControllerNodeTableRow(service, node)) | ||
75 | + .collect(Collectors.toList()); | ||
76 | + return list.toArray(new TableRow[list.size()]); | ||
74 | } | 77 | } |
75 | - return list.toArray(new TableRow[list.size()]); | ||
76 | } | 78 | } |
77 | 79 | ||
80 | + // ====================================================================== | ||
81 | + | ||
78 | /** | 82 | /** |
79 | * TableRow implementation for {@link ControllerNode controller nodes}. | 83 | * TableRow implementation for {@link ControllerNode controller nodes}. |
80 | */ | 84 | */ | ... | ... |
... | @@ -27,7 +27,8 @@ import org.onosproject.net.Link; | ... | @@ -27,7 +27,8 @@ import org.onosproject.net.Link; |
27 | import org.onosproject.net.Port; | 27 | import org.onosproject.net.Port; |
28 | import org.onosproject.net.device.DeviceService; | 28 | import org.onosproject.net.device.DeviceService; |
29 | import org.onosproject.net.link.LinkService; | 29 | import org.onosproject.net.link.LinkService; |
30 | -import org.onosproject.ui.UiMessageHandler; | 30 | +import org.onosproject.ui.RequestHandler; |
31 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
31 | import org.onosproject.ui.table.AbstractTableRow; | 32 | import org.onosproject.ui.table.AbstractTableRow; |
32 | import org.onosproject.ui.table.RowComparator; | 33 | import org.onosproject.ui.table.RowComparator; |
33 | import org.onosproject.ui.table.TableRow; | 34 | import org.onosproject.ui.table.TableRow; |
... | @@ -35,6 +36,7 @@ import org.onosproject.ui.table.TableUtils; | ... | @@ -35,6 +36,7 @@ import org.onosproject.ui.table.TableUtils; |
35 | 36 | ||
36 | import java.util.ArrayList; | 37 | import java.util.ArrayList; |
37 | import java.util.Arrays; | 38 | import java.util.Arrays; |
39 | +import java.util.Collection; | ||
38 | import java.util.Collections; | 40 | import java.util.Collections; |
39 | import java.util.List; | 41 | import java.util.List; |
40 | import java.util.Set; | 42 | import java.util.Set; |
... | @@ -42,7 +44,10 @@ import java.util.Set; | ... | @@ -42,7 +44,10 @@ import java.util.Set; |
42 | /** | 44 | /** |
43 | * Message handler for device view related messages. | 45 | * Message handler for device view related messages. |
44 | */ | 46 | */ |
45 | -public class DeviceViewMessageHandler extends UiMessageHandler { | 47 | +public class DeviceViewMessageHandler extends UiMessageHandlerTwo { |
48 | + | ||
49 | + private static final String DEV_DATA_REQ = "deviceDataRequest"; | ||
50 | + private static final String DEV_DETAIL_REQ = "deviceDetailRequest"; | ||
46 | 51 | ||
47 | private static final String ID = "id"; | 52 | private static final String ID = "id"; |
48 | private static final String TYPE = "type"; | 53 | private static final String TYPE = "type"; |
... | @@ -65,110 +70,120 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -65,110 +70,120 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
65 | private static final String NAME = "name"; | 70 | private static final String NAME = "name"; |
66 | 71 | ||
67 | 72 | ||
68 | - /** | 73 | + @Override |
69 | - * Creates a new message handler for the device messages. | 74 | + protected Collection<RequestHandler> getHandlers() { |
70 | - */ | 75 | + return ImmutableSet.of( |
71 | - protected DeviceViewMessageHandler() { | 76 | + new DataRequestHandler(), |
72 | - super(ImmutableSet.of("deviceDataRequest", "deviceDetailsRequest")); | 77 | + new DetailRequestHandler() |
78 | + ); | ||
73 | } | 79 | } |
74 | 80 | ||
75 | - @Override | 81 | + // ====================================================================== |
76 | - public void process(ObjectNode message) { | 82 | + |
77 | - String type = eventType(message); | 83 | + private final class DataRequestHandler extends RequestHandler { |
78 | - if (type.equals("deviceDataRequest")) { | 84 | + |
79 | - dataRequest(message); | 85 | + private DataRequestHandler() { |
80 | - } else if (type.equals("deviceDetailsRequest")) { | 86 | + super(DEV_DATA_REQ); |
81 | - detailsRequest(message); | ||
82 | } | 87 | } |
83 | - } | ||
84 | 88 | ||
85 | - private void dataRequest(ObjectNode message) { | 89 | + @Override |
86 | - ObjectNode payload = payload(message); | 90 | + public void process(long sid, ObjectNode payload) { |
87 | - RowComparator rc = TableUtils.createRowComparator(payload); | 91 | + RowComparator rc = TableUtils.createRowComparator(payload); |
92 | + | ||
93 | + DeviceService service = get(DeviceService.class); | ||
94 | + MastershipService mastershipService = get(MastershipService.class); | ||
95 | + TableRow[] rows = generateTableRows(service, mastershipService); | ||
96 | + Arrays.sort(rows, rc); | ||
97 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
98 | + rootNode.set("devices", TableUtils.generateArrayNode(rows)); | ||
88 | 99 | ||
89 | - DeviceService service = get(DeviceService.class); | 100 | + sendMessage("deviceDataResponse", 0, rootNode); |
90 | - MastershipService mastershipService = get(MastershipService.class); | 101 | + } |
91 | - TableRow[] rows = generateTableRows(service, mastershipService); | ||
92 | - Arrays.sort(rows, rc); | ||
93 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
94 | - rootNode.set("devices", TableUtils.generateArrayNode(rows)); | ||
95 | 102 | ||
96 | - connection().sendMessage("deviceDataResponse", 0, rootNode); | 103 | + private TableRow[] generateTableRows(DeviceService service, |
104 | + MastershipService mastershipService) { | ||
105 | + List<TableRow> list = new ArrayList<>(); | ||
106 | + for (Device dev : service.getDevices()) { | ||
107 | + list.add(new DeviceTableRow(service, mastershipService, dev)); | ||
108 | + } | ||
109 | + return list.toArray(new TableRow[list.size()]); | ||
110 | + } | ||
97 | } | 111 | } |
98 | 112 | ||
99 | - private void detailsRequest(ObjectNode message) { | 113 | + // ====================================================================== |
100 | - ObjectNode payload = payload(message); | 114 | + |
101 | - String id = string(payload, "id", "of:0000000000000000"); | 115 | + private final class DetailRequestHandler extends RequestHandler { |
102 | - | 116 | + private DetailRequestHandler() { |
103 | - DeviceId deviceId = DeviceId.deviceId(id); | 117 | + super(DEV_DETAIL_REQ); |
104 | - DeviceService service = get(DeviceService.class); | ||
105 | - MastershipService ms = get(MastershipService.class); | ||
106 | - Device device = service.getDevice(deviceId); | ||
107 | - ObjectNode data = mapper.createObjectNode(); | ||
108 | - | ||
109 | - data.put(ID, deviceId.toString()); | ||
110 | - data.put(TYPE, device.type().toString()); | ||
111 | - data.put(TYPE_IID, getTypeIconId(device)); | ||
112 | - data.put(MFR, device.manufacturer()); | ||
113 | - data.put(HW, device.hwVersion()); | ||
114 | - data.put(SW, device.swVersion()); | ||
115 | - data.put(SERIAL, device.serialNumber()); | ||
116 | - data.put(CHASSIS_ID, device.chassisId().toString()); | ||
117 | - data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); | ||
118 | - data.put(PROTOCOL, device.annotations().value(PROTOCOL)); | ||
119 | - | ||
120 | - ArrayNode ports = mapper.createArrayNode(); | ||
121 | - | ||
122 | - List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); | ||
123 | - Collections.sort(portList, (p1, p2) -> { | ||
124 | - long delta = p1.number().toLong() - p2.number().toLong(); | ||
125 | - return delta == 0 ? 0 : (delta < 0 ? -1 : +1); | ||
126 | - }); | ||
127 | - | ||
128 | - for (Port p : portList) { | ||
129 | - ports.add(portData(p, deviceId)); | ||
130 | } | 118 | } |
131 | - data.set(PORTS, ports); | ||
132 | 119 | ||
133 | - ObjectNode rootNode = mapper.createObjectNode(); | 120 | + @Override |
134 | - rootNode.set("details", data); | 121 | + public void process(long sid, ObjectNode payload) { |
135 | - connection().sendMessage("deviceDetailsResponse", 0, rootNode); | 122 | + String id = string(payload, "id", "of:0000000000000000"); |
136 | - } | 123 | + |
124 | + DeviceId deviceId = DeviceId.deviceId(id); | ||
125 | + DeviceService service = get(DeviceService.class); | ||
126 | + MastershipService ms = get(MastershipService.class); | ||
127 | + Device device = service.getDevice(deviceId); | ||
128 | + ObjectNode data = MAPPER.createObjectNode(); | ||
129 | + | ||
130 | + data.put(ID, deviceId.toString()); | ||
131 | + data.put(TYPE, device.type().toString()); | ||
132 | + data.put(TYPE_IID, getTypeIconId(device)); | ||
133 | + data.put(MFR, device.manufacturer()); | ||
134 | + data.put(HW, device.hwVersion()); | ||
135 | + data.put(SW, device.swVersion()); | ||
136 | + data.put(SERIAL, device.serialNumber()); | ||
137 | + data.put(CHASSIS_ID, device.chassisId().toString()); | ||
138 | + data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); | ||
139 | + data.put(PROTOCOL, device.annotations().value(PROTOCOL)); | ||
140 | + | ||
141 | + ArrayNode ports = MAPPER.createArrayNode(); | ||
142 | + | ||
143 | + List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); | ||
144 | + Collections.sort(portList, (p1, p2) -> { | ||
145 | + long delta = p1.number().toLong() - p2.number().toLong(); | ||
146 | + return delta == 0 ? 0 : (delta < 0 ? -1 : +1); | ||
147 | + }); | ||
148 | + | ||
149 | + for (Port p : portList) { | ||
150 | + ports.add(portData(p, deviceId)); | ||
151 | + } | ||
152 | + data.set(PORTS, ports); | ||
137 | 153 | ||
138 | - private TableRow[] generateTableRows(DeviceService service, | 154 | + ObjectNode rootNode = MAPPER.createObjectNode(); |
139 | - MastershipService mastershipService) { | 155 | + rootNode.set("details", data); |
140 | - List<TableRow> list = new ArrayList<>(); | 156 | + sendMessage("deviceDetailsResponse", 0, rootNode); |
141 | - for (Device dev : service.getDevices()) { | ||
142 | - list.add(new DeviceTableRow(service, mastershipService, dev)); | ||
143 | } | 157 | } |
144 | - return list.toArray(new TableRow[list.size()]); | ||
145 | - } | ||
146 | 158 | ||
147 | - private ObjectNode portData(Port p, DeviceId id) { | 159 | + private ObjectNode portData(Port p, DeviceId id) { |
148 | - ObjectNode port = mapper.createObjectNode(); | 160 | + ObjectNode port = MAPPER.createObjectNode(); |
149 | - LinkService ls = get(LinkService.class); | 161 | + LinkService ls = get(LinkService.class); |
150 | - String name = p.annotations().value(AnnotationKeys.PORT_NAME); | 162 | + String name = p.annotations().value(AnnotationKeys.PORT_NAME); |
151 | - | 163 | + |
152 | - port.put(ID, p.number().toString()); | 164 | + port.put(ID, p.number().toString()); |
153 | - port.put(TYPE, p.type().toString()); | 165 | + port.put(TYPE, p.type().toString()); |
154 | - port.put(SPEED, p.portSpeed()); | 166 | + port.put(SPEED, p.portSpeed()); |
155 | - port.put(ENABLED, p.isEnabled()); | 167 | + port.put(ENABLED, p.isEnabled()); |
156 | - port.put(NAME, name != null ? name : ""); | 168 | + port.put(NAME, name != null ? name : ""); |
157 | - | 169 | + |
158 | - Set<Link> links = ls.getEgressLinks(new ConnectPoint(id, p.number())); | 170 | + Set<Link> links = ls.getEgressLinks(new ConnectPoint(id, p.number())); |
159 | - if (!links.isEmpty()) { | 171 | + if (!links.isEmpty()) { |
160 | - StringBuilder egressLinks = new StringBuilder(); | 172 | + StringBuilder egressLinks = new StringBuilder(); |
161 | - for (Link l : links) { | 173 | + for (Link l : links) { |
162 | - ConnectPoint dest = l.dst(); | 174 | + ConnectPoint dest = l.dst(); |
163 | - egressLinks.append(dest.elementId()).append("/") | 175 | + egressLinks.append(dest.elementId()).append("/") |
164 | - .append(dest.port()).append(" "); | 176 | + .append(dest.port()).append(" "); |
177 | + } | ||
178 | + port.put(LINK_DEST, egressLinks.toString()); | ||
165 | } | 179 | } |
166 | - port.put(LINK_DEST, egressLinks.toString()); | 180 | + |
181 | + return port; | ||
167 | } | 182 | } |
168 | 183 | ||
169 | - return port; | ||
170 | } | 184 | } |
171 | 185 | ||
186 | + | ||
172 | private static String getTypeIconId(Device d) { | 187 | private static String getTypeIconId(Device d) { |
173 | return DEV_ICON_PREFIX + d.type().toString(); | 188 | return DEV_ICON_PREFIX + d.type().toString(); |
174 | } | 189 | } | ... | ... |
... | @@ -26,7 +26,8 @@ import org.onosproject.net.flow.TrafficSelector; | ... | @@ -26,7 +26,8 @@ import org.onosproject.net.flow.TrafficSelector; |
26 | import org.onosproject.net.flow.TrafficTreatment; | 26 | import org.onosproject.net.flow.TrafficTreatment; |
27 | import org.onosproject.net.flow.criteria.Criterion; | 27 | import org.onosproject.net.flow.criteria.Criterion; |
28 | import org.onosproject.net.flow.instructions.Instruction; | 28 | import org.onosproject.net.flow.instructions.Instruction; |
29 | -import org.onosproject.ui.UiMessageHandler; | 29 | +import org.onosproject.ui.RequestHandler; |
30 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
30 | import org.onosproject.ui.table.AbstractTableRow; | 31 | import org.onosproject.ui.table.AbstractTableRow; |
31 | import org.onosproject.ui.table.RowComparator; | 32 | import org.onosproject.ui.table.RowComparator; |
32 | import org.onosproject.ui.table.TableRow; | 33 | import org.onosproject.ui.table.TableRow; |
... | @@ -34,6 +35,7 @@ import org.onosproject.ui.table.TableUtils; | ... | @@ -34,6 +35,7 @@ import org.onosproject.ui.table.TableUtils; |
34 | 35 | ||
35 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
36 | import java.util.Arrays; | 37 | import java.util.Arrays; |
38 | +import java.util.Collection; | ||
37 | import java.util.List; | 39 | import java.util.List; |
38 | import java.util.Set; | 40 | import java.util.Set; |
39 | 41 | ||
... | @@ -41,55 +43,58 @@ import java.util.Set; | ... | @@ -41,55 +43,58 @@ import java.util.Set; |
41 | /** | 43 | /** |
42 | * Message handler for flow view related messages. | 44 | * Message handler for flow view related messages. |
43 | */ | 45 | */ |
44 | -public class FlowViewMessageHandler extends UiMessageHandler { | 46 | +public class FlowViewMessageHandler extends UiMessageHandlerTwo { |
45 | 47 | ||
46 | - private static final String NO_DEV = "none"; | 48 | + private static final String FLOW_DATA_REQ = "flowDataRequest"; |
47 | 49 | ||
48 | - /** | 50 | + private static final String NO_DEV = "none"; |
49 | - * Creates a new message handler for the flow messages. | ||
50 | - */ | ||
51 | - protected FlowViewMessageHandler() { | ||
52 | - super(ImmutableSet.of("flowDataRequest")); | ||
53 | - } | ||
54 | 51 | ||
55 | @Override | 52 | @Override |
56 | - public void process(ObjectNode message) { | 53 | + protected Collection<RequestHandler> getHandlers() { |
57 | - String type = eventType(message); | 54 | + return ImmutableSet.of(new FlowDataRequest()); |
58 | - if (type.equals("flowDataRequest")) { | ||
59 | - sendFlowList(message); | ||
60 | - } | ||
61 | } | 55 | } |
62 | 56 | ||
63 | - private void sendFlowList(ObjectNode message) { | 57 | + // ====================================================================== |
64 | - ObjectNode payload = payload(message); | 58 | + |
65 | - RowComparator rc = TableUtils.createRowComparator(payload); | 59 | + private final class FlowDataRequest extends RequestHandler { |
66 | - String uri = string(payload, "devId", NO_DEV); | 60 | + |
67 | - | 61 | + private FlowDataRequest() { |
68 | - ObjectNode rootNode; | 62 | + super(FLOW_DATA_REQ); |
69 | - if (uri.equals(NO_DEV)) { | ||
70 | - rootNode = mapper.createObjectNode(); | ||
71 | - rootNode.set("flows", mapper.createArrayNode()); | ||
72 | - } else { | ||
73 | - DeviceId deviceId = DeviceId.deviceId(uri); | ||
74 | - FlowRuleService service = get(FlowRuleService.class); | ||
75 | - TableRow[] rows = generateTableRows(service, deviceId); | ||
76 | - Arrays.sort(rows, rc); | ||
77 | - rootNode = mapper.createObjectNode(); | ||
78 | - rootNode.set("flows", TableUtils.generateArrayNode(rows)); | ||
79 | } | 63 | } |
80 | 64 | ||
81 | - connection().sendMessage("flowDataResponse", 0, rootNode); | 65 | + @Override |
82 | - } | 66 | + public void process(long sid, ObjectNode payload) { |
67 | + RowComparator rc = TableUtils.createRowComparator(payload); | ||
68 | + String uri = string(payload, "devId", NO_DEV); | ||
69 | + | ||
70 | + ObjectNode rootNode; | ||
71 | + if (uri.equals(NO_DEV)) { | ||
72 | + rootNode = MAPPER.createObjectNode(); | ||
73 | + rootNode.set("flows", MAPPER.createArrayNode()); | ||
74 | + } else { | ||
75 | + DeviceId deviceId = DeviceId.deviceId(uri); | ||
76 | + FlowRuleService service = get(FlowRuleService.class); | ||
77 | + TableRow[] rows = generateTableRows(service, deviceId); | ||
78 | + Arrays.sort(rows, rc); | ||
79 | + rootNode = MAPPER.createObjectNode(); | ||
80 | + rootNode.set("flows", TableUtils.generateArrayNode(rows)); | ||
81 | + } | ||
83 | 82 | ||
84 | - private TableRow[] generateTableRows(FlowRuleService service, | 83 | + sendMessage("flowDataResponse", 0, rootNode); |
85 | - DeviceId deviceId) { | 84 | + } |
86 | - List<TableRow> list = new ArrayList<>(); | 85 | + |
87 | - for (FlowEntry flow : service.getFlowEntries(deviceId)) { | 86 | + private TableRow[] generateTableRows(FlowRuleService service, |
88 | - list.add(new FlowTableRow(flow)); | 87 | + DeviceId deviceId) { |
88 | + List<TableRow> list = new ArrayList<>(); | ||
89 | + for (FlowEntry flow : service.getFlowEntries(deviceId)) { | ||
90 | + list.add(new FlowTableRow(flow)); | ||
91 | + } | ||
92 | + return list.toArray(new TableRow[list.size()]); | ||
89 | } | 93 | } |
90 | - return list.toArray(new TableRow[list.size()]); | ||
91 | } | 94 | } |
92 | 95 | ||
96 | + // ====================================================================== | ||
97 | + | ||
93 | /** | 98 | /** |
94 | * TableRow implementation for {@link org.onosproject.net.flow.FlowRule flows}. | 99 | * TableRow implementation for {@link org.onosproject.net.flow.FlowRule flows}. |
95 | */ | 100 | */ | ... | ... |
... | @@ -21,7 +21,8 @@ import org.onosproject.net.AnnotationKeys; | ... | @@ -21,7 +21,8 @@ import org.onosproject.net.AnnotationKeys; |
21 | import org.onosproject.net.Host; | 21 | import org.onosproject.net.Host; |
22 | import org.onosproject.net.HostLocation; | 22 | import org.onosproject.net.HostLocation; |
23 | import org.onosproject.net.host.HostService; | 23 | import org.onosproject.net.host.HostService; |
24 | -import org.onosproject.ui.UiMessageHandler; | 24 | +import org.onosproject.ui.RequestHandler; |
25 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
25 | import org.onosproject.ui.table.AbstractTableRow; | 26 | import org.onosproject.ui.table.AbstractTableRow; |
26 | import org.onosproject.ui.table.RowComparator; | 27 | import org.onosproject.ui.table.RowComparator; |
27 | import org.onosproject.ui.table.TableRow; | 28 | import org.onosproject.ui.table.TableRow; |
... | @@ -29,6 +30,7 @@ import org.onosproject.ui.table.TableUtils; | ... | @@ -29,6 +30,7 @@ import org.onosproject.ui.table.TableUtils; |
29 | 30 | ||
30 | import java.util.ArrayList; | 31 | import java.util.ArrayList; |
31 | import java.util.Arrays; | 32 | import java.util.Arrays; |
33 | +import java.util.Collection; | ||
32 | import java.util.List; | 34 | import java.util.List; |
33 | 35 | ||
34 | import static com.google.common.base.Strings.isNullOrEmpty; | 36 | import static com.google.common.base.Strings.isNullOrEmpty; |
... | @@ -36,44 +38,48 @@ import static com.google.common.base.Strings.isNullOrEmpty; | ... | @@ -36,44 +38,48 @@ import static com.google.common.base.Strings.isNullOrEmpty; |
36 | /** | 38 | /** |
37 | * Message handler for host view related messages. | 39 | * Message handler for host view related messages. |
38 | */ | 40 | */ |
39 | -public class HostViewMessageHandler extends UiMessageHandler { | 41 | +public class HostViewMessageHandler extends UiMessageHandlerTwo { |
42 | + | ||
43 | + private static final String HOST_DATA_REQ = "hostDataRequest"; | ||
40 | 44 | ||
41 | - /** | ||
42 | - * Creates a new message handler for the host messages. | ||
43 | - */ | ||
44 | - protected HostViewMessageHandler() { | ||
45 | - super(ImmutableSet.of("hostDataRequest")); | ||
46 | - } | ||
47 | 45 | ||
48 | @Override | 46 | @Override |
49 | - public void process(ObjectNode message) { | 47 | + protected Collection<RequestHandler> getHandlers() { |
50 | - String type = eventType(message); | 48 | + return ImmutableSet.of(new HostDataRequest()); |
51 | - if (type.equals("hostDataRequest")) { | ||
52 | - sendHostList(message); | ||
53 | - } | ||
54 | } | 49 | } |
55 | 50 | ||
56 | - private void sendHostList(ObjectNode message) { | 51 | + // ====================================================================== |
57 | - ObjectNode payload = payload(message); | ||
58 | - RowComparator rc = TableUtils.createRowComparator(payload); | ||
59 | 52 | ||
60 | - HostService service = get(HostService.class); | 53 | + private final class HostDataRequest extends RequestHandler { |
61 | - TableRow[] rows = generateTableRows(service); | ||
62 | - Arrays.sort(rows, rc); | ||
63 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
64 | - rootNode.set("hosts", TableUtils.generateArrayNode(rows)); | ||
65 | 54 | ||
66 | - connection().sendMessage("hostDataResponse", 0, rootNode); | 55 | + private HostDataRequest() { |
67 | - } | 56 | + super(HOST_DATA_REQ); |
57 | + } | ||
68 | 58 | ||
69 | - private TableRow[] generateTableRows(HostService service) { | 59 | + @Override |
70 | - List<TableRow> list = new ArrayList<>(); | 60 | + public void process(long sid, ObjectNode payload) { |
71 | - for (Host host : service.getHosts()) { | 61 | + RowComparator rc = TableUtils.createRowComparator(payload); |
72 | - list.add(new HostTableRow(host)); | 62 | + |
63 | + HostService service = get(HostService.class); | ||
64 | + TableRow[] rows = generateTableRows(service); | ||
65 | + Arrays.sort(rows, rc); | ||
66 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
67 | + rootNode.set("hosts", TableUtils.generateArrayNode(rows)); | ||
68 | + | ||
69 | + sendMessage("hostDataResponse", 0, rootNode); | ||
70 | + } | ||
71 | + | ||
72 | + private TableRow[] generateTableRows(HostService service) { | ||
73 | + List<TableRow> list = new ArrayList<>(); | ||
74 | + for (Host host : service.getHosts()) { | ||
75 | + list.add(new HostTableRow(host)); | ||
76 | + } | ||
77 | + return list.toArray(new TableRow[list.size()]); | ||
73 | } | 78 | } |
74 | - return list.toArray(new TableRow[list.size()]); | ||
75 | } | 79 | } |
76 | 80 | ||
81 | + // ====================================================================== | ||
82 | + | ||
77 | /** | 83 | /** |
78 | * TableRow implementation for {@link Host hosts}. | 84 | * TableRow implementation for {@link Host hosts}. |
79 | */ | 85 | */ | ... | ... |
... | @@ -31,7 +31,8 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ... | @@ -31,7 +31,8 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
31 | import org.onosproject.net.intent.PathIntent; | 31 | import org.onosproject.net.intent.PathIntent; |
32 | import org.onosproject.net.intent.PointToPointIntent; | 32 | import org.onosproject.net.intent.PointToPointIntent; |
33 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; | 33 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
34 | -import org.onosproject.ui.UiMessageHandler; | 34 | +import org.onosproject.ui.RequestHandler; |
35 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
35 | import org.onosproject.ui.table.AbstractTableRow; | 36 | import org.onosproject.ui.table.AbstractTableRow; |
36 | import org.onosproject.ui.table.RowComparator; | 37 | import org.onosproject.ui.table.RowComparator; |
37 | import org.onosproject.ui.table.TableRow; | 38 | import org.onosproject.ui.table.TableRow; |
... | @@ -39,50 +40,55 @@ import org.onosproject.ui.table.TableUtils; | ... | @@ -39,50 +40,55 @@ import org.onosproject.ui.table.TableUtils; |
39 | 40 | ||
40 | import java.util.ArrayList; | 41 | import java.util.ArrayList; |
41 | import java.util.Arrays; | 42 | import java.util.Arrays; |
43 | +import java.util.Collection; | ||
42 | import java.util.List; | 44 | import java.util.List; |
43 | import java.util.Set; | 45 | import java.util.Set; |
44 | 46 | ||
45 | /** | 47 | /** |
46 | * Message handler for intent view related messages. | 48 | * Message handler for intent view related messages. |
47 | */ | 49 | */ |
48 | -public class IntentViewMessageHandler extends UiMessageHandler { | 50 | +public class IntentViewMessageHandler extends UiMessageHandlerTwo { |
51 | + | ||
52 | + private static final String INTENT_DATA_REQ = "intentDataRequest"; | ||
49 | 53 | ||
50 | - /** | ||
51 | - * Creates a new message handler for the intent messages. | ||
52 | - */ | ||
53 | - protected IntentViewMessageHandler() { | ||
54 | - super(ImmutableSet.of("intentDataRequest")); | ||
55 | - } | ||
56 | 54 | ||
57 | @Override | 55 | @Override |
58 | - public void process(ObjectNode message) { | 56 | + protected Collection<RequestHandler> getHandlers() { |
59 | - String type = eventType(message); | 57 | + return ImmutableSet.of(new IntentDataRequest()); |
60 | - if (type.equals("intentDataRequest")) { | ||
61 | - sendIntentList(message); | ||
62 | - } | ||
63 | } | 58 | } |
64 | 59 | ||
65 | - private void sendIntentList(ObjectNode message) { | 60 | + // ====================================================================== |
66 | - ObjectNode payload = payload(message); | ||
67 | - RowComparator rc = TableUtils.createRowComparator(payload); | ||
68 | 61 | ||
69 | - IntentService service = get(IntentService.class); | 62 | + private final class IntentDataRequest extends RequestHandler { |
70 | - TableRow[] rows = generateTableRows(service); | ||
71 | - Arrays.sort(rows, rc); | ||
72 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
73 | - rootNode.set("intents", TableUtils.generateArrayNode(rows)); | ||
74 | 63 | ||
75 | - connection().sendMessage("intentDataResponse", 0, rootNode); | 64 | + private IntentDataRequest() { |
76 | - } | 65 | + super(INTENT_DATA_REQ); |
66 | + } | ||
77 | 67 | ||
78 | - private TableRow[] generateTableRows(IntentService service) { | 68 | + @Override |
79 | - List<TableRow> list = new ArrayList<>(); | 69 | + public void process(long sid, ObjectNode payload) { |
80 | - for (Intent intent : service.getIntents()) { | 70 | + RowComparator rc = TableUtils.createRowComparator(payload); |
81 | - list.add(new IntentTableRow(intent)); | 71 | + |
72 | + IntentService service = get(IntentService.class); | ||
73 | + TableRow[] rows = generateTableRows(service); | ||
74 | + Arrays.sort(rows, rc); | ||
75 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
76 | + rootNode.set("intents", TableUtils.generateArrayNode(rows)); | ||
77 | + | ||
78 | + sendMessage("intentDataResponse", 0, rootNode); | ||
79 | + } | ||
80 | + | ||
81 | + private TableRow[] generateTableRows(IntentService service) { | ||
82 | + List<TableRow> list = new ArrayList<>(); | ||
83 | + for (Intent intent : service.getIntents()) { | ||
84 | + list.add(new IntentTableRow(intent)); | ||
85 | + } | ||
86 | + return list.toArray(new TableRow[list.size()]); | ||
82 | } | 87 | } |
83 | - return list.toArray(new TableRow[list.size()]); | ||
84 | } | 88 | } |
85 | 89 | ||
90 | + // ====================================================================== | ||
91 | + | ||
86 | /** | 92 | /** |
87 | * TableRow implementation for {@link Intent intents}. | 93 | * TableRow implementation for {@link Intent intents}. |
88 | */ | 94 | */ | ... | ... |
... | @@ -23,7 +23,8 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -23,7 +23,8 @@ import org.onosproject.net.ConnectPoint; |
23 | import org.onosproject.net.Link; | 23 | import org.onosproject.net.Link; |
24 | import org.onosproject.net.LinkKey; | 24 | import org.onosproject.net.LinkKey; |
25 | import org.onosproject.net.link.LinkService; | 25 | import org.onosproject.net.link.LinkService; |
26 | -import org.onosproject.ui.UiMessageHandler; | 26 | +import org.onosproject.ui.RequestHandler; |
27 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
27 | import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; | 28 | import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; |
28 | import org.onosproject.ui.table.AbstractTableRow; | 29 | import org.onosproject.ui.table.AbstractTableRow; |
29 | import org.onosproject.ui.table.RowComparator; | 30 | import org.onosproject.ui.table.RowComparator; |
... | @@ -32,6 +33,7 @@ import org.onosproject.ui.table.TableUtils; | ... | @@ -32,6 +33,7 @@ import org.onosproject.ui.table.TableUtils; |
32 | 33 | ||
33 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
34 | import java.util.Arrays; | 35 | import java.util.Arrays; |
36 | +import java.util.Collection; | ||
35 | import java.util.List; | 37 | import java.util.List; |
36 | import java.util.Map; | 38 | import java.util.Map; |
37 | 39 | ||
... | @@ -40,48 +42,52 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; | ... | @@ -40,48 +42,52 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; |
40 | /** | 42 | /** |
41 | * Message handler for link view related messages. | 43 | * Message handler for link view related messages. |
42 | */ | 44 | */ |
43 | -public class LinkViewMessageHandler extends UiMessageHandler { | 45 | +public class LinkViewMessageHandler extends UiMessageHandlerTwo { |
46 | + | ||
47 | + private static final String LINK_DATA_REQ = "linkDataRequest"; | ||
44 | 48 | ||
45 | - /** | ||
46 | - * Creates a new message handler for the link messages. | ||
47 | - */ | ||
48 | - protected LinkViewMessageHandler() { | ||
49 | - super(ImmutableSet.of("linkDataRequest")); | ||
50 | - } | ||
51 | 49 | ||
52 | @Override | 50 | @Override |
53 | - public void process(ObjectNode message) { | 51 | + protected Collection<RequestHandler> getHandlers() { |
54 | - String type = eventType(message); | 52 | + return ImmutableSet.of(new LinkDataRequest()); |
55 | - if (type.equals("linkDataRequest")) { | ||
56 | - sendLinkList(message); | ||
57 | - } | ||
58 | } | 53 | } |
59 | 54 | ||
60 | - private void sendLinkList(ObjectNode message) { | 55 | + // ====================================================================== |
61 | - ObjectNode payload = payload(message); | ||
62 | - RowComparator rc = TableUtils.createRowComparator(payload, "one"); | ||
63 | 56 | ||
64 | - LinkService service = get(LinkService.class); | 57 | + private final class LinkDataRequest extends RequestHandler { |
65 | - TableRow[] rows = generateTableRows(service); | ||
66 | - Arrays.sort(rows, rc); | ||
67 | - ObjectNode rootNode = mapper.createObjectNode(); | ||
68 | - rootNode.set("links", TableUtils.generateArrayNode(rows)); | ||
69 | 58 | ||
70 | - connection().sendMessage("linkDataResponse", 0, rootNode); | 59 | + private LinkDataRequest() { |
71 | - } | 60 | + super(LINK_DATA_REQ); |
61 | + } | ||
72 | 62 | ||
73 | - private TableRow[] generateTableRows(LinkService service) { | 63 | + @Override |
74 | - List<TableRow> list = new ArrayList<>(); | 64 | + public void process(long sid, ObjectNode payload) { |
65 | + RowComparator rc = TableUtils.createRowComparator(payload, "one"); | ||
66 | + | ||
67 | + LinkService service = get(LinkService.class); | ||
68 | + TableRow[] rows = generateTableRows(service); | ||
69 | + Arrays.sort(rows, rc); | ||
70 | + ObjectNode rootNode = MAPPER.createObjectNode(); | ||
71 | + rootNode.set("links", TableUtils.generateArrayNode(rows)); | ||
72 | + | ||
73 | + sendMessage("linkDataResponse", 0, rootNode); | ||
74 | + } | ||
75 | 75 | ||
76 | - // First consolidate all uni-directional links into two-directional ones. | 76 | + private TableRow[] generateTableRows(LinkService service) { |
77 | - Map<LinkKey, BiLink> biLinks = Maps.newHashMap(); | 77 | + List<TableRow> list = new ArrayList<>(); |
78 | - service.getLinks().forEach(link -> addLink(biLinks, link)); | ||
79 | 78 | ||
80 | - // Now scan over all bi-links and produce table rows from them. | 79 | + // First consolidate all uni-directional links into two-directional ones. |
81 | - biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink))); | 80 | + Map<LinkKey, BiLink> biLinks = Maps.newHashMap(); |
82 | - return list.toArray(new TableRow[list.size()]); | 81 | + service.getLinks().forEach(link -> addLink(biLinks, link)); |
82 | + | ||
83 | + // Now scan over all bi-links and produce table rows from them. | ||
84 | + biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink))); | ||
85 | + return list.toArray(new TableRow[list.size()]); | ||
86 | + } | ||
83 | } | 87 | } |
84 | 88 | ||
89 | + // ====================================================================== | ||
90 | + | ||
85 | /** | 91 | /** |
86 | * TableRow implementation for {@link org.onosproject.net.Link links}. | 92 | * TableRow implementation for {@link org.onosproject.net.Link links}. |
87 | */ | 93 | */ | ... | ... |
... | @@ -54,9 +54,12 @@ import org.onosproject.net.intent.IntentListener; | ... | @@ -54,9 +54,12 @@ import org.onosproject.net.intent.IntentListener; |
54 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 54 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
55 | import org.onosproject.net.link.LinkEvent; | 55 | import org.onosproject.net.link.LinkEvent; |
56 | import org.onosproject.net.link.LinkListener; | 56 | import org.onosproject.net.link.LinkListener; |
57 | +import org.onosproject.ui.JsonUtils; | ||
58 | +import org.onosproject.ui.RequestHandler; | ||
57 | import org.onosproject.ui.UiConnection; | 59 | import org.onosproject.ui.UiConnection; |
58 | 60 | ||
59 | import java.util.ArrayList; | 61 | import java.util.ArrayList; |
62 | +import java.util.Collection; | ||
60 | import java.util.Collections; | 63 | import java.util.Collections; |
61 | import java.util.Comparator; | 64 | import java.util.Comparator; |
62 | import java.util.HashSet; | 65 | import java.util.HashSet; |
... | @@ -79,6 +82,26 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; | ... | @@ -79,6 +82,26 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; |
79 | */ | 82 | */ |
80 | public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | 83 | public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
81 | 84 | ||
85 | + private static final String REQ_DETAILS = "requestDetails"; | ||
86 | + private static final String UPDATE_META = "updateMeta"; | ||
87 | + private static final String ADD_HOST_INTENT = "addHostIntent"; | ||
88 | + private static final String ADD_MULTI_SRC_INTENT = "addMultiSourceIntent"; | ||
89 | + private static final String REQ_RELATED_INTENTS = "requestRelatedIntents"; | ||
90 | + private static final String REQ_NEXT_INTENT = "requestNextRelatedIntent"; | ||
91 | + private static final String REQ_PREV_INTENT = "requestPrevRelatedIntent"; | ||
92 | + private static final String REQ_SEL_INTENT_TRAFFIC = "requestSelectedIntentTraffic"; | ||
93 | + private static final String REQ_ALL_TRAFFIC = "requestAllTraffic"; | ||
94 | + private static final String REQ_DEV_LINK_FLOWS = "requestDeviceLinkFlows"; | ||
95 | + private static final String CANCEL_TRAFFIC = "cancelTraffic"; | ||
96 | + private static final String REQ_SUMMARY = "requestSummary"; | ||
97 | + private static final String CANCEL_SUMMARY = "cancelSummary"; | ||
98 | + private static final String EQ_MASTERS = "equalizeMasters"; | ||
99 | + private static final String SPRITE_LIST_REQ = "spriteListRequest"; | ||
100 | + private static final String SPRITE_DATA_REQ = "spriteDataRequest"; | ||
101 | + private static final String TOPO_START = "topoStart"; | ||
102 | + private static final String TOPO_STOP = "topoStop"; | ||
103 | + | ||
104 | + | ||
82 | private static final String APP_ID = "org.onosproject.gui"; | 105 | private static final String APP_ID = "org.onosproject.gui"; |
83 | 106 | ||
84 | private static final long TRAFFIC_FREQUENCY = 5000; | 107 | private static final long TRAFFIC_FREQUENCY = 5000; |
... | @@ -111,11 +134,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -111,11 +134,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
111 | 134 | ||
112 | private final Accumulator<Event> eventAccummulator = new InternalEventAccummulator(); | 135 | private final Accumulator<Event> eventAccummulator = new InternalEventAccummulator(); |
113 | 136 | ||
114 | - private TimerTask trafficTask; | 137 | + private TimerTask trafficTask = null; |
115 | - private ObjectNode trafficEvent; | 138 | + private TrafficEvent trafficEvent = null; |
116 | 139 | ||
117 | - private TimerTask summaryTask; | 140 | + private TimerTask summaryTask = null; |
118 | - private ObjectNode summaryEvent; | 141 | + private boolean summaryRunning = false; |
119 | 142 | ||
120 | private boolean listenersRemoved = false; | 143 | private boolean listenersRemoved = false; |
121 | 144 | ||
... | @@ -127,30 +150,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -127,30 +150,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
127 | private List<Intent> selectedIntents; | 150 | private List<Intent> selectedIntents; |
128 | private int currentIntentIndex = -1; | 151 | private int currentIntentIndex = -1; |
129 | 152 | ||
130 | - /** | ||
131 | - * Creates a new web-socket for serving data to GUI topology view. | ||
132 | - */ | ||
133 | - public TopologyViewMessageHandler() { | ||
134 | - super(ImmutableSet.of("topoStart", | ||
135 | - "topoStop", | ||
136 | - "requestDetails", | ||
137 | - "updateMeta", | ||
138 | - "addHostIntent", | ||
139 | - "addMultiSourceIntent", | ||
140 | - "requestRelatedIntents", | ||
141 | - "requestNextRelatedIntent", | ||
142 | - "requestPrevRelatedIntent", | ||
143 | - "requestSelectedIntentTraffic", | ||
144 | - "requestAllTraffic", | ||
145 | - "requestDeviceLinkFlows", | ||
146 | - "cancelTraffic", | ||
147 | - "requestSummary", | ||
148 | - "cancelSummary", | ||
149 | - "equalizeMasters", | ||
150 | - "spriteListRequest", | ||
151 | - "spriteDataRequest" | ||
152 | - )); | ||
153 | - } | ||
154 | 153 | ||
155 | @Override | 154 | @Override |
156 | public void init(UiConnection connection, ServiceDirectory directory) { | 155 | public void init(UiConnection connection, ServiceDirectory directory) { |
... | @@ -167,66 +166,326 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -167,66 +166,326 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
167 | super.destroy(); | 166 | super.destroy(); |
168 | } | 167 | } |
169 | 168 | ||
170 | - // Processes the specified event. | ||
171 | @Override | 169 | @Override |
172 | - public void process(ObjectNode event) { | 170 | + protected Collection<RequestHandler> getHandlers() { |
173 | - String type = string(event, "event", "unknown"); | 171 | + return ImmutableSet.of( |
174 | - if (type.equals("requestDetails")) { | 172 | + new TopoStart(), |
175 | - requestDetails(event); | 173 | + new TopoStop(), |
176 | - } else if (type.equals("updateMeta")) { | 174 | + new ReqSummary(), |
177 | - updateMetaUi(event); | 175 | + new CancelSummary(), |
178 | - | 176 | + new SpriteListReq(), |
179 | - } else if (type.equals("addHostIntent")) { | 177 | + new SpriteDataReq(), |
180 | - createHostIntent(event); | 178 | + new RequestDetails(), |
181 | - } else if (type.equals("addMultiSourceIntent")) { | 179 | + new UpdateMeta(), |
182 | - createMultiSourceIntent(event); | 180 | + new EqMasters(), |
183 | - | 181 | + |
184 | - } else if (type.equals("requestRelatedIntents")) { | 182 | + // TODO: migrate traffic related to separate app |
183 | + new AddHostIntent(), | ||
184 | + new AddMultiSourceIntent(), | ||
185 | + new ReqRelatedIntents(), | ||
186 | + new ReqNextIntent(), | ||
187 | + new ReqPrevIntent(), | ||
188 | + new ReqSelectedIntentTraffic(), | ||
189 | + new ReqAllTraffic(), | ||
190 | + new ReqDevLinkFlows(), | ||
191 | + new CancelTraffic() | ||
192 | + ); | ||
193 | + } | ||
194 | + | ||
195 | + // ================================================================== | ||
196 | + | ||
197 | + private final class TopoStart extends RequestHandler { | ||
198 | + private TopoStart() { | ||
199 | + super(TOPO_START); | ||
200 | + } | ||
201 | + | ||
202 | + @Override | ||
203 | + public void process(long sid, ObjectNode payload) { | ||
204 | + addListeners(); | ||
205 | + sendAllInstances(null); | ||
206 | + sendAllDevices(); | ||
207 | + sendAllLinks(); | ||
208 | + sendAllHosts(); | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + private final class TopoStop extends RequestHandler { | ||
213 | + private TopoStop() { | ||
214 | + super(TOPO_STOP); | ||
215 | + } | ||
216 | + | ||
217 | + @Override | ||
218 | + public void process(long sid, ObjectNode payload) { | ||
219 | + stopSummaryMonitoring(); | ||
220 | + stopTrafficMonitoring(); | ||
221 | + } | ||
222 | + } | ||
223 | + | ||
224 | + private final class ReqSummary extends RequestHandler { | ||
225 | + private ReqSummary() { | ||
226 | + super(REQ_SUMMARY); | ||
227 | + } | ||
228 | + | ||
229 | + @Override | ||
230 | + public void process(long sid, ObjectNode payload) { | ||
231 | + requestSummary(sid); | ||
232 | + startSummaryMonitoring(); | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + private final class CancelSummary extends RequestHandler { | ||
237 | + private CancelSummary() { | ||
238 | + super(CANCEL_SUMMARY); | ||
239 | + } | ||
240 | + | ||
241 | + @Override | ||
242 | + public void process(long sid, ObjectNode payload) { | ||
243 | + stopSummaryMonitoring(); | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + private final class SpriteListReq extends RequestHandler { | ||
248 | + private SpriteListReq() { | ||
249 | + super(SPRITE_LIST_REQ); | ||
250 | + } | ||
251 | + | ||
252 | + @Override | ||
253 | + public void process(long sid, ObjectNode payload) { | ||
254 | + ObjectNode root = mapper.createObjectNode(); | ||
255 | + ArrayNode names = mapper.createArrayNode(); | ||
256 | + get(SpriteService.class).getNames().forEach(names::add); | ||
257 | + root.set("names", names); | ||
258 | + sendMessage("spriteListResponse", sid, root); | ||
259 | + } | ||
260 | + } | ||
261 | + | ||
262 | + private final class SpriteDataReq extends RequestHandler { | ||
263 | + private SpriteDataReq() { | ||
264 | + super(SPRITE_DATA_REQ); | ||
265 | + } | ||
266 | + | ||
267 | + @Override | ||
268 | + public void process(long sid, ObjectNode payload) { | ||
269 | + String name = string(payload, "name"); | ||
270 | + ObjectNode root = mapper.createObjectNode(); | ||
271 | + root.set("data", get(SpriteService.class).get(name)); | ||
272 | + sendMessage("spriteDataResponse", sid, root); | ||
273 | + } | ||
274 | + } | ||
275 | + | ||
276 | + private final class RequestDetails extends RequestHandler { | ||
277 | + private RequestDetails() { | ||
278 | + super(REQ_DETAILS); | ||
279 | + } | ||
280 | + | ||
281 | + @Override | ||
282 | + public void process(long sid, ObjectNode payload) { | ||
283 | + String type = string(payload, "class", "unknown"); | ||
284 | + String id = JsonUtils.string(payload, "id"); | ||
285 | + | ||
286 | + if (type.equals("device")) { | ||
287 | + sendMessage(deviceDetails(deviceId(id), sid)); | ||
288 | + } else if (type.equals("host")) { | ||
289 | + sendMessage(hostDetails(hostId(id), sid)); | ||
290 | + } | ||
291 | + } | ||
292 | + } | ||
293 | + | ||
294 | + private final class UpdateMeta extends RequestHandler { | ||
295 | + private UpdateMeta() { | ||
296 | + super(UPDATE_META); | ||
297 | + } | ||
298 | + | ||
299 | + @Override | ||
300 | + public void process(long sid, ObjectNode payload) { | ||
301 | + updateMetaUi(payload); | ||
302 | + } | ||
303 | + } | ||
304 | + | ||
305 | + private final class EqMasters extends RequestHandler { | ||
306 | + private EqMasters() { | ||
307 | + super(EQ_MASTERS); | ||
308 | + } | ||
309 | + | ||
310 | + @Override | ||
311 | + public void process(long sid, ObjectNode payload) { | ||
312 | + directory.get(MastershipAdminService.class).balanceRoles(); | ||
313 | + } | ||
314 | + } | ||
315 | + | ||
316 | + // === TODO: move traffic related classes to traffic app | ||
317 | + | ||
318 | + private final class AddHostIntent extends RequestHandler { | ||
319 | + private AddHostIntent() { | ||
320 | + super(ADD_HOST_INTENT); | ||
321 | + } | ||
322 | + | ||
323 | + @Override | ||
324 | + public void process(long sid, ObjectNode payload) { | ||
325 | + // TODO: add protection against device ids and non-existent hosts. | ||
326 | + HostId one = hostId(string(payload, "one")); | ||
327 | + HostId two = hostId(string(payload, "two")); | ||
328 | + | ||
329 | + HostToHostIntent intent = HostToHostIntent.builder() | ||
330 | + .appId(appId) | ||
331 | + .one(one) | ||
332 | + .two(two) | ||
333 | + .build(); | ||
334 | + | ||
335 | + intentService.submit(intent); | ||
336 | + startMonitoringIntent(intent); | ||
337 | + } | ||
338 | + } | ||
339 | + | ||
340 | + private final class AddMultiSourceIntent extends RequestHandler { | ||
341 | + private AddMultiSourceIntent() { | ||
342 | + super(ADD_MULTI_SRC_INTENT); | ||
343 | + } | ||
344 | + | ||
345 | + @Override | ||
346 | + public void process(long sid, ObjectNode payload) { | ||
347 | + // TODO: add protection against device ids and non-existent hosts. | ||
348 | + Set<HostId> src = getHostIds((ArrayNode) payload.path("src")); | ||
349 | + HostId dst = hostId(string(payload, "dst")); | ||
350 | + Host dstHost = hostService.getHost(dst); | ||
351 | + | ||
352 | + Set<ConnectPoint> ingressPoints = getHostLocations(src); | ||
353 | + | ||
354 | + // FIXME: clearly, this is not enough | ||
355 | + TrafficSelector selector = DefaultTrafficSelector.builder() | ||
356 | + .matchEthDst(dstHost.mac()).build(); | ||
357 | + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | ||
358 | + | ||
359 | + MultiPointToSinglePointIntent intent = | ||
360 | + MultiPointToSinglePointIntent.builder() | ||
361 | + .appId(appId) | ||
362 | + .selector(selector) | ||
363 | + .treatment(treatment) | ||
364 | + .ingressPoints(ingressPoints) | ||
365 | + .egressPoint(dstHost.location()) | ||
366 | + .build(); | ||
367 | + | ||
368 | + intentService.submit(intent); | ||
369 | + startMonitoringIntent(intent); | ||
370 | + } | ||
371 | + } | ||
372 | + | ||
373 | + private final class ReqRelatedIntents extends RequestHandler { | ||
374 | + private ReqRelatedIntents() { | ||
375 | + super(REQ_RELATED_INTENTS); | ||
376 | + } | ||
377 | + | ||
378 | + @Override | ||
379 | + public void process(long sid, ObjectNode payload) { | ||
380 | + // Cancel any other traffic monitoring mode. | ||
185 | stopTrafficMonitoring(); | 381 | stopTrafficMonitoring(); |
186 | - requestRelatedIntents(event); | ||
187 | 382 | ||
188 | - } else if (type.equals("requestNextRelatedIntent")) { | 383 | + if (!payload.has("ids")) { |
384 | + return; | ||
385 | + } | ||
386 | + | ||
387 | + // Get the set of selected hosts and their intents. | ||
388 | + ArrayNode ids = (ArrayNode) payload.path("ids"); | ||
389 | + selectedHosts = getHosts(ids); | ||
390 | + selectedDevices = getDevices(ids); | ||
391 | + selectedIntents = intentFilter.findPathIntents( | ||
392 | + selectedHosts, selectedDevices, intentService.getIntents()); | ||
393 | + currentIntentIndex = -1; | ||
394 | + | ||
395 | + if (haveSelectedIntents()) { | ||
396 | + // Send a message to highlight all links of all monitored intents. | ||
397 | + sendMessage(trafficMessage(new TrafficClass("primary", selectedIntents))); | ||
398 | + } | ||
399 | + | ||
400 | + // TODO: Re-introduce once the client click vs hover gesture stuff is sorted out. | ||
401 | +// String hover = string(payload, "hover"); | ||
402 | +// if (!isNullOrEmpty(hover)) { | ||
403 | +// // If there is a hover node, include it in the selection and find intents. | ||
404 | +// processHoverExtendedSelection(sid, hover); | ||
405 | +// } | ||
406 | + } | ||
407 | + } | ||
408 | + | ||
409 | + private final class ReqNextIntent extends RequestHandler { | ||
410 | + private ReqNextIntent() { | ||
411 | + super(REQ_NEXT_INTENT); | ||
412 | + } | ||
413 | + | ||
414 | + @Override | ||
415 | + public void process(long sid, ObjectNode payload) { | ||
189 | stopTrafficMonitoring(); | 416 | stopTrafficMonitoring(); |
190 | - requestAnotherRelatedIntent(event, +1); | 417 | + requestAnotherRelatedIntent(+1); |
191 | - } else if (type.equals("requestPrevRelatedIntent")) { | 418 | + } |
419 | + } | ||
420 | + | ||
421 | + private final class ReqPrevIntent extends RequestHandler { | ||
422 | + private ReqPrevIntent() { | ||
423 | + super(REQ_PREV_INTENT); | ||
424 | + } | ||
425 | + | ||
426 | + @Override | ||
427 | + public void process(long sid, ObjectNode payload) { | ||
192 | stopTrafficMonitoring(); | 428 | stopTrafficMonitoring(); |
193 | - requestAnotherRelatedIntent(event, -1); | 429 | + requestAnotherRelatedIntent(-1); |
194 | - } else if (type.equals("requestSelectedIntentTraffic")) { | 430 | + } |
195 | - requestSelectedIntentTraffic(event); | 431 | + } |
196 | - startTrafficMonitoring(event); | ||
197 | - | ||
198 | - } else if (type.equals("requestAllTraffic")) { | ||
199 | - requestAllTraffic(event); | ||
200 | - startTrafficMonitoring(event); | ||
201 | - | ||
202 | - } else if (type.equals("requestDeviceLinkFlows")) { | ||
203 | - requestDeviceLinkFlows(event); | ||
204 | - startTrafficMonitoring(event); | ||
205 | - | ||
206 | - } else if (type.equals("cancelTraffic")) { | ||
207 | - cancelTraffic(event); | ||
208 | - | ||
209 | - } else if (type.equals("requestSummary")) { | ||
210 | - requestSummary(event); | ||
211 | - startSummaryMonitoring(event); | ||
212 | - } else if (type.equals("cancelSummary")) { | ||
213 | - stopSummaryMonitoring(); | ||
214 | 432 | ||
215 | - } else if (type.equals("equalizeMasters")) { | 433 | + private final class ReqSelectedIntentTraffic extends RequestHandler { |
216 | - equalizeMasters(event); | 434 | + private ReqSelectedIntentTraffic() { |
435 | + super(REQ_SEL_INTENT_TRAFFIC); | ||
436 | + } | ||
217 | 437 | ||
218 | - } else if (type.equals("spriteListRequest")) { | 438 | + @Override |
219 | - sendSpriteList(event); | 439 | + public void process(long sid, ObjectNode payload) { |
220 | - } else if (type.equals("spriteDataRequest")) { | 440 | + trafficEvent = |
221 | - sendSpriteData(event); | 441 | + new TrafficEvent(TrafficEvent.Type.SEL_INTENT, payload); |
442 | + requestSelectedIntentTraffic(); | ||
443 | + startTrafficMonitoring(); | ||
444 | + } | ||
445 | + } | ||
222 | 446 | ||
223 | - } else if (type.equals("topoStart")) { | 447 | + private final class ReqAllTraffic extends RequestHandler { |
224 | - sendAllInitialData(); | 448 | + private ReqAllTraffic() { |
225 | - } else if (type.equals("topoStop")) { | 449 | + super(REQ_ALL_TRAFFIC); |
226 | - cancelAllRequests(); | 450 | + } |
451 | + | ||
452 | + @Override | ||
453 | + public void process(long sid, ObjectNode payload) { | ||
454 | + trafficEvent = | ||
455 | + new TrafficEvent(TrafficEvent.Type.ALL_TRAFFIC, payload); | ||
456 | + requestAllTraffic(); | ||
227 | } | 457 | } |
228 | } | 458 | } |
229 | 459 | ||
460 | + private final class ReqDevLinkFlows extends RequestHandler { | ||
461 | + private ReqDevLinkFlows() { | ||
462 | + super(REQ_DEV_LINK_FLOWS); | ||
463 | + } | ||
464 | + | ||
465 | + @Override | ||
466 | + public void process(long sid, ObjectNode payload) { | ||
467 | + trafficEvent = | ||
468 | + new TrafficEvent(TrafficEvent.Type.DEV_LINK_FLOWS, payload); | ||
469 | + requestDeviceLinkFlows(payload); | ||
470 | + } | ||
471 | + } | ||
472 | + | ||
473 | + private final class CancelTraffic extends RequestHandler { | ||
474 | + private CancelTraffic() { | ||
475 | + super(CANCEL_TRAFFIC); | ||
476 | + } | ||
477 | + | ||
478 | + @Override | ||
479 | + public void process(long sid, ObjectNode payload) { | ||
480 | + selectedIntents = null; | ||
481 | + sendMessage(trafficMessage()); | ||
482 | + stopTrafficMonitoring(); | ||
483 | + } | ||
484 | + } | ||
485 | + | ||
486 | + //======================================================================= | ||
487 | + | ||
488 | + | ||
230 | // Sends the specified data to the client. | 489 | // Sends the specified data to the client. |
231 | protected synchronized void sendMessage(ObjectNode data) { | 490 | protected synchronized void sendMessage(ObjectNode data) { |
232 | UiConnection connection = connection(); | 491 | UiConnection connection = connection(); |
... | @@ -235,15 +494,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -235,15 +494,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
235 | } | 494 | } |
236 | } | 495 | } |
237 | 496 | ||
238 | - private void sendAllInitialData() { | 497 | + // Subscribes for summary messages. |
239 | - addListeners(); | 498 | + private synchronized void requestSummary(long sid) { |
240 | - sendAllInstances(null); | 499 | + sendMessage(summmaryMessage(sid)); |
241 | - sendAllDevices(); | ||
242 | - sendAllLinks(); | ||
243 | - sendAllHosts(); | ||
244 | - | ||
245 | } | 500 | } |
246 | 501 | ||
502 | + | ||
247 | private void cancelAllRequests() { | 503 | private void cancelAllRequests() { |
248 | stopSummaryMonitoring(); | 504 | stopSummaryMonitoring(); |
249 | stopTrafficMonitoring(); | 505 | stopTrafficMonitoring(); |
... | @@ -296,77 +552,15 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -296,77 +552,15 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
296 | } | 552 | } |
297 | } | 553 | } |
298 | 554 | ||
299 | - // Sends back device or host details. | ||
300 | - private void requestDetails(ObjectNode event) { | ||
301 | - ObjectNode payload = payload(event); | ||
302 | - String type = string(payload, "class", "unknown"); | ||
303 | - long sid = number(event, "sid"); | ||
304 | - | ||
305 | - if (type.equals("device")) { | ||
306 | - sendMessage(deviceDetails(deviceId(string(payload, "id")), sid)); | ||
307 | - } else if (type.equals("host")) { | ||
308 | - sendMessage(hostDetails(hostId(string(payload, "id")), sid)); | ||
309 | - } | ||
310 | - } | ||
311 | - | ||
312 | - | ||
313 | - // Creates host-to-host intent. | ||
314 | - private void createHostIntent(ObjectNode event) { | ||
315 | - ObjectNode payload = payload(event); | ||
316 | - long id = number(event, "sid"); | ||
317 | - // TODO: add protection against device ids and non-existent hosts. | ||
318 | - HostId one = hostId(string(payload, "one")); | ||
319 | - HostId two = hostId(string(payload, "two")); | ||
320 | - | ||
321 | - HostToHostIntent intent = | ||
322 | - HostToHostIntent.builder() | ||
323 | - .appId(appId) | ||
324 | - .one(one) | ||
325 | - .two(two) | ||
326 | - .build(); | ||
327 | - | ||
328 | - intentService.submit(intent); | ||
329 | - startMonitoringIntent(event, intent); | ||
330 | - } | ||
331 | - | ||
332 | - // Creates multi-source-to-single-dest intent. | ||
333 | - private void createMultiSourceIntent(ObjectNode event) { | ||
334 | - ObjectNode payload = payload(event); | ||
335 | - long id = number(event, "sid"); | ||
336 | - // TODO: add protection against device ids and non-existent hosts. | ||
337 | - Set<HostId> src = getHostIds((ArrayNode) payload.path("src")); | ||
338 | - HostId dst = hostId(string(payload, "dst")); | ||
339 | - Host dstHost = hostService.getHost(dst); | ||
340 | 555 | ||
341 | - Set<ConnectPoint> ingressPoints = getHostLocations(src); | 556 | + private synchronized void startMonitoringIntent(Intent intent) { |
342 | - | ||
343 | - // FIXME: clearly, this is not enough | ||
344 | - TrafficSelector selector = DefaultTrafficSelector.builder() | ||
345 | - .matchEthDst(dstHost.mac()).build(); | ||
346 | - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | ||
347 | - | ||
348 | - MultiPointToSinglePointIntent intent = | ||
349 | - MultiPointToSinglePointIntent.builder() | ||
350 | - .appId(appId) | ||
351 | - .selector(selector) | ||
352 | - .treatment(treatment) | ||
353 | - .ingressPoints(ingressPoints) | ||
354 | - .egressPoint(dstHost.location()) | ||
355 | - .build(); | ||
356 | - | ||
357 | - intentService.submit(intent); | ||
358 | - startMonitoringIntent(event, intent); | ||
359 | - } | ||
360 | - | ||
361 | - | ||
362 | - private synchronized void startMonitoringIntent(ObjectNode event, Intent intent) { | ||
363 | selectedHosts = new HashSet<>(); | 557 | selectedHosts = new HashSet<>(); |
364 | selectedDevices = new HashSet<>(); | 558 | selectedDevices = new HashSet<>(); |
365 | selectedIntents = new ArrayList<>(); | 559 | selectedIntents = new ArrayList<>(); |
366 | selectedIntents.add(intent); | 560 | selectedIntents.add(intent); |
367 | currentIntentIndex = -1; | 561 | currentIntentIndex = -1; |
368 | - requestAnotherRelatedIntent(event, +1); | 562 | + requestAnotherRelatedIntent(+1); |
369 | - requestSelectedIntentTraffic(event); | 563 | + requestSelectedIntentTraffic(); |
370 | } | 564 | } |
371 | 565 | ||
372 | 566 | ||
... | @@ -392,31 +586,27 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -392,31 +586,27 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
392 | } | 586 | } |
393 | 587 | ||
394 | 588 | ||
395 | - private synchronized long startTrafficMonitoring(ObjectNode event) { | 589 | + private synchronized void startTrafficMonitoring() { |
396 | stopTrafficMonitoring(); | 590 | stopTrafficMonitoring(); |
397 | - trafficEvent = event; | ||
398 | trafficTask = new TrafficMonitor(); | 591 | trafficTask = new TrafficMonitor(); |
399 | timer.schedule(trafficTask, TRAFFIC_FREQUENCY, TRAFFIC_FREQUENCY); | 592 | timer.schedule(trafficTask, TRAFFIC_FREQUENCY, TRAFFIC_FREQUENCY); |
400 | - return number(event, "sid"); | ||
401 | } | 593 | } |
402 | 594 | ||
403 | private synchronized void stopTrafficMonitoring() { | 595 | private synchronized void stopTrafficMonitoring() { |
404 | if (trafficTask != null) { | 596 | if (trafficTask != null) { |
405 | trafficTask.cancel(); | 597 | trafficTask.cancel(); |
406 | trafficTask = null; | 598 | trafficTask = null; |
407 | - trafficEvent = null; | ||
408 | } | 599 | } |
409 | } | 600 | } |
410 | 601 | ||
411 | // Subscribes for host traffic messages. | 602 | // Subscribes for host traffic messages. |
412 | - private synchronized void requestAllTraffic(ObjectNode event) { | 603 | + private synchronized void requestAllTraffic() { |
413 | - long sid = startTrafficMonitoring(event); | 604 | + startTrafficMonitoring(); |
414 | - sendMessage(trafficSummaryMessage(sid)); | 605 | + sendMessage(trafficSummaryMessage()); |
415 | } | 606 | } |
416 | 607 | ||
417 | - private void requestDeviceLinkFlows(ObjectNode event) { | 608 | + private void requestDeviceLinkFlows(ObjectNode payload) { |
418 | - ObjectNode payload = payload(event); | 609 | + startTrafficMonitoring(); |
419 | - long sid = startTrafficMonitoring(event); | ||
420 | 610 | ||
421 | // Get the set of selected hosts and their intents. | 611 | // Get the set of selected hosts and their intents. |
422 | ArrayNode ids = (ArrayNode) payload.path("ids"); | 612 | ArrayNode ids = (ArrayNode) payload.path("ids"); |
... | @@ -424,47 +614,14 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -424,47 +614,14 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
424 | Set<Device> devices = getDevices(ids); | 614 | Set<Device> devices = getDevices(ids); |
425 | 615 | ||
426 | // If there is a hover node, include it in the hosts and find intents. | 616 | // If there is a hover node, include it in the hosts and find intents. |
427 | - String hover = string(payload, "hover"); | 617 | + String hover = JsonUtils.string(payload, "hover"); |
428 | if (!isNullOrEmpty(hover)) { | 618 | if (!isNullOrEmpty(hover)) { |
429 | addHover(hosts, devices, hover); | 619 | addHover(hosts, devices, hover); |
430 | } | 620 | } |
431 | - sendMessage(flowSummaryMessage(sid, devices)); | 621 | + sendMessage(flowSummaryMessage(devices)); |
432 | } | 622 | } |
433 | 623 | ||
434 | 624 | ||
435 | - // Requests related intents message. | ||
436 | - private synchronized void requestRelatedIntents(ObjectNode event) { | ||
437 | - ObjectNode payload = payload(event); | ||
438 | - if (!payload.has("ids")) { | ||
439 | - return; | ||
440 | - } | ||
441 | - | ||
442 | - long sid = number(event, "sid"); | ||
443 | - | ||
444 | - // Cancel any other traffic monitoring mode. | ||
445 | - stopTrafficMonitoring(); | ||
446 | - | ||
447 | - // Get the set of selected hosts and their intents. | ||
448 | - ArrayNode ids = (ArrayNode) payload.path("ids"); | ||
449 | - selectedHosts = getHosts(ids); | ||
450 | - selectedDevices = getDevices(ids); | ||
451 | - selectedIntents = intentFilter.findPathIntents(selectedHosts, selectedDevices, | ||
452 | - intentService.getIntents()); | ||
453 | - currentIntentIndex = -1; | ||
454 | - | ||
455 | - if (haveSelectedIntents()) { | ||
456 | - // Send a message to highlight all links of all monitored intents. | ||
457 | - sendMessage(trafficMessage(sid, new TrafficClass("primary", selectedIntents))); | ||
458 | - } | ||
459 | - | ||
460 | - // FIXME: Re-introduce one the client click vs hover gesture stuff is sorted out. | ||
461 | -// String hover = string(payload, "hover"); | ||
462 | -// if (!isNullOrEmpty(hover)) { | ||
463 | -// // If there is a hover node, include it in the selection and find intents. | ||
464 | -// processHoverExtendedSelection(sid, hover); | ||
465 | -// } | ||
466 | - } | ||
467 | - | ||
468 | private boolean haveSelectedIntents() { | 625 | private boolean haveSelectedIntents() { |
469 | return selectedIntents != null && !selectedIntents.isEmpty(); | 626 | return selectedIntents != null && !selectedIntents.isEmpty(); |
470 | } | 627 | } |
... | @@ -483,12 +640,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -483,12 +640,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
483 | secondary.removeAll(primary); | 640 | secondary.removeAll(primary); |
484 | 641 | ||
485 | // Send a message to highlight all links of all monitored intents. | 642 | // Send a message to highlight all links of all monitored intents. |
486 | - sendMessage(trafficMessage(sid, new TrafficClass("primary", primary), | 643 | + sendMessage(trafficMessage(new TrafficClass("primary", primary), |
487 | new TrafficClass("secondary", secondary))); | 644 | new TrafficClass("secondary", secondary))); |
488 | } | 645 | } |
489 | 646 | ||
490 | // Requests next or previous related intent. | 647 | // Requests next or previous related intent. |
491 | - private void requestAnotherRelatedIntent(ObjectNode event, int offset) { | 648 | + private void requestAnotherRelatedIntent(int offset) { |
492 | if (haveSelectedIntents()) { | 649 | if (haveSelectedIntents()) { |
493 | currentIntentIndex = currentIntentIndex + offset; | 650 | currentIntentIndex = currentIntentIndex + offset; |
494 | if (currentIntentIndex < 0) { | 651 | if (currentIntentIndex < 0) { |
... | @@ -496,13 +653,13 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -496,13 +653,13 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
496 | } else if (currentIntentIndex >= selectedIntents.size()) { | 653 | } else if (currentIntentIndex >= selectedIntents.size()) { |
497 | currentIntentIndex = 0; | 654 | currentIntentIndex = 0; |
498 | } | 655 | } |
499 | - sendSelectedIntent(event); | 656 | + sendSelectedIntent(); |
500 | } | 657 | } |
501 | } | 658 | } |
502 | 659 | ||
503 | // Sends traffic information on the related intents with the currently | 660 | // Sends traffic information on the related intents with the currently |
504 | // selected intent highlighted. | 661 | // selected intent highlighted. |
505 | - private void sendSelectedIntent(ObjectNode event) { | 662 | + private void sendSelectedIntent() { |
506 | Intent selectedIntent = selectedIntents.get(currentIntentIndex); | 663 | Intent selectedIntent = selectedIntents.get(currentIntentIndex); |
507 | log.info("Requested next intent {}", selectedIntent.id()); | 664 | log.info("Requested next intent {}", selectedIntent.id()); |
508 | 665 | ||
... | @@ -513,13 +670,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -513,13 +670,12 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
513 | secondary.remove(selectedIntent); | 670 | secondary.remove(selectedIntent); |
514 | 671 | ||
515 | // Send a message to highlight all links of the selected intent. | 672 | // Send a message to highlight all links of the selected intent. |
516 | - sendMessage(trafficMessage(number(event, "sid"), | 673 | + sendMessage(trafficMessage(new TrafficClass("primary", primary), |
517 | - new TrafficClass("primary", primary), | ||
518 | new TrafficClass("secondary", secondary))); | 674 | new TrafficClass("secondary", secondary))); |
519 | } | 675 | } |
520 | 676 | ||
521 | // Requests monitoring of traffic for the selected intent. | 677 | // Requests monitoring of traffic for the selected intent. |
522 | - private void requestSelectedIntentTraffic(ObjectNode event) { | 678 | + private void requestSelectedIntentTraffic() { |
523 | if (haveSelectedIntents()) { | 679 | if (haveSelectedIntents()) { |
524 | if (currentIntentIndex < 0) { | 680 | if (currentIntentIndex < 0) { |
525 | currentIntentIndex = 0; | 681 | currentIntentIndex = 0; |
... | @@ -531,61 +687,23 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -531,61 +687,23 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
531 | primary.add(selectedIntent); | 687 | primary.add(selectedIntent); |
532 | 688 | ||
533 | // Send a message to highlight all links of the selected intent. | 689 | // Send a message to highlight all links of the selected intent. |
534 | - sendMessage(trafficMessage(number(event, "sid"), | 690 | + sendMessage(trafficMessage(new TrafficClass("primary", primary, true))); |
535 | - new TrafficClass("primary", primary, true))); | ||
536 | } | 691 | } |
537 | } | 692 | } |
538 | 693 | ||
539 | - // Cancels sending traffic messages. | 694 | + private synchronized void startSummaryMonitoring() { |
540 | - private void cancelTraffic(ObjectNode event) { | ||
541 | - selectedIntents = null; | ||
542 | - sendMessage(trafficMessage(number(event, "sid"))); | ||
543 | - stopTrafficMonitoring(); | ||
544 | - } | ||
545 | - | ||
546 | - | ||
547 | - private synchronized long startSummaryMonitoring(ObjectNode event) { | ||
548 | stopSummaryMonitoring(); | 695 | stopSummaryMonitoring(); |
549 | - summaryEvent = event; | ||
550 | summaryTask = new SummaryMonitor(); | 696 | summaryTask = new SummaryMonitor(); |
551 | timer.schedule(summaryTask, SUMMARY_FREQUENCY, SUMMARY_FREQUENCY); | 697 | timer.schedule(summaryTask, SUMMARY_FREQUENCY, SUMMARY_FREQUENCY); |
552 | - return number(event, "sid"); | 698 | + summaryRunning = true; |
553 | } | 699 | } |
554 | 700 | ||
555 | private synchronized void stopSummaryMonitoring() { | 701 | private synchronized void stopSummaryMonitoring() { |
556 | - if (summaryEvent != null) { | 702 | + if (summaryTask != null) { |
557 | summaryTask.cancel(); | 703 | summaryTask.cancel(); |
558 | summaryTask = null; | 704 | summaryTask = null; |
559 | - summaryEvent = null; | ||
560 | } | 705 | } |
561 | - } | 706 | + summaryRunning = false; |
562 | - | ||
563 | - // Subscribes for summary messages. | ||
564 | - private synchronized void requestSummary(ObjectNode event) { | ||
565 | - sendMessage(summmaryMessage(number(event, "sid"))); | ||
566 | - } | ||
567 | - | ||
568 | - | ||
569 | - // Forces mastership role rebalancing. | ||
570 | - private void equalizeMasters(ObjectNode event) { | ||
571 | - directory.get(MastershipAdminService.class).balanceRoles(); | ||
572 | - } | ||
573 | - | ||
574 | - // Sends a list of sprite names. | ||
575 | - private void sendSpriteList(ObjectNode event) { | ||
576 | - ObjectNode root = mapper.createObjectNode(); | ||
577 | - ArrayNode names = mapper.createArrayNode(); | ||
578 | - get(SpriteService.class).getNames().forEach(names::add); | ||
579 | - root.set("names", names); | ||
580 | - sendMessage(envelope("spriteListResponse", number(event, "sid"), root)); | ||
581 | - } | ||
582 | - | ||
583 | - // Sends requested sprite data. | ||
584 | - private void sendSpriteData(ObjectNode event) { | ||
585 | - String name = event.path("payload").path("name").asText(); | ||
586 | - ObjectNode root = mapper.createObjectNode(); | ||
587 | - root.set("data", get(SpriteService.class).get(name)); | ||
588 | - sendMessage(envelope("spriteDataResponse", number(event, "sid"), root)); | ||
589 | } | 707 | } |
590 | 708 | ||
591 | 709 | ||
... | @@ -666,8 +784,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -666,8 +784,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
666 | private class InternalIntentListener implements IntentListener { | 784 | private class InternalIntentListener implements IntentListener { |
667 | @Override | 785 | @Override |
668 | public void event(IntentEvent event) { | 786 | public void event(IntentEvent event) { |
669 | - if (trafficEvent != null) { | 787 | + if (trafficTask != null) { |
670 | - requestSelectedIntentTraffic(trafficEvent); | 788 | + requestSelectedIntentTraffic(); |
671 | } | 789 | } |
672 | eventAccummulator.add(event); | 790 | eventAccummulator.add(event); |
673 | } | 791 | } |
... | @@ -681,19 +799,38 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -681,19 +799,38 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
681 | } | 799 | } |
682 | } | 800 | } |
683 | 801 | ||
802 | + // encapsulate | ||
803 | + private static class TrafficEvent { | ||
804 | + enum Type { ALL_TRAFFIC, DEV_LINK_FLOWS, SEL_INTENT } | ||
805 | + | ||
806 | + private final Type type; | ||
807 | + private final ObjectNode payload; | ||
808 | + | ||
809 | + TrafficEvent(Type type, ObjectNode payload) { | ||
810 | + this.type = type; | ||
811 | + this.payload = payload; | ||
812 | + } | ||
813 | + } | ||
814 | + | ||
684 | // Periodic update of the traffic information | 815 | // Periodic update of the traffic information |
685 | private class TrafficMonitor extends TimerTask { | 816 | private class TrafficMonitor extends TimerTask { |
686 | @Override | 817 | @Override |
687 | public void run() { | 818 | public void run() { |
688 | try { | 819 | try { |
689 | if (trafficEvent != null) { | 820 | if (trafficEvent != null) { |
690 | - String type = string(trafficEvent, "event", "unknown"); | 821 | + switch (trafficEvent.type) { |
691 | - if (type.equals("requestAllTraffic")) { | 822 | + case ALL_TRAFFIC: |
692 | - requestAllTraffic(trafficEvent); | 823 | + requestAllTraffic(); |
693 | - } else if (type.equals("requestDeviceLinkFlows")) { | 824 | + break; |
694 | - requestDeviceLinkFlows(trafficEvent); | 825 | + case DEV_LINK_FLOWS: |
695 | - } else if (type.equals("requestSelectedIntentTraffic")) { | 826 | + requestDeviceLinkFlows(trafficEvent.payload); |
696 | - requestSelectedIntentTraffic(trafficEvent); | 827 | + break; |
828 | + case SEL_INTENT: | ||
829 | + requestSelectedIntentTraffic(); | ||
830 | + break; | ||
831 | + default: | ||
832 | + // nothing to do | ||
833 | + break; | ||
697 | } | 834 | } |
698 | } | 835 | } |
699 | } catch (Exception e) { | 836 | } catch (Exception e) { |
... | @@ -708,8 +845,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -708,8 +845,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
708 | @Override | 845 | @Override |
709 | public void run() { | 846 | public void run() { |
710 | try { | 847 | try { |
711 | - if (summaryEvent != null) { | 848 | + if (summaryRunning) { |
712 | - requestSummary(summaryEvent); | 849 | + requestSummary(0); |
713 | } | 850 | } |
714 | } catch (Exception e) { | 851 | } catch (Exception e) { |
715 | log.warn("Unable to handle summary request due to {}", e.getMessage()); | 852 | log.warn("Unable to handle summary request due to {}", e.getMessage()); |
... | @@ -727,8 +864,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -727,8 +864,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
727 | @Override | 864 | @Override |
728 | public void processItems(List<Event> items) { | 865 | public void processItems(List<Event> items) { |
729 | try { | 866 | try { |
730 | - if (summaryEvent != null) { | 867 | + if (summaryRunning) { |
731 | - sendMessage(summmaryMessage(0)); | 868 | + requestSummary(0); |
732 | } | 869 | } |
733 | } catch (Exception e) { | 870 | } catch (Exception e) { |
734 | log.warn("Unable to handle summary request due to {}", e.getMessage()); | 871 | log.warn("Unable to handle summary request due to {}", e.getMessage()); |
... | @@ -737,4 +874,3 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -737,4 +874,3 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
737 | } | 874 | } |
738 | } | 875 | } |
739 | } | 876 | } |
740 | - | ... | ... |
... | @@ -63,8 +63,9 @@ import org.onosproject.net.statistic.Load; | ... | @@ -63,8 +63,9 @@ import org.onosproject.net.statistic.Load; |
63 | import org.onosproject.net.statistic.StatisticService; | 63 | import org.onosproject.net.statistic.StatisticService; |
64 | import org.onosproject.net.topology.Topology; | 64 | import org.onosproject.net.topology.Topology; |
65 | import org.onosproject.net.topology.TopologyService; | 65 | import org.onosproject.net.topology.TopologyService; |
66 | +import org.onosproject.ui.JsonUtils; | ||
66 | import org.onosproject.ui.UiConnection; | 67 | import org.onosproject.ui.UiConnection; |
67 | -import org.onosproject.ui.UiMessageHandler; | 68 | +import org.onosproject.ui.UiMessageHandlerTwo; |
68 | import org.slf4j.Logger; | 69 | import org.slf4j.Logger; |
69 | import org.slf4j.LoggerFactory; | 70 | import org.slf4j.LoggerFactory; |
70 | 71 | ||
... | @@ -100,11 +101,13 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; | ... | @@ -100,11 +101,13 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; |
100 | /** | 101 | /** |
101 | * Facility for creating messages bound for the topology viewer. | 102 | * Facility for creating messages bound for the topology viewer. |
102 | */ | 103 | */ |
103 | -public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | 104 | +public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo { |
104 | 105 | ||
105 | - protected static final Logger log = LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); | 106 | + protected static final Logger log = |
107 | + LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); | ||
106 | 108 | ||
107 | - private static final ProviderId PID = new ProviderId("core", "org.onosproject.core", true); | 109 | + private static final ProviderId PID = |
110 | + new ProviderId("core", "org.onosproject.core", true); | ||
108 | private static final String COMPACT = "%s/%s-%s/%s"; | 111 | private static final String COMPACT = "%s/%s-%s/%s"; |
109 | 112 | ||
110 | private static final double KB = 1024; | 113 | private static final double KB = 1024; |
... | @@ -133,15 +136,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -133,15 +136,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
133 | private static Map<String, ObjectNode> metaUi = new ConcurrentHashMap<>(); | 136 | private static Map<String, ObjectNode> metaUi = new ConcurrentHashMap<>(); |
134 | 137 | ||
135 | /** | 138 | /** |
136 | - * Creates a new message handler for the specified set of message types. | ||
137 | - * | ||
138 | - * @param messageTypes set of message types | ||
139 | - */ | ||
140 | - protected TopologyViewMessageHandlerBase(Set<String> messageTypes) { | ||
141 | - super(messageTypes); | ||
142 | - } | ||
143 | - | ||
144 | - /** | ||
145 | * Returns read-only view of the meta-ui information. | 139 | * Returns read-only view of the meta-ui information. |
146 | * | 140 | * |
147 | * @return map of id to meta-ui mementos | 141 | * @return map of id to meta-ui mementos |
... | @@ -168,26 +162,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -168,26 +162,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
168 | version = ver.replace(".SNAPSHOT", "*").replaceFirst("~.*$", ""); | 162 | version = ver.replace(".SNAPSHOT", "*").replaceFirst("~.*$", ""); |
169 | } | 163 | } |
170 | 164 | ||
171 | - // Retrieves the payload from the specified event. | ||
172 | - protected ObjectNode payload(ObjectNode event) { | ||
173 | - return (ObjectNode) event.path("payload"); | ||
174 | - } | ||
175 | - | ||
176 | - // Returns the specified node property as a number | ||
177 | - protected long number(ObjectNode node, String name) { | ||
178 | - return node.path(name).asLong(); | ||
179 | - } | ||
180 | - | ||
181 | - // Returns the specified node property as a string. | ||
182 | - protected String string(ObjectNode node, String name) { | ||
183 | - return node.path(name).asText(); | ||
184 | - } | ||
185 | - | ||
186 | - // Returns the specified node property as a string. | ||
187 | - protected String string(ObjectNode node, String name, String defaultValue) { | ||
188 | - return node.path(name).asText(defaultValue); | ||
189 | - } | ||
190 | - | ||
191 | // Returns the specified set of IP addresses as a string. | 165 | // Returns the specified set of IP addresses as a string. |
192 | private String ip(Set<IpAddress> ipAddresses) { | 166 | private String ip(Set<IpAddress> ipAddresses) { |
193 | Iterator<IpAddress> it = ipAddresses.iterator(); | 167 | Iterator<IpAddress> it = ipAddresses.iterator(); |
... | @@ -222,21 +196,11 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -222,21 +196,11 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
222 | 196 | ||
223 | // Produces a log message event bound to the client. | 197 | // Produces a log message event bound to the client. |
224 | private ObjectNode message(String severity, long id, String message) { | 198 | private ObjectNode message(String severity, long id, String message) { |
225 | - return envelope("message", id, | 199 | + ObjectNode payload = mapper.createObjectNode() |
226 | - mapper.createObjectNode() | 200 | + .put("severity", severity) |
227 | - .put("severity", severity) | 201 | + .put("message", message); |
228 | - .put("message", message)); | ||
229 | - } | ||
230 | 202 | ||
231 | - // Puts the payload into an envelope and returns it. | 203 | + return JsonUtils.envelope("message", id, payload); |
232 | - protected ObjectNode envelope(String type, long sid, ObjectNode payload) { | ||
233 | - ObjectNode event = mapper.createObjectNode(); | ||
234 | - event.put("event", type); | ||
235 | - if (sid > 0) { | ||
236 | - event.put("sid", sid); | ||
237 | - } | ||
238 | - event.set("payload", payload); | ||
239 | - return event; | ||
240 | } | 204 | } |
241 | 205 | ||
242 | // Produces a set of all hosts listed in the specified JSON array. | 206 | // Produces a set of all hosts listed in the specified JSON array. |
... | @@ -320,7 +284,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -320,7 +284,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
320 | ((event.type() == INSTANCE_ADDED) ? "addInstance" : | 284 | ((event.type() == INSTANCE_ADDED) ? "addInstance" : |
321 | ((event.type() == INSTANCE_REMOVED ? "removeInstance" : | 285 | ((event.type() == INSTANCE_REMOVED ? "removeInstance" : |
322 | "addInstance"))); | 286 | "addInstance"))); |
323 | - return envelope(type, 0, payload); | 287 | + return JsonUtils.envelope(type, 0, payload); |
324 | } | 288 | } |
325 | 289 | ||
326 | // Produces a device event message to the client. | 290 | // Produces a device event message to the client. |
... | @@ -347,7 +311,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -347,7 +311,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
347 | 311 | ||
348 | String type = (event.type() == DEVICE_ADDED) ? "addDevice" : | 312 | String type = (event.type() == DEVICE_ADDED) ? "addDevice" : |
349 | ((event.type() == DEVICE_REMOVED) ? "removeDevice" : "updateDevice"); | 313 | ((event.type() == DEVICE_REMOVED) ? "removeDevice" : "updateDevice"); |
350 | - return envelope(type, 0, payload); | 314 | + return JsonUtils.envelope(type, 0, payload); |
351 | } | 315 | } |
352 | 316 | ||
353 | // Produces a link event message to the client. | 317 | // Produces a link event message to the client. |
... | @@ -364,7 +328,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -364,7 +328,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
364 | .put("dstPort", link.dst().port().toString()); | 328 | .put("dstPort", link.dst().port().toString()); |
365 | String type = (event.type() == LINK_ADDED) ? "addLink" : | 329 | String type = (event.type() == LINK_ADDED) ? "addLink" : |
366 | ((event.type() == LINK_REMOVED) ? "removeLink" : "updateLink"); | 330 | ((event.type() == LINK_REMOVED) ? "removeLink" : "updateLink"); |
367 | - return envelope(type, 0, payload); | 331 | + return JsonUtils.envelope(type, 0, payload); |
368 | } | 332 | } |
369 | 333 | ||
370 | // Produces a host event message to the client. | 334 | // Produces a host event message to the client. |
... | @@ -385,7 +349,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -385,7 +349,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
385 | 349 | ||
386 | String type = (event.type() == HOST_ADDED) ? "addHost" : | 350 | String type = (event.type() == HOST_ADDED) ? "addHost" : |
387 | ((event.type() == HOST_REMOVED) ? "removeHost" : "updateHost"); | 351 | ((event.type() == HOST_REMOVED) ? "removeHost" : "updateHost"); |
388 | - return envelope(type, 0, payload); | 352 | + return JsonUtils.envelope(type, 0, payload); |
389 | } | 353 | } |
390 | 354 | ||
391 | // Encodes the specified host location into a JSON object. | 355 | // Encodes the specified host location into a JSON object. |
... | @@ -447,15 +411,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -447,15 +411,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
447 | } | 411 | } |
448 | 412 | ||
449 | // Updates meta UI information for the specified object. | 413 | // Updates meta UI information for the specified object. |
450 | - protected void updateMetaUi(ObjectNode event) { | 414 | + protected void updateMetaUi(ObjectNode payload) { |
451 | - ObjectNode payload = payload(event); | 415 | + metaUi.put(JsonUtils.string(payload, "id"), |
452 | - metaUi.put(string(payload, "id"), (ObjectNode) payload.path("memento")); | 416 | + JsonUtils.node(payload, "memento")); |
453 | } | 417 | } |
454 | 418 | ||
455 | // Returns summary response. | 419 | // Returns summary response. |
456 | protected ObjectNode summmaryMessage(long sid) { | 420 | protected ObjectNode summmaryMessage(long sid) { |
457 | Topology topology = topologyService.currentTopology(); | 421 | Topology topology = topologyService.currentTopology(); |
458 | - return envelope("showSummary", sid, | 422 | + return JsonUtils.envelope("showSummary", sid, |
459 | json("ONOS Summary", "node", | 423 | json("ONOS Summary", "node", |
460 | new Prop("Devices", format(topology.deviceCount())), | 424 | new Prop("Devices", format(topology.deviceCount())), |
461 | new Prop("Links", format(topology.linkCount())), | 425 | new Prop("Links", format(topology.linkCount())), |
... | @@ -474,7 +438,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -474,7 +438,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
474 | String name = annot.value(AnnotationKeys.NAME); | 438 | String name = annot.value(AnnotationKeys.NAME); |
475 | int portCount = deviceService.getPorts(deviceId).size(); | 439 | int portCount = deviceService.getPorts(deviceId).size(); |
476 | int flowCount = getFlowCount(deviceId); | 440 | int flowCount = getFlowCount(deviceId); |
477 | - return envelope("showDetails", sid, | 441 | + return JsonUtils.envelope("showDetails", sid, |
478 | json(isNullOrEmpty(name) ? deviceId.toString() : name, | 442 | json(isNullOrEmpty(name) ? deviceId.toString() : name, |
479 | device.type().toString().toLowerCase(), | 443 | device.type().toString().toLowerCase(), |
480 | new Prop("URI", deviceId.toString()), | 444 | new Prop("URI", deviceId.toString()), |
... | @@ -552,7 +516,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -552,7 +516,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
552 | String type = annot.value(AnnotationKeys.TYPE); | 516 | String type = annot.value(AnnotationKeys.TYPE); |
553 | String name = annot.value(AnnotationKeys.NAME); | 517 | String name = annot.value(AnnotationKeys.NAME); |
554 | String vlan = host.vlan().toString(); | 518 | String vlan = host.vlan().toString(); |
555 | - return envelope("showDetails", sid, | 519 | + return JsonUtils.envelope("showDetails", sid, |
556 | json(isNullOrEmpty(name) ? hostId.toString() : name, | 520 | json(isNullOrEmpty(name) ? hostId.toString() : name, |
557 | isNullOrEmpty(type) ? "endstation" : type, | 521 | isNullOrEmpty(type) ? "endstation" : type, |
558 | new Prop("MAC", host.mac().toString()), | 522 | new Prop("MAC", host.mac().toString()), |
... | @@ -565,7 +529,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -565,7 +529,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
565 | 529 | ||
566 | 530 | ||
567 | // Produces JSON message to trigger traffic overview visualization | 531 | // Produces JSON message to trigger traffic overview visualization |
568 | - protected ObjectNode trafficSummaryMessage(long sid) { | 532 | + protected ObjectNode trafficSummaryMessage() { |
569 | ObjectNode payload = mapper.createObjectNode(); | 533 | ObjectNode payload = mapper.createObjectNode(); |
570 | ArrayNode paths = mapper.createArrayNode(); | 534 | ArrayNode paths = mapper.createArrayNode(); |
571 | payload.set("paths", paths); | 535 | payload.set("paths", paths); |
... | @@ -603,7 +567,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -603,7 +567,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
603 | } | 567 | } |
604 | } | 568 | } |
605 | } | 569 | } |
606 | - return envelope("showTraffic", sid, payload); | 570 | + return JsonUtils.envelope("showTraffic", 0, payload); |
607 | } | 571 | } |
608 | 572 | ||
609 | private Collection<BiLink> consolidateLinks(Iterable<Link> links) { | 573 | private Collection<BiLink> consolidateLinks(Iterable<Link> links) { |
... | @@ -615,7 +579,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -615,7 +579,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
615 | } | 579 | } |
616 | 580 | ||
617 | // Produces JSON message to trigger flow overview visualization | 581 | // Produces JSON message to trigger flow overview visualization |
618 | - protected ObjectNode flowSummaryMessage(long sid, Set<Device> devices) { | 582 | + protected ObjectNode flowSummaryMessage(Set<Device> devices) { |
619 | ObjectNode payload = mapper.createObjectNode(); | 583 | ObjectNode payload = mapper.createObjectNode(); |
620 | ArrayNode paths = mapper.createArrayNode(); | 584 | ArrayNode paths = mapper.createArrayNode(); |
621 | payload.set("paths", paths); | 585 | payload.set("paths", paths); |
... | @@ -626,7 +590,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -626,7 +590,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
626 | addLinkFlows(link, paths, counts.get(link)); | 590 | addLinkFlows(link, paths, counts.get(link)); |
627 | } | 591 | } |
628 | } | 592 | } |
629 | - return envelope("showTraffic", sid, payload); | 593 | + return JsonUtils.envelope("showTraffic", 0, payload); |
630 | } | 594 | } |
631 | 595 | ||
632 | private void addLinkFlows(Link link, ArrayNode paths, Integer count) { | 596 | private void addLinkFlows(Link link, ArrayNode paths, Integer count) { |
... | @@ -644,7 +608,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -644,7 +608,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
644 | 608 | ||
645 | 609 | ||
646 | // Produces JSON message to trigger traffic visualization | 610 | // Produces JSON message to trigger traffic visualization |
647 | - protected ObjectNode trafficMessage(long sid, TrafficClass... trafficClasses) { | 611 | + protected ObjectNode trafficMessage(TrafficClass... trafficClasses) { |
648 | ObjectNode payload = mapper.createObjectNode(); | 612 | ObjectNode payload = mapper.createObjectNode(); |
649 | ArrayNode paths = mapper.createArrayNode(); | 613 | ArrayNode paths = mapper.createArrayNode(); |
650 | payload.set("paths", paths); | 614 | payload.set("paths", paths); |
... | @@ -670,7 +634,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -670,7 +634,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
670 | ((ArrayNode) pathNode.path("labels")).add(hasTraffic ? formatBytes(biLink.bytes) : ""); | 634 | ((ArrayNode) pathNode.path("labels")).add(hasTraffic ? formatBytes(biLink.bytes) : ""); |
671 | } | 635 | } |
672 | 636 | ||
673 | - return envelope("showTraffic", sid, payload); | 637 | + return JsonUtils.envelope("showTraffic", 0, payload); |
674 | } | 638 | } |
675 | 639 | ||
676 | // Classifies the link traffic according to the specified classes. | 640 | // Classifies the link traffic according to the specified classes. | ... | ... |
... | @@ -24,8 +24,8 @@ import org.onosproject.cluster.ClusterService; | ... | @@ -24,8 +24,8 @@ import org.onosproject.cluster.ClusterService; |
24 | import org.onosproject.cluster.ControllerNode; | 24 | import org.onosproject.cluster.ControllerNode; |
25 | import org.onosproject.ui.UiConnection; | 25 | import org.onosproject.ui.UiConnection; |
26 | import org.onosproject.ui.UiExtensionService; | 26 | import org.onosproject.ui.UiExtensionService; |
27 | -import org.onosproject.ui.UiMessageHandler; | ||
28 | import org.onosproject.ui.UiMessageHandlerFactory; | 27 | import org.onosproject.ui.UiMessageHandlerFactory; |
28 | +import org.onosproject.ui.UiMessageHandlerTwo; | ||
29 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; | 30 | import org.slf4j.LoggerFactory; |
31 | 31 | ||
... | @@ -56,7 +56,7 @@ public class UiWebSocket | ... | @@ -56,7 +56,7 @@ public class UiWebSocket |
56 | 56 | ||
57 | private long lastActive = System.currentTimeMillis(); | 57 | private long lastActive = System.currentTimeMillis(); |
58 | 58 | ||
59 | - private Map<String, UiMessageHandler> handlers; | 59 | + private Map<String, UiMessageHandlerTwo> handlers; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Creates a new web-socket for serving data to GUI. | 62 | * Creates a new web-socket for serving data to GUI. |
... | @@ -123,7 +123,7 @@ public class UiWebSocket | ... | @@ -123,7 +123,7 @@ public class UiWebSocket |
123 | try { | 123 | try { |
124 | ObjectNode message = (ObjectNode) mapper.reader().readTree(data); | 124 | ObjectNode message = (ObjectNode) mapper.reader().readTree(data); |
125 | String type = message.path("event").asText("unknown"); | 125 | String type = message.path("event").asText("unknown"); |
126 | - UiMessageHandler handler = handlers.get(type); | 126 | + UiMessageHandlerTwo handler = handlers.get(type); |
127 | if (handler != null) { | 127 | if (handler != null) { |
128 | handler.process(message); | 128 | handler.process(message); |
129 | } else { | 129 | } else { | ... | ... |
-
Please register or login to post a comment