Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 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 | package org.onosproject.ui.impl.topo.model; |
| 18 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 19 | import org.onosproject.cluster.ControllerNode; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 20 | import org.onosproject.cluster.NodeId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 21 | import org.onosproject.cluster.RoleInfo; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 22 | import org.onosproject.event.EventDispatcher; |
| 23 | import org.onosproject.net.Device; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 24 | import org.onosproject.net.DeviceId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 25 | import org.onosproject.net.EdgeLink; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 26 | import org.onosproject.net.Host; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 27 | import org.onosproject.net.HostId; |
| 28 | import org.onosproject.net.HostLocation; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 29 | import org.onosproject.net.Link; |
| 30 | import org.onosproject.net.region.Region; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 31 | import org.onosproject.net.region.RegionId; |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 32 | import org.onosproject.ui.UiTopoLayoutService; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 33 | import org.onosproject.ui.model.ServiceBundle; |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 34 | import org.onosproject.ui.model.topo.UiClusterMember; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 35 | import org.onosproject.ui.model.topo.UiDevice; |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 36 | import org.onosproject.ui.model.topo.UiDeviceLink; |
| 37 | import org.onosproject.ui.model.topo.UiEdgeLink; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 38 | import org.onosproject.ui.model.topo.UiElement; |
| 39 | import org.onosproject.ui.model.topo.UiHost; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 40 | import org.onosproject.ui.model.topo.UiLinkId; |
| 41 | import org.onosproject.ui.model.topo.UiRegion; |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 42 | import org.onosproject.ui.model.topo.UiSynthLink; |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 43 | import org.onosproject.ui.model.topo.UiTopoLayout; |
| 44 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 45 | import org.onosproject.ui.model.topo.UiTopology; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 46 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 48 | |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 49 | import java.util.HashSet; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 50 | import java.util.List; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 51 | import java.util.Set; |
| 52 | |
| 53 | import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 54 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.CLUSTER_MEMBER_ADDED_OR_UPDATED; |
| 55 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.CLUSTER_MEMBER_REMOVED; |
| 56 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_ADDED_OR_UPDATED; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 57 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_REMOVED; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 58 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.HOST_ADDED_OR_UPDATED; |
| 59 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.HOST_MOVED; |
| 60 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.HOST_REMOVED; |
| 61 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.LINK_ADDED_OR_UPDATED; |
| 62 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.LINK_REMOVED; |
| 63 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.REGION_ADDED_OR_UPDATED; |
| 64 | import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.REGION_REMOVED; |
| 65 | import static org.onosproject.ui.model.topo.UiLinkId.uiLinkId; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * UI Topology Model cache. |
| 69 | */ |
| 70 | class ModelCache { |
| 71 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 72 | private static final String E_NO_ELEMENT = "Tried to remove non-member {}: {}"; |
| 73 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 74 | private static final Logger log = LoggerFactory.getLogger(ModelCache.class); |
| 75 | |
| 76 | private final ServiceBundle services; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 77 | private final EventDispatcher dispatcher; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 78 | private final UiTopology uiTopology = new UiTopology(); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 79 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 80 | ModelCache(ServiceBundle services, EventDispatcher eventDispatcher) { |
| 81 | this.services = services; |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 82 | this.dispatcher = eventDispatcher; |
| 83 | } |
| 84 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 85 | @Override |
| 86 | public String toString() { |
| 87 | return "ModelCache{" + uiTopology + "}"; |
| 88 | } |
| 89 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 90 | private void postEvent(UiModelEvent.Type type, UiElement subject) { |
| 91 | dispatcher.post(new UiModelEvent(type, subject)); |
| 92 | } |
| 93 | |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 94 | void clear() { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 95 | uiTopology.clear(); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 99 | * Create our internal model of the global topology. An assumption we are |
| 100 | * making is that the topology is empty to start. |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 101 | */ |
| 102 | void load() { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 103 | loadClusterMembers(); |
| 104 | loadRegions(); |
| 105 | loadDevices(); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 106 | loadDeviceLinks(); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 107 | loadHosts(); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 111 | // === CLUSTER MEMBERS |
| 112 | |
| 113 | private UiClusterMember addNewClusterMember(ControllerNode n) { |
| 114 | UiClusterMember member = new UiClusterMember(uiTopology, n); |
| 115 | uiTopology.add(member); |
| 116 | return member; |
| 117 | } |
| 118 | |
| 119 | private void updateClusterMember(UiClusterMember member) { |
| 120 | ControllerNode.State state = services.cluster().getState(member.id()); |
| 121 | member.setState(state); |
| 122 | member.setMastership(services.mastership().getDevicesOf(member.id())); |
| 123 | // NOTE: 'UI-attached' is session-based data, not global, so will |
| 124 | // be set elsewhere |
| 125 | } |
| 126 | |
| 127 | private void loadClusterMembers() { |
| 128 | for (ControllerNode n : services.cluster().getNodes()) { |
| 129 | UiClusterMember member = addNewClusterMember(n); |
| 130 | updateClusterMember(member); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // invoked from UiSharedTopologyModel cluster event listener |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 135 | void addOrUpdateClusterMember(ControllerNode cnode) { |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 136 | NodeId id = cnode.id(); |
| 137 | UiClusterMember member = uiTopology.findClusterMember(id); |
| 138 | if (member == null) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 139 | member = addNewClusterMember(cnode); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 140 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 141 | updateClusterMember(member); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 142 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 143 | postEvent(CLUSTER_MEMBER_ADDED_OR_UPDATED, member); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 146 | // package private for unit test access |
| 147 | UiClusterMember accessClusterMember(NodeId id) { |
| 148 | return uiTopology.findClusterMember(id); |
| 149 | } |
| 150 | |
| 151 | // invoked from UiSharedTopologyModel cluster event listener |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 152 | void removeClusterMember(ControllerNode cnode) { |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 153 | NodeId id = cnode.id(); |
| 154 | UiClusterMember member = uiTopology.findClusterMember(id); |
| 155 | if (member != null) { |
| 156 | uiTopology.remove(member); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 157 | postEvent(CLUSTER_MEMBER_REMOVED, member); |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 158 | } else { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 159 | log.warn(E_NO_ELEMENT, "cluster node", id); |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 160 | } |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 163 | List<UiClusterMember> getAllClusterMembers() { |
| 164 | return uiTopology.allClusterMembers(); |
| 165 | } |
| 166 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 167 | |
| 168 | // === MASTERSHIP CHANGES |
| 169 | |
| 170 | // invoked from UiSharedTopologyModel mastership listener |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 171 | void updateMasterships(DeviceId deviceId, RoleInfo roleInfo) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 172 | // To think about:: do we need to store mastership info? |
| 173 | // or can we rely on looking it up live? |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 174 | // TODO: store the updated mastership information |
| 175 | // TODO: post event |
| 176 | } |
| 177 | |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 178 | // === THE NULL REGION |
| 179 | |
| 180 | UiRegion nullRegion() { |
| 181 | return uiTopology.nullRegion(); |
| 182 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 183 | |
| 184 | // === REGIONS |
| 185 | |
| 186 | private UiRegion addNewRegion(Region r) { |
| 187 | UiRegion region = new UiRegion(uiTopology, r); |
| 188 | uiTopology.add(region); |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 189 | log.debug("Region {} added to topology", region); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 190 | return region; |
| 191 | } |
| 192 | |
| 193 | private void updateRegion(UiRegion region) { |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 194 | RegionId rid = region.id(); |
| 195 | Set<DeviceId> deviceIds = services.region().getRegionDevices(rid); |
| 196 | |
| 197 | // Make sure device objects refer to their region |
| 198 | deviceIds.forEach(d -> { |
| 199 | UiDevice dev = uiTopology.findDevice(d); |
| 200 | if (dev != null) { |
| 201 | dev.setRegionId(rid); |
| 202 | } else { |
| 203 | // if we don't have the UiDevice in the topology, what can we do? |
| 204 | log.warn("Region device {}, but we don't have UiDevice in topology", d); |
| 205 | } |
| 206 | }); |
| 207 | |
| 208 | // Make sure the region object refers to the devices |
| 209 | region.reconcileDevices(deviceIds); |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 210 | |
| 211 | fixupContainmentHierarchy(region); |
| 212 | } |
| 213 | |
| 214 | private void fixupContainmentHierarchy(UiRegion region) { |
| 215 | UiTopoLayoutService ls = services.layout(); |
| 216 | RegionId regionId = region.id(); |
| 217 | |
| 218 | UiTopoLayout layout = ls.getLayout(regionId); |
| 219 | if (layout == null) { |
| 220 | // no layout backed by this region |
| 221 | log.warn("No layout backed by region {}", regionId); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | UiTopoLayoutId layoutId = layout.id(); |
| 226 | |
| 227 | if (!layout.isRoot()) { |
| 228 | UiTopoLayoutId parentId = layout.parent(); |
| 229 | UiTopoLayout parentLayout = ls.getLayout(parentId); |
| 230 | RegionId parentRegionId = parentLayout.regionId(); |
| 231 | region.setParent(parentRegionId); |
| 232 | } |
| 233 | |
| 234 | Set<UiTopoLayout> kids = ls.getChildren(layoutId); |
| 235 | Set<RegionId> kidRegionIds = new HashSet<>(kids.size()); |
| 236 | kids.forEach(k -> kidRegionIds.add(k.regionId())); |
| 237 | region.setChildren(kidRegionIds); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | private void loadRegions() { |
| 241 | for (Region r : services.region().getRegions()) { |
| 242 | UiRegion region = addNewRegion(r); |
| 243 | updateRegion(region); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // invoked from UiSharedTopologyModel region listener |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 248 | void addOrUpdateRegion(Region region) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 249 | RegionId id = region.id(); |
| 250 | UiRegion uiRegion = uiTopology.findRegion(id); |
| 251 | if (uiRegion == null) { |
| 252 | uiRegion = addNewRegion(region); |
| 253 | } |
| 254 | updateRegion(uiRegion); |
| 255 | |
| 256 | postEvent(REGION_ADDED_OR_UPDATED, uiRegion); |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 259 | // package private for unit test access |
| 260 | UiRegion accessRegion(RegionId id) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 261 | return id == null ? null : uiTopology.findRegion(id); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 264 | // invoked from UiSharedTopologyModel region listener |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 265 | void removeRegion(Region region) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 266 | RegionId id = region.id(); |
| 267 | UiRegion uiRegion = uiTopology.findRegion(id); |
| 268 | if (uiRegion != null) { |
| 269 | uiTopology.remove(uiRegion); |
| 270 | postEvent(REGION_REMOVED, uiRegion); |
| 271 | } else { |
| 272 | log.warn(E_NO_ELEMENT, "region", id); |
| 273 | } |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Simon Hunt | 10973dd | 2016-08-01 15:50:35 -0700 | [diff] [blame] | 276 | Set<UiRegion> getAllRegions() { |
| 277 | return uiTopology.allRegions(); |
| 278 | } |
| 279 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 280 | |
| 281 | // === DEVICES |
| 282 | |
| 283 | private UiDevice addNewDevice(Device d) { |
| 284 | UiDevice device = new UiDevice(uiTopology, d); |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 285 | updateDevice(device); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 286 | uiTopology.add(device); |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 287 | log.debug("Device {} added to topology", device); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 288 | return device; |
| 289 | } |
| 290 | |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 291 | // make sure the UiDevice is tagged with the region it belongs to |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 292 | private void updateDevice(UiDevice device) { |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 293 | Region r = services.region().getRegionForDevice(device.id()); |
| 294 | RegionId rid = r == null ? UiRegion.NULL_ID : r.id(); |
| 295 | device.setRegionId(rid); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | private void loadDevices() { |
| 299 | for (Device d : services.device().getDevices()) { |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 300 | addNewDevice(d); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | // invoked from UiSharedTopologyModel device listener |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 305 | void addOrUpdateDevice(Device device) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 306 | DeviceId id = device.id(); |
| 307 | UiDevice uiDevice = uiTopology.findDevice(id); |
| 308 | if (uiDevice == null) { |
| 309 | uiDevice = addNewDevice(device); |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 310 | } else { |
| 311 | updateDevice(uiDevice); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 312 | } |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 313 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 314 | postEvent(DEVICE_ADDED_OR_UPDATED, uiDevice); |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 317 | // package private for unit test access |
| 318 | UiDevice accessDevice(DeviceId id) { |
| 319 | return uiTopology.findDevice(id); |
| 320 | } |
| 321 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 322 | // invoked from UiSharedTopologyModel device listener |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 323 | void removeDevice(Device device) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 324 | DeviceId id = device.id(); |
| 325 | UiDevice uiDevice = uiTopology.findDevice(id); |
| 326 | if (uiDevice != null) { |
| 327 | uiTopology.remove(uiDevice); |
| 328 | postEvent(DEVICE_REMOVED, uiDevice); |
| 329 | } else { |
| 330 | log.warn(E_NO_ELEMENT, "device", id); |
| 331 | } |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -0700 | [diff] [blame] | 334 | Set<UiDevice> getAllDevices() { |
| 335 | return uiTopology.allDevices(); |
| 336 | } |
| 337 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 338 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 339 | // === LINKS === |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 340 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 341 | private UiDeviceLink addNewDeviceLink(UiLinkId id) { |
| 342 | UiDeviceLink uiDeviceLink = new UiDeviceLink(uiTopology, id); |
| 343 | uiTopology.add(uiDeviceLink); |
| 344 | return uiDeviceLink; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 347 | private UiEdgeLink addNewEdgeLink(UiLinkId id) { |
| 348 | UiEdgeLink uiEdgeLink = new UiEdgeLink(uiTopology, id); |
| 349 | uiTopology.add(uiEdgeLink); |
| 350 | return uiEdgeLink; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 353 | private void updateDeviceLink(UiDeviceLink uiDeviceLink, Link link) { |
| 354 | uiDeviceLink.attachBackingLink(link); |
| 355 | } |
| 356 | |
| 357 | private void loadDeviceLinks() { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 358 | for (Link link : services.link().getLinks()) { |
| 359 | UiLinkId id = uiLinkId(link); |
| 360 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 361 | UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id); |
| 362 | if (uiDeviceLink == null) { |
| 363 | uiDeviceLink = addNewDeviceLink(id); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 364 | } |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 365 | updateDeviceLink(uiDeviceLink, link); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | // invoked from UiSharedTopologyModel link listener |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 370 | void addOrUpdateDeviceLink(Link link) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 371 | UiLinkId id = uiLinkId(link); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 372 | UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id); |
| 373 | if (uiDeviceLink == null) { |
| 374 | uiDeviceLink = addNewDeviceLink(id); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 375 | } |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 376 | updateDeviceLink(uiDeviceLink, link); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 377 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 378 | postEvent(LINK_ADDED_OR_UPDATED, uiDeviceLink); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 381 | // package private for unit test access |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 382 | UiDeviceLink accessDeviceLink(UiLinkId id) { |
| 383 | return uiTopology.findDeviceLink(id); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 386 | // invoked from UiSharedTopologyModel link listener |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 387 | void removeDeviceLink(Link link) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 388 | UiLinkId id = uiLinkId(link); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 389 | UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id); |
| 390 | if (uiDeviceLink != null) { |
| 391 | boolean remaining = uiDeviceLink.detachBackingLink(link); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 392 | if (remaining) { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 393 | postEvent(LINK_ADDED_OR_UPDATED, uiDeviceLink); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 394 | } else { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 395 | uiTopology.remove(uiDeviceLink); |
| 396 | postEvent(LINK_REMOVED, uiDeviceLink); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 397 | } |
| 398 | } else { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 399 | log.warn(E_NO_ELEMENT, "Device link", id); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 400 | } |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 403 | Set<UiDeviceLink> getAllDeviceLinks() { |
| 404 | return uiTopology.allDeviceLinks(); |
Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -0700 | [diff] [blame] | 405 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 406 | |
| 407 | // === HOSTS |
| 408 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 409 | private EdgeLink synthesizeLink(Host h) { |
| 410 | return createEdgeLink(h, true); |
| 411 | } |
| 412 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 413 | private UiHost addNewHost(Host h) { |
| 414 | UiHost host = new UiHost(uiTopology, h); |
| 415 | uiTopology.add(host); |
| 416 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 417 | EdgeLink elink = synthesizeLink(h); |
| 418 | UiLinkId elinkId = uiLinkId(elink); |
| 419 | host.setEdgeLinkId(elinkId); |
| 420 | |
| 421 | // add synthesized edge link to the topology |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 422 | UiEdgeLink edgeLink = addNewEdgeLink(elinkId); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 423 | edgeLink.attachEdgeLink(elink); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 424 | |
| 425 | return host; |
| 426 | } |
| 427 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 428 | private void insertNewUiEdgeLink(UiLinkId id, EdgeLink e) { |
| 429 | UiEdgeLink newEdgeLink = addNewEdgeLink(id); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 430 | newEdgeLink.attachEdgeLink(e); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | private void updateHost(UiHost uiHost, Host h) { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 434 | UiEdgeLink existing = uiTopology.findEdgeLink(uiHost.edgeLinkId()); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 435 | |
| 436 | EdgeLink currentElink = synthesizeLink(h); |
| 437 | UiLinkId currentElinkId = uiLinkId(currentElink); |
| 438 | |
| 439 | if (existing != null) { |
| 440 | if (!currentElinkId.equals(existing.id())) { |
| 441 | // edge link has changed |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 442 | insertNewUiEdgeLink(currentElinkId, currentElink); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 443 | uiHost.setEdgeLinkId(currentElinkId); |
| 444 | |
| 445 | uiTopology.remove(existing); |
| 446 | } |
| 447 | |
| 448 | } else { |
| 449 | // no previously existing edge link |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 450 | insertNewUiEdgeLink(currentElinkId, currentElink); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 451 | uiHost.setEdgeLinkId(currentElinkId); |
| 452 | |
| 453 | } |
| 454 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 455 | HostLocation hloc = h.location(); |
| 456 | uiHost.setLocation(hloc.deviceId(), hloc.port()); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | private void loadHosts() { |
| 460 | for (Host h : services.host().getHosts()) { |
| 461 | UiHost host = addNewHost(h); |
| 462 | updateHost(host, h); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // invoked from UiSharedTopologyModel host listener |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 467 | void addOrUpdateHost(Host host) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 468 | HostId id = host.id(); |
| 469 | UiHost uiHost = uiTopology.findHost(id); |
| 470 | if (uiHost == null) { |
| 471 | uiHost = addNewHost(host); |
| 472 | } |
| 473 | updateHost(uiHost, host); |
| 474 | |
| 475 | postEvent(HOST_ADDED_OR_UPDATED, uiHost); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 478 | // invoked from UiSharedTopologyModel host listener |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 479 | void moveHost(Host host, Host prevHost) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 480 | UiHost uiHost = uiTopology.findHost(prevHost.id()); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 481 | if (uiHost != null) { |
| 482 | updateHost(uiHost, host); |
| 483 | postEvent(HOST_MOVED, uiHost); |
| 484 | } else { |
| 485 | log.warn(E_NO_ELEMENT, "host", prevHost.id()); |
| 486 | } |
| 487 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 488 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 489 | // package private for unit test access |
| 490 | UiHost accessHost(HostId id) { |
| 491 | return uiTopology.findHost(id); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 494 | // invoked from UiSharedTopologyModel host listener |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 495 | void removeHost(Host host) { |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 496 | HostId id = host.id(); |
| 497 | UiHost uiHost = uiTopology.findHost(id); |
| 498 | if (uiHost != null) { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 499 | UiEdgeLink edgeLink = uiTopology.findEdgeLink(uiHost.edgeLinkId()); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 500 | uiTopology.remove(edgeLink); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 501 | uiTopology.remove(uiHost); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 502 | postEvent(HOST_REMOVED, uiHost); |
| 503 | } else { |
| 504 | log.warn(E_NO_ELEMENT, "host", id); |
| 505 | } |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 506 | } |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 507 | |
Simon Hunt | 4854f3d | 2016-08-02 18:13:15 -0700 | [diff] [blame] | 508 | Set<UiHost> getAllHosts() { |
| 509 | return uiTopology.allHosts(); |
| 510 | } |
| 511 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 512 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 513 | // === SYNTHETIC LINKS |
| 514 | |
| 515 | List<UiSynthLink> getSynthLinks(RegionId regionId) { |
| 516 | return uiTopology.findSynthLinks(regionId); |
| 517 | } |
| 518 | |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 519 | /** |
| 520 | * Refreshes the internal state. |
| 521 | */ |
| 522 | public void refresh() { |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 523 | // fix up internal linkages to ensure they are correct |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 524 | |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 525 | // make sure regions reflect layout containment hierarchy |
| 526 | fixupContainmentHierarchy(uiTopology.nullRegion()); |
| 527 | uiTopology.allRegions().forEach(this::fixupContainmentHierarchy); |
| 528 | |
| 529 | // make sure devices are in the correct region |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 530 | Set<UiDevice> allDevices = uiTopology.allDevices(); |
| 531 | |
| 532 | services.region().getRegions().forEach(r -> { |
| 533 | RegionId rid = r.id(); |
| 534 | UiRegion region = uiTopology.findRegion(rid); |
| 535 | if (region != null) { |
| 536 | Set<DeviceId> deviceIds = services.region().getRegionDevices(rid); |
| 537 | region.reconcileDevices(deviceIds); |
| 538 | |
| 539 | deviceIds.forEach(devId -> { |
| 540 | UiDevice dev = uiTopology.findDevice(devId); |
| 541 | if (dev != null) { |
| 542 | dev.setRegionId(r.id()); |
| 543 | allDevices.remove(dev); |
| 544 | } else { |
| 545 | log.warn("Region device ID {} but no UiDevice in topology", |
| 546 | devId); |
| 547 | } |
| 548 | }); |
| 549 | } else { |
| 550 | log.warn("No UiRegion in topology for ID {}", rid); |
| 551 | } |
| 552 | }); |
| 553 | |
| 554 | // what is left over, must belong to the null-region |
| 555 | Set<DeviceId> leftOver = new HashSet<>(allDevices.size()); |
| 556 | allDevices.forEach(d -> leftOver.add(d.id())); |
| 557 | uiTopology.nullRegion().reconcileDevices(leftOver); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 558 | |
| 559 | // now that we have correct region hierarchy, and devices are in their |
| 560 | // respective regions, we can compute synthetic links for each region. |
| 561 | uiTopology.computeSynthLinks(); |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 564 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 565 | // === CACHE STATISTICS |
| 566 | |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 567 | /** |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 568 | * Returns a detailed (multi-line) string showing the contents of the cache. |
| 569 | * |
| 570 | * @return detailed string |
| 571 | */ |
| 572 | public String dumpString() { |
| 573 | return uiTopology.dumpString(); |
| 574 | } |
| 575 | |
| 576 | /** |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 577 | * Returns the number of members in the cluster. |
| 578 | * |
| 579 | * @return number of cluster members |
| 580 | */ |
| 581 | public int clusterMemberCount() { |
| 582 | return uiTopology.clusterMemberCount(); |
| 583 | } |
| 584 | |
| 585 | /** |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 586 | * Returns the number of regions in the topology. |
Simon Hunt | 338a3b4 | 2016-04-14 09:43:52 -0700 | [diff] [blame] | 587 | * |
| 588 | * @return number of regions |
| 589 | */ |
| 590 | public int regionCount() { |
| 591 | return uiTopology.regionCount(); |
| 592 | } |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 593 | |
| 594 | /** |
| 595 | * Returns the number of devices in the topology. |
| 596 | * |
| 597 | * @return number of devices |
| 598 | */ |
| 599 | public int deviceCount() { |
| 600 | return uiTopology.deviceCount(); |
| 601 | } |
| 602 | |
| 603 | /** |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 604 | * Returns the number of device links in the topology. |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 605 | * |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 606 | * @return number of device links |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 607 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 608 | public int deviceLinkCount() { |
| 609 | return uiTopology.deviceLinkCount(); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Returns the number of edge links in the topology. |
| 614 | * |
| 615 | * @return number of edge links |
| 616 | */ |
| 617 | public int edgeLinkCount() { |
| 618 | return uiTopology.edgeLinkCount(); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Returns the number of hosts in the topology. |
| 623 | * |
| 624 | * @return number of hosts |
| 625 | */ |
| 626 | public int hostCount() { |
| 627 | return uiTopology.hostCount(); |
| 628 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 629 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 630 | /** |
| 631 | * Returns the number of synthetic links in the topology. |
| 632 | * |
| 633 | * @return the number of synthetic links |
| 634 | */ |
| 635 | public int synthLinkCount() { |
| 636 | return uiTopology.synthLinkCount(); |
| 637 | } |
Simon Hunt | cda9c03 | 2016-04-11 10:32:54 -0700 | [diff] [blame] | 638 | } |