blob: 6a9fbf8b9a8e2e1952750daa70d3de76a5c2fc60 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070017
18import java.util.Set;
Madan Jampanif7536ab2015-05-07 23:23:23 -070019import java.util.concurrent.CompletableFuture;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070020
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.cluster.NodeId;
22import org.onosproject.cluster.RoleInfo;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.MastershipRole;
25import org.onosproject.store.Store;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070026
27/**
tome4729872014-09-23 00:37:37 -070028 * Manages inventory of mastership roles for devices, across controller
29 * instances; not intended for direct use.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070030 */
tomf80c9722014-09-24 14:49:18 -070031public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070032
tome4729872014-09-23 00:37:37 -070033 // three things to map: NodeId, DeviceId, MastershipRole
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070034
35 /**
tomb41d1ac2014-09-24 01:51:24 -070036 * Requests role of the local node for the specified device.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070037 *
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070038 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070039 * @return established or newly negotiated mastership role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070040 */
Madan Jampanide003d92015-05-11 17:14:20 -070041 CompletableFuture<MastershipRole> requestRole(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070042
43 /**
tomb41d1ac2014-09-24 01:51:24 -070044 * Returns the role of a device for a specific controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070045 *
tomb41d1ac2014-09-24 01:51:24 -070046 * @param nodeId the instance identifier
47 * @param deviceId the device identifiers
48 * @return the role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070049 */
tomb41d1ac2014-09-24 01:51:24 -070050 MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070051
52 /**
53 * Returns the master for a device.
54 *
55 * @param deviceId the device identifier
56 * @return the instance identifier of the master
57 */
tome4729872014-09-23 00:37:37 -070058 NodeId getMaster(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070059
60 /**
Ayaka Koshibeabedb092014-10-20 17:01:31 -070061 * Returns the master and backup nodes for a device.
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070062 *
63 * @param deviceId the device identifier
Ayaka Koshibeabedb092014-10-20 17:01:31 -070064 * @return a RoleInfo containing controller IDs
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070065 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070066 RoleInfo getNodes(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070067
68 /**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070069 * Returns the devices that a controller instance is master of.
70 *
tome4729872014-09-23 00:37:37 -070071 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070072 * @return a set of device identifiers
73 */
tome4729872014-09-23 00:37:37 -070074 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070075
76 /**
tomb41d1ac2014-09-24 01:51:24 -070077 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070078 *
tomb41d1ac2014-09-24 01:51:24 -070079 * @param nodeId controller instance identifier
80 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070081 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070082 */
Madan Jampanif7536ab2015-05-07 23:23:23 -070083 CompletableFuture<MastershipEvent> setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070084
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 Koshibed9f693e2014-09-29 18:04:54 -070093
94 /**
Jordan Halterman0a2bd452018-06-13 17:24:58 -070095 * 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 Koshibec4047702014-10-07 14:43:52 -0700103 * 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 Koshibed9f693e2014-09-29 18:04:54 -0700106 *
107 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -0700108 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700109 * @return a mastership event
110 */
Madan Jampanif7536ab2015-05-07 23:23:23 -0700111 CompletableFuture<MastershipEvent> setStandby(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700112
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 Jampanif7536ab2015-05-07 23:23:23 -0700122 CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700123
HIGUCHI Yuta59f02292015-02-25 19:51:48 -0800124 /**
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);
pierventrecdcd91c2021-05-06 09:27:00 +0200132
133 /**
134 * Attempts to demote a node to the bottom of the backup list. It is not allowed
135 * to demote the current master
136 *
137 * @param instance controller instance identifier
138 * @param deviceId device identifier
139 */
140 void demote(NodeId instance, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -0700141}