Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | package org.onosproject.ui.impl.topo; |
| 18 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 23 | import org.onlab.osgi.ServiceDirectory; |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 25 | import org.onosproject.cluster.ClusterService; |
| 26 | import org.onosproject.cluster.NodeId; |
| 27 | import org.onosproject.incubator.net.PortStatisticsService; |
| 28 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 29 | import org.onosproject.mastership.MastershipService; |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 30 | import org.onosproject.net.Annotated; |
| 31 | import org.onosproject.net.Annotations; |
| 32 | import org.onosproject.net.Device; |
Steven Burrows | ad75aa2 | 2016-12-14 17:17:24 -0500 | [diff] [blame] | 33 | import org.onosproject.net.DeviceId; |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 34 | import org.onosproject.net.Host; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceService; |
| 36 | import org.onosproject.net.flow.FlowRuleService; |
| 37 | import org.onosproject.net.host.HostService; |
| 38 | import org.onosproject.net.intent.IntentService; |
| 39 | import org.onosproject.net.link.LinkService; |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 40 | import org.onosproject.net.region.Region; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 41 | import org.onosproject.net.statistic.StatisticService; |
| 42 | import org.onosproject.net.topology.TopologyService; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 43 | import org.onosproject.ui.JsonUtils; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 44 | import org.onosproject.ui.UiExtensionService; |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 45 | import org.onosproject.ui.UiPreferencesService; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 46 | import org.onosproject.ui.UiTopoMap; |
| 47 | import org.onosproject.ui.UiTopoMapFactory; |
Steven Burrows | 512b627 | 2016-12-19 14:09:45 -0500 | [diff] [blame] | 48 | import org.onosproject.ui.impl.topo.model.UiModelEvent; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 49 | import org.onosproject.ui.model.topo.UiClusterMember; |
| 50 | import org.onosproject.ui.model.topo.UiDevice; |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 51 | import org.onosproject.ui.model.topo.UiElement; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 52 | import org.onosproject.ui.model.topo.UiHost; |
| 53 | import org.onosproject.ui.model.topo.UiLink; |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 54 | import org.onosproject.ui.model.topo.UiNode; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 55 | import org.onosproject.ui.model.topo.UiRegion; |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 56 | import org.onosproject.ui.model.topo.UiSynthLink; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 57 | import org.onosproject.ui.model.topo.UiTopoLayout; |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 58 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 59 | import org.slf4j.Logger; |
| 60 | import org.slf4j.LoggerFactory; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 61 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 62 | import java.util.ArrayList; |
| 63 | import java.util.HashMap; |
| 64 | import java.util.HashSet; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 65 | import java.util.List; |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 66 | import java.util.Map; |
| 67 | import java.util.Set; |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 68 | import java.util.concurrent.ConcurrentHashMap; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 69 | |
| 70 | import static com.google.common.base.Preconditions.checkNotNull; |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 71 | import static org.onosproject.net.AnnotationKeys.GRID_X; |
| 72 | import static org.onosproject.net.AnnotationKeys.GRID_Y; |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 73 | import static org.onosproject.net.AnnotationKeys.LATITUDE; |
| 74 | import static org.onosproject.net.AnnotationKeys.LONGITUDE; |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 75 | import static org.onosproject.ui.model.topo.UiNode.LAYER_DEFAULT; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Facility for creating JSON messages to send to the topology view in the |
| 79 | * Web client. |
| 80 | */ |
Simon Hunt | 537bc76 | 2016-12-20 12:15:13 -0800 | [diff] [blame] | 81 | public class Topo2Jsonifier { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 82 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 83 | private static final String E_DEF_NOT_LAST = |
| 84 | "UiNode.LAYER_DEFAULT not last in layer list"; |
| 85 | private static final String E_UNKNOWN_UI_NODE = |
| 86 | "Unknown subclass of UiNode: "; |
| 87 | |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 88 | private static final String REGION = "region"; |
| 89 | private static final String DEVICE = "device"; |
| 90 | private static final String HOST = "host"; |
Steven Burrows | 512b627 | 2016-12-19 14:09:45 -0500 | [diff] [blame] | 91 | private static final String TYPE = "type"; |
| 92 | private static final String SUBJECT = "subject"; |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 93 | private static final String DATA = "data"; |
| 94 | private static final String MEMO = "memo"; |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 95 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 96 | private static final String GEO = "geo"; |
| 97 | private static final String GRID = "grid"; |
| 98 | private static final String PKEY_TOPO_ZOOM = "topo2_zoom"; |
| 99 | private static final String ZOOM_SCALE = "zoomScale"; |
| 100 | private static final String ZOOM_PAN_X = "zoomPanX"; |
| 101 | private static final String ZOOM_PAN_Y = "zoomPanY"; |
| 102 | private static final String DEFAULT_SCALE = "1.0"; |
| 103 | private static final String DEFAULT_PAN = "0.0"; |
| 104 | |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 105 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 106 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 107 | private final ObjectMapper mapper = new ObjectMapper(); |
| 108 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 109 | // preferences are stored per user name... |
| 110 | private final String userName; |
| 111 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 112 | private ServiceDirectory directory; |
| 113 | private ClusterService clusterService; |
| 114 | private DeviceService deviceService; |
| 115 | private LinkService linkService; |
| 116 | private HostService hostService; |
| 117 | private MastershipService mastershipService; |
| 118 | private IntentService intentService; |
| 119 | private FlowRuleService flowService; |
| 120 | private StatisticService flowStatsService; |
| 121 | private PortStatisticsService portStatsService; |
| 122 | private TopologyService topologyService; |
| 123 | private TunnelService tunnelService; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 124 | private UiExtensionService uiextService; |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 125 | private UiPreferencesService prefService; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 126 | |
| 127 | |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 128 | // NOTE: we'll stick this here for now, but maybe there is a better home? |
| 129 | // (this is not distributed across the cluster) |
| 130 | private static Map<String, ObjectNode> metaUi = new ConcurrentHashMap<>(); |
| 131 | |
| 132 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Creates an instance with a reference to the services directory, so that |
| 135 | * additional information about network elements may be looked up on |
| 136 | * on the fly. |
| 137 | * |
| 138 | * @param directory service directory |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 139 | * @param userName logged in user name |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 140 | */ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 141 | public Topo2Jsonifier(ServiceDirectory directory, String userName) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 142 | this.directory = checkNotNull(directory, "Directory cannot be null"); |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 143 | this.userName = checkNotNull(userName, "User name cannot be null"); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 144 | |
| 145 | clusterService = directory.get(ClusterService.class); |
| 146 | deviceService = directory.get(DeviceService.class); |
| 147 | linkService = directory.get(LinkService.class); |
| 148 | hostService = directory.get(HostService.class); |
| 149 | mastershipService = directory.get(MastershipService.class); |
| 150 | intentService = directory.get(IntentService.class); |
| 151 | flowService = directory.get(FlowRuleService.class); |
| 152 | flowStatsService = directory.get(StatisticService.class); |
| 153 | portStatsService = directory.get(PortStatisticsService.class); |
| 154 | topologyService = directory.get(TopologyService.class); |
| 155 | tunnelService = directory.get(TunnelService.class); |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 156 | uiextService = directory.get(UiExtensionService.class); |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 157 | prefService = directory.get(UiPreferencesService.class); |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 158 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 159 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 160 | // for unit testing |
| 161 | Topo2Jsonifier() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 162 | userName = "(unit-test)"; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | private ObjectNode objectNode() { |
| 166 | return mapper.createObjectNode(); |
| 167 | } |
| 168 | |
| 169 | private ArrayNode arrayNode() { |
| 170 | return mapper.createArrayNode(); |
| 171 | } |
| 172 | |
| 173 | private String nullIsEmpty(Object o) { |
| 174 | return o == null ? "" : o.toString(); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /** |
| 179 | * Returns a JSON representation of the cluster members (ONOS instances). |
| 180 | * |
| 181 | * @param instances the instance model objects |
| 182 | * @return a JSON representation of the data |
| 183 | */ |
| 184 | ObjectNode instances(List<UiClusterMember> instances) { |
| 185 | NodeId local = clusterService.getLocalNode().id(); |
| 186 | ObjectNode payload = objectNode(); |
| 187 | |
| 188 | ArrayNode members = arrayNode(); |
| 189 | payload.set("members", members); |
| 190 | for (UiClusterMember member : instances) { |
| 191 | members.add(json(member, member.id().equals(local))); |
| 192 | } |
| 193 | |
| 194 | return payload; |
| 195 | } |
| 196 | |
| 197 | private ObjectNode json(UiClusterMember member, boolean isUiAttached) { |
Steven Burrows | ad75aa2 | 2016-12-14 17:17:24 -0500 | [diff] [blame] | 198 | int switchCount = mastershipService.getDevicesOf(member.id()).size(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 199 | return objectNode() |
| 200 | .put("id", member.id().toString()) |
| 201 | .put("ip", member.ip().toString()) |
| 202 | .put("online", member.isOnline()) |
| 203 | .put("ready", member.isReady()) |
| 204 | .put("uiAttached", isUiAttached) |
Steven Burrows | ad75aa2 | 2016-12-14 17:17:24 -0500 | [diff] [blame] | 205 | .put("switches", switchCount); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Returns a JSON representation of the layout to use for displaying in |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 210 | * the topology view. The identifiers and names of regions from the |
| 211 | * current to the root is included, so that the bread-crumb widget can |
| 212 | * be rendered. |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 213 | * |
| 214 | * @param layout the layout to transform |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 215 | * @param crumbs list of layouts in bread-crumb order |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 216 | * @return a JSON representation of the data |
| 217 | */ |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 218 | ObjectNode layout(UiTopoLayout layout, List<UiTopoLayout> crumbs) { |
| 219 | ObjectNode result = objectNode() |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 220 | .put("id", layout.id().toString()) |
| 221 | .put("parent", nullIsEmpty(layout.parent())) |
| 222 | .put("region", nullIsEmpty(layout.regionId())) |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 223 | .put("regionName", UiRegion.safeName(layout.region())); |
| 224 | addCrumbs(result, crumbs); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 225 | addBgRef(result, layout); |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 226 | return result; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 229 | private void addBgRef(ObjectNode result, UiTopoLayout layout) { |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 230 | String mapId = layout.geomap(); |
| 231 | String sprId = layout.sprites(); |
| 232 | |
| 233 | if (mapId != null) { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 234 | result.put("bgType", GEO).put("bgId", mapId); |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 235 | addMapParameters(result, mapId); |
| 236 | } else if (sprId != null) { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 237 | result.put("bgType", GRID).put("bgId", sprId); |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 238 | } |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 239 | addZoomPan(result, layout.id()); |
| 240 | } |
| 241 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 242 | private ObjectNode initialZoomForLayout(ObjectNode zoomPrefs, String id) { |
| 243 | ObjectNode zoomForLayout = defaultZoomForLayout(); |
| 244 | zoomPrefs.set(id, zoomForLayout); |
| 245 | prefService.setPreference(userName, PKEY_TOPO_ZOOM, zoomPrefs); |
| 246 | return zoomPrefs; |
| 247 | } |
| 248 | |
| 249 | private ObjectNode defaultZoomForLayout() { |
| 250 | return objectNode() |
| 251 | .put(ZOOM_SCALE, DEFAULT_SCALE) |
| 252 | .put(ZOOM_PAN_X, DEFAULT_PAN) |
| 253 | .put(ZOOM_PAN_Y, DEFAULT_PAN); |
| 254 | } |
| 255 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 256 | private void addZoomPan(ObjectNode result, UiTopoLayoutId layoutId) { |
| 257 | // need to look up topo_zoom settings from preferences service. |
| 258 | |
| 259 | // NOTE: |
| 260 | // UiPreferencesService API only allows us to retrieve ALL prefs for |
| 261 | // the given user. It would be better if we could call something like: |
| 262 | // |
| 263 | // ObjectNode value = prefService.getPreference(userName, prefKey); |
| 264 | // |
| 265 | // to get back a single value. |
| 266 | |
| 267 | Map<String, ObjectNode> userPrefs = prefService.getPreferences(userName); |
| 268 | ObjectNode zoomPrefs = userPrefs.get(PKEY_TOPO_ZOOM); |
| 269 | |
| 270 | if (zoomPrefs == null) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 271 | zoomPrefs = initialZoomForLayout(objectNode(), layoutId.id()); |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 272 | } |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 273 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 274 | ObjectNode zoomData = (ObjectNode) zoomPrefs.get(layoutId.id()); |
| 275 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 276 | if (zoomData == null) { |
| 277 | zoomPrefs = initialZoomForLayout(zoomPrefs, layoutId.id()); |
| 278 | zoomData = (ObjectNode) zoomPrefs.get(layoutId.id()); |
| 279 | } |
| 280 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 281 | result.put("bgZoomScale", zoomData.get(ZOOM_SCALE).asText()); |
| 282 | result.put("bgZoomPanX", zoomData.get(ZOOM_PAN_X).asText()); |
| 283 | result.put("bgZoomPanY", zoomData.get(ZOOM_PAN_Y).asText()); |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | private void addMapParameters(ObjectNode result, String mapId) { |
| 287 | |
| 288 | // TODO: This ought to be written more efficiently. |
| 289 | |
| 290 | // ALSO: Should retrieving a UiTopoMap by ID be something that |
| 291 | // the UiExtensionService provides, along with other |
| 292 | // useful lookups? |
| 293 | // |
| 294 | // Or should it remain very basic / general? |
| 295 | // |
| 296 | // return uiextService.getTopoMap(String mapId); |
| 297 | |
| 298 | final UiTopoMap[] map = {null}; |
| 299 | |
| 300 | uiextService.getExtensions().forEach(ext -> { |
| 301 | UiTopoMapFactory factory = ext.topoMapFactory(); |
| 302 | |
| 303 | // TODO: use .stream().filter(...) here |
| 304 | if (map[0] == null && factory != null) { |
| 305 | List<UiTopoMap> topoMaps = factory.geoMaps(); |
| 306 | |
| 307 | topoMaps.forEach(m -> { |
| 308 | if (map[0] == null && m.id().equals(mapId)) { |
| 309 | map[0] = m; |
| 310 | } |
| 311 | }); |
| 312 | } |
| 313 | }); |
| 314 | |
| 315 | UiTopoMap m = map[0]; |
| 316 | if (m != null) { |
| 317 | result.put("bgDesc", m.description()) |
| 318 | .put("bgFilePath", m.filePath()) |
| 319 | .put("bgDefaultScale", m.scale()); |
| 320 | } else { |
| 321 | result.put("bgWarn", "no map registered with id: " + mapId); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 325 | private void addCrumbs(ObjectNode result, List<UiTopoLayout> crumbs) { |
| 326 | ArrayNode trail = arrayNode(); |
| 327 | crumbs.forEach(c -> { |
| 328 | ObjectNode n = objectNode() |
| 329 | .put("id", c.regionId().toString()) |
| 330 | .put("name", UiRegion.safeName(c.region())); |
| 331 | trail.add(n); |
| 332 | }); |
| 333 | result.set("crumbs", trail); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Returns a JSON representation of the region to display in the topology |
| 338 | * view. |
| 339 | * |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 340 | * @param region the region to transform to JSON |
| 341 | * @param subRegions the subregions within this region |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 342 | * @param links the links within this region |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 343 | * @return a JSON representation of the data |
| 344 | */ |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 345 | ObjectNode region(UiRegion region, Set<UiRegion> subRegions, |
| 346 | List<UiSynthLink> links) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 347 | ObjectNode payload = objectNode(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 348 | if (region == null) { |
| 349 | payload.put("note", "no-region"); |
| 350 | return payload; |
| 351 | } |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 352 | payload.put("id", region.idAsString()); |
Simon Hunt | cd508a6 | 2016-10-27 12:47:24 -0700 | [diff] [blame] | 353 | payload.set("subregions", jsonSubRegions(subRegions)); |
| 354 | payload.set("links", jsonLinks(links)); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 355 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 356 | List<String> layerTags = region.layerOrder(); |
| 357 | List<Set<UiNode>> splitDevices = splitByLayer(layerTags, region.devices()); |
| 358 | List<Set<UiNode>> splitHosts = splitByLayer(layerTags, region.hosts()); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 359 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 360 | payload.set("devices", jsonGrouped(splitDevices)); |
| 361 | payload.set("hosts", jsonGrouped(splitHosts)); |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 362 | payload.set("layerOrder", jsonStrings(layerTags)); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 363 | |
| 364 | return payload; |
| 365 | } |
| 366 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 367 | private ArrayNode jsonSubRegions(Set<UiRegion> subregions) { |
| 368 | ArrayNode kids = arrayNode(); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 369 | subregions.forEach(s -> kids.add(jsonClosedRegion(s))); |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 370 | return kids; |
| 371 | } |
| 372 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 373 | private JsonNode jsonLinks(List<UiSynthLink> links) { |
| 374 | ArrayNode synthLinks = arrayNode(); |
| 375 | links.forEach(l -> synthLinks.add(json(l))); |
| 376 | return synthLinks; |
| 377 | } |
| 378 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 379 | private ArrayNode jsonStrings(List<String> strings) { |
| 380 | ArrayNode array = arrayNode(); |
| 381 | strings.forEach(array::add); |
| 382 | return array; |
| 383 | } |
| 384 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 385 | private ArrayNode jsonGrouped(List<Set<UiNode>> groupedNodes) { |
| 386 | ArrayNode result = arrayNode(); |
| 387 | groupedNodes.forEach(g -> { |
| 388 | ArrayNode subset = arrayNode(); |
| 389 | g.forEach(n -> subset.add(json(n))); |
| 390 | result.add(subset); |
| 391 | }); |
| 392 | return result; |
| 393 | } |
| 394 | |
Simon Hunt | 537bc76 | 2016-12-20 12:15:13 -0800 | [diff] [blame] | 395 | /** |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 396 | * Creates a JSON representation of a UI element. |
| 397 | * |
| 398 | * @param element the source element |
| 399 | * @return a JSON representation of that element |
| 400 | */ |
| 401 | public ObjectNode jsonUiElement(UiElement element) { |
| 402 | if (element instanceof UiNode) { |
| 403 | return json((UiNode) element); |
| 404 | } |
| 405 | if (element instanceof UiLink) { |
| 406 | return json((UiLink) element); |
| 407 | } |
| 408 | |
| 409 | // TODO: UiClusterMember |
| 410 | |
| 411 | // Unrecognized UiElement class |
| 412 | return objectNode() |
| 413 | .put("warning", "unknown UiElement... cannot encode") |
| 414 | .put("javaclass", element.getClass().toString()); |
| 415 | } |
| 416 | |
| 417 | /** |
Simon Hunt | 537bc76 | 2016-12-20 12:15:13 -0800 | [diff] [blame] | 418 | * Creates a JSON representation of a UI model event. |
| 419 | * |
| 420 | * @param modelEvent the source model event |
| 421 | * @return a JSON representation of that event |
| 422 | */ |
| 423 | public ObjectNode jsonEvent(UiModelEvent modelEvent) { |
Steven Burrows | 512b627 | 2016-12-19 14:09:45 -0500 | [diff] [blame] | 424 | ObjectNode payload = objectNode(); |
| 425 | payload.put(TYPE, enumToString(modelEvent.type())); |
| 426 | payload.put(SUBJECT, modelEvent.subject().idAsString()); |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 427 | payload.set(DATA, modelEvent.data()); |
| 428 | payload.put(MEMO, modelEvent.memo()); |
Steven Burrows | 512b627 | 2016-12-19 14:09:45 -0500 | [diff] [blame] | 429 | return payload; |
| 430 | } |
| 431 | |
| 432 | // TODO: Investigate why we can't do this inline |
| 433 | private String enumToString(Enum<?> e) { |
| 434 | return e.toString(); |
| 435 | } |
| 436 | |
Steven Burrows | ad75aa2 | 2016-12-14 17:17:24 -0500 | [diff] [blame] | 437 | // Returns the name of the master node for the specified device id. |
| 438 | private String master(DeviceId deviceId) { |
| 439 | NodeId master = mastershipService.getMasterFor(deviceId); |
| 440 | return master != null ? master.toString() : ""; |
| 441 | } |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 442 | |
| 443 | private ObjectNode json(UiNode node) { |
| 444 | if (node instanceof UiRegion) { |
| 445 | return jsonClosedRegion((UiRegion) node); |
| 446 | } |
| 447 | if (node instanceof UiDevice) { |
| 448 | return json((UiDevice) node); |
| 449 | } |
| 450 | if (node instanceof UiHost) { |
| 451 | return json((UiHost) node); |
| 452 | } |
| 453 | throw new IllegalStateException(E_UNKNOWN_UI_NODE + node.getClass()); |
| 454 | } |
| 455 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 456 | private ObjectNode json(UiDevice device) { |
| 457 | ObjectNode node = objectNode() |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 458 | .put("id", device.idAsString()) |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 459 | .put("nodeType", DEVICE) |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 460 | .put("type", device.type()) |
Simon Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 461 | .put("online", deviceService.isAvailable(device.id())) |
Steven Burrows | ad75aa2 | 2016-12-14 17:17:24 -0500 | [diff] [blame] | 462 | .put("master", master(device.id())) |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 463 | .put("layer", device.layer()); |
| 464 | |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 465 | Device d = device.backingDevice(); |
| 466 | |
| 467 | addProps(node, d); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 468 | addGeoGridLocation(node, d); |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 469 | addMetaUi(node, device.idAsString()); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 470 | |
| 471 | return node; |
| 472 | } |
| 473 | |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 474 | private void addProps(ObjectNode node, Annotated a) { |
| 475 | Annotations annot = a.annotations(); |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 476 | ObjectNode props = objectNode(); |
| 477 | if (annot != null) { |
| 478 | annot.keys().forEach(k -> props.put(k, annot.value(k))); |
| 479 | } |
| 480 | node.set("props", props); |
| 481 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 482 | |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 483 | private void addMetaUi(ObjectNode node, String metaInstanceId) { |
| 484 | ObjectNode meta = metaUi.get(metaInstanceId); |
| 485 | if (meta != null) { |
| 486 | node.set("metaUi", meta); |
| 487 | } |
| 488 | } |
| 489 | |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 490 | private void addGeoGridLocation(ObjectNode node, Annotated a) { |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 491 | List<String> lngLat = getAnnotValues(a, LONGITUDE, LATITUDE); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 492 | List<String> gridYX = getAnnotValues(a, GRID_Y, GRID_X); |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 493 | |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 494 | if (lngLat != null) { |
| 495 | attachLocation(node, "geo", "lng", "lat", lngLat); |
| 496 | } else if (gridYX != null) { |
| 497 | attachLocation(node, "grid", "gridY", "gridX", gridYX); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | private void attachLocation(ObjectNode node, String locType, |
| 502 | String keyA, String keyB, List<String> values) { |
| 503 | try { |
| 504 | double valA = Double.parseDouble(values.get(0)); |
| 505 | double valB = Double.parseDouble(values.get(1)); |
| 506 | ObjectNode loc = objectNode() |
| 507 | .put("type", locType) |
| 508 | .put(keyA, valA) |
| 509 | .put(keyB, valB); |
| 510 | node.set("location", loc); |
| 511 | |
| 512 | } catch (NumberFormatException e) { |
| 513 | log.warn("Invalid {} data: long/Y={}, lat/X={}", |
| 514 | locType, values.get(0), values.get(1)); |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 518 | private void addIps(ObjectNode node, Host h) { |
| 519 | Set<IpAddress> ips = h.ipAddresses(); |
| 520 | |
| 521 | ArrayNode a = arrayNode(); |
| 522 | for (IpAddress ip : ips) { |
| 523 | a.add(ip.toString()); |
| 524 | } |
| 525 | |
| 526 | node.set("ips", a); |
| 527 | } |
| 528 | |
Simon Hunt | 6a8cb4f | 2016-08-09 15:08:57 -0700 | [diff] [blame] | 529 | // return list of string values from annotated instance, for given keys |
| 530 | // return null if any keys are not present |
| 531 | List<String> getAnnotValues(Annotated a, String... annotKeys) { |
| 532 | List<String> result = new ArrayList<>(annotKeys.length); |
| 533 | for (String k : annotKeys) { |
| 534 | String v = a.annotations().value(k); |
| 535 | if (v == null) { |
| 536 | return null; |
| 537 | } |
| 538 | result.add(v); |
| 539 | } |
| 540 | return result; |
| 541 | } |
| 542 | |
| 543 | // derive JSON object from annotations |
| 544 | private ObjectNode props(Annotations annotations) { |
| 545 | ObjectNode p = objectNode(); |
| 546 | if (annotations != null) { |
| 547 | annotations.keys().forEach(k -> p.put(k, annotations.value(k))); |
| 548 | } |
| 549 | return p; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | private ObjectNode json(UiHost host) { |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 553 | ObjectNode node = objectNode() |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 554 | .put("id", host.idAsString()) |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 555 | .put("nodeType", HOST) |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 556 | .put("layer", host.layer()); |
| 557 | // TODO: complete host details |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 558 | Host h = host.backingHost(); |
| 559 | |
| 560 | addIps(node, h); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 561 | addProps(node, h); |
| 562 | addGeoGridLocation(node, h); |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 563 | addMetaUi(node, host.idAsString()); |
| 564 | |
| 565 | return node; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 568 | private ObjectNode json(UiSynthLink sLink) { |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 569 | return json(sLink.link()); |
| 570 | } |
| 571 | |
| 572 | private ObjectNode json(UiLink link) { |
Simon Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 573 | ObjectNode data = objectNode() |
Simon Hunt | 8eac4ae | 2017-01-20 12:56:45 -0800 | [diff] [blame] | 574 | .put("id", link.idAsString()) |
| 575 | .put("epA", link.endPointA()) |
| 576 | .put("epB", link.endPointB()) |
| 577 | .put("type", link.type()); |
| 578 | String pA = link.endPortA(); |
| 579 | String pB = link.endPortB(); |
Simon Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 580 | if (pA != null) { |
| 581 | data.put("portA", pA); |
| 582 | } |
| 583 | if (pB != null) { |
| 584 | data.put("portB", pB); |
| 585 | } |
| 586 | return data; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 590 | private ObjectNode jsonClosedRegion(UiRegion region) { |
Steven Burrows | 482d950 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 591 | ObjectNode node = objectNode() |
Simon Hunt | b1ce260 | 2016-07-23 14:04:31 -0700 | [diff] [blame] | 592 | .put("id", region.idAsString()) |
Simon Hunt | f836a87 | 2016-08-10 17:37:36 -0700 | [diff] [blame] | 593 | .put("name", region.name()) |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 594 | .put("nodeType", REGION) |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 595 | .put("nDevs", region.deviceCount()) |
| 596 | .put("nHosts", region.hostCount()); |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 597 | |
| 598 | Region r = region.backingRegion(); |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 599 | addGeoGridLocation(node, r); |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 600 | addProps(node, r); |
Steven Burrows | 482d950 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 601 | |
| 602 | addMetaUi(node, region.idAsString()); |
| 603 | return node; |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 606 | /** |
| 607 | * Returns a JSON array representation of a set of regions/devices. Note |
| 608 | * that the information is sufficient for showing regions as nodes. |
| 609 | * |
| 610 | * @param nodes the nodes |
| 611 | * @return a JSON representation of the nodes |
| 612 | */ |
| 613 | public ArrayNode closedNodes(Set<UiNode> nodes) { |
| 614 | ArrayNode array = arrayNode(); |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 615 | for (UiNode node : nodes) { |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 616 | if (node instanceof UiRegion) { |
| 617 | array.add(jsonClosedRegion((UiRegion) node)); |
| 618 | } else if (node instanceof UiDevice) { |
| 619 | array.add(json((UiDevice) node)); |
| 620 | } else { |
| 621 | log.warn("Unexpected node instance: {}", node.getClass()); |
| 622 | } |
| 623 | } |
| 624 | return array; |
| 625 | } |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 626 | |
| 627 | /** |
| 628 | * Returns a JSON array representation of a list of regions. Note that the |
| 629 | * information about each region is limited to what needs to be used to |
| 630 | * show the regions as nodes on the view. |
| 631 | * |
| 632 | * @param regions the regions |
| 633 | * @return a JSON representation of the minimal region information |
| 634 | */ |
| 635 | public ArrayNode closedRegions(Set<UiRegion> regions) { |
| 636 | ArrayNode array = arrayNode(); |
| 637 | for (UiRegion r : regions) { |
| 638 | array.add(jsonClosedRegion(r)); |
| 639 | } |
| 640 | return array; |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Returns a JSON array representation of a list of devices. |
| 645 | * |
| 646 | * @param devices the devices |
| 647 | * @return a JSON representation of the devices |
| 648 | */ |
| 649 | public ArrayNode devices(Set<UiDevice> devices) { |
| 650 | ArrayNode array = arrayNode(); |
| 651 | for (UiDevice device : devices) { |
| 652 | array.add(json(device)); |
| 653 | } |
| 654 | return array; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * Returns a JSON array representation of a list of hosts. |
| 659 | * |
| 660 | * @param hosts the hosts |
| 661 | * @return a JSON representation of the hosts |
| 662 | */ |
| 663 | public ArrayNode hosts(Set<UiHost> hosts) { |
| 664 | ArrayNode array = arrayNode(); |
| 665 | for (UiHost host : hosts) { |
| 666 | array.add(json(host)); |
| 667 | } |
| 668 | return array; |
| 669 | } |
| 670 | |
Simon Hunt | 977aa05 | 2016-07-20 17:08:29 -0700 | [diff] [blame] | 671 | // package-private for unit testing |
| 672 | List<Set<UiNode>> splitByLayer(List<String> layerTags, |
| 673 | Set<? extends UiNode> nodes) { |
| 674 | final int nLayers = layerTags.size(); |
| 675 | if (!layerTags.get(nLayers - 1).equals(LAYER_DEFAULT)) { |
| 676 | throw new IllegalArgumentException(E_DEF_NOT_LAST); |
| 677 | } |
| 678 | |
| 679 | List<Set<UiNode>> splitList = new ArrayList<>(layerTags.size()); |
| 680 | Map<String, Set<UiNode>> byLayer = new HashMap<>(layerTags.size()); |
| 681 | |
| 682 | for (String tag : layerTags) { |
| 683 | Set<UiNode> set = new HashSet<>(); |
| 684 | byLayer.put(tag, set); |
| 685 | splitList.add(set); |
| 686 | } |
| 687 | |
| 688 | for (UiNode n : nodes) { |
| 689 | String which = n.layer(); |
| 690 | if (!layerTags.contains(which)) { |
| 691 | which = LAYER_DEFAULT; |
| 692 | } |
| 693 | byLayer.get(which).add(n); |
| 694 | } |
| 695 | |
| 696 | return splitList; |
| 697 | } |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 698 | |
| 699 | /** |
| 700 | * Stores the memento for an element. |
| 701 | * This method assumes the payload has an id String, memento ObjectNode |
| 702 | * |
| 703 | * @param payload event payload |
| 704 | */ |
| 705 | void updateMeta(ObjectNode payload) { |
| 706 | |
| 707 | String id = JsonUtils.string(payload, "id"); |
| 708 | metaUi.put(id, JsonUtils.node(payload, "memento")); |
| 709 | |
| 710 | log.debug("Storing metadata for {}", id); |
| 711 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 712 | } |