blob: 450bcc545e6812482258ddb2eb23d1775ea7619e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.mastership;
tomca90c462014-09-22 11:40:58 -070017
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070018import java.util.Set;
Madan Jampanide003d92015-05-11 17:14:20 -070019import java.util.concurrent.CompletableFuture;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070020
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.cluster.NodeId;
22import org.onosproject.cluster.RoleInfo;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.MastershipRole;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070025
tomca90c462014-09-22 11:40:58 -070026/**
27 * Service responsible for determining the controller instance mastership of
28 * a device in a clustered environment. This is the central authority for
29 * determining mastership, but is not responsible for actually applying it
30 * to the devices; this falls on the device service.
31 */
32public interface MastershipService {
33
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070034 /**
tomb41d1ac2014-09-24 01:51:24 -070035 * Returns the role of the local node for the specified device, without
36 * triggering master selection.
37 *
Yuta HIGUCHI2d48ced2014-10-04 21:35:03 -070038 * @param deviceId the the identifier of the device
tomb41d1ac2014-09-24 01:51:24 -070039 * @return role of the current node
40 */
41 MastershipRole getLocalRole(DeviceId deviceId);
42
43 /**
44 * Returns the mastership status of the local controller for a given
45 * device forcing master selection if necessary.
46 *
47 * @param deviceId the the identifier of the device
48 * @return the role of this controller instance
49 */
Madan Jampanide003d92015-05-11 17:14:20 -070050 CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId);
tomb41d1ac2014-09-24 01:51:24 -070051
52 /**
53 * Abandons mastership of the specified device on the local node thus
54 * forcing selection of a new master. If the local node is not a master
Ayaka Koshibec4047702014-10-07 14:43:52 -070055 * for this device, no master selection will occur.
tomb41d1ac2014-09-24 01:51:24 -070056 *
57 * @param deviceId the identifier of the device
58 */
59 void relinquishMastership(DeviceId deviceId);
60
61 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070062 * Returns the current master for a given device.
63 *
64 * @param deviceId the identifier of the device
65 * @return the ID of the master controller for the device
66 */
tome4729872014-09-23 00:37:37 -070067 NodeId getMasterFor(DeviceId deviceId);
tomca90c462014-09-22 11:40:58 -070068
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070069 /**
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070070 * Returns controllers connected to a given device, in order of
71 * preference. The first entry in the list is the current master.
72 *
73 * @param deviceId the identifier of the device
74 * @return a list of controller IDs
75 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070076 RoleInfo getNodesFor(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070077
78 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070079 * Returns the devices for which a controller is master.
80 *
tome4729872014-09-23 00:37:37 -070081 * @param nodeId the ID of the controller
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070082 * @return a set of device IDs
83 */
tome4729872014-09-23 00:37:37 -070084 Set<DeviceId> getDevicesOf(NodeId nodeId);
tomca90c462014-09-22 11:40:58 -070085
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070086 /**
tomfc9a4ff2014-09-22 18:22:47 -070087 * Adds the specified mastership change listener.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070088 *
89 * @param listener the mastership listener
90 */
91 void addListener(MastershipListener listener);
92
93 /**
tomfc9a4ff2014-09-22 18:22:47 -070094 * Removes the specified mastership change listener.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070095 *
96 * @param listener the mastership listener
97 */
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070098 void removeListener(MastershipListener listener);
tomca90c462014-09-22 11:40:58 -070099
100}