Ayaka Koshibe

Added providerService for mastership

Change-Id: I1572161f70c696961a663cba17f197e23f96967e
1 package org.onlab.onos.cluster; 1 package org.onlab.onos.cluster;
2 2
3 +import org.onlab.onos.net.MastershipRole;
3 import org.onlab.onos.net.provider.Provider; 4 import org.onlab.onos.net.provider.Provider;
4 5
6 +/**
7 + * Abstraction of a mastership information provider.
8 + */
5 public interface MastershipProvider extends Provider { 9 public interface MastershipProvider extends Provider {
6 - 10 + // do we get role info from the local OFcontroller impl?
11 + // needs to also read from distributed store and emit events?
12 + // roleChanged(DeviceId deviceId, MastershipRole newRole);
7 } 13 }
......
...@@ -13,6 +13,6 @@ public interface MastershipProviderService extends ...@@ -13,6 +13,6 @@ public interface MastershipProviderService extends
13 * @param deviceId the device ID 13 * @param deviceId the device ID
14 * @param role the new mastership role of this controller instance 14 * @param role the new mastership role of this controller instance
15 */ 15 */
16 - void roleChanged(DeviceId deviceId, MastershipRole role); 16 + void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role);
17 17
18 } 18 }
......
...@@ -20,13 +20,15 @@ import org.onlab.onos.event.AbstractListenerRegistry; ...@@ -20,13 +20,15 @@ import org.onlab.onos.event.AbstractListenerRegistry;
20 import org.onlab.onos.event.EventDeliveryService; 20 import org.onlab.onos.event.EventDeliveryService;
21 import org.onlab.onos.net.DeviceId; 21 import org.onlab.onos.net.DeviceId;
22 import org.onlab.onos.net.MastershipRole; 22 import org.onlab.onos.net.MastershipRole;
23 +import org.onlab.onos.net.provider.AbstractProviderRegistry;
23 import org.onlab.onos.net.provider.AbstractProviderService; 24 import org.onlab.onos.net.provider.AbstractProviderService;
24 import org.slf4j.Logger; 25 import org.slf4j.Logger;
25 26
26 import static com.google.common.base.Preconditions.checkNotNull; 27 import static com.google.common.base.Preconditions.checkNotNull;
27 28
28 -public class MastershipManager implements MastershipService, 29 +public class MastershipManager
29 - MastershipAdminService { 30 + extends AbstractProviderRegistry<MastershipProvider, MastershipProviderService>
31 + implements MastershipService, MastershipAdminService {
30 32
31 private static final String NODE_ID_NULL = "Node ID cannot be null"; 33 private static final String NODE_ID_NULL = "Node ID cannot be null";
32 private static final String DEVICE_ID_NULL = "Device ID cannot be null"; 34 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
...@@ -58,7 +60,6 @@ public class MastershipManager implements MastershipService, ...@@ -58,7 +60,6 @@ public class MastershipManager implements MastershipService,
58 log.info("Stopped"); 60 log.info("Stopped");
59 } 61 }
60 62
61 -
62 @Override 63 @Override
63 public void setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { 64 public void setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
64 checkNotNull(nodeId, NODE_ID_NULL); 65 checkNotNull(nodeId, NODE_ID_NULL);
...@@ -98,6 +99,12 @@ public class MastershipManager implements MastershipService, ...@@ -98,6 +99,12 @@ public class MastershipManager implements MastershipService,
98 listenerRegistry.removeListener(listener); 99 listenerRegistry.removeListener(listener);
99 } 100 }
100 101
102 + @Override
103 + protected MastershipProviderService createProviderService(
104 + MastershipProvider provider) {
105 + return new InternalMastershipProviderService(provider);
106 + }
107 +
101 private class InternalMastershipProviderService 108 private class InternalMastershipProviderService
102 extends AbstractProviderService<MastershipProvider> 109 extends AbstractProviderService<MastershipProvider>
103 implements MastershipProviderService { 110 implements MastershipProviderService {
...@@ -107,9 +114,11 @@ public class MastershipManager implements MastershipService, ...@@ -107,9 +114,11 @@ public class MastershipManager implements MastershipService,
107 } 114 }
108 115
109 @Override 116 @Override
110 - public void roleChanged(DeviceId deviceId, MastershipRole role) { 117 + public void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
111 // TODO Auto-generated method stub 118 // TODO Auto-generated method stub
112 - 119 + MastershipEvent event =
120 + store.addOrUpdateDevice(nodeId, deviceId, role);
121 + post(event);
113 } 122 }
114 } 123 }
115 124
...@@ -119,4 +128,5 @@ public class MastershipManager implements MastershipService, ...@@ -119,4 +128,5 @@ public class MastershipManager implements MastershipService,
119 eventDispatcher.post(event); 128 eventDispatcher.post(event);
120 } 129 }
121 } 130 }
131 +
122 } 132 }
......