BUG 2817 - Basic implementation of RemoveServer in the Raft code
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorContext.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.raft;
10
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSelection;
13 import akka.actor.ActorSystem;
14 import akka.actor.Props;
15 import com.google.common.annotations.VisibleForTesting;
16 import com.google.common.base.Supplier;
17 import java.util.Collection;
18 import javax.annotation.Nullable;
19 import org.opendaylight.controller.cluster.DataPersistenceProvider;
20 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
21 import org.slf4j.Logger;
22
23 /**
24  * The RaftActorContext contains that portion of the RaftActors state that
25  * needs to be shared with it's behaviors. A RaftActorContext should NEVER be
26  * used in any actor context outside the RaftActor that constructed it.
27  */
28 public interface RaftActorContext {
29     /**
30      * Create a new local actor
31      * @param props
32      * @return a reference to the newly created actor
33      */
34     ActorRef actorOf(Props props);
35
36     /**
37      * Create a actor selection
38      * @param path
39      * @return an actor selection for the given actor path
40      */
41     ActorSelection actorSelection(String path);
42
43     /**
44      * Get the identifier for the RaftActor. This identifier represents the
45      * name of the actor whose common state is being shared. For example the
46      * id could be 'inventory'
47      *
48      * @return the identifier
49      */
50     String getId();
51
52     /**
53      * @return A reference to the RaftActor itself. This could be used to send messages
54      * to the RaftActor
55      */
56     ActorRef getActor();
57
58     /**
59      * @return the ElectionTerm information
60      */
61     ElectionTerm getTermInformation();
62
63     /**
64      * @return index of highest log entry known to be committed (initialized to 0, increases monotonically)
65      */
66     long getCommitIndex();
67
68
69     /**
70      * @param commitIndex new commit index
71      */
72     void setCommitIndex(long commitIndex);
73
74     /**
75      * @return index of highest log entry applied to state machine (initialized to 0, increases monotonically)
76      */
77     long getLastApplied();
78
79
80     /**
81      * @param lastApplied the index of the last log entry that was applied to the state
82      */
83     void setLastApplied(long lastApplied);
84
85     /**
86      *
87      * @param replicatedLog the replicated log of the current RaftActor
88      */
89     void setReplicatedLog(ReplicatedLog replicatedLog);
90
91     /**
92      * @return A representation of the log
93      */
94     ReplicatedLog getReplicatedLog();
95
96     /**
97      * @return The ActorSystem associated with this context
98      */
99     ActorSystem getActorSystem();
100
101     /**
102      * @return the logger to be used for logging messages to a log file
103      */
104     Logger getLogger();
105
106     /**
107      * Get the address of the peer as a String. This is the same format in
108      * which a consumer would provide the address
109      *
110      * @param peerId
111      * @return The address of the peer or null if the address has not yet been
112      *         resolved
113      */
114     String getPeerAddress(String peerId);
115
116     /**
117      * @param serverCfgPayload
118      */
119     void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
120
121     /**
122      * @return list of PeerInfo
123      */
124     Collection<PeerInfo> getPeers();
125
126     /**
127      * @return the list of peer IDs.
128      */
129     Collection<String> getPeerIds();
130
131     /**
132      * Get the PeerInfo for the given peer.
133      *
134      * @param peerId
135      * @return the PeerInfo
136      */
137     PeerInfo getPeerInfo(String peerId);
138
139     /**
140      * Add to actor peers
141      *
142      * @param name
143      * @param address
144      */
145     void addToPeers(String name, String address, VotingState votingState);
146
147     /**
148      *
149      * @param name
150      */
151     void removePeer(String name);
152
153     /**
154      * Given a peerId return the corresponding actor
155      * <p>
156      *
157      *
158      * @param peerId
159      * @return The actorSelection corresponding to the peer or null if the
160      *         address has not yet been resolved
161      */
162     ActorSelection getPeerActorSelection(String peerId);
163
164     /**
165      * Set Peer Address can be called at a later time to change the address of
166      * a known peer.
167      *
168      * <p>
169      * Throws an IllegalStateException if the peer is unknown
170      *
171      * @param peerId
172      * @param peerAddress
173      */
174     void setPeerAddress(String peerId, String peerAddress);
175
176     /**
177      * @return ConfigParams
178      */
179     ConfigParams getConfigParams();
180
181     /**
182      *
183      * @return the SnapshotManager for this RaftActor
184      */
185     SnapshotManager getSnapshotManager();
186
187     /**
188      *
189      * @return the DataPersistenceProvider for this RaftActor
190      */
191     DataPersistenceProvider getPersistenceProvider();
192
193     /**
194      *
195      * @return true if the RaftActor has followers else false
196      */
197     boolean hasFollowers();
198
199     /**
200      *
201      * @return the total memory used by the ReplicatedLog
202      */
203     long getTotalMemory();
204
205     /**
206      *
207      * @param retriever a supplier of the total memory metric
208      */
209     @VisibleForTesting
210     void setTotalMemoryRetriever(Supplier<Long> retriever);
211
212     /**
213      *
214      * @return the payload version to be used when replicating data
215      */
216     short getPayloadVersion();
217
218     /**
219      * @return an implementation of the RaftPolicy so that the Raft code can be adapted
220      */
221     RaftPolicy getRaftPolicy();
222
223     /**
224      * @return true if there are any dynamic server configuration changes available,
225      *  false if static peer configurations are still in use
226      */
227     boolean isDynamicServerConfigurationInUse();
228
229     /**
230      * Configures the dynamic server configurations are avaialble for the RaftActor
231      */
232     void setDynamicServerConfigurationInUse();
233
234     /**
235      * @return the RaftActor's peer information as a ServerConfigurationPayload if the
236      * dynamic server configurations are available, otherwise returns null
237      */
238     @Nullable ServerConfigurationPayload getPeerServerInfo();
239 }