Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cluster; |
| 2 | |
| 3 | import java.util.Set; |
| 4 | |
| 5 | import org.onlab.onos.net.DeviceId; |
| 6 | import org.onlab.onos.net.MastershipRole; |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 7 | import org.onlab.onos.store.Store; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 8 | |
| 9 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 10 | * Manages inventory of mastership roles for devices, across controller |
| 11 | * instances; not intended for direct use. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 12 | */ |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 13 | public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> { |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 14 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 15 | // three things to map: NodeId, DeviceId, MastershipRole |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 18 | * Requests role of the local node for the specified device. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 19 | * |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 20 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 21 | * @return established or newly negotiated mastership role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 22 | */ |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 23 | MastershipRole requestRole(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 26 | * Returns the role of a device for a specific controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 27 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 28 | * @param nodeId the instance identifier |
| 29 | * @param deviceId the device identifiers |
| 30 | * @return the role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 31 | */ |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 32 | MastershipRole getRole(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Returns the master for a device. |
| 36 | * |
| 37 | * @param deviceId the device identifier |
| 38 | * @return the instance identifier of the master |
| 39 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 40 | NodeId getMaster(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Returns the devices that a controller instance is master of. |
| 44 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 45 | * @param nodeId the instance identifier |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 46 | * @return a set of device identifiers |
| 47 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 48 | Set<DeviceId> getDevices(NodeId nodeId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 51 | * Sets a device's role for a specified controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 52 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 53 | * @param nodeId controller instance identifier |
| 54 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 55 | * @return a mastership event |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 56 | */ |
Ayaka Koshibe | 406d010 | 2014-09-24 16:08:12 -0700 | [diff] [blame] | 57 | MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Returns the current master and number of past mastership hand-offs |
| 61 | * (terms) for a device. |
| 62 | * |
| 63 | * @param deviceId the device identifier |
| 64 | * @return the current master's ID and the term value for device, or null |
| 65 | */ |
| 66 | MastershipTerm getTermFor(DeviceId deviceId); |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Revokes a controller instance's mastership over a device and hands |
| 70 | * over mastership to another controller instance. |
| 71 | * |
| 72 | * @param nodeId the controller instance identifier |
| 73 | * @param deviceId device to revoke mastership for |
| 74 | * @return a mastership event |
| 75 | */ |
| 76 | MastershipEvent unsetMaster(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 77 | } |