blob: 75d0eac0bf6c5f699af55151875deaf16828cf0b [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;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070023import org.onosproject.event.ListenerService;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.DeviceId;
25import org.onosproject.net.MastershipRole;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070026
tomca90c462014-09-22 11:40:58 -070027/**
28 * Service responsible for determining the controller instance mastership of
29 * a device in a clustered environment. This is the central authority for
30 * determining mastership, but is not responsible for actually applying it
31 * to the devices; this falls on the device service.
32 */
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070033public interface MastershipService
34 extends ListenerService<MastershipEvent, MastershipListener> {
tomca90c462014-09-22 11:40:58 -070035
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070036 /**
tomb41d1ac2014-09-24 01:51:24 -070037 * Returns the role of the local node for the specified device, without
38 * triggering master selection.
39 *
Yuta HIGUCHI2d48ced2014-10-04 21:35:03 -070040 * @param deviceId the the identifier of the device
tomb41d1ac2014-09-24 01:51:24 -070041 * @return role of the current node
42 */
43 MastershipRole getLocalRole(DeviceId deviceId);
44
45 /**
46 * Returns the mastership status of the local controller for a given
47 * device forcing master selection if necessary.
48 *
49 * @param deviceId the the identifier of the device
50 * @return the role of this controller instance
51 */
Madan Jampanide003d92015-05-11 17:14:20 -070052 CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId);
tomb41d1ac2014-09-24 01:51:24 -070053
54 /**
55 * Abandons mastership of the specified device on the local node thus
56 * forcing selection of a new master. If the local node is not a master
Ayaka Koshibec4047702014-10-07 14:43:52 -070057 * for this device, no master selection will occur.
tomb41d1ac2014-09-24 01:51:24 -070058 *
59 * @param deviceId the identifier of the device
Madan Jampanic6e574f2015-05-29 13:41:52 -070060 * @return future that is completed when relinquish is complete
tomb41d1ac2014-09-24 01:51:24 -070061 */
Madan Jampanic6e574f2015-05-29 13:41:52 -070062 CompletableFuture<Void> relinquishMastership(DeviceId deviceId);
tomb41d1ac2014-09-24 01:51:24 -070063
64 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070065 * Returns the current master for a given device.
66 *
67 * @param deviceId the identifier of the device
68 * @return the ID of the master controller for the device
69 */
tome4729872014-09-23 00:37:37 -070070 NodeId getMasterFor(DeviceId deviceId);
tomca90c462014-09-22 11:40:58 -070071
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070072 /**
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070073 * Returns controllers connected to a given device, in order of
74 * preference. The first entry in the list is the current master.
75 *
76 * @param deviceId the identifier of the device
77 * @return a list of controller IDs
78 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070079 RoleInfo getNodesFor(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070080
81 /**
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070082 * Returns the devices for which a controller is master.
83 *
tome4729872014-09-23 00:37:37 -070084 * @param nodeId the ID of the controller
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070085 * @return a set of device IDs
86 */
tome4729872014-09-23 00:37:37 -070087 Set<DeviceId> getDevicesOf(NodeId nodeId);
tomca90c462014-09-22 11:40:58 -070088
tomca90c462014-09-22 11:40:58 -070089}