Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Set; |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 19 | import java.util.concurrent.CompletableFuture; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -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; |
| 25 | import org.onosproject.store.Store; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 28 | * Manages inventory of mastership roles for devices, across controller |
| 29 | * instances; not intended for direct use. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 30 | */ |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 31 | public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> { |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 32 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 33 | // three things to map: NodeId, DeviceId, MastershipRole |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 36 | * Requests role of the local node for the specified device. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 37 | * |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 38 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 39 | * @return established or newly negotiated mastership role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 40 | */ |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 41 | CompletableFuture<MastershipRole> requestRole(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 44 | * Returns the role of a device for a specific controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 45 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 46 | * @param nodeId the instance identifier |
| 47 | * @param deviceId the device identifiers |
| 48 | * @return the role |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 49 | */ |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 50 | MastershipRole getRole(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Returns the master for a device. |
| 54 | * |
| 55 | * @param deviceId the device identifier |
| 56 | * @return the instance identifier of the master |
| 57 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 58 | NodeId getMaster(DeviceId deviceId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 61 | * Returns the master and backup nodes for a device. |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 62 | * |
| 63 | * @param deviceId the device identifier |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 64 | * @return a RoleInfo containing controller IDs |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 65 | */ |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 66 | RoleInfo getNodes(DeviceId deviceId); |
Ayaka Koshibe | 45503ce | 2014-10-14 11:26:45 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 69 | * Returns the devices that a controller instance is master of. |
| 70 | * |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 71 | * @param nodeId the instance identifier |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 72 | * @return a set of device identifiers |
| 73 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 74 | Set<DeviceId> getDevices(NodeId nodeId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 77 | * Sets a device's role for a specified controller instance. |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 78 | * |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 79 | * @param nodeId controller instance identifier |
| 80 | * @param deviceId device identifier |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 81 | * @return a mastership event |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 82 | */ |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 83 | CompletableFuture<MastershipEvent> setMaster(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Returns the current master and number of past mastership hand-offs |
| 87 | * (terms) for a device. |
| 88 | * |
| 89 | * @param deviceId the device identifier |
| 90 | * @return the current master's ID and the term value for device, or null |
| 91 | */ |
| 92 | MastershipTerm getTermFor(DeviceId deviceId); |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Jordan Halterman | 0a2bd45 | 2018-06-13 17:24:58 -0700 | [diff] [blame] | 95 | * Returns the mastership info for the given device. |
| 96 | * |
| 97 | * @param deviceId the device for which to return the mastership info |
| 98 | * @return the mastership info for the given device |
| 99 | */ |
| 100 | MastershipInfo getMastership(DeviceId deviceId); |
| 101 | |
| 102 | /** |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 103 | * Sets a controller instance's mastership role to STANDBY for a device. |
| 104 | * If the role is MASTER, another controller instance will be selected |
| 105 | * as a candidate master. |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 106 | * |
| 107 | * @param nodeId the controller instance identifier |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 108 | * @param deviceId device to revoke mastership role for |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 109 | * @return a mastership event |
| 110 | */ |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 111 | CompletableFuture<MastershipEvent> setStandby(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Allows a controller instance to give up its current role for a device. |
| 115 | * If the role is MASTER, another controller instance will be selected |
| 116 | * as a candidate master. |
| 117 | * |
| 118 | * @param nodeId the controller instance identifier |
| 119 | * @param deviceId device to revoke mastership role for |
| 120 | * @return a mastership event |
| 121 | */ |
Madan Jampani | f7536ab | 2015-05-07 23:23:23 -0700 | [diff] [blame] | 122 | CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId); |
Ayaka Koshibe | c404770 | 2014-10-07 14:43:52 -0700 | [diff] [blame] | 123 | |
HIGUCHI Yuta | 59f0229 | 2015-02-25 19:51:48 -0800 | [diff] [blame] | 124 | /** |
| 125 | * Removes all the roles for the specified controller instance. |
| 126 | * If the role was MASTER, another controller instance will be selected |
| 127 | * as a candidate master. |
| 128 | * |
| 129 | * @param nodeId the controller instance identifier |
| 130 | */ |
| 131 | void relinquishAllRole(NodeId nodeId); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 132 | } |