blob: 2112029f19bec8cfe2a716bfbab33e9780eb2ece [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.mastership;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070017
18import java.util.Set;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cluster.NodeId;
21import org.onosproject.cluster.RoleInfo;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.MastershipRole;
24import org.onosproject.store.Store;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070025
26/**
tome4729872014-09-23 00:37:37 -070027 * Manages inventory of mastership roles for devices, across controller
28 * instances; not intended for direct use.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070029 */
tomf80c9722014-09-24 14:49:18 -070030public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070031
tome4729872014-09-23 00:37:37 -070032 // three things to map: NodeId, DeviceId, MastershipRole
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070033
34 /**
tomb41d1ac2014-09-24 01:51:24 -070035 * Requests role of the local node for the specified device.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070036 *
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070037 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070038 * @return established or newly negotiated mastership role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070039 */
tomb41d1ac2014-09-24 01:51:24 -070040 MastershipRole requestRole(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070041
42 /**
tomb41d1ac2014-09-24 01:51:24 -070043 * Returns the role of a device for a specific controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070044 *
tomb41d1ac2014-09-24 01:51:24 -070045 * @param nodeId the instance identifier
46 * @param deviceId the device identifiers
47 * @return the role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070048 */
tomb41d1ac2014-09-24 01:51:24 -070049 MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070050
51 /**
52 * Returns the master for a device.
53 *
54 * @param deviceId the device identifier
55 * @return the instance identifier of the master
56 */
tome4729872014-09-23 00:37:37 -070057 NodeId getMaster(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070058
59 /**
Ayaka Koshibeabedb092014-10-20 17:01:31 -070060 * Returns the master and backup nodes for a device.
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070061 *
62 * @param deviceId the device identifier
Ayaka Koshibeabedb092014-10-20 17:01:31 -070063 * @return a RoleInfo containing controller IDs
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070064 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070065 RoleInfo getNodes(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070066
67 /**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070068 * Returns the devices that a controller instance is master of.
69 *
tome4729872014-09-23 00:37:37 -070070 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070071 * @return a set of device identifiers
72 */
tome4729872014-09-23 00:37:37 -070073 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070074
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070075
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070076 /**
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 */
Ayaka Koshibe406d0102014-09-24 16:08:12 -070083 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 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070095 * Sets a controller instance's mastership role to STANDBY for a device.
96 * If the role is MASTER, another controller instance will be selected
97 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070098 *
99 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -0700100 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700101 * @return a mastership event
102 */
Ayaka Koshibec4047702014-10-07 14:43:52 -0700103 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
104
105 /**
106 * Allows a controller instance to give up its current role for a device.
107 * If the role is MASTER, another controller instance will be selected
108 * as a candidate master.
109 *
110 * @param nodeId the controller instance identifier
111 * @param deviceId device to revoke mastership role for
112 * @return a mastership event
113 */
114 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
115
Ayaka Koshibe8d504a92014-09-22 17:07:36 -0700116}