Bug 5450: Query akka cluster state on Follower ElectionTimeout
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorContext.java
index 0c9d698cd5404f0675d11df935351df529b448f2..ba6645f2407c55afdbbdae8cffd524dfbcc466a7 100644 (file)
@@ -12,11 +12,15 @@ import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
 import akka.actor.Props;
+import akka.cluster.Cluster;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Supplier;
 import java.util.Collection;
-import java.util.Map;
+import java.util.Optional;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
+import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
+import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
 import org.slf4j.Logger;
 
@@ -55,6 +59,13 @@ public interface RaftActorContext {
      */
     ActorRef getActor();
 
+    /**
+     * The akka Cluster singleton for the actor system if one is configured.
+     *
+     * @return an Optional containing the CLuster instance is present.
+     */
+    Optional<Cluster> getCluster();
+
     /**
      * @return the ElectionTerm information
      */
@@ -103,12 +114,6 @@ public interface RaftActorContext {
      */
     Logger getLogger();
 
-    /**
-     * @return a copy of the mapping of peerId's to their addresses
-     *
-     */
-    Map<String, String> getPeerAddresses();
-
     /**
      * Get the address of the peer as a String. This is the same format in
      * which a consumer would provide the address
@@ -119,18 +124,36 @@ public interface RaftActorContext {
      */
     String getPeerAddress(String peerId);
 
+    /**
+     * @param serverCfgPayload
+     */
+    void updatePeerIds(ServerConfigurationPayload serverCfgPayload);
+
+    /**
+     * @return list of PeerInfo
+     */
+    Collection<PeerInfo> getPeers();
+
     /**
      * @return the list of peer IDs.
      */
     Collection<String> getPeerIds();
 
+    /**
+     * Get the PeerInfo for the given peer.
+     *
+     * @param peerId
+     * @return the PeerInfo
+     */
+    PeerInfo getPeerInfo(String peerId);
+
     /**
      * Add to actor peers
      *
      * @param name
      * @param address
      */
-    void addToPeers(String name, String address);
+    void addToPeers(String name, String address, VotingState votingState);
 
     /**
      *
@@ -195,7 +218,7 @@ public interface RaftActorContext {
      * @param retriever a supplier of the total memory metric
      */
     @VisibleForTesting
-    void setTotalMemoryRetriever(Supplier<Long> retriever);
+    void setTotalMemoryRetriever(LongSupplier retriever);
 
     /**
      *
@@ -207,4 +230,36 @@ public interface RaftActorContext {
      * @return an implementation of the RaftPolicy so that the Raft code can be adapted
      */
     RaftPolicy getRaftPolicy();
+
+    /**
+     * @return true if there are any dynamic server configuration changes available,
+     *  false if static peer configurations are still in use
+     */
+    boolean isDynamicServerConfigurationInUse();
+
+    /**
+     * Configures the dynamic server configurations are avaialble for the RaftActor
+     */
+    void setDynamicServerConfigurationInUse();
+
+    /**
+     * @return the RaftActor's peer information as a ServerConfigurationPayload if the
+     * dynamic server configurations are available, otherwise returns null
+     */
+    @Nullable ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
+
+    /**
+     * @return true if this RaftActor is a voting member of the cluster, false otherwise.
+     */
+    boolean isVotingMember();
+
+    /**
+     * @return true if there are any voting peers, false otherwise.
+     */
+    boolean anyVotingPeers();
+
+    /**
+     * @return current behavior attached to the raft actor.
+     */
+    RaftActorBehavior getCurrentBehavior();
 }