blob: ebc6b4cb88bdfb4022bb5c8be151bfd5c5ab2c48 [file] [log] [blame]
Madan Jampani620f70d2016-01-30 22:22:47 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampani620f70d2016-01-30 22:22:47 -08003 *
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 */
16package org.onosproject.cluster;
17
18import java.util.Map;
pierventreb59c51d2021-05-06 09:27:00 +020019
Madan Jampani620f70d2016-01-30 22:22:47 -080020import org.onosproject.store.Store;
21
22/**
23 * Store interface for managing {@link LeadershipService} state.
24 */
25public interface LeadershipStore extends Store<LeadershipEvent, LeadershipStoreDelegate> {
26
27 /**
Jon Hall7a8bfc62016-05-26 17:59:04 -070028 * Adds registration for the local instance to be part of the leadership contest for topic.
Madan Jampani620f70d2016-01-30 22:22:47 -080029 *
30 * @param topic leadership topic
31 * @return Updated leadership after operation is completed
32 */
33 Leadership addRegistration(String topic);
34
35 /**
36 * Unregisters the local instance from leadership contest for topic.
37 *
38 * @param topic leadership topic
39 */
40 void removeRegistration(String topic);
41
42 /**
43 * Unregisters an instance from all leadership contests.
44 *
45 * @param nodeId node identifier
46 */
47 void removeRegistration(NodeId nodeId);
48
49 /**
50 * Updates state so that given node is leader for a topic.
51 *
52 * @param topic leadership topic
53 * @param toNodeId identifier of the desired leader
54 * @return {@code true} if the transfer succeeded; {@code false} otherwise.
55 * This method can return {@code false} if the node is not registered for the topic
56 */
57 boolean moveLeadership(String topic, NodeId toNodeId);
58
59 /**
60 * Attempts to make a node the top candidate.
61 *
62 * @param topic leadership topic
63 * @param nodeId node identifier
64 * @return {@code true} if the specified node is now the top candidate.
65 * This method will return {@code false} if the node is not registered for the topic
66 */
67 boolean makeTopCandidate(String topic, NodeId nodeId);
68
69 /**
70 * Returns the current leadership for topic.
71 *
72 * @param topic leadership topic
73 * @return current leadership
74 */
75 Leadership getLeadership(String topic);
76
77 /**
78 * Return current leadership for all topics.
79 *
80 * @return topic to leadership mapping
81 */
82 Map<String, Leadership> getLeaderships();
pierventreb59c51d2021-05-06 09:27:00 +020083
84 /**
85 * Attempts to demote a node to the bottom of the candidate list. It is not allowed
86 * to demote the current leader
87 *
88 * @param topic leadership topic
89 * @param nodeId identifier of node to be demoted
90 * @return {@code true} if nodeId is now the bottom candidate. This method returns {@code false}
91 * if {@code nodeId} is not one of the candidates for the topic or if it is the leader.
92 */
93 boolean demote(String topic, NodeId nodeId);
Madan Jampani620f70d2016-01-30 22:22:47 -080094}