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