Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 1 | package org.onlab.onos.mastership; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 2 | |
| 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 | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.MastershipRole; |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 9 | import org.onlab.onos.store.Store; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 12 | * Manages inventory of mastership roles for devices, across controller |
| 13 | * instances; not intended for direct use. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 14 | */ |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 15 | public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> { |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 16 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 17 | // three things to map: NodeId, DeviceId, MastershipRole |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 18 | |
| 19 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 20 | * Requests role of the local node for the specified device. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 21 | * |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 22 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 23 | * @return established or newly negotiated mastership role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 24 | */ |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 25 | MastershipRole requestRole(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 28 | * Returns the role of a device for a specific controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 29 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 30 | * @param nodeId the instance identifier |
| 31 | * @param deviceId the device identifiers |
| 32 | * @return the role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 33 | */ |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 34 | MastershipRole getRole(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Returns the master for a device. |
| 38 | * |
| 39 | * @param deviceId the device identifier |
| 40 | * @return the instance identifier of the master |
| 41 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 42 | NodeId getMaster(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 45 | * Returns the master and backup nodes for a device. |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 46 | * |
| 47 | * @param deviceId the device identifier |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 48 | * @return a RoleInfo containing controller IDs |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 49 | */ |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 50 | RoleInfo getNodes(DeviceId deviceId); |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 53 | * Returns the devices that a controller instance is master of. |
| 54 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 55 | * @param nodeId the instance identifier |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 56 | * @return a set of device identifiers |
| 57 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 58 | Set<DeviceId> getDevices(NodeId nodeId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 59 | |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 60 | |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 61 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 62 | * Sets a device's role for a specified controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 63 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 64 | * @param nodeId controller instance identifier |
| 65 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 66 | * @return a mastership event |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 67 | */ |
Ayaka Koshibe | 406d010 | 2014-09-24 16:08:12 -0700 | [diff] [blame] | 68 | MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Returns the current master and number of past mastership hand-offs |
| 72 | * (terms) for a device. |
| 73 | * |
| 74 | * @param deviceId the device identifier |
| 75 | * @return the current master's ID and the term value for device, or null |
| 76 | */ |
| 77 | MastershipTerm getTermFor(DeviceId deviceId); |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 80 | * Sets a controller instance's mastership role to STANDBY for a device. |
| 81 | * If the role is MASTER, another controller instance will be selected |
| 82 | * as a candidate master. |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 83 | * |
| 84 | * @param nodeId the controller instance identifier |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 85 | * @param deviceId device to revoke mastership role for |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 86 | * @return a mastership event |
| 87 | */ |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 88 | MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId); |
| 89 | |
| 90 | /** |
| 91 | * Allows a controller instance to give up its current role for a device. |
| 92 | * If the role is MASTER, another controller instance will be selected |
| 93 | * as a candidate master. |
| 94 | * |
| 95 | * @param nodeId the controller instance identifier |
| 96 | * @param deviceId device to revoke mastership role for |
| 97 | * @return a mastership event |
| 98 | */ |
| 99 | MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId); |
| 100 | |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 101 | } |