blob: bc490d94fbad39d29efe287fd7737d4cf20cd8cd [file] [log] [blame]
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -08001/*
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.cluster;
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080017
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080018import java.util.Map;
Madan Jampani59610512015-02-25 15:25:43 -080019import java.util.Set;
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070020import java.util.List;
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080021
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080022/**
Madan Jampani1d3494e2014-11-20 11:24:22 -080023 * Service for leader election.
Madan Jampani1ee91782014-11-20 20:24:24 -080024 * Leadership contests are organized around topics. A instance can join the
25 * leadership race for a topic or withdraw from a race it has previously joined.
26 * Listeners can be added to receive notifications asynchronously for various
27 * leadership contests.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080028 */
29public interface LeadershipService {
30
31 /**
Madan Jampani59610512015-02-25 15:25:43 -080032 * Returns the current leader for the topic.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070033 *
Madan Jampani1ee91782014-11-20 20:24:24 -080034 * @param path topic
Madan Jampani8d21c792014-12-01 16:31:07 -080035 * @return nodeId of the leader, null if so such topic exists.
Madan Jampani1ee91782014-11-20 20:24:24 -080036 */
Madan Jampani8d21c792014-12-01 16:31:07 -080037 NodeId getLeader(String path);
Madan Jampani1ee91782014-11-20 20:24:24 -080038
39 /**
Madan Jampani59610512015-02-25 15:25:43 -080040 * Returns the current leadership info for the topic.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070041 *
Madan Jampani59610512015-02-25 15:25:43 -080042 * @param path topic
43 * @return leadership info or null if so such topic exists.
44 */
45 Leadership getLeadership(String path);
46
47 /**
48 * Returns the set of topics owned by the specified node.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070049 *
Madan Jampani59610512015-02-25 15:25:43 -080050 * @param nodeId node Id.
51 * @return set of topics for which this node is the current leader.
52 */
53 Set<String> ownedTopics(NodeId nodeId);
54
55 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080056 * Joins the leadership contest.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070057 *
Madan Jampani1d3494e2014-11-20 11:24:22 -080058 * @param path topic for which this controller node wishes to be a leader.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080059 */
Madan Jampani1d3494e2014-11-20 11:24:22 -080060 void runForLeadership(String path);
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080061
62 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080063 * Withdraws from a leadership contest.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070064 *
Madan Jampani1d3494e2014-11-20 11:24:22 -080065 * @param path topic for which this controller node no longer wishes to be a leader.
66 */
67 void withdraw(String path);
68
Madan Jampani59610512015-02-25 15:25:43 -080069 /**
70 * Returns the current leader board.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070071 *
Madan Jampani59610512015-02-25 15:25:43 -080072 * @return mapping from topic to leadership info.
73 */
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080074 Map<String, Leadership> getLeaderBoard();
75
Madan Jampani1d3494e2014-11-20 11:24:22 -080076 /**
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070077 * Returns the candidates for all known topics.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070078 *
Ayaka Koshibefd26a302015-04-13 13:59:54 -070079 * @return A mapping from topics to up-to-date candidate info.
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070080 */
Ayaka Koshibefd26a302015-04-13 13:59:54 -070081 Map<String, Leadership> getCandidates();
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070082
83 /**
84 * Returns the candidates for a given topic.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070085 *
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070086 * @param path topic
87 * @return A lists of NodeIds, which may be empty.
88 */
89 List<NodeId> getCandidates(String path);
90
91 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080092 * Registers a event listener to be notified of leadership events.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -070093 *
Madan Jampani1d3494e2014-11-20 11:24:22 -080094 * @param listener listener that will asynchronously notified of leadership events.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080095 */
96 void addListener(LeadershipEventListener listener);
97
98 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080099 * Unregisters a event listener for leadership events.
Sho SHIMIZU25d843c2015-04-10 16:52:33 -0700100 *
Madan Jampani1d3494e2014-11-20 11:24:22 -0800101 * @param listener listener to be removed.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -0800102 */
103 void removeListener(LeadershipEventListener listener);
Brian O'Connorabafb502014-12-02 22:26:20 -0800104}