blob: 15a198c3207d03e2abf48dbe535ad3830265afa2 [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.
Madan Jampani1ee91782014-11-20 20:24:24 -080033 * @param path topic
Madan Jampani8d21c792014-12-01 16:31:07 -080034 * @return nodeId of the leader, null if so such topic exists.
Madan Jampani1ee91782014-11-20 20:24:24 -080035 */
Madan Jampani8d21c792014-12-01 16:31:07 -080036 NodeId getLeader(String path);
Madan Jampani1ee91782014-11-20 20:24:24 -080037
38 /**
Madan Jampani59610512015-02-25 15:25:43 -080039 * Returns the current leadership info for the topic.
40 * @param path topic
41 * @return leadership info or null if so such topic exists.
42 */
43 Leadership getLeadership(String path);
44
45 /**
46 * Returns the set of topics owned by the specified node.
47 * @param nodeId node Id.
48 * @return set of topics for which this node is the current leader.
49 */
50 Set<String> ownedTopics(NodeId nodeId);
51
52 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080053 * Joins the leadership contest.
54 * @param path topic for which this controller node wishes to be a leader.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080055 */
Madan Jampani1d3494e2014-11-20 11:24:22 -080056 void runForLeadership(String path);
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080057
58 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080059 * Withdraws from a leadership contest.
60 * @param path topic for which this controller node no longer wishes to be a leader.
61 */
62 void withdraw(String path);
63
Madan Jampani59610512015-02-25 15:25:43 -080064 /**
65 * Returns the current leader board.
66 * @return mapping from topic to leadership info.
67 */
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080068 Map<String, Leadership> getLeaderBoard();
69
Madan Jampani1d3494e2014-11-20 11:24:22 -080070 /**
Ayaka Koshibec19b8b82015-04-08 15:18:24 -070071 * Returns the candidates for all known topics.
72 * @return A map of topics to lists of NodeIds.
73 */
74 Map<String, List<NodeId>> getCandidates();
75
76 /**
77 * Returns the candidates for a given topic.
78 * @param path topic
79 * @return A lists of NodeIds, which may be empty.
80 */
81 List<NodeId> getCandidates(String path);
82
83 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080084 * Registers a event listener to be notified of leadership events.
85 * @param listener listener that will asynchronously notified of leadership events.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080086 */
87 void addListener(LeadershipEventListener listener);
88
89 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080090 * Unregisters a event listener for leadership events.
91 * @param listener listener to be removed.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080092 */
93 void removeListener(LeadershipEventListener listener);
Brian O'Connorabafb502014-12-02 22:26:20 -080094}