Committed by
Gerrit Code Review
Move GossipDeviceStore away from deprecated ClusterCommunicationService API
Change-Id: Ib0ca7125e17013156aac27f8437ca717a96a56f0
Showing
2 changed files
with
160 additions
and
227 deletions
... | @@ -15,26 +15,10 @@ | ... | @@ -15,26 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.device.impl; | 16 | package org.onosproject.store.device.impl; |
17 | 17 | ||
18 | -import java.io.IOException; | 18 | +import com.google.common.collect.FluentIterable; |
19 | -import java.util.ArrayList; | 19 | +import com.google.common.collect.ImmutableList; |
20 | -import java.util.Collection; | 20 | +import com.google.common.collect.Maps; |
21 | -import java.util.Collections; | 21 | +import com.google.common.collect.Sets; |
22 | -import java.util.HashMap; | ||
23 | -import java.util.HashSet; | ||
24 | -import java.util.Iterator; | ||
25 | -import java.util.List; | ||
26 | -import java.util.Map; | ||
27 | -import java.util.Map.Entry; | ||
28 | -import java.util.Objects; | ||
29 | -import java.util.Optional; | ||
30 | -import java.util.Set; | ||
31 | -import java.util.concurrent.ConcurrentHashMap; | ||
32 | -import java.util.concurrent.ConcurrentMap; | ||
33 | -import java.util.concurrent.ExecutorService; | ||
34 | -import java.util.concurrent.ScheduledExecutorService; | ||
35 | -import java.util.concurrent.TimeUnit; | ||
36 | -import java.util.stream.Stream; | ||
37 | - | ||
38 | import org.apache.commons.lang3.RandomUtils; | 22 | import org.apache.commons.lang3.RandomUtils; |
39 | import org.apache.felix.scr.annotations.Activate; | 23 | import org.apache.felix.scr.annotations.Activate; |
40 | import org.apache.felix.scr.annotations.Component; | 24 | import org.apache.felix.scr.annotations.Component; |
... | @@ -81,8 +65,6 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -81,8 +65,6 @@ import org.onosproject.net.provider.ProviderId; |
81 | import org.onosproject.store.AbstractStore; | 65 | import org.onosproject.store.AbstractStore; |
82 | import org.onosproject.store.Timestamp; | 66 | import org.onosproject.store.Timestamp; |
83 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 67 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
84 | -import org.onosproject.store.cluster.messaging.ClusterMessage; | ||
85 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | ||
86 | import org.onosproject.store.cluster.messaging.MessageSubject; | 68 | import org.onosproject.store.cluster.messaging.MessageSubject; |
87 | import org.onosproject.store.impl.Timestamped; | 69 | import org.onosproject.store.impl.Timestamped; |
88 | import org.onosproject.store.serializers.KryoNamespaces; | 70 | import org.onosproject.store.serializers.KryoNamespaces; |
... | @@ -96,10 +78,26 @@ import org.onosproject.store.service.StorageService; | ... | @@ -96,10 +78,26 @@ import org.onosproject.store.service.StorageService; |
96 | import org.onosproject.store.service.WallClockTimestamp; | 78 | import org.onosproject.store.service.WallClockTimestamp; |
97 | import org.slf4j.Logger; | 79 | import org.slf4j.Logger; |
98 | 80 | ||
99 | -import com.google.common.collect.FluentIterable; | 81 | +import java.io.IOException; |
100 | -import com.google.common.collect.ImmutableList; | 82 | +import java.util.ArrayList; |
101 | -import com.google.common.collect.Maps; | 83 | +import java.util.Collection; |
102 | -import com.google.common.collect.Sets; | 84 | +import java.util.Collections; |
85 | +import java.util.HashMap; | ||
86 | +import java.util.HashSet; | ||
87 | +import java.util.Iterator; | ||
88 | +import java.util.List; | ||
89 | +import java.util.Map; | ||
90 | +import java.util.Map.Entry; | ||
91 | +import java.util.Objects; | ||
92 | +import java.util.Optional; | ||
93 | +import java.util.Set; | ||
94 | +import java.util.concurrent.ConcurrentHashMap; | ||
95 | +import java.util.concurrent.ConcurrentMap; | ||
96 | +import java.util.concurrent.ExecutorService; | ||
97 | +import java.util.concurrent.ScheduledExecutorService; | ||
98 | +import java.util.concurrent.TimeUnit; | ||
99 | +import java.util.function.Consumer; | ||
100 | +import java.util.stream.Stream; | ||
103 | 101 | ||
104 | import static com.google.common.base.Preconditions.checkArgument; | 102 | import static com.google.common.base.Preconditions.checkArgument; |
105 | import static com.google.common.base.Predicates.notNull; | 103 | import static com.google.common.base.Predicates.notNull; |
... | @@ -117,8 +115,13 @@ import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED; | ... | @@ -117,8 +115,13 @@ import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED; |
117 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; | 115 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; |
118 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; | 116 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; |
119 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_INJECTED; | 117 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_INJECTED; |
118 | +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE; | ||
119 | +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVED; | ||
120 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ; | 120 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ; |
121 | +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_UPDATE; | ||
121 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_INJECTED; | 122 | import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_INJECTED; |
123 | +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE; | ||
124 | +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_UPDATE; | ||
122 | import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; | 125 | import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; |
123 | import static org.slf4j.LoggerFactory.getLogger; | 126 | import static org.slf4j.LoggerFactory.getLogger; |
124 | 127 | ||
... | @@ -208,29 +211,15 @@ public class GossipDeviceStore | ... | @@ -208,29 +211,15 @@ public class GossipDeviceStore |
208 | backgroundExecutor = | 211 | backgroundExecutor = |
209 | newSingleThreadScheduledExecutor(minPriority(groupedThreads("onos/device", "bg-%d", log))); | 212 | newSingleThreadScheduledExecutor(minPriority(groupedThreads("onos/device", "bg-%d", log))); |
210 | 213 | ||
211 | - clusterCommunicator.addSubscriber( | 214 | + addSubscriber(DEVICE_UPDATE, this::handleDeviceEvent); |
212 | - GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, new InternalDeviceEventListener(), executor); | 215 | + addSubscriber(DEVICE_OFFLINE, this::handleDeviceOfflineEvent); |
213 | - clusterCommunicator.addSubscriber( | 216 | + addSubscriber(DEVICE_REMOVE_REQ, this::handleRemoveRequest); |
214 | - GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE, | 217 | + addSubscriber(DEVICE_REMOVED, this::handleDeviceRemovedEvent); |
215 | - new InternalDeviceOfflineEventListener(), | 218 | + addSubscriber(PORT_UPDATE, this::handlePortEvent); |
216 | - executor); | 219 | + addSubscriber(PORT_STATUS_UPDATE, this::handlePortStatusEvent); |
217 | - clusterCommunicator.addSubscriber(DEVICE_REMOVE_REQ, | 220 | + addSubscriber(DEVICE_ADVERTISE, this::handleDeviceAdvertisement); |
218 | - new InternalRemoveRequestListener(), | 221 | + addSubscriber(DEVICE_INJECTED, this::handleDeviceInjectedEvent); |
219 | - executor); | 222 | + addSubscriber(PORT_INJECTED, this::handlePortInjectedEvent); |
220 | - clusterCommunicator.addSubscriber( | ||
221 | - GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, new InternalDeviceRemovedEventListener(), executor); | ||
222 | - clusterCommunicator.addSubscriber( | ||
223 | - GossipDeviceStoreMessageSubjects.PORT_UPDATE, new InternalPortEventListener(), executor); | ||
224 | - clusterCommunicator.addSubscriber( | ||
225 | - GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, new InternalPortStatusEventListener(), executor); | ||
226 | - clusterCommunicator.addSubscriber( | ||
227 | - GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE, | ||
228 | - new InternalDeviceAdvertisementListener(), | ||
229 | - backgroundExecutor); | ||
230 | - clusterCommunicator.addSubscriber( | ||
231 | - GossipDeviceStoreMessageSubjects.DEVICE_INJECTED, new DeviceInjectedEventListener(), executor); | ||
232 | - clusterCommunicator.addSubscriber( | ||
233 | - GossipDeviceStoreMessageSubjects.PORT_INJECTED, new PortInjectedEventListener(), executor); | ||
234 | 223 | ||
235 | // start anti-entropy thread | 224 | // start anti-entropy thread |
236 | backgroundExecutor.scheduleAtFixedRate(new SendAdvertisementTask(), | 225 | backgroundExecutor.scheduleAtFixedRate(new SendAdvertisementTask(), |
... | @@ -261,6 +250,10 @@ public class GossipDeviceStore | ... | @@ -261,6 +250,10 @@ public class GossipDeviceStore |
261 | log.info("Started"); | 250 | log.info("Started"); |
262 | } | 251 | } |
263 | 252 | ||
253 | + private <M> void addSubscriber(MessageSubject subject, Consumer<M> handler) { | ||
254 | + clusterCommunicator.addSubscriber(subject, SERIALIZER::decode, handler, executor); | ||
255 | + } | ||
256 | + | ||
264 | @Deactivate | 257 | @Deactivate |
265 | public void deactivate() { | 258 | public void deactivate() { |
266 | devicePortStats.removeListener(portStatsListener); | 259 | devicePortStats.removeListener(portStatsListener); |
... | @@ -281,24 +274,15 @@ public class GossipDeviceStore | ... | @@ -281,24 +274,15 @@ public class GossipDeviceStore |
281 | devices.clear(); | 274 | devices.clear(); |
282 | devicePorts.clear(); | 275 | devicePorts.clear(); |
283 | availableDevices.clear(); | 276 | availableDevices.clear(); |
284 | - clusterCommunicator.removeSubscriber( | 277 | + clusterCommunicator.removeSubscriber(DEVICE_UPDATE); |
285 | - GossipDeviceStoreMessageSubjects.DEVICE_UPDATE); | 278 | + clusterCommunicator.removeSubscriber(DEVICE_OFFLINE); |
286 | - clusterCommunicator.removeSubscriber( | 279 | + clusterCommunicator.removeSubscriber(DEVICE_REMOVE_REQ); |
287 | - GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE); | 280 | + clusterCommunicator.removeSubscriber(DEVICE_REMOVED); |
288 | - clusterCommunicator.removeSubscriber( | 281 | + clusterCommunicator.removeSubscriber(PORT_UPDATE); |
289 | - GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ); | 282 | + clusterCommunicator.removeSubscriber(PORT_STATUS_UPDATE); |
290 | - clusterCommunicator.removeSubscriber( | 283 | + clusterCommunicator.removeSubscriber(DEVICE_ADVERTISE); |
291 | - GossipDeviceStoreMessageSubjects.DEVICE_REMOVED); | 284 | + clusterCommunicator.removeSubscriber(DEVICE_INJECTED); |
292 | - clusterCommunicator.removeSubscriber( | 285 | + clusterCommunicator.removeSubscriber(PORT_INJECTED); |
293 | - GossipDeviceStoreMessageSubjects.PORT_UPDATE); | ||
294 | - clusterCommunicator.removeSubscriber( | ||
295 | - GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE); | ||
296 | - clusterCommunicator.removeSubscriber( | ||
297 | - GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE); | ||
298 | - clusterCommunicator.removeSubscriber( | ||
299 | - GossipDeviceStoreMessageSubjects.DEVICE_INJECTED); | ||
300 | - clusterCommunicator.removeSubscriber( | ||
301 | - GossipDeviceStoreMessageSubjects.PORT_INJECTED); | ||
302 | log.info("Stopped"); | 286 | log.info("Stopped"); |
303 | } | 287 | } |
304 | 288 | ||
... | @@ -1336,7 +1320,7 @@ public class GossipDeviceStore | ... | @@ -1336,7 +1320,7 @@ public class GossipDeviceStore |
1336 | } | 1320 | } |
1337 | 1321 | ||
1338 | private void notifyPeers(InternalDeviceEvent event) { | 1322 | private void notifyPeers(InternalDeviceEvent event) { |
1339 | - broadcastMessage(GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, event); | 1323 | + broadcastMessage(DEVICE_UPDATE, event); |
1340 | } | 1324 | } |
1341 | 1325 | ||
1342 | private void notifyPeers(InternalDeviceOfflineEvent event) { | 1326 | private void notifyPeers(InternalDeviceOfflineEvent event) { |
... | @@ -1357,7 +1341,7 @@ public class GossipDeviceStore | ... | @@ -1357,7 +1341,7 @@ public class GossipDeviceStore |
1357 | 1341 | ||
1358 | private void notifyPeer(NodeId recipient, InternalDeviceEvent event) { | 1342 | private void notifyPeer(NodeId recipient, InternalDeviceEvent event) { |
1359 | try { | 1343 | try { |
1360 | - unicastMessage(recipient, GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, event); | 1344 | + unicastMessage(recipient, DEVICE_UPDATE, event); |
1361 | } catch (IOException e) { | 1345 | } catch (IOException e) { |
1362 | log.error("Failed to send" + event + " to " + recipient, e); | 1346 | log.error("Failed to send" + event + " to " + recipient, e); |
1363 | } | 1347 | } |
... | @@ -1631,188 +1615,124 @@ public class GossipDeviceStore | ... | @@ -1631,188 +1615,124 @@ public class GossipDeviceStore |
1631 | } | 1615 | } |
1632 | } | 1616 | } |
1633 | 1617 | ||
1634 | - private final class InternalDeviceEventListener | 1618 | + private void handleDeviceEvent(InternalDeviceEvent event) { |
1635 | - implements ClusterMessageHandler { | 1619 | + ProviderId providerId = event.providerId(); |
1636 | - @Override | 1620 | + DeviceId deviceId = event.deviceId(); |
1637 | - public void handle(ClusterMessage message) { | 1621 | + Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); |
1638 | - log.debug("Received device update event from peer: {}", message.sender()); | ||
1639 | - InternalDeviceEvent event = SERIALIZER.decode(message.payload()); | ||
1640 | - | ||
1641 | - ProviderId providerId = event.providerId(); | ||
1642 | - DeviceId deviceId = event.deviceId(); | ||
1643 | - Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); | ||
1644 | 1622 | ||
1645 | - try { | 1623 | + try { |
1646 | - notifyDelegateIfNotNull(createOrUpdateDeviceInternal(providerId, deviceId, | 1624 | + notifyDelegateIfNotNull(createOrUpdateDeviceInternal(providerId, deviceId, |
1647 | - deviceDescription)); | 1625 | + deviceDescription)); |
1648 | - } catch (Exception e) { | 1626 | + } catch (Exception e) { |
1649 | - log.warn("Exception thrown handling device update", e); | 1627 | + log.warn("Exception thrown handling device update", e); |
1650 | - } | ||
1651 | } | 1628 | } |
1652 | } | 1629 | } |
1653 | 1630 | ||
1654 | - private final class InternalDeviceOfflineEventListener | 1631 | + private void handleDeviceOfflineEvent(InternalDeviceOfflineEvent event) { |
1655 | - implements ClusterMessageHandler { | 1632 | + DeviceId deviceId = event.deviceId(); |
1656 | - @Override | 1633 | + Timestamp timestamp = event.timestamp(); |
1657 | - public void handle(ClusterMessage message) { | ||
1658 | - log.debug("Received device offline event from peer: {}", message.sender()); | ||
1659 | - InternalDeviceOfflineEvent event = SERIALIZER.decode(message.payload()); | ||
1660 | 1634 | ||
1661 | - DeviceId deviceId = event.deviceId(); | 1635 | + try { |
1662 | - Timestamp timestamp = event.timestamp(); | 1636 | + notifyDelegateIfNotNull(markOfflineInternal(deviceId, timestamp)); |
1663 | - | 1637 | + } catch (Exception e) { |
1664 | - try { | 1638 | + log.warn("Exception thrown handling device offline", e); |
1665 | - notifyDelegateIfNotNull(markOfflineInternal(deviceId, timestamp)); | ||
1666 | - } catch (Exception e) { | ||
1667 | - log.warn("Exception thrown handling device offline", e); | ||
1668 | - } | ||
1669 | } | 1639 | } |
1670 | } | 1640 | } |
1671 | 1641 | ||
1672 | - private final class InternalRemoveRequestListener | 1642 | + private void handleRemoveRequest(DeviceId did) { |
1673 | - implements ClusterMessageHandler { | 1643 | + try { |
1674 | - @Override | 1644 | + removeDevice(did); |
1675 | - public void handle(ClusterMessage message) { | 1645 | + } catch (Exception e) { |
1676 | - log.debug("Received device remove request from peer: {}", message.sender()); | 1646 | + log.warn("Exception thrown handling device remove", e); |
1677 | - DeviceId did = SERIALIZER.decode(message.payload()); | ||
1678 | - | ||
1679 | - try { | ||
1680 | - removeDevice(did); | ||
1681 | - } catch (Exception e) { | ||
1682 | - log.warn("Exception thrown handling device remove", e); | ||
1683 | - } | ||
1684 | } | 1647 | } |
1685 | } | 1648 | } |
1686 | 1649 | ||
1687 | - private final class InternalDeviceRemovedEventListener | 1650 | + private void handleDeviceRemovedEvent(InternalDeviceRemovedEvent event) { |
1688 | - implements ClusterMessageHandler { | 1651 | + DeviceId deviceId = event.deviceId(); |
1689 | - @Override | 1652 | + Timestamp timestamp = event.timestamp(); |
1690 | - public void handle(ClusterMessage message) { | ||
1691 | - log.debug("Received device removed event from peer: {}", message.sender()); | ||
1692 | - InternalDeviceRemovedEvent event = SERIALIZER.decode(message.payload()); | ||
1693 | - | ||
1694 | - DeviceId deviceId = event.deviceId(); | ||
1695 | - Timestamp timestamp = event.timestamp(); | ||
1696 | 1653 | ||
1697 | - try { | 1654 | + try { |
1698 | - notifyDelegateIfNotNull(removeDeviceInternal(deviceId, timestamp)); | 1655 | + notifyDelegateIfNotNull(removeDeviceInternal(deviceId, timestamp)); |
1699 | - } catch (Exception e) { | 1656 | + } catch (Exception e) { |
1700 | - log.warn("Exception thrown handling device removed", e); | 1657 | + log.warn("Exception thrown handling device removed", e); |
1701 | - } | ||
1702 | } | 1658 | } |
1703 | } | 1659 | } |
1704 | 1660 | ||
1705 | - private final class InternalPortEventListener | 1661 | + private void handlePortEvent(InternalPortEvent event) { |
1706 | - implements ClusterMessageHandler { | 1662 | + ProviderId providerId = event.providerId(); |
1707 | - @Override | 1663 | + DeviceId deviceId = event.deviceId(); |
1708 | - public void handle(ClusterMessage message) { | 1664 | + Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); |
1709 | - | ||
1710 | - log.debug("Received port update event from peer: {}", message.sender()); | ||
1711 | - InternalPortEvent event = SERIALIZER.decode(message.payload()); | ||
1712 | - | ||
1713 | - ProviderId providerId = event.providerId(); | ||
1714 | - DeviceId deviceId = event.deviceId(); | ||
1715 | - Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); | ||
1716 | 1665 | ||
1717 | - if (getDevice(deviceId) == null) { | 1666 | + if (getDevice(deviceId) == null) { |
1718 | - log.debug("{} not found on this node yet, ignoring.", deviceId); | 1667 | + log.debug("{} not found on this node yet, ignoring.", deviceId); |
1719 | - // Note: dropped information will be recovered by anti-entropy | 1668 | + // Note: dropped information will be recovered by anti-entropy |
1720 | - return; | 1669 | + return; |
1721 | - } | 1670 | + } |
1722 | 1671 | ||
1723 | - try { | 1672 | + try { |
1724 | - notifyDelegate(updatePortsInternal(providerId, deviceId, portDescriptions)); | 1673 | + notifyDelegate(updatePortsInternal(providerId, deviceId, portDescriptions)); |
1725 | - } catch (Exception e) { | 1674 | + } catch (Exception e) { |
1726 | - log.warn("Exception thrown handling port update", e); | 1675 | + log.warn("Exception thrown handling port update", e); |
1727 | - } | ||
1728 | } | 1676 | } |
1729 | } | 1677 | } |
1730 | 1678 | ||
1731 | - private final class InternalPortStatusEventListener | 1679 | + private void handlePortStatusEvent(InternalPortStatusEvent event) { |
1732 | - implements ClusterMessageHandler { | 1680 | + ProviderId providerId = event.providerId(); |
1733 | - @Override | 1681 | + DeviceId deviceId = event.deviceId(); |
1734 | - public void handle(ClusterMessage message) { | 1682 | + Timestamped<PortDescription> portDescription = event.portDescription(); |
1735 | - | ||
1736 | - log.debug("Received port status update event from peer: {}", message.sender()); | ||
1737 | - InternalPortStatusEvent event = SERIALIZER.decode(message.payload()); | ||
1738 | 1683 | ||
1739 | - ProviderId providerId = event.providerId(); | 1684 | + if (getDevice(deviceId) == null) { |
1740 | - DeviceId deviceId = event.deviceId(); | 1685 | + log.debug("{} not found on this node yet, ignoring.", deviceId); |
1741 | - Timestamped<PortDescription> portDescription = event.portDescription(); | 1686 | + // Note: dropped information will be recovered by anti-entropy |
1742 | - | 1687 | + return; |
1743 | - if (getDevice(deviceId) == null) { | 1688 | + } |
1744 | - log.debug("{} not found on this node yet, ignoring.", deviceId); | ||
1745 | - // Note: dropped information will be recovered by anti-entropy | ||
1746 | - return; | ||
1747 | - } | ||
1748 | 1689 | ||
1749 | - try { | 1690 | + try { |
1750 | - notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription)); | 1691 | + notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription)); |
1751 | - } catch (Exception e) { | 1692 | + } catch (Exception e) { |
1752 | - log.warn("Exception thrown handling port update", e); | 1693 | + log.warn("Exception thrown handling port update", e); |
1753 | - } | ||
1754 | } | 1694 | } |
1755 | } | 1695 | } |
1756 | 1696 | ||
1757 | - private final class InternalDeviceAdvertisementListener | 1697 | + private void handleDeviceAdvertisement(DeviceAntiEntropyAdvertisement advertisement) { |
1758 | - implements ClusterMessageHandler { | 1698 | + try { |
1759 | - @Override | 1699 | + handleAdvertisement(advertisement); |
1760 | - public void handle(ClusterMessage message) { | 1700 | + } catch (Exception e) { |
1761 | - log.trace("Received Device Anti-Entropy advertisement from peer: {}", message.sender()); | 1701 | + log.warn("Exception thrown handling Device advertisements.", e); |
1762 | - DeviceAntiEntropyAdvertisement advertisement = SERIALIZER.decode(message.payload()); | ||
1763 | - try { | ||
1764 | - handleAdvertisement(advertisement); | ||
1765 | - } catch (Exception e) { | ||
1766 | - log.warn("Exception thrown handling Device advertisements.", e); | ||
1767 | - } | ||
1768 | } | 1702 | } |
1769 | } | 1703 | } |
1770 | 1704 | ||
1771 | - private final class DeviceInjectedEventListener | 1705 | + private void handleDeviceInjectedEvent(DeviceInjectedEvent event) { |
1772 | - implements ClusterMessageHandler { | 1706 | + ProviderId providerId = event.providerId(); |
1773 | - @Override | 1707 | + DeviceId deviceId = event.deviceId(); |
1774 | - public void handle(ClusterMessage message) { | 1708 | + DeviceDescription deviceDescription = event.deviceDescription(); |
1775 | - log.debug("Received injected device event from peer: {}", message.sender()); | 1709 | + if (!deviceClockService.isTimestampAvailable(deviceId)) { |
1776 | - DeviceInjectedEvent event = SERIALIZER.decode(message.payload()); | 1710 | + // workaround for ONOS-1208 |
1777 | - | 1711 | + log.warn("Not ready to accept update. Dropping {}", deviceDescription); |
1778 | - ProviderId providerId = event.providerId(); | 1712 | + return; |
1779 | - DeviceId deviceId = event.deviceId(); | 1713 | + } |
1780 | - DeviceDescription deviceDescription = event.deviceDescription(); | ||
1781 | - if (!deviceClockService.isTimestampAvailable(deviceId)) { | ||
1782 | - // workaround for ONOS-1208 | ||
1783 | - log.warn("Not ready to accept update. Dropping {}", deviceDescription); | ||
1784 | - return; | ||
1785 | - } | ||
1786 | 1714 | ||
1787 | - try { | 1715 | + try { |
1788 | - createOrUpdateDevice(providerId, deviceId, deviceDescription); | 1716 | + createOrUpdateDevice(providerId, deviceId, deviceDescription); |
1789 | - } catch (Exception e) { | 1717 | + } catch (Exception e) { |
1790 | - log.warn("Exception thrown handling device injected event.", e); | 1718 | + log.warn("Exception thrown handling device injected event.", e); |
1791 | - } | ||
1792 | } | 1719 | } |
1793 | } | 1720 | } |
1794 | 1721 | ||
1795 | - private final class PortInjectedEventListener | 1722 | + private void handlePortInjectedEvent(PortInjectedEvent event) { |
1796 | - implements ClusterMessageHandler { | 1723 | + ProviderId providerId = event.providerId(); |
1797 | - @Override | 1724 | + DeviceId deviceId = event.deviceId(); |
1798 | - public void handle(ClusterMessage message) { | 1725 | + List<PortDescription> portDescriptions = event.portDescriptions(); |
1799 | - log.debug("Received injected port event from peer: {}", message.sender()); | 1726 | + if (!deviceClockService.isTimestampAvailable(deviceId)) { |
1800 | - PortInjectedEvent event = SERIALIZER.decode(message.payload()); | 1727 | + // workaround for ONOS-1208 |
1801 | - | 1728 | + log.warn("Not ready to accept update. Dropping {}", portDescriptions); |
1802 | - ProviderId providerId = event.providerId(); | 1729 | + return; |
1803 | - DeviceId deviceId = event.deviceId(); | 1730 | + } |
1804 | - List<PortDescription> portDescriptions = event.portDescriptions(); | ||
1805 | - if (!deviceClockService.isTimestampAvailable(deviceId)) { | ||
1806 | - // workaround for ONOS-1208 | ||
1807 | - log.warn("Not ready to accept update. Dropping {}", portDescriptions); | ||
1808 | - return; | ||
1809 | - } | ||
1810 | 1731 | ||
1811 | - try { | 1732 | + try { |
1812 | - updatePorts(providerId, deviceId, portDescriptions); | 1733 | + updatePorts(providerId, deviceId, portDescriptions); |
1813 | - } catch (Exception e) { | 1734 | + } catch (Exception e) { |
1814 | - log.warn("Exception thrown handling port injected event.", e); | 1735 | + log.warn("Exception thrown handling port injected event.", e); |
1815 | - } | ||
1816 | } | 1736 | } |
1817 | } | 1737 | } |
1818 | 1738 | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.store.device.impl; | ... | @@ -17,7 +17,6 @@ package org.onosproject.store.device.impl; |
17 | 17 | ||
18 | import com.google.common.collect.Iterables; | 18 | import com.google.common.collect.Iterables; |
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | - | ||
21 | import org.easymock.Capture; | 20 | import org.easymock.Capture; |
22 | import org.junit.After; | 21 | import org.junit.After; |
23 | import org.junit.AfterClass; | 22 | import org.junit.AfterClass; |
... | @@ -55,12 +54,12 @@ import org.onosproject.store.Timestamp; | ... | @@ -55,12 +54,12 @@ import org.onosproject.store.Timestamp; |
55 | import org.onosproject.store.cluster.StaticClusterService; | 54 | import org.onosproject.store.cluster.StaticClusterService; |
56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 55 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
57 | import org.onosproject.store.cluster.messaging.ClusterMessage; | 56 | import org.onosproject.store.cluster.messaging.ClusterMessage; |
58 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | ||
59 | import org.onosproject.store.cluster.messaging.MessageSubject; | 57 | import org.onosproject.store.cluster.messaging.MessageSubject; |
60 | import org.onosproject.store.impl.MastershipBasedTimestamp; | 58 | import org.onosproject.store.impl.MastershipBasedTimestamp; |
61 | import org.onosproject.store.service.EventuallyConsistentMap; | 59 | import org.onosproject.store.service.EventuallyConsistentMap; |
62 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; | 60 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
63 | import org.onosproject.store.service.StorageService; | 61 | import org.onosproject.store.service.StorageService; |
62 | + | ||
64 | import java.io.IOException; | 63 | import java.io.IOException; |
65 | import java.util.Arrays; | 64 | import java.util.Arrays; |
66 | import java.util.Collections; | 65 | import java.util.Collections; |
... | @@ -70,20 +69,37 @@ import java.util.Map; | ... | @@ -70,20 +69,37 @@ import java.util.Map; |
70 | import java.util.Set; | 69 | import java.util.Set; |
71 | import java.util.concurrent.CompletableFuture; | 70 | import java.util.concurrent.CompletableFuture; |
72 | import java.util.concurrent.CountDownLatch; | 71 | import java.util.concurrent.CountDownLatch; |
73 | -import java.util.concurrent.ExecutorService; | ||
74 | import java.util.concurrent.TimeUnit; | 72 | import java.util.concurrent.TimeUnit; |
75 | import java.util.concurrent.atomic.AtomicLong; | 73 | import java.util.concurrent.atomic.AtomicLong; |
76 | import java.util.function.BiFunction; | 74 | import java.util.function.BiFunction; |
77 | import java.util.function.Function; | 75 | import java.util.function.Function; |
78 | 76 | ||
79 | import static java.util.Arrays.asList; | 77 | import static java.util.Arrays.asList; |
80 | -import static org.easymock.EasyMock.*; | 78 | +import static org.easymock.EasyMock.anyObject; |
81 | -import static org.junit.Assert.*; | 79 | +import static org.easymock.EasyMock.capture; |
80 | +import static org.easymock.EasyMock.createNiceMock; | ||
81 | +import static org.easymock.EasyMock.expect; | ||
82 | +import static org.easymock.EasyMock.expectLastCall; | ||
83 | +import static org.easymock.EasyMock.replay; | ||
84 | +import static org.easymock.EasyMock.reset; | ||
85 | +import static org.easymock.EasyMock.verify; | ||
86 | +import static org.junit.Assert.assertEquals; | ||
87 | +import static org.junit.Assert.assertFalse; | ||
88 | +import static org.junit.Assert.assertNotNull; | ||
89 | +import static org.junit.Assert.assertNull; | ||
90 | +import static org.junit.Assert.assertTrue; | ||
91 | +import static org.junit.Assert.fail; | ||
82 | import static org.onosproject.cluster.ControllerNode.State.ACTIVE; | 92 | import static org.onosproject.cluster.ControllerNode.State.ACTIVE; |
83 | import static org.onosproject.net.DefaultAnnotations.union; | 93 | import static org.onosproject.net.DefaultAnnotations.union; |
84 | import static org.onosproject.net.Device.Type.SWITCH; | 94 | import static org.onosproject.net.Device.Type.SWITCH; |
85 | import static org.onosproject.net.DeviceId.deviceId; | 95 | import static org.onosproject.net.DeviceId.deviceId; |
86 | -import static org.onosproject.net.device.DeviceEvent.Type.*; | 96 | +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; |
97 | +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; | ||
98 | +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED; | ||
99 | +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED; | ||
100 | +import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED; | ||
101 | +import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED; | ||
102 | +import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; | ||
87 | 103 | ||
88 | 104 | ||
89 | // TODO add tests for remote replication | 105 | // TODO add tests for remote replication |
... | @@ -157,9 +173,6 @@ public class GossipDeviceStoreTest { | ... | @@ -157,9 +173,6 @@ public class GossipDeviceStoreTest { |
157 | @Before | 173 | @Before |
158 | public void setUp() throws Exception { | 174 | public void setUp() throws Exception { |
159 | clusterCommunicator = createNiceMock(ClusterCommunicationService.class); | 175 | clusterCommunicator = createNiceMock(ClusterCommunicationService.class); |
160 | - clusterCommunicator.addSubscriber(anyObject(MessageSubject.class), | ||
161 | - anyObject(ClusterMessageHandler.class), anyObject(ExecutorService.class)); | ||
162 | - expectLastCall().anyTimes(); | ||
163 | replay(clusterCommunicator); | 176 | replay(clusterCommunicator); |
164 | ClusterService clusterService = new TestClusterService(); | 177 | ClusterService clusterService = new TestClusterService(); |
165 | 178 | ... | ... |
-
Please register or login to post a comment