blob: 30cb545dceb91652e7a2b2c9b5a8d99e0cf2b1ff [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.mastership;
tomca90c462014-09-22 11:40:58 -07002
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07003import java.util.Set;
4
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07005import org.onlab.onos.cluster.NodeId;
Ayaka Koshibeabedb092014-10-20 17:01:31 -07006import org.onlab.onos.cluster.RoleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07007import org.onlab.onos.net.DeviceId;
8import org.onlab.onos.net.MastershipRole;
9
tomca90c462014-09-22 11:40:58 -070010/**
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 */
16public interface MastershipService {
17
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070018 /**
tomb41d1ac2014-09-24 01:51:24 -070019 * Returns the role of the local node for the specified device, without
20 * triggering master selection.
21 *
Yuta HIGUCHI2d48ced2014-10-04 21:35:03 -070022 * @param deviceId the the identifier of the device
tomb41d1ac2014-09-24 01:51:24 -070023 * @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 Koshibec4047702014-10-07 14:43:52 -070039 * for this device, no master selection will occur.
tomb41d1ac2014-09-24 01:51:24 -070040 *
41 * @param deviceId the identifier of the device
42 */
43 void relinquishMastership(DeviceId deviceId);
44
45 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070046 * 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 */
tome4729872014-09-23 00:37:37 -070051 NodeId getMasterFor(DeviceId deviceId);
tomca90c462014-09-22 11:40:58 -070052
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070053 /**
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070054 * 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 Koshibeabedb092014-10-20 17:01:31 -070060 RoleInfo getNodesFor(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070061
62 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070063 * Returns the devices for which a controller is master.
64 *
tome4729872014-09-23 00:37:37 -070065 * @param nodeId the ID of the controller
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070066 * @return a set of device IDs
67 */
tome4729872014-09-23 00:37:37 -070068 Set<DeviceId> getDevicesOf(NodeId nodeId);
tomca90c462014-09-22 11:40:58 -070069
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070070 /**
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070071 * Returns the mastership term service for getting read-only
72 * term information.
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070073 *
74 * @return the MastershipTermService for this mastership manager
75 */
76 MastershipTermService requestTermService();
77
78 /**
tomfc9a4ff2014-09-22 18:22:47 -070079 * Adds the specified mastership change listener.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070080 *
81 * @param listener the mastership listener
82 */
83 void addListener(MastershipListener listener);
84
85 /**
tomfc9a4ff2014-09-22 18:22:47 -070086 * Removes the specified mastership change listener.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070087 *
88 * @param listener the mastership listener
89 */
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070090 void removeListener(MastershipListener listener);
tomca90c462014-09-22 11:40:58 -070091
92}