blob: dc5603fad543d88bf9d59a67484cd6a9ffe707de [file] [log] [blame]
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07001package org.onlab.onos.cluster;
2
3import java.util.Set;
4
5import org.onlab.onos.net.DeviceId;
6import org.onlab.onos.net.MastershipRole;
tomf80c9722014-09-24 14:49:18 -07007import org.onlab.onos.store.Store;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07008
9/**
tome4729872014-09-23 00:37:37 -070010 * Manages inventory of mastership roles for devices, across controller
11 * instances; not intended for direct use.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070012 */
tomf80c9722014-09-24 14:49:18 -070013public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070014
tome4729872014-09-23 00:37:37 -070015 // three things to map: NodeId, DeviceId, MastershipRole
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070016
17 /**
tomb41d1ac2014-09-24 01:51:24 -070018 * Requests role of the local node for the specified device.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070019 *
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070020 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070021 * @return established or newly negotiated mastership role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070022 */
tomb41d1ac2014-09-24 01:51:24 -070023 MastershipRole requestRole(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070024
25 /**
tomb41d1ac2014-09-24 01:51:24 -070026 * Returns the role of a device for a specific controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070027 *
tomb41d1ac2014-09-24 01:51:24 -070028 * @param nodeId the instance identifier
29 * @param deviceId the device identifiers
30 * @return the role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070031 */
tomb41d1ac2014-09-24 01:51:24 -070032 MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070033
34 /**
35 * Returns the master for a device.
36 *
37 * @param deviceId the device identifier
38 * @return the instance identifier of the master
39 */
tome4729872014-09-23 00:37:37 -070040 NodeId getMaster(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070041
42 /**
43 * Returns the devices that a controller instance is master of.
44 *
tome4729872014-09-23 00:37:37 -070045 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070046 * @return a set of device identifiers
47 */
tome4729872014-09-23 00:37:37 -070048 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070049
50 /**
tomb41d1ac2014-09-24 01:51:24 -070051 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070052 *
tomb41d1ac2014-09-24 01:51:24 -070053 * @param nodeId controller instance identifier
54 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070055 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070056 */
Ayaka Koshibe406d0102014-09-24 16:08:12 -070057 MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070058
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 Koshibed9f693e2014-09-29 18:04:54 -070067
68 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070069 * Sets a controller instance's mastership role to STANDBY for a device.
70 * If the role is MASTER, another controller instance will be selected
71 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070072 *
73 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -070074 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070075 * @return a mastership event
76 */
Ayaka Koshibec4047702014-10-07 14:43:52 -070077 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
78
79 /**
80 * Allows a controller instance to give up its current role for a device.
81 * If the role is MASTER, another controller instance will be selected
82 * as a candidate master.
83 *
84 * @param nodeId the controller instance identifier
85 * @param deviceId device to revoke mastership role for
86 * @return a mastership event
87 */
88 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
89
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070090}