@Test public final void testRemoveDevice() { putDevice(DID1, SW1, A1); List<PortDescription> pds = Arrays.<PortDescription>asList( new DefaultPortDescription(P1, true, A2) ); deviceStore.updatePorts(PID, DID1, pds); putDevice(DID2, SW1); assertEquals(2, deviceStore.getDeviceCount()); assertEquals(1, deviceStore.getPorts(DID1).size()); assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations(), A1); assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations(), A2); Capture<InternalDeviceEvent> message = new Capture<>(); Capture<MessageSubject> subject = new Capture<>(); Capture<Function<InternalDeviceEvent, byte[]>> encoder = new Capture<>(); resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); DeviceEvent event = deviceStore.removeDevice(DID1); assertEquals(DEVICE_REMOVED, event.type()); assertDevice(DID1, SW1, event.subject()); assertEquals(1, deviceStore.getDeviceCount()); assertEquals(0, deviceStore.getPorts(DID1).size()); verify(clusterCommunicator); assertTrue(message.hasCaptured()); putDevice(DID1, SW1); List<PortDescription> pds2 = Arrays.<PortDescription>asList( new DefaultPortDescription(P1, true) ); deviceStore.updatePorts(PID, DID1, pds2); assertEquals(2, deviceStore.getDeviceCount()); assertEquals(1, deviceStore.getPorts(DID1).size()); assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations()); assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations()); }
@Override public synchronized DeviceEvent removeDevice(DeviceId deviceId) { final NodeId myId = clusterService.getLocalNode().id(); NodeId master = mastershipService.getMasterFor(deviceId); boolean relinquishAtEnd = false; if (master == null) { final MastershipRole myRole = mastershipService.getLocalRole(deviceId); if (myRole != MastershipRole.NONE) { relinquishAtEnd = true; } log.debug("Temporarily requesting role for {} to remove", deviceId); mastershipService.requestRoleFor(deviceId); MastershipTerm term = termService.getMastershipTerm(deviceId); if (term != null && myId.equals(term.master())) { master = myId; } } if (!myId.equals(master)) { log.debug("{} has control of {}, forwarding remove request", master, deviceId); clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master); return null; } Timestamp timestamp = deviceClockService.getTimestamp(deviceId); DeviceEvent event = removeDeviceInternal(deviceId, timestamp); if (event != null) { log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId); notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp)); } if (relinquishAtEnd) { log.debug("Relinquishing temporary role acquired for {}", deviceId); mastershipService.relinquishMastership(deviceId); } return event; }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @Override public synchronized DeviceEvent removeDevice(DeviceId deviceId) { final NodeId myId = clusterService.getLocalNode().id(); NodeId master = mastershipService.getMasterFor(deviceId); boolean relinquishAtEnd = false; if (master == null) { final MastershipRole myRole = mastershipService.getLocalRole(deviceId); if (myRole != MastershipRole.NONE) { relinquishAtEnd = true; } log.debug("Temporarily requesting role for {} to remove", deviceId); mastershipService.requestRoleFor(deviceId); MastershipTerm term = termService.getMastershipTerm(deviceId); if (term != null && myId.equals(term.master())) { master = myId; } } if (!myId.equals(master)) { log.debug("{} has control of {}, forwarding remove request", master, deviceId); clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master); return null; } Timestamp timestamp = deviceClockService.getTimestamp(deviceId); DeviceEvent event = removeDeviceInternal(deviceId, timestamp); if (event != null) { log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId); notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp)); } if (relinquishAtEnd) { log.debug("Relinquishing temporary role acquired for {}", deviceId); mastershipService.relinquishMastership(deviceId); } return event; } }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @Override public synchronized DeviceEvent removeDevice(DeviceId deviceId) { final NodeId myId = clusterService.getLocalNode().id(); NodeId master = mastershipService.getMasterFor(deviceId); boolean relinquishAtEnd = false; if (master == null) { final MastershipRole myRole = mastershipService.getLocalRole(deviceId); if (myRole != MastershipRole.NONE) { relinquishAtEnd = true; } log.debug("Temporarily requesting role for {} to remove", deviceId); mastershipService.requestRoleFor(deviceId); MastershipTerm term = termService.getMastershipTerm(deviceId); if (term != null && myId.equals(term.master())) { master = myId; } } if (!myId.equals(master)) { log.debug("{} has control of {}, forwarding remove request", master, deviceId); clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master); return null; } Timestamp timestamp = deviceClockService.getTimestamp(deviceId); DeviceEvent event = removeDeviceInternal(deviceId, timestamp); if (event != null) { log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId); notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp)); } if (relinquishAtEnd) { log.debug("Relinquishing temporary role acquired for {}", deviceId); mastershipService.relinquishMastership(deviceId); } return event; }  }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @Override public synchronized DeviceEvent removeDevice(DeviceId deviceId) { final NodeId myId = clusterService.getLocalNode().id(); NodeId master = mastershipService.getMasterFor(deviceId); boolean relinquishAtEnd = false; if (master == null) { final MastershipRole myRole = mastershipService.getLocalRole(deviceId); if (myRole != MastershipRole.NONE) { relinquishAtEnd = true; } log.debug("Temporarily requesting role for {} to remove", deviceId); mastershipService.requestRoleFor(deviceId); MastershipTerm term = termService.getMastershipTerm(deviceId); if (term != null && myId.equals(term.master())) { master = myId; } } if (!myId.equals(master)) { log.debug("{} has control of {}, forwarding remove request", master, deviceId); clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master); return null; } Timestamp timestamp = deviceClockService.getTimestamp(deviceId); DeviceEvent event = removeDeviceInternal(deviceId, timestamp); if (event != null) { log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId); notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp)); } if (relinquishAtEnd) { log.debug("Relinquishing temporary role acquired for {}", deviceId); mastershipService.relinquishMastership(deviceId); } return event; }  @Activate void activate(); @Deactivate void deactivate(); @Override int getDeviceCount(); @Override Iterable<Device> getDevices(); @Override Iterable<Device> getAvailableDevices(); @Override Device getDevice(DeviceId deviceId); @Override synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId,
                                                         DeviceId deviceId,
                                                         DeviceDescription deviceDescription); @Override DeviceEvent markOffline(DeviceId deviceId); @Override synchronized List<DeviceEvent> updatePorts(ProviderId providerId,
                                                      DeviceId deviceId,
                                                      List<PortDescription> portDescriptions); @Override synchronized DeviceEvent updatePortStatus(ProviderId providerId,
                                                     DeviceId deviceId,
                                                     PortDescription portDescription); @Override List<Port> getPorts(DeviceId deviceId); @Override DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId,
                                            Collection<PortStatistics> newStatsCollection); PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats); @Override List<PortStatistics> getPortStatistics(DeviceId deviceId); @Override List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId); @Override Port getPort(DeviceId deviceId, PortNumber portNumber); @Override boolean isAvailable(DeviceId deviceId); @Override synchronized DeviceEvent removeDevice(DeviceId deviceId); }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @Override public synchronized DeviceEvent removeDevice(DeviceId deviceId) { final NodeId myId = clusterService.getLocalNode().id(); NodeId master = mastershipService.getMasterFor(deviceId); boolean relinquishAtEnd = false; if (master == null) { final MastershipRole myRole = mastershipService.getLocalRole(deviceId); if (myRole != MastershipRole.NONE) { relinquishAtEnd = true; } log.debug("Temporarily requesting role for {} to remove", deviceId); mastershipService.requestRoleFor(deviceId); MastershipTerm term = termService.getMastershipTerm(deviceId); if (term != null && myId.equals(term.master())) { master = myId; } } if (!myId.equals(master)) { log.debug("{} has control of {}, forwarding remove request", master, deviceId); clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master); return null; } Timestamp timestamp = deviceClockService.getTimestamp(deviceId); DeviceEvent event = removeDeviceInternal(deviceId, timestamp); if (event != null) { log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId); notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp)); } if (relinquishAtEnd) { log.debug("Relinquishing temporary role acquired for {}", deviceId); mastershipService.relinquishMastership(deviceId); } return event; }  @Activate void activate(); @Deactivate void deactivate(); @Override int getDeviceCount(); @Override Iterable<Device> getDevices(); @Override Iterable<Device> getAvailableDevices(); @Override Device getDevice(DeviceId deviceId); @Override synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId,
                                                         DeviceId deviceId,
                                                         DeviceDescription deviceDescription); @Override DeviceEvent markOffline(DeviceId deviceId); @Override synchronized List<DeviceEvent> updatePorts(ProviderId providerId,
                                                      DeviceId deviceId,
                                                      List<PortDescription> portDescriptions); @Override synchronized DeviceEvent updatePortStatus(ProviderId providerId,
                                                     DeviceId deviceId,
                                                     PortDescription portDescription); @Override List<Port> getPorts(DeviceId deviceId); @Override DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId,
                                            Collection<PortStatistics> newStatsCollection); PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats); @Override List<PortStatistics> getPortStatistics(DeviceId deviceId); @Override List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId); @Override Port getPort(DeviceId deviceId, PortNumber portNumber); @Override boolean isAvailable(DeviceId deviceId); @Override synchronized DeviceEvent removeDevice(DeviceId deviceId);  }