Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.mastership; |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 17 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 18 | import java.util.Set; |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 19 | import java.util.concurrent.CompletableFuture; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.cluster.NodeId; |
| 22 | import org.onosproject.cluster.RoleInfo; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.MastershipRole; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 25 | |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 26 | /** |
| 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 | */ |
| 32 | public interface MastershipService { |
| 33 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 34 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 35 | * Returns the role of the local node for the specified device, without |
| 36 | * triggering master selection. |
| 37 | * |
Yuta HIGUCHI | 2d48ced | 2014-10-04 21:35:03 -0700 | [diff] [blame] | 38 | * @param deviceId the the identifier of the device |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 39 | * @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 Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 50 | CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 51 | |
| 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 Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 55 | * for this device, no master selection will occur. |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 56 | * |
| 57 | * @param deviceId the identifier of the device |
Madan Jampani | c6e574f | 2015-05-29 13:41:52 -0700 | [diff] [blame] | 58 | * @return future that is completed when relinquish is complete |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 59 | */ |
Madan Jampani | c6e574f | 2015-05-29 13:41:52 -0700 | [diff] [blame] | 60 | CompletableFuture<Void> relinquishMastership(DeviceId deviceId); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 63 | * Returns the current master for a given device. |
| 64 | * |
| 65 | * @param deviceId the identifier of the device |
| 66 | * @return the ID of the master controller for the device |
| 67 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 68 | NodeId getMasterFor(DeviceId deviceId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 69 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 70 | /** |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 71 | * Returns controllers connected to a given device, in order of |
| 72 | * preference. The first entry in the list is the current master. |
| 73 | * |
| 74 | * @param deviceId the identifier of the device |
| 75 | * @return a list of controller IDs |
| 76 | */ |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 77 | RoleInfo getNodesFor(DeviceId deviceId); |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 80 | * Returns the devices for which a controller is master. |
| 81 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 82 | * @param nodeId the ID of the controller |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 83 | * @return a set of device IDs |
| 84 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 85 | Set<DeviceId> getDevicesOf(NodeId nodeId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 86 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 87 | /** |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 88 | * Adds the specified mastership change listener. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 89 | * |
| 90 | * @param listener the mastership listener |
| 91 | */ |
| 92 | void addListener(MastershipListener listener); |
| 93 | |
| 94 | /** |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 95 | * Removes the specified mastership change listener. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 96 | * |
| 97 | * @param listener the mastership listener |
| 98 | */ |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 99 | void removeListener(MastershipListener listener); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 100 | |
| 101 | } |