Flatten MastershipTermService
Change-Id: Ic75b7376f7436c76f69127d6137577ec2fc09d2b
diff --git a/core/api/src/main/java/org/onlab/onos/mastership/MastershipService.java b/core/api/src/main/java/org/onlab/onos/mastership/MastershipService.java
index 5a6ca0e..6a6244b 100644
--- a/core/api/src/main/java/org/onlab/onos/mastership/MastershipService.java
+++ b/core/api/src/main/java/org/onlab/onos/mastership/MastershipService.java
@@ -83,14 +83,6 @@
Set<DeviceId> getDevicesOf(NodeId nodeId);
/**
- * Returns the mastership term service for getting read-only
- * term information.
- *
- * @return the MastershipTermService for this mastership manager
- */
- MastershipTermService requestTermService();
-
- /**
* Adds the specified mastership change listener.
*
* @param listener the mastership listener
diff --git a/core/api/src/test/java/org/onlab/onos/mastership/MastershipServiceAdapter.java b/core/api/src/test/java/org/onlab/onos/mastership/MastershipServiceAdapter.java
index 97dd7a9..860e7e7 100644
--- a/core/api/src/test/java/org/onlab/onos/mastership/MastershipServiceAdapter.java
+++ b/core/api/src/test/java/org/onlab/onos/mastership/MastershipServiceAdapter.java
@@ -59,11 +59,6 @@
}
@Override
- public MastershipTermService requestTermService() {
- return null;
- }
-
- @Override
public RoleInfo getNodesFor(DeviceId deviceId) {
return null;
}
diff --git a/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java b/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
index dbb3ae4..e97a553 100644
--- a/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
+++ b/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
@@ -50,7 +50,7 @@
@Component(immediate = true)
@Service
public class MastershipManager
-implements MastershipService, MastershipAdminService {
+ implements MastershipService, MastershipAdminService, MastershipTermService {
private static final String NODE_ID_NULL = "Node ID cannot be null";
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
@@ -159,8 +159,8 @@
}
@Override
- public MastershipTermService requestTermService() {
- return new InternalMastershipTermService();
+ public MastershipTerm getMastershipTerm(DeviceId deviceId) {
+ return store.getTermFor(deviceId);
}
@Override
@@ -184,14 +184,7 @@
}
}
- private class InternalMastershipTermService implements MastershipTermService {
- @Override
- public MastershipTerm getMastershipTerm(DeviceId deviceId) {
- return store.getTermFor(deviceId);
- }
-
- }
//callback for reacting to cluster events
private class InternalClusterEventListener implements ClusterEventListener {
diff --git a/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
index f45d4de..95723b3 100644
--- a/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
@@ -100,6 +100,7 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipTermService termService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -112,7 +113,6 @@
store.setDelegate(delegate);
eventDispatcher.addSink(DeviceEvent.class, listenerRegistry);
mastershipService.addListener(mastershipListener);
- termService = mastershipService.requestTermService();
backgroundService.scheduleWithFixedDelay(new Runnable() {
diff --git a/core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java b/core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java
index 33961e4..2c781d0 100644
--- a/core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java
@@ -139,7 +139,7 @@
@Test
public void termService() {
- MastershipTermService ts = mgr.requestTermService();
+ MastershipTermService ts = mgr;
//term = 1 for both
mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER);
diff --git a/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
index 58af77a..693a90f 100644
--- a/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
@@ -102,7 +102,9 @@
registry = mgr;
mgr.store = new SimpleDeviceStore();
mgr.eventDispatcher = new TestEventDispatcher();
- mgr.mastershipService = new TestMastershipService();
+ TestMastershipManager mastershipManager = new TestMastershipManager();
+ mgr.mastershipService = mastershipManager;
+ mgr.termService = mastershipManager;
mgr.clusterService = new TestClusterService();
mgr.deviceClockProviderService = new TestClockProviderService();
mgr.activate();
@@ -283,8 +285,8 @@
}
}
- private static class TestMastershipService
- extends MastershipServiceAdapter {
+ private static class TestMastershipManager
+ extends MastershipServiceAdapter implements MastershipTermService {
@Override
public MastershipRole getLocalRole(DeviceId deviceId) {
return MastershipRole.MASTER;
@@ -301,14 +303,9 @@
}
@Override
- public MastershipTermService requestTermService() {
- return new MastershipTermService() {
- @Override
- public MastershipTerm getMastershipTerm(DeviceId deviceId) {
- // FIXME: just returning something not null
- return MastershipTerm.of(NID_LOCAL, 1);
- }
- };
+ public MastershipTerm getMastershipTerm(DeviceId deviceId) {
+ // FIXME: just returning something not null
+ return MastershipTerm.of(NID_LOCAL, 1);
}
}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
index 0de64ca..b623b5d 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
@@ -137,6 +137,10 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipTermService termService;
+
+
protected static final KryoSerializer SERIALIZER = new KryoSerializer() {
@Override
protected void setupKryoPool() {
@@ -736,7 +740,6 @@
}
log.debug("Temporarily requesting role for {} to remove", deviceId);
mastershipService.requestRoleFor(deviceId);
- MastershipTermService termService = mastershipService.requestTermService();
MastershipTerm term = termService.getMastershipTerm(deviceId);
if (myId.equals(term.master())) {
master = myId;
diff --git a/providers/lldp/src/test/java/org/onlab/onos/provider/lldp/impl/LLDPLinkProviderTest.java b/providers/lldp/src/test/java/org/onlab/onos/provider/lldp/impl/LLDPLinkProviderTest.java
index c9fca75..4311bb4 100644
--- a/providers/lldp/src/test/java/org/onlab/onos/provider/lldp/impl/LLDPLinkProviderTest.java
+++ b/providers/lldp/src/test/java/org/onlab/onos/provider/lldp/impl/LLDPLinkProviderTest.java
@@ -27,7 +27,6 @@
import org.onlab.onos.cluster.RoleInfo;
import org.onlab.onos.mastership.MastershipListener;
import org.onlab.onos.mastership.MastershipService;
-import org.onlab.onos.mastership.MastershipTermService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultDevice;
import org.onlab.onos.net.DefaultPort;
@@ -482,11 +481,6 @@
}
@Override
- public MastershipTermService requestTermService() {
- return null;
- }
-
- @Override
public void addListener(MastershipListener listener) {
}