Yuta HIGUCHI

removeDevice on non-master node to silently ignore the request

instead of throwing IllegalState exception

Change-Id: Ida778ec112e80507fb05921e49297350d74dc519
......@@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.mastership.MastershipService;
import org.onlab.onos.net.AnnotationsUtil;
import org.onlab.onos.net.DefaultAnnotations;
import org.onlab.onos.net.DefaultDevice;
......@@ -114,6 +115,9 @@ public class GossipDeviceStore
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
protected static final KryoSerializer SERIALIZER = new KryoSerializer() {
@Override
protected void setupKryoPool() {
......@@ -664,6 +668,14 @@ public class GossipDeviceStore
@Override
public synchronized DeviceEvent removeDevice(DeviceId deviceId) {
final NodeId master = mastershipService.getMasterFor(deviceId);
if (!clusterService.getLocalNode().id().equals(master)) {
log.info("remove Device {} requested on non master node", deviceId);
// FIXME silently ignoring. Should be forwarding or broadcasting to
// master.
return null;
}
Timestamp timestamp = deviceClockService.getTimestamp(deviceId);
DeviceEvent event = removeDeviceInternal(deviceId, timestamp);
if (event != null) {
......
......@@ -32,6 +32,7 @@ import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.ControllerNode.State;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.mastership.MastershipServiceAdapter;
import org.onlab.onos.mastership.MastershipTerm;
import org.onlab.onos.net.Annotations;
import org.onlab.onos.net.DefaultAnnotations;
......@@ -143,6 +144,8 @@ public class GossipDeviceStoreTest {
ClusterService clusterService = new TestClusterService();
testGossipDeviceStore = new TestGossipDeviceStore(deviceClockService, clusterService, clusterCommunicator);
testGossipDeviceStore.mastershipService = new TestMastershipService();
gossipDeviceStore = testGossipDeviceStore;
gossipDeviceStore.activate();
deviceStore = gossipDeviceStore;
......@@ -797,6 +800,13 @@ public class GossipDeviceStoreTest {
assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
private final class TestMastershipService extends MastershipServiceAdapter {
@Override
public NodeId getMasterFor(DeviceId deviceId) {
return NID1;
}
}
private static final class TestGossipDeviceStore extends GossipDeviceStore {
public TestGossipDeviceStore(
......