Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.cluster; |
| 17 | |
| 18 | import java.util.Map; |
pierventre | b59c51d | 2021-05-06 09:27:00 +0200 | [diff] [blame] | 19 | |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 20 | import org.onosproject.store.Store; |
| 21 | |
| 22 | /** |
| 23 | * Store interface for managing {@link LeadershipService} state. |
| 24 | */ |
| 25 | public interface LeadershipStore extends Store<LeadershipEvent, LeadershipStoreDelegate> { |
| 26 | |
| 27 | /** |
Jon Hall | 7a8bfc6 | 2016-05-26 17:59:04 -0700 | [diff] [blame] | 28 | * Adds registration for the local instance to be part of the leadership contest for topic. |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 29 | * |
| 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(); |
pierventre | b59c51d | 2021-05-06 09:27:00 +0200 | [diff] [blame] | 83 | |
| 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 Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 94 | } |