removeDevice on non-master node to silently ignore the request
instead of throwing IllegalState exception Change-Id: Ida778ec112e80507fb05921e49297350d74dc519
Showing
2 changed files
with
22 additions
and
0 deletions
... | @@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.Service; |
16 | import org.onlab.onos.cluster.ClusterService; | 16 | import org.onlab.onos.cluster.ClusterService; |
17 | import org.onlab.onos.cluster.ControllerNode; | 17 | import org.onlab.onos.cluster.ControllerNode; |
18 | import org.onlab.onos.cluster.NodeId; | 18 | import org.onlab.onos.cluster.NodeId; |
19 | +import org.onlab.onos.mastership.MastershipService; | ||
19 | import org.onlab.onos.net.AnnotationsUtil; | 20 | import org.onlab.onos.net.AnnotationsUtil; |
20 | import org.onlab.onos.net.DefaultAnnotations; | 21 | import org.onlab.onos.net.DefaultAnnotations; |
21 | import org.onlab.onos.net.DefaultDevice; | 22 | import org.onlab.onos.net.DefaultDevice; |
... | @@ -114,6 +115,9 @@ public class GossipDeviceStore | ... | @@ -114,6 +115,9 @@ public class GossipDeviceStore |
114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
115 | protected ClusterService clusterService; | 116 | protected ClusterService clusterService; |
116 | 117 | ||
118 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
119 | + protected MastershipService mastershipService; | ||
120 | + | ||
117 | protected static final KryoSerializer SERIALIZER = new KryoSerializer() { | 121 | protected static final KryoSerializer SERIALIZER = new KryoSerializer() { |
118 | @Override | 122 | @Override |
119 | protected void setupKryoPool() { | 123 | protected void setupKryoPool() { |
... | @@ -664,6 +668,14 @@ public class GossipDeviceStore | ... | @@ -664,6 +668,14 @@ public class GossipDeviceStore |
664 | 668 | ||
665 | @Override | 669 | @Override |
666 | public synchronized DeviceEvent removeDevice(DeviceId deviceId) { | 670 | public synchronized DeviceEvent removeDevice(DeviceId deviceId) { |
671 | + final NodeId master = mastershipService.getMasterFor(deviceId); | ||
672 | + if (!clusterService.getLocalNode().id().equals(master)) { | ||
673 | + log.info("remove Device {} requested on non master node", deviceId); | ||
674 | + // FIXME silently ignoring. Should be forwarding or broadcasting to | ||
675 | + // master. | ||
676 | + return null; | ||
677 | + } | ||
678 | + | ||
667 | Timestamp timestamp = deviceClockService.getTimestamp(deviceId); | 679 | Timestamp timestamp = deviceClockService.getTimestamp(deviceId); |
668 | DeviceEvent event = removeDeviceInternal(deviceId, timestamp); | 680 | DeviceEvent event = removeDeviceInternal(deviceId, timestamp); |
669 | if (event != null) { | 681 | if (event != null) { | ... | ... |
... | @@ -32,6 +32,7 @@ import org.onlab.onos.cluster.ControllerNode; | ... | @@ -32,6 +32,7 @@ import org.onlab.onos.cluster.ControllerNode; |
32 | import org.onlab.onos.cluster.ControllerNode.State; | 32 | import org.onlab.onos.cluster.ControllerNode.State; |
33 | import org.onlab.onos.cluster.DefaultControllerNode; | 33 | import org.onlab.onos.cluster.DefaultControllerNode; |
34 | import org.onlab.onos.cluster.NodeId; | 34 | import org.onlab.onos.cluster.NodeId; |
35 | +import org.onlab.onos.mastership.MastershipServiceAdapter; | ||
35 | import org.onlab.onos.mastership.MastershipTerm; | 36 | import org.onlab.onos.mastership.MastershipTerm; |
36 | import org.onlab.onos.net.Annotations; | 37 | import org.onlab.onos.net.Annotations; |
37 | import org.onlab.onos.net.DefaultAnnotations; | 38 | import org.onlab.onos.net.DefaultAnnotations; |
... | @@ -143,6 +144,8 @@ public class GossipDeviceStoreTest { | ... | @@ -143,6 +144,8 @@ public class GossipDeviceStoreTest { |
143 | ClusterService clusterService = new TestClusterService(); | 144 | ClusterService clusterService = new TestClusterService(); |
144 | 145 | ||
145 | testGossipDeviceStore = new TestGossipDeviceStore(deviceClockService, clusterService, clusterCommunicator); | 146 | testGossipDeviceStore = new TestGossipDeviceStore(deviceClockService, clusterService, clusterCommunicator); |
147 | + testGossipDeviceStore.mastershipService = new TestMastershipService(); | ||
148 | + | ||
146 | gossipDeviceStore = testGossipDeviceStore; | 149 | gossipDeviceStore = testGossipDeviceStore; |
147 | gossipDeviceStore.activate(); | 150 | gossipDeviceStore.activate(); |
148 | deviceStore = gossipDeviceStore; | 151 | deviceStore = gossipDeviceStore; |
... | @@ -797,6 +800,13 @@ public class GossipDeviceStoreTest { | ... | @@ -797,6 +800,13 @@ public class GossipDeviceStoreTest { |
797 | assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS)); | 800 | assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS)); |
798 | } | 801 | } |
799 | 802 | ||
803 | + private final class TestMastershipService extends MastershipServiceAdapter { | ||
804 | + @Override | ||
805 | + public NodeId getMasterFor(DeviceId deviceId) { | ||
806 | + return NID1; | ||
807 | + } | ||
808 | + } | ||
809 | + | ||
800 | private static final class TestGossipDeviceStore extends GossipDeviceStore { | 810 | private static final class TestGossipDeviceStore extends GossipDeviceStore { |
801 | 811 | ||
802 | public TestGossipDeviceStore( | 812 | public TestGossipDeviceStore( | ... | ... |
-
Please register or login to post a comment