Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 1 | package org.onlab.onos.mastership; |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 2 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 3 | import java.util.Set; |
| 4 | |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 5 | import org.onlab.onos.cluster.NodeId; |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 6 | import org.onlab.onos.cluster.RoleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.MastershipRole; |
| 9 | |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 10 | /** |
| 11 | * Service responsible for determining the controller instance mastership of |
| 12 | * a device in a clustered environment. This is the central authority for |
| 13 | * determining mastership, but is not responsible for actually applying it |
| 14 | * to the devices; this falls on the device service. |
| 15 | */ |
| 16 | public interface MastershipService { |
| 17 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 18 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 19 | * Returns the role of the local node for the specified device, without |
| 20 | * triggering master selection. |
| 21 | * |
Yuta HIGUCHI | 2d48ced | 2014-10-04 21:35:03 -0700 | [diff] [blame] | 22 | * @param deviceId the the identifier of the device |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 23 | * @return role of the current node |
| 24 | */ |
| 25 | MastershipRole getLocalRole(DeviceId deviceId); |
| 26 | |
| 27 | /** |
| 28 | * Returns the mastership status of the local controller for a given |
| 29 | * device forcing master selection if necessary. |
| 30 | * |
| 31 | * @param deviceId the the identifier of the device |
| 32 | * @return the role of this controller instance |
| 33 | */ |
| 34 | MastershipRole requestRoleFor(DeviceId deviceId); |
| 35 | |
| 36 | /** |
| 37 | * Abandons mastership of the specified device on the local node thus |
| 38 | * forcing selection of a new master. If the local node is not a master |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 39 | * for this device, no master selection will occur. |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 40 | * |
| 41 | * @param deviceId the identifier of the device |
| 42 | */ |
| 43 | void relinquishMastership(DeviceId deviceId); |
| 44 | |
| 45 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 46 | * Returns the current master for a given device. |
| 47 | * |
| 48 | * @param deviceId the identifier of the device |
| 49 | * @return the ID of the master controller for the device |
| 50 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 51 | NodeId getMasterFor(DeviceId deviceId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 52 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 53 | /** |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 54 | * Returns controllers connected to a given device, in order of |
| 55 | * preference. The first entry in the list is the current master. |
| 56 | * |
| 57 | * @param deviceId the identifier of the device |
| 58 | * @return a list of controller IDs |
| 59 | */ |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 60 | RoleInfo getNodesFor(DeviceId deviceId); |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 63 | * Returns the devices for which a controller is master. |
| 64 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 65 | * @param nodeId the ID of the controller |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 66 | * @return a set of device IDs |
| 67 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 68 | Set<DeviceId> getDevicesOf(NodeId nodeId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 69 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 70 | /** |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 71 | * Returns the mastership term service for getting read-only |
| 72 | * term information. |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 73 | * |
| 74 | * @return the MastershipTermService for this mastership manager |
| 75 | */ |
| 76 | MastershipTermService requestTermService(); |
| 77 | |
| 78 | /** |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 79 | * Adds the specified mastership change listener. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 80 | * |
| 81 | * @param listener the mastership listener |
| 82 | */ |
| 83 | void addListener(MastershipListener listener); |
| 84 | |
| 85 | /** |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 86 | * Removes the specified mastership change listener. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 87 | * |
| 88 | * @param listener the mastership listener |
| 89 | */ |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 90 | void removeListener(MastershipListener listener); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 91 | |
| 92 | } |