blob: 701e690d68da8424a2ad7852258ffd5b94a0b38c [file] [log] [blame]
Madan Jampani620f70d2016-01-30 22:22:47 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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;
19import org.onosproject.store.Store;
20
21/**
22 * Store interface for managing {@link LeadershipService} state.
23 */
24public interface LeadershipStore extends Store<LeadershipEvent, LeadershipStoreDelegate> {
25
26 /**
Jon Hall7a8bfc62016-05-26 17:59:04 -070027 * Adds registration for the local instance to be part of the leadership contest for topic.
Madan Jampani620f70d2016-01-30 22:22:47 -080028 *
29 * @param topic leadership topic
30 * @return Updated leadership after operation is completed
31 */
32 Leadership addRegistration(String topic);
33
34 /**
35 * Unregisters the local instance from leadership contest for topic.
36 *
37 * @param topic leadership topic
38 */
39 void removeRegistration(String topic);
40
41 /**
42 * Unregisters an instance from all leadership contests.
43 *
44 * @param nodeId node identifier
45 */
46 void removeRegistration(NodeId nodeId);
47
48 /**
49 * Updates state so that given node is leader for a topic.
50 *
51 * @param topic leadership topic
52 * @param toNodeId identifier of the desired leader
53 * @return {@code true} if the transfer succeeded; {@code false} otherwise.
54 * This method can return {@code false} if the node is not registered for the topic
55 */
56 boolean moveLeadership(String topic, NodeId toNodeId);
57
58 /**
59 * Attempts to make a node the top candidate.
60 *
61 * @param topic leadership topic
62 * @param nodeId node identifier
63 * @return {@code true} if the specified node is now the top candidate.
64 * This method will return {@code false} if the node is not registered for the topic
65 */
66 boolean makeTopCandidate(String topic, NodeId nodeId);
67
68 /**
69 * Returns the current leadership for topic.
70 *
71 * @param topic leadership topic
72 * @return current leadership
73 */
74 Leadership getLeadership(String topic);
75
76 /**
77 * Return current leadership for all topics.
78 *
79 * @return topic to leadership mapping
80 */
81 Map<String, Leadership> getLeaderships();
82}