Simon Hunt

GUI -- deleting experimental code for topo refactoring.

Change-Id: I3984f2f4a29496259877bf045c4cc8f46d78c033
...@@ -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.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 -}
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