blob: 36503889deb916d05d7f9f1d325556a13582e587 [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
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070076
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070077 /**
tomb41d1ac2014-09-24 01:51:24 -070078 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070079 *
tomb41d1ac2014-09-24 01:51:24 -070080 * @param nodeId controller instance identifier
81 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070082 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070083 */
Madan Jampanif7536ab2015-05-07 23:23:23 -070084 CompletableFuture<MastershipEvent> setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070085
86 /**
87 * Returns the current master and number of past mastership hand-offs
88 * (terms) for a device.
89 *
90 * @param deviceId the device identifier
91 * @return the current master's ID and the term value for device, or null
92 */
93 MastershipTerm getTermFor(DeviceId deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070094
95 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070096 * Sets a controller instance's mastership role to STANDBY for a device.
97 * If the role is MASTER, another controller instance will be selected
98 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070099 *
100 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -0700101 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700102 * @return a mastership event
103 */
Madan Jampanif7536ab2015-05-07 23:23:23 -0700104 CompletableFuture<MastershipEvent> setStandby(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700105
106 /**
107 * Allows a controller instance to give up its current role for a device.
108 * If the role is MASTER, another controller instance will be selected
109 * as a candidate master.
110 *
111 * @param nodeId the controller instance identifier
112 * @param deviceId device to revoke mastership role for
113 * @return a mastership event
114 */
Madan Jampanif7536ab2015-05-07 23:23:23 -0700115 CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700116
HIGUCHI Yuta59f02292015-02-25 19:51:48 -0800117 /**
118 * Removes all the roles for the specified controller instance.
119 * If the role was MASTER, another controller instance will be selected
120 * as a candidate master.
121 *
122 * @param nodeId the controller instance identifier
123 */
124 void relinquishAllRole(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -0700125}