GUI -- deleting experimental code for topo refactoring.
Change-Id: I3984f2f4a29496259877bf045c4cc8f46d78c033
Showing
17 changed files
with
4 additions
and
1612 deletions
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | -import com.google.common.collect.ImmutableSet; | ||
22 | -import com.google.common.collect.Maps; | ||
23 | -import org.onlab.osgi.ServiceDirectory; | ||
24 | -import org.onosproject.core.CoreService; | ||
25 | -import org.onosproject.ui.JsonUtils; | ||
26 | -import org.onosproject.ui.RequestHandler; | ||
27 | -import org.onosproject.ui.UiConnection; | ||
28 | -import org.onosproject.ui.UiMessageHandler; | ||
29 | -import org.onosproject.ui.impl.topo.OverlayService; | ||
30 | -import org.onosproject.ui.impl.topo.SummaryData; | ||
31 | -import org.onosproject.ui.impl.topo.TopoUiEvent; | ||
32 | -import org.onosproject.ui.impl.topo.TopoUiListener; | ||
33 | -import org.onosproject.ui.impl.topo.TopoUiModelService; | ||
34 | -import org.onosproject.ui.impl.topo.overlay.AbstractSummaryGenerator; | ||
35 | -import org.onosproject.ui.impl.topo.overlay.SummaryGenerator; | ||
36 | -import org.slf4j.Logger; | ||
37 | -import org.slf4j.LoggerFactory; | ||
38 | - | ||
39 | -import java.util.Collection; | ||
40 | -import java.util.HashMap; | ||
41 | -import java.util.Map; | ||
42 | - | ||
43 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
44 | -import static java.lang.System.currentTimeMillis; | ||
45 | -import static org.onosproject.ui.impl.topo.TopoUiEvent.Type.SUMMARY_UPDATE; | ||
46 | - | ||
47 | -/** | ||
48 | - * Facility for handling inbound messages from the topology view, and | ||
49 | - * generating outbound messages for the same. | ||
50 | - */ | ||
51 | -public class AltTopoViewMessageHandler extends UiMessageHandler | ||
52 | - implements OverlayService { | ||
53 | - | ||
54 | - private static final String TOPO_START = "topoStart"; | ||
55 | - private static final String TOPO_HEARTBEAT = "topoHeartbeat"; | ||
56 | - private static final String TOPO_STOP = "topoStop"; | ||
57 | - private static final String REQ_SUMMARY = "requestSummary"; | ||
58 | - private static final String CANCEL_SUMMARY = "cancelSummary"; | ||
59 | - | ||
60 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
61 | - | ||
62 | - protected ServiceDirectory directory; | ||
63 | - protected TopoUiModelService modelService; | ||
64 | - | ||
65 | - private ModelListener modelListener; | ||
66 | - private String version; | ||
67 | - private SummaryGenerator defaultSummaryGenerator; | ||
68 | - private SummaryGenerator currentSummaryGenerator; | ||
69 | - | ||
70 | - | ||
71 | - private boolean topoActive = false; | ||
72 | - | ||
73 | - @Override | ||
74 | - public void init(UiConnection connection, ServiceDirectory directory) { | ||
75 | - super.init(connection, directory); | ||
76 | - this.directory = checkNotNull(directory, "Directory cannot be null"); | ||
77 | - modelService = directory.get(TopoUiModelService.class); | ||
78 | - defaultSummaryGenerator = new DefSummaryGenerator("node", "ONOS Summary"); | ||
79 | - | ||
80 | - bindEventHandlers(); | ||
81 | - modelListener = new ModelListener(); | ||
82 | - version = getVersion(); | ||
83 | - currentSummaryGenerator = defaultSummaryGenerator; | ||
84 | - } | ||
85 | - | ||
86 | - @Override | ||
87 | - public void destroy() { | ||
88 | - cancelAllMonitoring(); | ||
89 | - stopListeningToModel(); | ||
90 | - super.destroy(); | ||
91 | - } | ||
92 | - | ||
93 | - | ||
94 | - @Override | ||
95 | - protected Collection<RequestHandler> createRequestHandlers() { | ||
96 | - return ImmutableSet.of( | ||
97 | - new TopoStart(), | ||
98 | - new TopoHeartbeat(), | ||
99 | - new TopoStop(), | ||
100 | - new ReqSummary(), | ||
101 | - new CancelSummary() | ||
102 | - // TODO: add more handlers here..... | ||
103 | - ); | ||
104 | - } | ||
105 | - | ||
106 | - // ===================================================================== | ||
107 | - | ||
108 | - private void cancelAllMonitoring() { | ||
109 | - // TODO: | ||
110 | - } | ||
111 | - | ||
112 | - private void startListeningToModel() { | ||
113 | - topoActive = true; | ||
114 | - modelService.addListener(modelListener); | ||
115 | - } | ||
116 | - | ||
117 | - private void stopListeningToModel() { | ||
118 | - topoActive = false; | ||
119 | - modelService.removeListener(modelListener); | ||
120 | - } | ||
121 | - | ||
122 | - private String getVersion() { | ||
123 | - String ver = directory.get(CoreService.class).version().toString(); | ||
124 | - return ver.replace(".SNAPSHOT", "*").replaceFirst("~.*$", ""); | ||
125 | - } | ||
126 | - | ||
127 | - // ===================================================================== | ||
128 | - // Overlay Service | ||
129 | - // TODO: figure out how we are going to switch overlays in and out... | ||
130 | - | ||
131 | - private final Map<String, SummaryGenerator> summGenCache = Maps.newHashMap(); | ||
132 | - | ||
133 | - @Override | ||
134 | - public void addSummaryGenerator(String overlayId, SummaryGenerator generator) { | ||
135 | - log.info("Adding custom Summary Generator for overlay [{}]", overlayId); | ||
136 | - summGenCache.put(overlayId, generator); | ||
137 | - } | ||
138 | - | ||
139 | - @Override | ||
140 | - public void removeSummaryGenerator(String overlayId) { | ||
141 | - summGenCache.remove(overlayId); | ||
142 | - log.info("Custom Summary Generator for overlay [{}] removed", overlayId); | ||
143 | - } | ||
144 | - | ||
145 | - | ||
146 | - | ||
147 | - // ===================================================================== | ||
148 | - // Request Handlers for (topo view) events from the UI... | ||
149 | - | ||
150 | - private final class TopoStart extends RequestHandler { | ||
151 | - private TopoStart() { | ||
152 | - super(TOPO_START); | ||
153 | - } | ||
154 | - | ||
155 | - @Override | ||
156 | - public void process(long sid, ObjectNode payload) { | ||
157 | - startListeningToModel(); | ||
158 | - sendMessages(modelService.getInitialState()); | ||
159 | - } | ||
160 | - } | ||
161 | - | ||
162 | - private final class TopoHeartbeat extends RequestHandler { | ||
163 | - private TopoHeartbeat() { | ||
164 | - super(TOPO_HEARTBEAT); | ||
165 | - } | ||
166 | - @Override | ||
167 | - public void process(long sid, ObjectNode payload) { | ||
168 | - modelListener.nudge(); | ||
169 | - } | ||
170 | - } | ||
171 | - | ||
172 | - private final class TopoStop extends RequestHandler { | ||
173 | - private TopoStop() { | ||
174 | - super(TOPO_STOP); | ||
175 | - } | ||
176 | - | ||
177 | - @Override | ||
178 | - public void process(long sid, ObjectNode payload) { | ||
179 | - stopListeningToModel(); | ||
180 | - } | ||
181 | - } | ||
182 | - | ||
183 | - private final class ReqSummary extends RequestHandler { | ||
184 | - private ReqSummary() { | ||
185 | - super(REQ_SUMMARY); | ||
186 | - } | ||
187 | - | ||
188 | - @Override | ||
189 | - public void process(long sid, ObjectNode payload) { | ||
190 | - modelService.startSummaryMonitoring(); | ||
191 | - // NOTE: showSummary messages forwarded through the model listener | ||
192 | - } | ||
193 | - } | ||
194 | - | ||
195 | - private final class CancelSummary extends RequestHandler { | ||
196 | - private CancelSummary() { | ||
197 | - super(CANCEL_SUMMARY); | ||
198 | - } | ||
199 | - | ||
200 | - @Override | ||
201 | - public void process(long sid, ObjectNode payload) { | ||
202 | - modelService.stopSummaryMonitoring(); | ||
203 | - } | ||
204 | - } | ||
205 | - | ||
206 | - // ===================================================================== | ||
207 | - | ||
208 | - private final class DefSummaryGenerator extends AbstractSummaryGenerator { | ||
209 | - public DefSummaryGenerator(String iconId, String title) { | ||
210 | - super(iconId, title); | ||
211 | - } | ||
212 | - | ||
213 | - @Override | ||
214 | - public ObjectNode generateSummary() { | ||
215 | - SummaryData data = modelService.getSummaryData(); | ||
216 | - iconId("node"); | ||
217 | - title("ONOS Summary"); | ||
218 | - clearProps(); | ||
219 | - prop("Devices", format(data.deviceCount())); | ||
220 | - prop("Links", format(data.linkCount())); | ||
221 | - prop("Hosts", format(data.hostCount())); | ||
222 | - prop("Topology SCCs", format(data.clusterCount())); | ||
223 | - separator(); | ||
224 | - prop("Intents", format(data.intentCount())); | ||
225 | - prop("Flows", format(data.flowRuleCount())); | ||
226 | - prop("Version", version); | ||
227 | - return buildObjectNode(); | ||
228 | - } | ||
229 | - } | ||
230 | - | ||
231 | - // ===================================================================== | ||
232 | - // Private Helper Methods... | ||
233 | - | ||
234 | - private void sendMessages(Collection<ObjectNode> messages) { | ||
235 | - if (topoActive) { | ||
236 | - UiConnection connection = connection(); | ||
237 | - if (connection != null) { | ||
238 | - messages.forEach(connection::sendMessage); | ||
239 | - } | ||
240 | - } | ||
241 | - } | ||
242 | - | ||
243 | - private void sendMessages(ObjectNode message) { | ||
244 | - if (topoActive) { | ||
245 | - UiConnection connection = connection(); | ||
246 | - if (connection != null) { | ||
247 | - connection.sendMessage(message); | ||
248 | - } | ||
249 | - } | ||
250 | - } | ||
251 | - | ||
252 | - // ===================================================================== | ||
253 | - // Our listener for model events so we can push changes out to the UI... | ||
254 | - | ||
255 | - private class ModelListener implements TopoUiListener { | ||
256 | - private static final long AWAKE_THRESHOLD_MS = 6000; | ||
257 | - | ||
258 | - private long lastNudged = currentTimeMillis(); | ||
259 | - | ||
260 | - @Override | ||
261 | - public void event(TopoUiEvent event) { | ||
262 | - log.debug("Handle Event: {}", event); | ||
263 | - ModelEventHandler handler = eventHandlerBinding.get(event.type()); | ||
264 | - | ||
265 | - // any handlers not bound explicitly are assumed to be pass-thru... | ||
266 | - if (handler == null) { | ||
267 | - handler = passThruHandler; | ||
268 | - } | ||
269 | - handler.handleEvent(event); | ||
270 | - } | ||
271 | - | ||
272 | - @Override | ||
273 | - public boolean isAwake() { | ||
274 | - return currentTimeMillis() - lastNudged < AWAKE_THRESHOLD_MS; | ||
275 | - } | ||
276 | - | ||
277 | - public void nudge() { | ||
278 | - lastNudged = currentTimeMillis(); | ||
279 | - } | ||
280 | - } | ||
281 | - | ||
282 | - | ||
283 | - // ===================================================================== | ||
284 | - // Model Event Handler definitions and bindings... | ||
285 | - | ||
286 | - private interface ModelEventHandler { | ||
287 | - void handleEvent(TopoUiEvent event); | ||
288 | - } | ||
289 | - | ||
290 | - private ModelEventHandler passThruHandler = event -> { | ||
291 | - // simply forward the event message as is | ||
292 | - ObjectNode message = event.subject(); | ||
293 | - if (message != null) { | ||
294 | - sendMessages(event.subject()); | ||
295 | - } | ||
296 | - }; | ||
297 | - | ||
298 | - private ModelEventHandler summaryHandler = event -> { | ||
299 | - // use the currently selected summary generator to create the body.. | ||
300 | - ObjectNode payload = currentSummaryGenerator.generateSummary(); | ||
301 | - sendMessages(JsonUtils.envelope("showSummary", payload)); | ||
302 | - }; | ||
303 | - | ||
304 | - | ||
305 | - // TopoUiEvent type binding of handlers | ||
306 | - private final Map<TopoUiEvent.Type, ModelEventHandler> | ||
307 | - eventHandlerBinding = new HashMap<>(); | ||
308 | - | ||
309 | - private void bindEventHandlers() { | ||
310 | - eventHandlerBinding.put(SUMMARY_UPDATE, summaryHandler); | ||
311 | - // NOTE: no need to bind pass-thru handlers | ||
312 | - } | ||
313 | -} |
... | @@ -211,10 +211,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -211,10 +211,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
211 | 211 | ||
212 | // ================================================================== | 212 | // ================================================================== |
213 | 213 | ||
214 | - /** | ||
215 | - * @deprecated in Cardinal Release | ||
216 | - */ | ||
217 | - @Deprecated | ||
218 | private final class TopoStart extends RequestHandler { | 214 | private final class TopoStart extends RequestHandler { |
219 | private TopoStart() { | 215 | private TopoStart() { |
220 | super(TOPO_START); | 216 | super(TOPO_START); |
... | @@ -230,10 +226,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -230,10 +226,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
230 | } | 226 | } |
231 | } | 227 | } |
232 | 228 | ||
233 | - /** | ||
234 | - * @deprecated in Cardinal Release | ||
235 | - */ | ||
236 | - @Deprecated | ||
237 | private final class TopoHeartbeat extends RequestHandler { | 229 | private final class TopoHeartbeat extends RequestHandler { |
238 | private TopoHeartbeat() { | 230 | private TopoHeartbeat() { |
239 | super(TOPO_HEARTBEAT); | 231 | super(TOPO_HEARTBEAT); |
... | @@ -258,10 +250,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -258,10 +250,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
258 | } | 250 | } |
259 | } | 251 | } |
260 | 252 | ||
261 | - /** | ||
262 | - * @deprecated in Cardinal Release | ||
263 | - */ | ||
264 | - @Deprecated | ||
265 | private final class TopoStop extends RequestHandler { | 253 | private final class TopoStop extends RequestHandler { |
266 | private TopoStop() { | 254 | private TopoStop() { |
267 | super(TOPO_STOP); | 255 | super(TOPO_STOP); |
... | @@ -274,10 +262,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { | ... | @@ -274,10 +262,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { |
274 | } | 262 | } |
275 | } | 263 | } |
276 | 264 | ||
277 | - /** | ||
278 | - * @deprecated in Cardinal Release | ||
279 | - */ | ||
280 | - @Deprecated | ||
281 | private final class ReqSummary extends RequestHandler { | 265 | private final class ReqSummary extends RequestHandler { |
282 | private ReqSummary() { | 266 | private ReqSummary() { |
283 | super(REQ_SUMMARY); | 267 | super(REQ_SUMMARY); | ... | ... |
... | @@ -110,10 +110,7 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.StatsType.P | ... | @@ -110,10 +110,7 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.StatsType.P |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Facility for creating messages bound for the topology viewer. | 112 | * Facility for creating messages bound for the topology viewer. |
113 | - * | ||
114 | - * @deprecated in Cardinal Release | ||
115 | */ | 113 | */ |
116 | -@Deprecated | ||
117 | public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | 114 | public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
118 | 115 | ||
119 | protected static final Logger log = | 116 | protected static final Logger log = |
... | @@ -943,6 +940,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -943,6 +940,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
943 | } | 940 | } |
944 | 941 | ||
945 | // Auxiliary key/value carrier. | 942 | // Auxiliary key/value carrier. |
943 | + @Deprecated | ||
946 | static class Prop { | 944 | static class Prop { |
947 | public final String key; | 945 | public final String key; |
948 | public final String value; | 946 | public final String value; |
... | @@ -954,12 +952,14 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -954,12 +952,14 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
954 | } | 952 | } |
955 | 953 | ||
956 | // Auxiliary properties separator | 954 | // Auxiliary properties separator |
955 | + @Deprecated | ||
957 | static class Separator extends Prop { | 956 | static class Separator extends Prop { |
958 | protected Separator() { | 957 | protected Separator() { |
959 | super("-", ""); | 958 | super("-", ""); |
960 | } | 959 | } |
961 | } | 960 | } |
962 | 961 | ||
962 | + // TODO: move this to traffic overlay component | ||
963 | // Auxiliary carrier of data for requesting traffic message. | 963 | // Auxiliary carrier of data for requesting traffic message. |
964 | static class TrafficClass { | 964 | static class TrafficClass { |
965 | public final boolean showTraffic; | 965 | public final boolean showTraffic; | ... | ... |
... | @@ -33,8 +33,6 @@ import org.onosproject.ui.UiMessageHandlerFactory; | ... | @@ -33,8 +33,6 @@ import org.onosproject.ui.UiMessageHandlerFactory; |
33 | import org.onosproject.ui.UiTopoOverlayFactory; | 33 | import org.onosproject.ui.UiTopoOverlayFactory; |
34 | import org.onosproject.ui.UiView; | 34 | import org.onosproject.ui.UiView; |
35 | import org.onosproject.ui.UiViewHidden; | 35 | import org.onosproject.ui.UiViewHidden; |
36 | -import org.onosproject.ui.impl.topo.OverlayService; | ||
37 | -import org.onosproject.ui.impl.topo.overlay.SummaryGenerator; | ||
38 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
39 | import org.slf4j.LoggerFactory; | 37 | import org.slf4j.LoggerFactory; |
40 | 38 | ||
... | @@ -52,8 +50,7 @@ import static org.onosproject.ui.UiView.Category.PLATFORM; | ... | @@ -52,8 +50,7 @@ import static org.onosproject.ui.UiView.Category.PLATFORM; |
52 | */ | 50 | */ |
53 | @Component(immediate = true) | 51 | @Component(immediate = true) |
54 | @Service | 52 | @Service |
55 | -public class UiExtensionManager | 53 | +public class UiExtensionManager implements UiExtensionService, SpriteService { |
56 | - implements UiExtensionService, SpriteService, OverlayService { | ||
57 | 54 | ||
58 | private static final ClassLoader CL = | 55 | private static final ClassLoader CL = |
59 | UiExtensionManager.class.getClassLoader(); | 56 | UiExtensionManager.class.getClassLoader(); |
... | @@ -70,9 +67,6 @@ public class UiExtensionManager | ... | @@ -70,9 +67,6 @@ public class UiExtensionManager |
70 | // Core views & core extension | 67 | // Core views & core extension |
71 | private final UiExtension core = createCoreExtension(); | 68 | private final UiExtension core = createCoreExtension(); |
72 | 69 | ||
73 | - // Topology Message Handler | ||
74 | - private final AltTopoViewMessageHandler topoHandler = | ||
75 | - new AltTopoViewMessageHandler(); | ||
76 | 70 | ||
77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
78 | protected MastershipService mastershipService; | 72 | protected MastershipService mastershipService; |
... | @@ -96,7 +90,6 @@ public class UiExtensionManager | ... | @@ -96,7 +90,6 @@ public class UiExtensionManager |
96 | UiMessageHandlerFactory messageHandlerFactory = | 90 | UiMessageHandlerFactory messageHandlerFactory = |
97 | () -> ImmutableList.of( | 91 | () -> ImmutableList.of( |
98 | new TopologyViewMessageHandler(), | 92 | new TopologyViewMessageHandler(), |
99 | -// topoHandler, | ||
100 | new DeviceViewMessageHandler(), | 93 | new DeviceViewMessageHandler(), |
101 | new LinkViewMessageHandler(), | 94 | new LinkViewMessageHandler(), |
102 | new HostViewMessageHandler(), | 95 | new HostViewMessageHandler(), |
... | @@ -182,18 +175,4 @@ public class UiExtensionManager | ... | @@ -182,18 +175,4 @@ public class UiExtensionManager |
182 | return sprites.get(name); | 175 | return sprites.get(name); |
183 | } | 176 | } |
184 | 177 | ||
185 | - | ||
186 | - // ===================================================================== | ||
187 | - // Topology Overlay API -- pass through to topology message handler | ||
188 | - | ||
189 | - // NOTE: while WIP, comment out calls to topoHandler (for checked in code) | ||
190 | - @Override | ||
191 | - public void addSummaryGenerator(String overlayId, SummaryGenerator generator) { | ||
192 | - topoHandler.addSummaryGenerator(overlayId, generator); | ||
193 | - } | ||
194 | - | ||
195 | - @Override | ||
196 | - public void removeSummaryGenerator(String overlayId) { | ||
197 | - topoHandler.removeSummaryGenerator(overlayId); | ||
198 | - } | ||
199 | } | 178 | } | ... | ... |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | - | ||
22 | -import java.util.Map; | ||
23 | -import java.util.concurrent.ConcurrentHashMap; | ||
24 | - | ||
25 | -/** | ||
26 | - * A database of meta information stored for topology objects. | ||
27 | - */ | ||
28 | -// package private | ||
29 | -class MetaDb { | ||
30 | - | ||
31 | - private static Map<String, ObjectNode> metaCache = new ConcurrentHashMap<>(); | ||
32 | - | ||
33 | - /** | ||
34 | - * Adds meta UI information about the specified object to the given payload. | ||
35 | - * | ||
36 | - * @param id object identifier | ||
37 | - * @param payload payload to which the info should be added | ||
38 | - */ | ||
39 | - public void addMetaUi(String id, ObjectNode payload) { | ||
40 | - ObjectNode meta = metaCache.get(id); | ||
41 | - if (meta != null) { | ||
42 | - payload.set("metaUi", meta); | ||
43 | - } | ||
44 | - } | ||
45 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import org.onosproject.event.ListenerRegistry; | ||
21 | -import org.slf4j.Logger; | ||
22 | - | ||
23 | -import java.util.HashSet; | ||
24 | -import java.util.Set; | ||
25 | - | ||
26 | -import static org.slf4j.LoggerFactory.getLogger; | ||
27 | - | ||
28 | -/** | ||
29 | - * A listener registry that automatically prunes listeners that have not | ||
30 | - * been sending heartbeat messages to assure us they are really listening. | ||
31 | - */ | ||
32 | -// package private | ||
33 | -class ModelListenerRegistry | ||
34 | - extends ListenerRegistry<TopoUiEvent, TopoUiListener> { | ||
35 | - | ||
36 | - private final Logger log = getLogger(getClass()); | ||
37 | - | ||
38 | - private final Set<TopoUiListener> zombies = new HashSet<>(); | ||
39 | - | ||
40 | - @Override | ||
41 | - public void process(TopoUiEvent event) { | ||
42 | - zombies.clear(); | ||
43 | - for (TopoUiListener listener : listeners) { | ||
44 | - try { | ||
45 | - if (listener.isAwake()) { | ||
46 | - listener.event(event); | ||
47 | - } else { | ||
48 | - zombies.add(listener); | ||
49 | - } | ||
50 | - } catch (Exception error) { | ||
51 | - reportProblem(event, error); | ||
52 | - } | ||
53 | - } | ||
54 | - | ||
55 | - // clean up zombie listeners | ||
56 | - for (TopoUiListener z : zombies) { | ||
57 | - log.debug("Removing zombie model listener: {}", z); | ||
58 | - removeListener(z); | ||
59 | - } | ||
60 | - } | ||
61 | - | ||
62 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import org.onosproject.ui.impl.topo.overlay.SummaryGenerator; | ||
21 | - | ||
22 | -/** | ||
23 | - * Provides the API for external agents to inject topology overlay behavior. | ||
24 | - */ | ||
25 | -// TODO: move to core-api module | ||
26 | -public interface OverlayService { | ||
27 | - | ||
28 | - /** | ||
29 | - * Registers a custom summary generator for the specified overlay. | ||
30 | - * | ||
31 | - * @param overlayId overlay identifier | ||
32 | - * @param generator generator to register | ||
33 | - */ | ||
34 | - void addSummaryGenerator(String overlayId, SummaryGenerator generator); | ||
35 | - | ||
36 | - /** | ||
37 | - * Unregisters the generator associated with the specified overlay. | ||
38 | - * | ||
39 | - * @param overlayId overlay identifier | ||
40 | - */ | ||
41 | - void removeSummaryGenerator(String overlayId); | ||
42 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -/** | ||
21 | - * Provides basic summary data for the topology. | ||
22 | - */ | ||
23 | -// TODO: review -- move to core-api module? | ||
24 | -public interface SummaryData { | ||
25 | - | ||
26 | - /** | ||
27 | - * Returns the number of devices. | ||
28 | - * | ||
29 | - * @return number of devices | ||
30 | - */ | ||
31 | - int deviceCount(); | ||
32 | - | ||
33 | - /** | ||
34 | - * Returns the number of links. | ||
35 | - * | ||
36 | - * @return number of links | ||
37 | - */ | ||
38 | - int linkCount(); | ||
39 | - | ||
40 | - /** | ||
41 | - * Returns the number of hosts. | ||
42 | - * | ||
43 | - * @return number of hosts | ||
44 | - */ | ||
45 | - int hostCount(); | ||
46 | - | ||
47 | - /** | ||
48 | - * Returns the number of clusters (topology SCCs). | ||
49 | - * | ||
50 | - * @return number of clusters | ||
51 | - */ | ||
52 | - int clusterCount(); | ||
53 | - | ||
54 | - /** | ||
55 | - * Returns the number of intents in the system. | ||
56 | - * | ||
57 | - * @return number of intents | ||
58 | - */ | ||
59 | - long intentCount(); | ||
60 | - | ||
61 | - /** | ||
62 | - * Returns the number of flow rules in the system. | ||
63 | - * | ||
64 | - * @return number of flow rules | ||
65 | - */ | ||
66 | - int flowRuleCount(); | ||
67 | - | ||
68 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
21 | -import com.fasterxml.jackson.databind.node.ArrayNode; | ||
22 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
23 | -import org.onlab.packet.IpAddress; | ||
24 | -import org.onosproject.cluster.ClusterEvent; | ||
25 | -import org.onosproject.cluster.ClusterService; | ||
26 | -import org.onosproject.cluster.ControllerNode; | ||
27 | -import org.onosproject.cluster.NodeId; | ||
28 | -import org.onosproject.mastership.MastershipService; | ||
29 | -import org.onosproject.net.Annotated; | ||
30 | -import org.onosproject.net.AnnotationKeys; | ||
31 | -import org.onosproject.net.Annotations; | ||
32 | -import org.onosproject.net.ConnectPoint; | ||
33 | -import org.onosproject.net.DefaultEdgeLink; | ||
34 | -import org.onosproject.net.Device; | ||
35 | -import org.onosproject.net.DeviceId; | ||
36 | -import org.onosproject.net.EdgeLink; | ||
37 | -import org.onosproject.net.Host; | ||
38 | -import org.onosproject.net.HostId; | ||
39 | -import org.onosproject.net.HostLocation; | ||
40 | -import org.onosproject.net.Link; | ||
41 | -import org.onosproject.net.PortNumber; | ||
42 | -import org.onosproject.net.device.DeviceEvent; | ||
43 | -import org.onosproject.net.device.DeviceService; | ||
44 | -import org.onosproject.net.host.HostEvent; | ||
45 | -import org.onosproject.net.host.HostService; | ||
46 | -import org.onosproject.net.link.LinkEvent; | ||
47 | -import org.onosproject.net.link.LinkService; | ||
48 | -import org.onosproject.net.provider.ProviderId; | ||
49 | -import org.onosproject.ui.JsonUtils; | ||
50 | -import org.slf4j.Logger; | ||
51 | -import org.slf4j.LoggerFactory; | ||
52 | - | ||
53 | -import java.util.HashMap; | ||
54 | -import java.util.Iterator; | ||
55 | -import java.util.Map; | ||
56 | -import java.util.Set; | ||
57 | - | ||
58 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
59 | -import static org.onosproject.cluster.ControllerNode.State.ACTIVE; | ||
60 | -import static org.onosproject.net.PortNumber.portNumber; | ||
61 | - | ||
62 | -/** | ||
63 | - * Facility for generating messages in {@link ObjectNode} form from | ||
64 | - * ONOS model events. | ||
65 | - */ | ||
66 | -// package private | ||
67 | -class TopoMessageFactory { | ||
68 | - | ||
69 | - private static final ProviderId PROVIDER_ID = | ||
70 | - new ProviderId("core", "org.onosproject.core", true); | ||
71 | - private static final String COMPACT = "%s/%s-%s/%s"; | ||
72 | - private static final PortNumber PORT_ZERO = portNumber(0); | ||
73 | - | ||
74 | - private static final Map<Enum<?>, String> LOOKUP = new HashMap<>(); | ||
75 | - | ||
76 | - static { | ||
77 | - LOOKUP.put(ClusterEvent.Type.INSTANCE_ADDED, "addInstance"); | ||
78 | - LOOKUP.put(ClusterEvent.Type.INSTANCE_REMOVED, "removeInstance"); | ||
79 | - LOOKUP.put(DeviceEvent.Type.DEVICE_ADDED, "addDevice"); | ||
80 | - LOOKUP.put(DeviceEvent.Type.DEVICE_UPDATED, "updateDevice"); | ||
81 | - LOOKUP.put(DeviceEvent.Type.DEVICE_REMOVED, "removeDevice"); | ||
82 | - LOOKUP.put(LinkEvent.Type.LINK_ADDED, "addLink"); | ||
83 | - LOOKUP.put(LinkEvent.Type.LINK_UPDATED, "updateLink"); | ||
84 | - LOOKUP.put(LinkEvent.Type.LINK_REMOVED, "removeLink"); | ||
85 | - LOOKUP.put(HostEvent.Type.HOST_ADDED, "addHost"); | ||
86 | - LOOKUP.put(HostEvent.Type.HOST_UPDATED, "updateHost"); | ||
87 | - LOOKUP.put(HostEvent.Type.HOST_REMOVED, "removeHost"); | ||
88 | - } | ||
89 | - | ||
90 | - private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
91 | - | ||
92 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
93 | - | ||
94 | - private MetaDb metaDb; | ||
95 | - | ||
96 | - private ClusterService clusterService; | ||
97 | - private DeviceService deviceService; | ||
98 | - private LinkService linkService; | ||
99 | - private HostService hostService; | ||
100 | - private MastershipService mastershipService; | ||
101 | - | ||
102 | - | ||
103 | - // =================================================================== | ||
104 | - // Private helper methods | ||
105 | - | ||
106 | - private ObjectNode objectNode() { | ||
107 | - return MAPPER.createObjectNode(); | ||
108 | - } | ||
109 | - | ||
110 | - private ArrayNode arrayNode() { | ||
111 | - return MAPPER.createArrayNode(); | ||
112 | - } | ||
113 | - | ||
114 | - private String toLc(Object o) { | ||
115 | - return o.toString().toLowerCase(); | ||
116 | - } | ||
117 | - | ||
118 | - // Event type to message type lookup (with fallback). | ||
119 | - private String messageTypeLookup(Enum<?> type, String fallback) { | ||
120 | - String msgType = LOOKUP.get(type); | ||
121 | - return msgType == null ? fallback : msgType; | ||
122 | - } | ||
123 | - | ||
124 | - // Returns the name of the master node for the specified device ID. | ||
125 | - private String master(DeviceId deviceId) { | ||
126 | - NodeId master = mastershipService.getMasterFor(deviceId); | ||
127 | - return master != null ? master.toString() : ""; | ||
128 | - } | ||
129 | - | ||
130 | - // Produces JSON structure from annotations. | ||
131 | - private ObjectNode props(Annotations annotations) { | ||
132 | - ObjectNode props = objectNode(); | ||
133 | - if (annotations != null) { | ||
134 | - for (String key : annotations.keys()) { | ||
135 | - props.put(key, annotations.value(key)); | ||
136 | - } | ||
137 | - } | ||
138 | - return props; | ||
139 | - } | ||
140 | - | ||
141 | - // Adds a geo location JSON to the specified payload object. | ||
142 | - private void addGeoLocation(Annotated annotated, ObjectNode payload) { | ||
143 | - Annotations annot = annotated.annotations(); | ||
144 | - if (annot == null) { | ||
145 | - return; | ||
146 | - } | ||
147 | - | ||
148 | - String slat = annot.value(AnnotationKeys.LATITUDE); | ||
149 | - String slng = annot.value(AnnotationKeys.LONGITUDE); | ||
150 | - try { | ||
151 | - if (!isNullOrEmpty(slat) && !isNullOrEmpty(slng)) { | ||
152 | - double lat = Double.parseDouble(slat); | ||
153 | - double lng = Double.parseDouble(slng); | ||
154 | - ObjectNode loc = objectNode() | ||
155 | - .put("type", "latlng") | ||
156 | - .put("lat", lat) | ||
157 | - .put("lng", lng); | ||
158 | - payload.set("location", loc); | ||
159 | - } | ||
160 | - } catch (NumberFormatException e) { | ||
161 | - log.warn("Invalid geo data latitude={}; longitude={}", slat, slng); | ||
162 | - } | ||
163 | - } | ||
164 | - | ||
165 | - // Produces compact string representation of a link. | ||
166 | - private String compactLinkString(Link link) { | ||
167 | - return String.format(COMPACT, link.src().elementId(), link.src().port(), | ||
168 | - link.dst().elementId(), link.dst().port()); | ||
169 | - } | ||
170 | - | ||
171 | - // Generates an edge link from the specified host location. | ||
172 | - private EdgeLink edgeLink(Host host, boolean isIngress) { | ||
173 | - ConnectPoint cp = new ConnectPoint(host.id(), PORT_ZERO); | ||
174 | - return new DefaultEdgeLink(PROVIDER_ID, cp, host.location(), isIngress); | ||
175 | - } | ||
176 | - | ||
177 | - // Encodes the specified host location into a JSON object. | ||
178 | - private ObjectNode hostConnect(HostLocation loc) { | ||
179 | - return objectNode() | ||
180 | - .put("device", loc.deviceId().toString()) | ||
181 | - .put("port", loc.port().toLong()); | ||
182 | - } | ||
183 | - | ||
184 | - // Returns the first IP address from the specified set. | ||
185 | - private String firstIp(Set<IpAddress> addresses) { | ||
186 | - Iterator<IpAddress> it = addresses.iterator(); | ||
187 | - return it.hasNext() ? it.next().toString() : "unknown"; | ||
188 | - } | ||
189 | - | ||
190 | - // Returns a JSON array of the specified strings. | ||
191 | - private ArrayNode labels(String... labels) { | ||
192 | - ArrayNode array = arrayNode(); | ||
193 | - for (String label : labels) { | ||
194 | - array.add(label); | ||
195 | - } | ||
196 | - return array; | ||
197 | - } | ||
198 | - | ||
199 | - // =================================================================== | ||
200 | - // API for generating messages | ||
201 | - | ||
202 | - /** | ||
203 | - * Injects service references so that the message compilation methods | ||
204 | - * can do required lookups when needed. | ||
205 | - * | ||
206 | - * @param meta meta DB | ||
207 | - * @param cs cluster service | ||
208 | - * @param ds device service | ||
209 | - * @param ls link service | ||
210 | - * @param hs host service | ||
211 | - * @param ms mastership service | ||
212 | - */ | ||
213 | - public void injectServices(MetaDb meta, ClusterService cs, DeviceService ds, | ||
214 | - LinkService ls, HostService hs, | ||
215 | - MastershipService ms) { | ||
216 | - metaDb = meta; | ||
217 | - clusterService = cs; | ||
218 | - deviceService = ds; | ||
219 | - linkService = ls; | ||
220 | - hostService = hs; | ||
221 | - mastershipService = ms; | ||
222 | - } | ||
223 | - | ||
224 | - /** | ||
225 | - * Transforms a cluster event into an object-node-based message. | ||
226 | - * | ||
227 | - * @param ev cluster event | ||
228 | - * @return marshaled event message | ||
229 | - */ | ||
230 | - public ObjectNode instanceMessage(ClusterEvent ev) { | ||
231 | - ControllerNode node = ev.subject(); | ||
232 | - NodeId nid = node.id(); | ||
233 | - String id = nid.toString(); | ||
234 | - String ip = node.ip().toString(); | ||
235 | - int switchCount = mastershipService.getDevicesOf(nid).size(); | ||
236 | - | ||
237 | - ObjectNode payload = objectNode() | ||
238 | - .put("id", id) | ||
239 | - .put("ip", ip) | ||
240 | - .put("online", clusterService.getState(nid) == ACTIVE) | ||
241 | - .put("uiAttached", node.equals(clusterService.getLocalNode())) | ||
242 | - .put("switches", switchCount); | ||
243 | - | ||
244 | - ArrayNode labels = arrayNode().add(id).add(ip); | ||
245 | - | ||
246 | - payload.set("labels", labels); | ||
247 | - metaDb.addMetaUi(id, payload); | ||
248 | - | ||
249 | - String msgType = messageTypeLookup(ev.type(), "addInstance"); | ||
250 | - return JsonUtils.envelope(msgType, payload); | ||
251 | - } | ||
252 | - | ||
253 | - /** | ||
254 | - * Transforms a device event into an object-node-based message. | ||
255 | - * | ||
256 | - * @param ev device event | ||
257 | - * @return marshaled event message | ||
258 | - */ | ||
259 | - public ObjectNode deviceMessage(DeviceEvent ev) { | ||
260 | - Device device = ev.subject(); | ||
261 | - DeviceId did = device.id(); | ||
262 | - String id = did.toString(); | ||
263 | - | ||
264 | - ObjectNode payload = objectNode() | ||
265 | - .put("id", id) | ||
266 | - .put("type", toLc(device.type())) | ||
267 | - .put("online", deviceService.isAvailable(did)) | ||
268 | - .put("master", master(did)); | ||
269 | - | ||
270 | - Annotations annot = device.annotations(); | ||
271 | - String name = annot.value(AnnotationKeys.NAME); | ||
272 | - String friendly = isNullOrEmpty(name) ? id : name; | ||
273 | - payload.set("labels", labels("", friendly, id)); | ||
274 | - payload.set("props", props(annot)); | ||
275 | - | ||
276 | - addGeoLocation(device, payload); | ||
277 | - metaDb.addMetaUi(id, payload); | ||
278 | - | ||
279 | - String msgType = messageTypeLookup(ev.type(), "updateDevice"); | ||
280 | - return JsonUtils.envelope(msgType, payload); | ||
281 | - } | ||
282 | - | ||
283 | - /** | ||
284 | - * Transforms a link event into an object-node-based message. | ||
285 | - * | ||
286 | - * @param ev link event | ||
287 | - * @return marshaled event message | ||
288 | - */ | ||
289 | - public ObjectNode linkMessage(LinkEvent ev) { | ||
290 | - Link link = ev.subject(); | ||
291 | - ObjectNode payload = objectNode() | ||
292 | - .put("id", compactLinkString(link)) | ||
293 | - .put("type", toLc(link.type())) | ||
294 | - .put("online", link.state() == Link.State.ACTIVE) | ||
295 | - .put("linkWidth", 1.2) | ||
296 | - .put("src", link.src().deviceId().toString()) | ||
297 | - .put("srcPort", link.src().port().toString()) | ||
298 | - .put("dst", link.dst().deviceId().toString()) | ||
299 | - .put("dstPort", link.dst().port().toString()); | ||
300 | - | ||
301 | - String msgType = messageTypeLookup(ev.type(), "updateLink"); | ||
302 | - return JsonUtils.envelope(msgType, payload); | ||
303 | - } | ||
304 | - | ||
305 | - /** | ||
306 | - * Transforms a host event into an object-node-based message. | ||
307 | - * | ||
308 | - * @param ev host event | ||
309 | - * @return marshaled event message | ||
310 | - */ | ||
311 | - public ObjectNode hostMessage(HostEvent ev) { | ||
312 | - Host host = ev.subject(); | ||
313 | - HostId hid = host.id(); | ||
314 | - String id = hid.toString(); | ||
315 | - Annotations annot = host.annotations(); | ||
316 | - | ||
317 | - String hostType = annot.value(AnnotationKeys.TYPE); | ||
318 | - | ||
319 | - ObjectNode payload = objectNode() | ||
320 | - .put("id", id) | ||
321 | - .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType) | ||
322 | - .put("ingress", compactLinkString(edgeLink(host, true))) | ||
323 | - .put("egress", compactLinkString(edgeLink(host, false))); | ||
324 | - | ||
325 | - // TODO: make cp an array of connect point objects (multi-homed) | ||
326 | - payload.set("cp", hostConnect(host.location())); | ||
327 | - String ipStr = firstIp(host.ipAddresses()); | ||
328 | - String macStr = host.mac().toString(); | ||
329 | - payload.set("labels", labels(ipStr, macStr)); | ||
330 | - payload.set("props", props(annot)); | ||
331 | - addGeoLocation(host, payload); | ||
332 | - metaDb.addMetaUi(id, payload); | ||
333 | - | ||
334 | - String mstType = messageTypeLookup(ev.type(), "updateHost"); | ||
335 | - return JsonUtils.envelope(mstType, payload); | ||
336 | - } | ||
337 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | -import org.onosproject.event.AbstractEvent; | ||
22 | - | ||
23 | -/** | ||
24 | - * Describes Topology UI Model events. | ||
25 | - */ | ||
26 | -public class TopoUiEvent extends AbstractEvent<TopoUiEvent.Type, ObjectNode> { | ||
27 | - | ||
28 | - /** | ||
29 | - * Type of Topology UI Model events. | ||
30 | - */ | ||
31 | - public enum Type { | ||
32 | - // notification events | ||
33 | - SUMMARY_UPDATE, | ||
34 | - | ||
35 | - // unsolicited topology events | ||
36 | - INSTANCE_ADDED, | ||
37 | - INSTANCE_REMOVED, | ||
38 | - DEVICE_ADDED, | ||
39 | - DEVICE_UPDATED, | ||
40 | - DEVICE_REMOVED, | ||
41 | - LINK_ADDED, | ||
42 | - LINK_UPDATED, | ||
43 | - LINK_REMOVED, | ||
44 | - HOST_ADDED, | ||
45 | - HOST_UPDATED, | ||
46 | - HOST_REMOVED | ||
47 | - } | ||
48 | - | ||
49 | - | ||
50 | - protected TopoUiEvent(Type type, ObjectNode subject) { | ||
51 | - super(type, subject); | ||
52 | - } | ||
53 | - | ||
54 | - protected TopoUiEvent(Type type, ObjectNode subject, long time) { | ||
55 | - super(type, subject, time); | ||
56 | - } | ||
57 | - | ||
58 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import org.onosproject.event.EventListener; | ||
21 | - | ||
22 | -/** | ||
23 | - * Defines a listener of Topology UI Model events. | ||
24 | - */ | ||
25 | -public interface TopoUiListener extends EventListener<TopoUiEvent> { | ||
26 | - | ||
27 | - /** | ||
28 | - * Returns true if the listener really is listening. | ||
29 | - * | ||
30 | - * @return true if awake | ||
31 | - */ | ||
32 | - boolean isAwake(); | ||
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | -import org.apache.felix.scr.annotations.Activate; | ||
22 | -import org.apache.felix.scr.annotations.Component; | ||
23 | -import org.apache.felix.scr.annotations.Deactivate; | ||
24 | -import org.apache.felix.scr.annotations.Reference; | ||
25 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
26 | -import org.apache.felix.scr.annotations.Service; | ||
27 | -import org.onosproject.cluster.ClusterEvent; | ||
28 | -import org.onosproject.cluster.ClusterService; | ||
29 | -import org.onosproject.cluster.ControllerNode; | ||
30 | -import org.onosproject.event.EventDeliveryService; | ||
31 | -import org.onosproject.mastership.MastershipService; | ||
32 | -import org.onosproject.net.Device; | ||
33 | -import org.onosproject.net.Host; | ||
34 | -import org.onosproject.net.Link; | ||
35 | -import org.onosproject.net.device.DeviceEvent; | ||
36 | -import org.onosproject.net.device.DeviceService; | ||
37 | -import org.onosproject.net.flow.FlowRuleService; | ||
38 | -import org.onosproject.net.host.HostEvent; | ||
39 | -import org.onosproject.net.host.HostService; | ||
40 | -import org.onosproject.net.intent.IntentService; | ||
41 | -import org.onosproject.net.link.LinkEvent; | ||
42 | -import org.onosproject.net.link.LinkService; | ||
43 | -import org.onosproject.net.topology.Topology; | ||
44 | -import org.onosproject.net.topology.TopologyService; | ||
45 | -import org.slf4j.Logger; | ||
46 | -import org.slf4j.LoggerFactory; | ||
47 | - | ||
48 | -import java.util.ArrayList; | ||
49 | -import java.util.Collections; | ||
50 | -import java.util.Comparator; | ||
51 | -import java.util.List; | ||
52 | -import java.util.Timer; | ||
53 | -import java.util.TimerTask; | ||
54 | - | ||
55 | -import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED; | ||
56 | -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; | ||
57 | -import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; | ||
58 | -import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; | ||
59 | -import static org.onosproject.ui.impl.topo.TopoUiEvent.Type.SUMMARY_UPDATE; | ||
60 | - | ||
61 | - | ||
62 | -/** | ||
63 | - * Maintains a UI-centric model of the topology, as inferred from interactions | ||
64 | - * with the different (device, host, link, ...) services. Will serve up this | ||
65 | - * model to anyone who cares to {@link TopoUiListener listen}. | ||
66 | - */ | ||
67 | -@Component(immediate = true) | ||
68 | -@Service | ||
69 | -public class TopoUiModelManager implements TopoUiModelService { | ||
70 | - | ||
71 | - // TODO: put back to 30,000 ms for production | ||
72 | - private static final long SUMMARY_PERIOD = 15_000; | ||
73 | - | ||
74 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
75 | - | ||
76 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
77 | - protected ClusterService clusterService; | ||
78 | - | ||
79 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
80 | - protected DeviceService deviceService; | ||
81 | - | ||
82 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
83 | - protected LinkService linkService; | ||
84 | - | ||
85 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
86 | - protected HostService hostService; | ||
87 | - | ||
88 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
89 | - protected MastershipService mastershipService; | ||
90 | - | ||
91 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
92 | - protected IntentService intentService; | ||
93 | - | ||
94 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
95 | - protected FlowRuleService flowRuleService; | ||
96 | - | ||
97 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
98 | - protected TopologyService topologyService; | ||
99 | - | ||
100 | - | ||
101 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
102 | - protected EventDeliveryService eventDispatcher; | ||
103 | - | ||
104 | - | ||
105 | - private final ModelListenerRegistry listenerRegistry = | ||
106 | - new ModelListenerRegistry(); | ||
107 | - | ||
108 | - private final TopoMessageFactory messageFactory = new TopoMessageFactory(); | ||
109 | - private final MetaDb metaDb = new MetaDb(); | ||
110 | - | ||
111 | - private final Timer timer = new Timer("topology-view"); | ||
112 | - | ||
113 | - private TimerTask summaryTask = null; | ||
114 | - private boolean summaryRunning = false; | ||
115 | - | ||
116 | - | ||
117 | - @Activate | ||
118 | - public void activate() { | ||
119 | - eventDispatcher.addSink(TopoUiEvent.class, listenerRegistry); | ||
120 | - messageFactory.injectServices( | ||
121 | - metaDb, | ||
122 | - clusterService, | ||
123 | - deviceService, | ||
124 | - linkService, | ||
125 | - hostService, | ||
126 | - mastershipService | ||
127 | - // TODO: others?? | ||
128 | - ); | ||
129 | - log.info("Started"); | ||
130 | - } | ||
131 | - | ||
132 | - @Deactivate | ||
133 | - public void deactivate() { | ||
134 | - eventDispatcher.removeSink(TopoUiEvent.class); | ||
135 | - log.info("Stopped"); | ||
136 | - } | ||
137 | - | ||
138 | - | ||
139 | - @Override | ||
140 | - public void addListener(TopoUiListener listener) { | ||
141 | - listenerRegistry.addListener(listener); | ||
142 | - } | ||
143 | - | ||
144 | - @Override | ||
145 | - public void removeListener(TopoUiListener listener) { | ||
146 | - listenerRegistry.removeListener(listener); | ||
147 | - } | ||
148 | - | ||
149 | - @Override | ||
150 | - public List<ObjectNode> getInitialState() { | ||
151 | - List<ObjectNode> results = new ArrayList<>(); | ||
152 | - addInstances(results); | ||
153 | - addDevices(results); | ||
154 | - addLinks(results); | ||
155 | - addHosts(results); | ||
156 | - return results; | ||
157 | - } | ||
158 | - | ||
159 | - @Override | ||
160 | - public synchronized void startSummaryMonitoring() { | ||
161 | - // first, cancel previous task if not canceled already | ||
162 | - stopSummaryMonitoring(); | ||
163 | - | ||
164 | - // create and start a summary task, to execute with no delay, and | ||
165 | - // every SUMMARY_PERIOD milliseconds thereafter. | ||
166 | - summaryTask = new TimerTask() { | ||
167 | - @Override | ||
168 | - public void run() { | ||
169 | - if (summaryRunning) { | ||
170 | - post(new TopoUiEvent(SUMMARY_UPDATE, null)); | ||
171 | - } | ||
172 | - } | ||
173 | - }; | ||
174 | - | ||
175 | - timer.schedule(summaryTask, 0, SUMMARY_PERIOD); | ||
176 | - summaryRunning = true; | ||
177 | - } | ||
178 | - | ||
179 | - @Override | ||
180 | - public synchronized void stopSummaryMonitoring() { | ||
181 | - if (summaryTask != null) { | ||
182 | - summaryTask.cancel(); | ||
183 | - summaryTask = null; | ||
184 | - } | ||
185 | - summaryRunning = false; | ||
186 | - } | ||
187 | - | ||
188 | - @Override | ||
189 | - public SummaryData getSummaryData() { | ||
190 | - return new SummaryDataImpl(); | ||
191 | - } | ||
192 | - | ||
193 | - // ===================================================================== | ||
194 | - | ||
195 | - private final class SummaryDataImpl implements SummaryData { | ||
196 | - private final Topology topology = topologyService.currentTopology(); | ||
197 | - | ||
198 | - @Override | ||
199 | - public int deviceCount() { | ||
200 | - return topology.deviceCount(); | ||
201 | - } | ||
202 | - | ||
203 | - @Override | ||
204 | - public int linkCount() { | ||
205 | - return topology.linkCount(); | ||
206 | - } | ||
207 | - | ||
208 | - @Override | ||
209 | - public int hostCount() { | ||
210 | - return hostService.getHostCount(); | ||
211 | - } | ||
212 | - | ||
213 | - @Override | ||
214 | - public int clusterCount() { | ||
215 | - return topology.clusterCount(); | ||
216 | - } | ||
217 | - | ||
218 | - @Override | ||
219 | - public long intentCount() { | ||
220 | - return intentService.getIntentCount(); | ||
221 | - } | ||
222 | - | ||
223 | - @Override | ||
224 | - public int flowRuleCount() { | ||
225 | - return flowRuleService.getFlowRuleCount(); | ||
226 | - } | ||
227 | - } | ||
228 | - | ||
229 | - // ===================================================================== | ||
230 | - | ||
231 | - private static final Comparator<? super ControllerNode> NODE_COMPARATOR = | ||
232 | - (o1, o2) -> o1.id().toString().compareTo(o2.id().toString()); | ||
233 | - | ||
234 | - // ===================================================================== | ||
235 | - | ||
236 | - private void addInstances(List<ObjectNode> results) { | ||
237 | - List<ControllerNode> nodes = new ArrayList<>(clusterService.getNodes()); | ||
238 | - Collections.sort(nodes, NODE_COMPARATOR); | ||
239 | - for (ControllerNode node : nodes) { | ||
240 | - ClusterEvent ev = new ClusterEvent(INSTANCE_ADDED, node); | ||
241 | - results.add(messageFactory.instanceMessage(ev)); | ||
242 | - } | ||
243 | - } | ||
244 | - | ||
245 | - private void addDevices(List<ObjectNode> results) { | ||
246 | - // Send optical first, others later -- for layered rendering | ||
247 | - List<DeviceEvent> deferred = new ArrayList<>(); | ||
248 | - | ||
249 | - for (Device device : deviceService.getDevices()) { | ||
250 | - DeviceEvent ev = new DeviceEvent(DEVICE_ADDED, device); | ||
251 | - if (device.type() == Device.Type.ROADM) { | ||
252 | - results.add(messageFactory.deviceMessage(ev)); | ||
253 | - } else { | ||
254 | - deferred.add(ev); | ||
255 | - } | ||
256 | - } | ||
257 | - | ||
258 | - for (DeviceEvent ev : deferred) { | ||
259 | - results.add(messageFactory.deviceMessage(ev)); | ||
260 | - } | ||
261 | - } | ||
262 | - | ||
263 | - private void addLinks(List<ObjectNode> results) { | ||
264 | - // Send optical first, others later -- for layered rendering | ||
265 | - List<LinkEvent> deferred = new ArrayList<>(); | ||
266 | - | ||
267 | - for (Link link : linkService.getLinks()) { | ||
268 | - LinkEvent ev = new LinkEvent(LINK_ADDED, link); | ||
269 | - if (link.type() == Link.Type.OPTICAL) { | ||
270 | - results.add(messageFactory.linkMessage(ev)); | ||
271 | - } else { | ||
272 | - deferred.add(ev); | ||
273 | - } | ||
274 | - } | ||
275 | - | ||
276 | - for (LinkEvent ev : deferred) { | ||
277 | - results.add(messageFactory.linkMessage(ev)); | ||
278 | - } | ||
279 | - } | ||
280 | - | ||
281 | - private void addHosts(List<ObjectNode> results) { | ||
282 | - for (Host host : hostService.getHosts()) { | ||
283 | - HostEvent ev = new HostEvent(HOST_ADDED, host); | ||
284 | - results.add(messageFactory.hostMessage(ev)); | ||
285 | - } | ||
286 | - } | ||
287 | - | ||
288 | - // ===================================================================== | ||
289 | - | ||
290 | - private void post(TopoUiEvent event) { | ||
291 | - if (event != null) { | ||
292 | - eventDispatcher.post(event); | ||
293 | - } | ||
294 | - } | ||
295 | - | ||
296 | - // NOTE: session-independent state only | ||
297 | - // private inner classes to listen to device/host/link events | ||
298 | - // TODO.. | ||
299 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | - | ||
22 | -import java.util.List; | ||
23 | - | ||
24 | -/**t | ||
25 | - * Defines the API for the Topology UI Model. | ||
26 | - */ | ||
27 | -public interface TopoUiModelService { | ||
28 | - | ||
29 | - /** | ||
30 | - * Registers the specified listener for Topology UI Model events. | ||
31 | - * | ||
32 | - * @param listener the listener | ||
33 | - */ | ||
34 | - void addListener(TopoUiListener listener); | ||
35 | - | ||
36 | - /** | ||
37 | - * Unregister the specified listener. | ||
38 | - * | ||
39 | - * @param listener the listener | ||
40 | - */ | ||
41 | - void removeListener(TopoUiListener listener); | ||
42 | - | ||
43 | - | ||
44 | - /** | ||
45 | - * Returns events describing the current state of the model. | ||
46 | - * <p> | ||
47 | - * These will be in the form of "addInstance", "addDevice", "addLink", | ||
48 | - * and "addHost" events, as appropriate. | ||
49 | - * | ||
50 | - * @return initial state messages | ||
51 | - */ | ||
52 | - List<ObjectNode> getInitialState(); | ||
53 | - | ||
54 | - /** | ||
55 | - * Starts the summary monitoring process. | ||
56 | - * <p> | ||
57 | - * Sends a "showSummary" message now, and schedules a task to send | ||
58 | - * updates whenever the data changes. | ||
59 | - */ | ||
60 | - void startSummaryMonitoring(); | ||
61 | - | ||
62 | - /** | ||
63 | - * Cancels the task that sends summary updates. | ||
64 | - */ | ||
65 | - void stopSummaryMonitoring(); | ||
66 | - | ||
67 | - /** | ||
68 | - * Returns base data about the topology. | ||
69 | - * | ||
70 | - * @return summary data | ||
71 | - */ | ||
72 | - SummaryData getSummaryData(); | ||
73 | -} |
web/gui/src/main/java/org/onosproject/ui/impl/topo/overlay/AbstractSummaryGenerator.java
deleted
100644 → 0
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo.overlay; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
21 | -import com.fasterxml.jackson.databind.node.ArrayNode; | ||
22 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
23 | - | ||
24 | -import java.text.DecimalFormat; | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.List; | ||
27 | - | ||
28 | -/** | ||
29 | - * Base implementation of a {@link SummaryGenerator}. Provides convenience | ||
30 | - * methods for compiling a list of properties to be displayed in the summary | ||
31 | - * panel on the UI. | ||
32 | - */ | ||
33 | -public abstract class AbstractSummaryGenerator implements SummaryGenerator { | ||
34 | - private static final String NUMBER_FORMAT = "#,###"; | ||
35 | - private static final DecimalFormat DF = new DecimalFormat(NUMBER_FORMAT); | ||
36 | - private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
37 | - | ||
38 | - private final List<Prop> props = new ArrayList<>(); | ||
39 | - private String iconId; | ||
40 | - private String title; | ||
41 | - | ||
42 | - /** | ||
43 | - * Constructs a summary generator without specifying the icon ID or title. | ||
44 | - * It is expected that the title (and optionally the icon ID) will be set | ||
45 | - * later via {@link #title(String)} (and {@link #iconId(String)}), before | ||
46 | - * {@link #buildObjectNode()} is invoked to generate the message payload. | ||
47 | - */ | ||
48 | - public AbstractSummaryGenerator() { | ||
49 | - } | ||
50 | - | ||
51 | - /** | ||
52 | - * Constructs a summary generator that uses the specified iconId ID and | ||
53 | - * title in its generated output. | ||
54 | - * | ||
55 | - * @param iconId iconId ID | ||
56 | - * @param title title | ||
57 | - */ | ||
58 | - public AbstractSummaryGenerator(String iconId, String title) { | ||
59 | - this.iconId = iconId; | ||
60 | - this.title = title; | ||
61 | - } | ||
62 | - | ||
63 | - /** | ||
64 | - * Subclasses need to provide an implementation. | ||
65 | - * | ||
66 | - * @return the summary payload | ||
67 | - */ | ||
68 | - @Override | ||
69 | - public abstract ObjectNode generateSummary(); | ||
70 | - | ||
71 | - /** | ||
72 | - * Formats the given number into a string, using comma separator. | ||
73 | - * | ||
74 | - * @param number the number | ||
75 | - * @return formatted as a string | ||
76 | - */ | ||
77 | - protected String format(Number number) { | ||
78 | - return DF.format(number); | ||
79 | - } | ||
80 | - | ||
81 | - /** | ||
82 | - * Sets the iconId ID to use. | ||
83 | - * | ||
84 | - * @param iconId iconId ID | ||
85 | - */ | ||
86 | - protected void iconId(String iconId) { | ||
87 | - this.iconId = iconId; | ||
88 | - } | ||
89 | - | ||
90 | - /** | ||
91 | - * Sets the summary panel title. | ||
92 | - * | ||
93 | - * @param title the title | ||
94 | - */ | ||
95 | - protected void title(String title) { | ||
96 | - this.title = title; | ||
97 | - } | ||
98 | - | ||
99 | - /** | ||
100 | - * Clears out the cache of properties. | ||
101 | - */ | ||
102 | - protected void clearProps() { | ||
103 | - props.clear(); | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * Adds a property to the summary. Note that the value is converted to | ||
108 | - * a string by invoking the <code>toString()</code> method on it. | ||
109 | - * | ||
110 | - * @param label the label | ||
111 | - * @param value the value | ||
112 | - */ | ||
113 | - protected void prop(String label, Object value) { | ||
114 | - props.add(new Prop(label, value)); | ||
115 | - } | ||
116 | - | ||
117 | - /** | ||
118 | - * Adds a separator to the summary; when rendered on the client, a visible | ||
119 | - * break between properties. | ||
120 | - */ | ||
121 | - protected void separator() { | ||
122 | - props.add(new Prop("-", "")); | ||
123 | - } | ||
124 | - | ||
125 | - /** | ||
126 | - * Builds an object node from the current state of the summary generator. | ||
127 | - * | ||
128 | - * @return summary payload as JSON object node | ||
129 | - */ | ||
130 | - protected ObjectNode buildObjectNode() { | ||
131 | - ObjectNode result = MAPPER.createObjectNode(); | ||
132 | - // NOTE: "id" and "type" are currently used for title and iconID | ||
133 | - // so that this structure can be "re-used" with detail panel payloads | ||
134 | - result.put("id", title).put("type", iconId); | ||
135 | - | ||
136 | - ObjectNode pnode = MAPPER.createObjectNode(); | ||
137 | - ArrayNode porder = MAPPER.createArrayNode(); | ||
138 | - | ||
139 | - for (Prop p : props) { | ||
140 | - porder.add(p.label); | ||
141 | - pnode.put(p.label, p.value); | ||
142 | - } | ||
143 | - result.set("propOrder", porder); | ||
144 | - result.set("props", pnode); | ||
145 | - | ||
146 | - return result; | ||
147 | - } | ||
148 | - | ||
149 | - // =================================================================== | ||
150 | - | ||
151 | - /** | ||
152 | - * Abstraction of a property, that is, a label-value pair. | ||
153 | - */ | ||
154 | - private static class Prop { | ||
155 | - private final String label; | ||
156 | - private final String value; | ||
157 | - | ||
158 | - public Prop(String label, Object value) { | ||
159 | - this.label = label; | ||
160 | - this.value = value.toString(); | ||
161 | - } | ||
162 | - } | ||
163 | -} |
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 | - */ | ||
17 | - | ||
18 | -package org.onosproject.ui.impl.topo.overlay; | ||
19 | - | ||
20 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | - | ||
22 | -/** | ||
23 | - * May be called upon to generate the summary messages for the topology view | ||
24 | - * in the GUI. | ||
25 | - * <p> | ||
26 | - * It is assumed that if a custom summary generator is installed on the server | ||
27 | - * (as part of a topology overlay), a peer custom summary message handler will | ||
28 | - * be installed on the client side to handle the messages thus generated. | ||
29 | - */ | ||
30 | -public interface SummaryGenerator { | ||
31 | - /** | ||
32 | - * Generates the payload for the "showSummary" message. | ||
33 | - * | ||
34 | - * @return the message payload | ||
35 | - */ | ||
36 | - ObjectNode generateSummary(); | ||
37 | -} |
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 | - | ||
17 | -/** | ||
18 | - * Base abstractions and utilities for creating topology view overlays; experimental. | ||
19 | - */ | ||
20 | -package org.onosproject.ui.impl.topo.overlay; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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 | - | ||
17 | -/** | ||
18 | - * Topology view server-side model service with ability for apps to overlay | ||
19 | - * their own functionality and information; experimental. | ||
20 | - */ | ||
21 | -package org.onosproject.ui.impl.topo; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment