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