Committed by
Gerrit Code Review
Move GossipDeviceStore away from deprecated ClusterCommunicationService API
Change-Id: Ib0ca7125e17013156aac27f8437ca717a96a56f0
Showing
2 changed files
with
84 additions
and
151 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,13 +1615,7 @@ public class GossipDeviceStore | ... | @@ -1631,13 +1615,7 @@ public class GossipDeviceStore |
1631 | } | 1615 | } |
1632 | } | 1616 | } |
1633 | 1617 | ||
1634 | - private final class InternalDeviceEventListener | 1618 | + private void handleDeviceEvent(InternalDeviceEvent event) { |
1635 | - implements ClusterMessageHandler { | ||
1636 | - @Override | ||
1637 | - public void handle(ClusterMessage message) { | ||
1638 | - log.debug("Received device update event from peer: {}", message.sender()); | ||
1639 | - InternalDeviceEvent event = SERIALIZER.decode(message.payload()); | ||
1640 | - | ||
1641 | ProviderId providerId = event.providerId(); | 1619 | ProviderId providerId = event.providerId(); |
1642 | DeviceId deviceId = event.deviceId(); | 1620 | DeviceId deviceId = event.deviceId(); |
1643 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); | 1621 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); |
... | @@ -1649,15 +1627,8 @@ public class GossipDeviceStore | ... | @@ -1649,15 +1627,8 @@ public class GossipDeviceStore |
1649 | log.warn("Exception thrown handling device update", e); | 1627 | log.warn("Exception thrown handling device update", e); |
1650 | } | 1628 | } |
1651 | } | 1629 | } |
1652 | - } | ||
1653 | - | ||
1654 | - private final class InternalDeviceOfflineEventListener | ||
1655 | - implements ClusterMessageHandler { | ||
1656 | - @Override | ||
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 | 1630 | ||
1631 | + private void handleDeviceOfflineEvent(InternalDeviceOfflineEvent event) { | ||
1661 | DeviceId deviceId = event.deviceId(); | 1632 | DeviceId deviceId = event.deviceId(); |
1662 | Timestamp timestamp = event.timestamp(); | 1633 | Timestamp timestamp = event.timestamp(); |
1663 | 1634 | ||
... | @@ -1667,30 +1638,16 @@ public class GossipDeviceStore | ... | @@ -1667,30 +1638,16 @@ public class GossipDeviceStore |
1667 | log.warn("Exception thrown handling device offline", e); | 1638 | log.warn("Exception thrown handling device offline", e); |
1668 | } | 1639 | } |
1669 | } | 1640 | } |
1670 | - } | ||
1671 | - | ||
1672 | - private final class InternalRemoveRequestListener | ||
1673 | - implements ClusterMessageHandler { | ||
1674 | - @Override | ||
1675 | - public void handle(ClusterMessage message) { | ||
1676 | - log.debug("Received device remove request from peer: {}", message.sender()); | ||
1677 | - DeviceId did = SERIALIZER.decode(message.payload()); | ||
1678 | 1641 | ||
1642 | + private void handleRemoveRequest(DeviceId did) { | ||
1679 | try { | 1643 | try { |
1680 | removeDevice(did); | 1644 | removeDevice(did); |
1681 | } catch (Exception e) { | 1645 | } catch (Exception e) { |
1682 | log.warn("Exception thrown handling device remove", e); | 1646 | log.warn("Exception thrown handling device remove", e); |
1683 | } | 1647 | } |
1684 | } | 1648 | } |
1685 | - } | ||
1686 | - | ||
1687 | - private final class InternalDeviceRemovedEventListener | ||
1688 | - implements ClusterMessageHandler { | ||
1689 | - @Override | ||
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 | 1649 | ||
1650 | + private void handleDeviceRemovedEvent(InternalDeviceRemovedEvent event) { | ||
1694 | DeviceId deviceId = event.deviceId(); | 1651 | DeviceId deviceId = event.deviceId(); |
1695 | Timestamp timestamp = event.timestamp(); | 1652 | Timestamp timestamp = event.timestamp(); |
1696 | 1653 | ||
... | @@ -1700,16 +1657,8 @@ public class GossipDeviceStore | ... | @@ -1700,16 +1657,8 @@ public class GossipDeviceStore |
1700 | log.warn("Exception thrown handling device removed", e); | 1657 | log.warn("Exception thrown handling device removed", e); |
1701 | } | 1658 | } |
1702 | } | 1659 | } |
1703 | - } | ||
1704 | - | ||
1705 | - private final class InternalPortEventListener | ||
1706 | - implements ClusterMessageHandler { | ||
1707 | - @Override | ||
1708 | - public void handle(ClusterMessage message) { | ||
1709 | - | ||
1710 | - log.debug("Received port update event from peer: {}", message.sender()); | ||
1711 | - InternalPortEvent event = SERIALIZER.decode(message.payload()); | ||
1712 | 1660 | ||
1661 | + private void handlePortEvent(InternalPortEvent event) { | ||
1713 | ProviderId providerId = event.providerId(); | 1662 | ProviderId providerId = event.providerId(); |
1714 | DeviceId deviceId = event.deviceId(); | 1663 | DeviceId deviceId = event.deviceId(); |
1715 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); | 1664 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); |
... | @@ -1726,16 +1675,8 @@ public class GossipDeviceStore | ... | @@ -1726,16 +1675,8 @@ public class GossipDeviceStore |
1726 | log.warn("Exception thrown handling port update", e); | 1675 | log.warn("Exception thrown handling port update", e); |
1727 | } | 1676 | } |
1728 | } | 1677 | } |
1729 | - } | ||
1730 | - | ||
1731 | - private final class InternalPortStatusEventListener | ||
1732 | - implements ClusterMessageHandler { | ||
1733 | - @Override | ||
1734 | - public void handle(ClusterMessage message) { | ||
1735 | - | ||
1736 | - log.debug("Received port status update event from peer: {}", message.sender()); | ||
1737 | - InternalPortStatusEvent event = SERIALIZER.decode(message.payload()); | ||
1738 | 1678 | ||
1679 | + private void handlePortStatusEvent(InternalPortStatusEvent event) { | ||
1739 | ProviderId providerId = event.providerId(); | 1680 | ProviderId providerId = event.providerId(); |
1740 | DeviceId deviceId = event.deviceId(); | 1681 | DeviceId deviceId = event.deviceId(); |
1741 | Timestamped<PortDescription> portDescription = event.portDescription(); | 1682 | Timestamped<PortDescription> portDescription = event.portDescription(); |
... | @@ -1752,29 +1693,16 @@ public class GossipDeviceStore | ... | @@ -1752,29 +1693,16 @@ public class GossipDeviceStore |
1752 | log.warn("Exception thrown handling port update", e); | 1693 | log.warn("Exception thrown handling port update", e); |
1753 | } | 1694 | } |
1754 | } | 1695 | } |
1755 | - } | ||
1756 | 1696 | ||
1757 | - private final class InternalDeviceAdvertisementListener | 1697 | + private void handleDeviceAdvertisement(DeviceAntiEntropyAdvertisement advertisement) { |
1758 | - implements ClusterMessageHandler { | ||
1759 | - @Override | ||
1760 | - public void handle(ClusterMessage message) { | ||
1761 | - log.trace("Received Device Anti-Entropy advertisement from peer: {}", message.sender()); | ||
1762 | - DeviceAntiEntropyAdvertisement advertisement = SERIALIZER.decode(message.payload()); | ||
1763 | try { | 1698 | try { |
1764 | handleAdvertisement(advertisement); | 1699 | handleAdvertisement(advertisement); |
1765 | } catch (Exception e) { | 1700 | } catch (Exception e) { |
1766 | log.warn("Exception thrown handling Device advertisements.", e); | 1701 | log.warn("Exception thrown handling Device advertisements.", e); |
1767 | } | 1702 | } |
1768 | } | 1703 | } |
1769 | - } | ||
1770 | - | ||
1771 | - private final class DeviceInjectedEventListener | ||
1772 | - implements ClusterMessageHandler { | ||
1773 | - @Override | ||
1774 | - public void handle(ClusterMessage message) { | ||
1775 | - log.debug("Received injected device event from peer: {}", message.sender()); | ||
1776 | - DeviceInjectedEvent event = SERIALIZER.decode(message.payload()); | ||
1777 | 1704 | ||
1705 | + private void handleDeviceInjectedEvent(DeviceInjectedEvent event) { | ||
1778 | ProviderId providerId = event.providerId(); | 1706 | ProviderId providerId = event.providerId(); |
1779 | DeviceId deviceId = event.deviceId(); | 1707 | DeviceId deviceId = event.deviceId(); |
1780 | DeviceDescription deviceDescription = event.deviceDescription(); | 1708 | DeviceDescription deviceDescription = event.deviceDescription(); |
... | @@ -1790,15 +1718,8 @@ public class GossipDeviceStore | ... | @@ -1790,15 +1718,8 @@ public class GossipDeviceStore |
1790 | log.warn("Exception thrown handling device injected event.", e); | 1718 | log.warn("Exception thrown handling device injected event.", e); |
1791 | } | 1719 | } |
1792 | } | 1720 | } |
1793 | - } | ||
1794 | - | ||
1795 | - private final class PortInjectedEventListener | ||
1796 | - implements ClusterMessageHandler { | ||
1797 | - @Override | ||
1798 | - public void handle(ClusterMessage message) { | ||
1799 | - log.debug("Received injected port event from peer: {}", message.sender()); | ||
1800 | - PortInjectedEvent event = SERIALIZER.decode(message.payload()); | ||
1801 | 1721 | ||
1722 | + private void handlePortInjectedEvent(PortInjectedEvent event) { | ||
1802 | ProviderId providerId = event.providerId(); | 1723 | ProviderId providerId = event.providerId(); |
1803 | DeviceId deviceId = event.deviceId(); | 1724 | DeviceId deviceId = event.deviceId(); |
1804 | List<PortDescription> portDescriptions = event.portDescriptions(); | 1725 | List<PortDescription> portDescriptions = event.portDescriptions(); |
... | @@ -1814,7 +1735,6 @@ public class GossipDeviceStore | ... | @@ -1814,7 +1735,6 @@ public class GossipDeviceStore |
1814 | log.warn("Exception thrown handling port injected event.", e); | 1735 | log.warn("Exception thrown handling port injected event.", e); |
1815 | } | 1736 | } |
1816 | } | 1737 | } |
1817 | - } | ||
1818 | 1738 | ||
1819 | private class InternalPortStatsListener | 1739 | private class InternalPortStatsListener |
1820 | implements EventuallyConsistentMapListener<DeviceId, Map<PortNumber, PortStatistics>> { | 1740 | implements EventuallyConsistentMapListener<DeviceId, Map<PortNumber, PortStatistics>> { | ... | ... |
... | @@ -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