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 | |
Madan Jampani | 565a66a | 2015-07-25 17:01:13 -0700 | [diff] [blame] | 18 | import static org.onosproject.net.MastershipRole.MASTER; |
| 19 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 20 | import java.util.Set; |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 21 | import java.util.concurrent.CompletableFuture; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 22 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.cluster.NodeId; |
| 24 | import org.onosproject.cluster.RoleInfo; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 25 | import org.onosproject.event.ListenerService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.MastershipRole; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 28 | |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Service responsible for determining the controller instance mastership of |
| 31 | * a device in a clustered environment. This is the central authority for |
| 32 | * determining mastership, but is not responsible for actually applying it |
| 33 | * to the devices; this falls on the device service. |
| 34 | */ |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 35 | public interface MastershipService |
| 36 | extends ListenerService<MastershipEvent, MastershipListener> { |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 37 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 38 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 39 | * Returns the role of the local node for the specified device, without |
| 40 | * triggering master selection. |
| 41 | * |
Yuta HIGUCHI | 2d48ced | 2014-10-04 21:35:03 -0700 | [diff] [blame] | 42 | * @param deviceId the the identifier of the device |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 43 | * @return role of the current node |
| 44 | */ |
| 45 | MastershipRole getLocalRole(DeviceId deviceId); |
| 46 | |
| 47 | /** |
Madan Jampani | 565a66a | 2015-07-25 17:01:13 -0700 | [diff] [blame] | 48 | * Returns true if the local controller is the Master for the specified deviceId. |
| 49 | * |
| 50 | * @param deviceId the the identifier of the device |
| 51 | * @return true if local node is master; false otherwise |
| 52 | */ |
| 53 | default boolean isLocalMaster(DeviceId deviceId) { |
| 54 | return getLocalRole(deviceId) == MASTER; |
| 55 | } |
| 56 | |
| 57 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 58 | * Returns the mastership status of the local controller for a given |
| 59 | * device forcing master selection if necessary. |
| 60 | * |
| 61 | * @param deviceId the the identifier of the device |
| 62 | * @return the role of this controller instance |
| 63 | */ |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 64 | CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Abandons mastership of the specified device on the local node thus |
| 68 | * 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] | 69 | * for this device, no master selection will occur. |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 70 | * |
| 71 | * @param deviceId the identifier of the device |
Madan Jampani | c6e574f | 2015-05-29 13:41:52 -0700 | [diff] [blame] | 72 | * @return future that is completed when relinquish is complete |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 73 | */ |
Madan Jampani | c6e574f | 2015-05-29 13:41:52 -0700 | [diff] [blame] | 74 | CompletableFuture<Void> relinquishMastership(DeviceId deviceId); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 77 | * Returns the current master for a given device. |
| 78 | * |
| 79 | * @param deviceId the identifier of the device |
| 80 | * @return the ID of the master controller for the device |
| 81 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 82 | NodeId getMasterFor(DeviceId deviceId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 83 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 84 | /** |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 85 | * Returns controllers connected to a given device, in order of |
| 86 | * preference. The first entry in the list is the current master. |
| 87 | * |
| 88 | * @param deviceId the identifier of the device |
| 89 | * @return a list of controller IDs |
| 90 | */ |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 91 | RoleInfo getNodesFor(DeviceId deviceId); |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 94 | * Returns the devices for which a controller is master. |
| 95 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 96 | * @param nodeId the ID of the controller |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 97 | * @return a set of device IDs |
| 98 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 99 | Set<DeviceId> getDevicesOf(NodeId nodeId); |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 100 | |
tom | ca90c46 | 2014-09-22 11:40:58 -0700 | [diff] [blame] | 101 | } |