fix for host remove event when an instance comes back online
Change-Id: Ie9099eabcda7f7e0435a09eeca17e2f8954e051d
diff --git a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
index c76cb7f..0e05278 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
@@ -105,6 +105,8 @@
hosts = host.asJavaMap();
+ prevHosts.putAll(hosts);
+
host.addListener(hostLocationTracker);
log.info("Started");
@@ -293,19 +295,25 @@
@Override
public void event(MapEvent<HostId, DefaultHost> event) {
DefaultHost host = checkNotNull(event.value().value());
- if (event.type() == MapEvent.Type.INSERT) {
- Host prevHost = prevHosts.put(host.id(), host);
- if (prevHost == null) {
+ Host prevHost = prevHosts.put(host.id(), host);
+ switch (event.type()) {
+ case INSERT:
notifyDelegate(new HostEvent(HOST_ADDED, host));
- } else if (!Objects.equals(prevHost.location(), host.location())) {
- notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost));
- } else if (!Objects.equals(prevHost, host)) {
- notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost));
- }
- } else if (event.type() == MapEvent.Type.REMOVE) {
- if (prevHosts.remove(host.id()) != null) {
- notifyDelegate(new HostEvent(HOST_REMOVED, host));
- }
+ break;
+ case UPDATE:
+ if (!Objects.equals(prevHost.location(), host.location())) {
+ notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost));
+ } else if (!Objects.equals(prevHost, host)) {
+ notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost));
+ }
+ break;
+ case REMOVE:
+ if (prevHosts.remove(host.id()) != null) {
+ notifyDelegate(new HostEvent(HOST_REMOVED, host));
+ }
+ break;
+ default:
+ log.warn("Unknown map event type: {}", event.type());
}
}
}