Added providerService for mastership
Change-Id: I1572161f70c696961a663cba17f197e23f96967e
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java
index 2cbad7f..01d91d6 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java
@@ -1,7 +1,13 @@
package org.onlab.onos.cluster;
+import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.provider.Provider;
+/**
+ * Abstraction of a mastership information provider.
+ */
public interface MastershipProvider extends Provider {
-
+ // do we get role info from the local OFcontroller impl?
+ // needs to also read from distributed store and emit events?
+ // roleChanged(DeviceId deviceId, MastershipRole newRole);
}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java
index a777f63..111b2ca 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java
@@ -13,6 +13,6 @@
* @param deviceId the device ID
* @param role the new mastership role of this controller instance
*/
- void roleChanged(DeviceId deviceId, MastershipRole role);
+ void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role);
}
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 3d7b5bc..492f0d4 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
@@ -20,13 +20,15 @@
import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
-public class MastershipManager implements MastershipService,
- MastershipAdminService {
+public class MastershipManager
+ extends AbstractProviderRegistry<MastershipProvider, MastershipProviderService>
+ implements MastershipService, MastershipAdminService {
private static final String NODE_ID_NULL = "Node ID cannot be null";
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
@@ -58,7 +60,6 @@
log.info("Stopped");
}
-
@Override
public void setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
checkNotNull(nodeId, NODE_ID_NULL);
@@ -98,6 +99,12 @@
listenerRegistry.removeListener(listener);
}
+ @Override
+ protected MastershipProviderService createProviderService(
+ MastershipProvider provider) {
+ return new InternalMastershipProviderService(provider);
+ }
+
private class InternalMastershipProviderService
extends AbstractProviderService<MastershipProvider>
implements MastershipProviderService {
@@ -107,9 +114,11 @@
}
@Override
- public void roleChanged(DeviceId deviceId, MastershipRole role) {
+ public void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
// TODO Auto-generated method stub
-
+ MastershipEvent event =
+ store.addOrUpdateDevice(nodeId, deviceId, role);
+ post(event);
}
}
@@ -119,4 +128,5 @@
eventDispatcher.post(event);
}
}
+
}