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