Committed by
Gerrit Code Review
Carry previous host subject in HostEvent
This is an enhanced version of gerrit 6085 that provides not only the old location but also the entire old host subject. The main purpose is allowing apps to be aware of the change of IP address as well Change-Id: I448d73b0d1e705996259cb0ec777f959f485d9c2
Showing
4 changed files
with
31 additions
and
26 deletions
... | @@ -98,7 +98,8 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -98,7 +98,8 @@ public class DefaultHost extends AbstractElement implements Host { |
98 | return Objects.equals(this.id, other.id) && | 98 | return Objects.equals(this.id, other.id) && |
99 | Objects.equals(this.mac, other.mac) && | 99 | Objects.equals(this.mac, other.mac) && |
100 | Objects.equals(this.vlan, other.vlan) && | 100 | Objects.equals(this.vlan, other.vlan) && |
101 | - Objects.equals(this.location, other.location); | 101 | + Objects.equals(this.location, other.location) && |
102 | + Objects.equals(this.ipAddresses(), other.ipAddresses()); | ||
102 | } | 103 | } |
103 | return false; | 104 | return false; |
104 | } | 105 | } | ... | ... |
... | @@ -18,7 +18,6 @@ package org.onosproject.net.host; | ... | @@ -18,7 +18,6 @@ package org.onosproject.net.host; |
18 | import org.joda.time.LocalDateTime; | 18 | import org.joda.time.LocalDateTime; |
19 | import org.onosproject.event.AbstractEvent; | 19 | import org.onosproject.event.AbstractEvent; |
20 | import org.onosproject.net.Host; | 20 | import org.onosproject.net.Host; |
21 | -import org.onosproject.net.HostLocation; | ||
22 | 21 | ||
23 | import static com.google.common.base.MoreObjects.toStringHelper; | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
24 | 23 | ||
... | @@ -52,7 +51,7 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { | ... | @@ -52,7 +51,7 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { |
52 | HOST_MOVED | 51 | HOST_MOVED |
53 | } | 52 | } |
54 | 53 | ||
55 | - private HostLocation prevLocation; | 54 | + private Host prevSubject; |
56 | 55 | ||
57 | /** | 56 | /** |
58 | * Creates an event of a given type and for the specified host and the | 57 | * Creates an event of a given type and for the specified host and the |
... | @@ -77,25 +76,29 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { | ... | @@ -77,25 +76,29 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { |
77 | } | 76 | } |
78 | 77 | ||
79 | /** | 78 | /** |
80 | - * Creates an event with HOST_MOVED type along with the previous location | 79 | + * Creates an event with previous subject. |
81 | - * of the host. | ||
82 | * | 80 | * |
81 | + * The previous subject is ignored if the type is not moved or updated | ||
82 | + * | ||
83 | + * @param type host event type | ||
83 | * @param host event host subject | 84 | * @param host event host subject |
84 | - * @param prevLocation previous location of the host | 85 | + * @param prevSubject previous host subject |
85 | */ | 86 | */ |
86 | - public HostEvent(Host host, HostLocation prevLocation) { | 87 | + public HostEvent(Type type, Host host, Host prevSubject) { |
87 | - super(Type.HOST_MOVED, host); | 88 | + super(type, host); |
88 | - this.prevLocation = prevLocation; | 89 | + if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED) { |
90 | + this.prevSubject = prevSubject; | ||
91 | + } | ||
89 | } | 92 | } |
90 | 93 | ||
91 | /** | 94 | /** |
92 | - * Gets the previous location information in this host event. | 95 | + * Gets the previous subject in this host event. |
93 | * | 96 | * |
94 | - * @return the previous location, or null if previous location is not | 97 | + * @return the previous subject, or null if previous subject is not |
95 | * specified. | 98 | * specified. |
96 | */ | 99 | */ |
97 | - public HostLocation prevLocation() { | 100 | + public Host prevSubject() { |
98 | - return this.prevLocation; | 101 | + return this.prevSubject; |
99 | } | 102 | } |
100 | 103 | ||
101 | @Override | 104 | @Override |
... | @@ -104,7 +107,7 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { | ... | @@ -104,7 +107,7 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { |
104 | .add("time", new LocalDateTime(time())) | 107 | .add("time", new LocalDateTime(time())) |
105 | .add("type", type()) | 108 | .add("type", type()) |
106 | .add("subject", subject()) | 109 | .add("subject", subject()) |
107 | - .add("prevLocation", prevLocation()) | 110 | + .add("prevSubject", prevSubject()) |
108 | .toString(); | 111 | .toString(); |
109 | } | 112 | } |
110 | } | 113 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
19 | import static com.google.common.base.Preconditions.checkState; | 19 | import static com.google.common.base.Preconditions.checkState; |
20 | import static org.onosproject.net.DefaultAnnotations.merge; | 20 | import static org.onosproject.net.DefaultAnnotations.merge; |
21 | import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; | 21 | import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; |
22 | +import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED; | ||
22 | import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; | 23 | import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; |
23 | import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; | 24 | import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; |
24 | import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; | 25 | import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; |
... | @@ -88,7 +89,7 @@ public class ECHostStore | ... | @@ -88,7 +89,7 @@ public class ECHostStore |
88 | 89 | ||
89 | private EventuallyConsistentMap<HostId, DefaultHost> hosts; | 90 | private EventuallyConsistentMap<HostId, DefaultHost> hosts; |
90 | 91 | ||
91 | - private final ConcurrentHashMap<HostId, HostLocation> locations = | 92 | + private final ConcurrentHashMap<HostId, DefaultHost> prevHosts = |
92 | new ConcurrentHashMap<>(); | 93 | new ConcurrentHashMap<>(); |
93 | 94 | ||
94 | private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker = | 95 | private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker = |
... | @@ -114,7 +115,7 @@ public class ECHostStore | ... | @@ -114,7 +115,7 @@ public class ECHostStore |
114 | public void deactivate() { | 115 | public void deactivate() { |
115 | hosts.removeListener(hostLocationTracker); | 116 | hosts.removeListener(hostLocationTracker); |
116 | hosts.destroy(); | 117 | hosts.destroy(); |
117 | - locations.clear(); | 118 | + prevHosts.clear(); |
118 | 119 | ||
119 | log.info("Stopped"); | 120 | log.info("Stopped"); |
120 | } | 121 | } |
... | @@ -253,16 +254,16 @@ public class ECHostStore | ... | @@ -253,16 +254,16 @@ public class ECHostStore |
253 | public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) { | 254 | public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) { |
254 | DefaultHost host = checkNotNull(event.value()); | 255 | DefaultHost host = checkNotNull(event.value()); |
255 | if (event.type() == PUT) { | 256 | if (event.type() == PUT) { |
256 | - HostLocation prevLocation = locations.put(host.id(), host.location()); | 257 | + Host prevHost = prevHosts.put(host.id(), host); |
257 | - if (prevLocation == null) { | 258 | + if (prevHost == null) { |
258 | notifyDelegate(new HostEvent(HOST_ADDED, host)); | 259 | notifyDelegate(new HostEvent(HOST_ADDED, host)); |
259 | - } else if (!Objects.equals(prevLocation, host.location())) { | 260 | + } else if (!Objects.equals(prevHost.location(), host.location())) { |
260 | - notifyDelegate(new HostEvent(host, prevLocation)); | 261 | + notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); |
261 | - } else { | 262 | + } else if (!Objects.equals(prevHost, host)) { |
262 | - notifyDelegate(new HostEvent(HOST_UPDATED, host)); | 263 | + notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); |
263 | } | 264 | } |
264 | } else if (event.type() == REMOVE) { | 265 | } else if (event.type() == REMOVE) { |
265 | - if (locations.remove(host.id()) != null) { | 266 | + if (prevHosts.remove(host.id()) != null) { |
266 | notifyDelegate(new HostEvent(HOST_REMOVED, host)); | 267 | notifyDelegate(new HostEvent(HOST_REMOVED, host)); |
267 | } | 268 | } |
268 | } | 269 | } | ... | ... |
... | @@ -291,8 +291,8 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -291,8 +291,8 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
291 | // Produces a host event message to the client. | 291 | // Produces a host event message to the client. |
292 | protected ObjectNode hostMessage(HostEvent event) { | 292 | protected ObjectNode hostMessage(HostEvent event) { |
293 | Host host = event.subject(); | 293 | Host host = event.subject(); |
294 | + Host prevHost = event.prevSubject(); | ||
294 | String hostType = host.annotations().value(AnnotationKeys.TYPE); | 295 | String hostType = host.annotations().value(AnnotationKeys.TYPE); |
295 | - HostLocation prevLoc = event.prevLocation(); | ||
296 | 296 | ||
297 | ObjectNode payload = objectNode() | 297 | ObjectNode payload = objectNode() |
298 | .put("id", host.id().toString()) | 298 | .put("id", host.id().toString()) |
... | @@ -300,8 +300,8 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { | ... | @@ -300,8 +300,8 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { |
300 | .put("ingress", compactLinkString(edgeLink(host, true))) | 300 | .put("ingress", compactLinkString(edgeLink(host, true))) |
301 | .put("egress", compactLinkString(edgeLink(host, false))); | 301 | .put("egress", compactLinkString(edgeLink(host, false))); |
302 | payload.set("cp", hostConnect(host.location())); | 302 | payload.set("cp", hostConnect(host.location())); |
303 | - if (prevLoc != null) { | 303 | + if (prevHost != null && prevHost.location() != null) { |
304 | - payload.set("prevCp", hostConnect(event.prevLocation())); | 304 | + payload.set("prevCp", hostConnect(prevHost.location())); |
305 | } | 305 | } |
306 | payload.set("labels", labels(ip(host.ipAddresses()), | 306 | payload.set("labels", labels(ip(host.ipAddresses()), |
307 | host.mac().toString())); | 307 | host.mac().toString())); | ... | ... |
-
Please register or login to post a comment