Introduce cluster 'team' setting and add to Member

Introduced cluster-team.md so we can grow the documentation with each
PR, but did not add it to the ToC yet.

(cherry picked from commit a06badaa03fa9f3c9a942b1468090f758c74a869)
This commit is contained in:
Arnout Engelen 2017-06-26 14:32:57 +02:00 committed by Patrik Nordwall
parent a7dc938188
commit 2f11ec6f25
8 changed files with 57 additions and 8 deletions

View file

@ -65,6 +65,11 @@ akka {
# move 'WeaklyUp' members to 'Up' status once convergence has been reached.
allow-weakly-up-members = on
# Teams are used to make islands of the cluster that are colocated. It can be used
# to make the cluster "dc-aware", run the cluster in multiple availability zones or regions.
# The team is added to the list of roles of the node with the prefix "team-".
team = "default"
# The roles of this member. List of strings, e.g. roles = ["A", "B"].
# The roles are part of the membership information and can be used by
# routers or other services to distribute work to certain member types,

View file

@ -93,7 +93,8 @@ final class ClusterSettings(val config: Config, val systemName: String) {
val AllowWeaklyUpMembers = cc.getBoolean("allow-weakly-up-members")
val Roles: Set[String] = immutableSeq(cc.getStringList("roles")).toSet
val Team: String = cc.getString("team")
val Roles: Set[String] = immutableSeq(cc.getStringList("roles")).toSet + s"team-$Team"
val MinNrOfMembers: Int = {
cc.getInt("min-nr-of-members")
} requiring (_ > 0, "min-nr-of-members must be > 0")

View file

@ -22,6 +22,9 @@ class Member private[cluster] (
val status: MemberStatus,
val roles: Set[String]) extends Serializable {
lazy val team = roles.find(_.startsWith("team-"))
.getOrElse(throw new IllegalStateException("Team undefined, should not be possible"))
def address: Address = uniqueAddress.address
override def hashCode = uniqueAddress.##

View file

@ -120,28 +120,32 @@ abstract class MBeanSpec
| {
| "address": "${sortedNodes(0)}",
| "roles": [
| "testNode"
| "testNode",
| "team-default"
| ],
| "status": "Up"
| },
| {
| "address": "${sortedNodes(1)}",
| "roles": [
| "testNode"
| "testNode",
| "team-default"
| ],
| "status": "Up"
| },
| {
| "address": "${sortedNodes(2)}",
| "roles": [
| "testNode"
| "testNode",
| "team-default"
| ],
| "status": "Up"
| },
| {
| "address": "${sortedNodes(3)}",
| "roles": [
| "testNode"
| "testNode",
| "team-default"
| ],
| "status": "Up"
| }

View file

@ -91,7 +91,7 @@ abstract class QuickRestartSpec
Cluster(system).state.members.size should ===(totalNumberOfNodes)
Cluster(system).state.members.map(_.status == MemberStatus.Up)
// use the role to test that it is the new incarnation that joined, sneaky
Cluster(system).state.members.flatMap(_.roles) should ===(Set(s"round-$n"))
Cluster(system).state.members.flatMap(_.roles) should ===(Set(s"round-$n", "team-default"))
}
}
enterBarrier("members-up-" + n)

View file

@ -5,9 +5,13 @@
package akka.cluster
import language.postfixOps
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.testkit.AkkaSpec
import akka.dispatch.Dispatchers
import scala.concurrent.duration._
import akka.remote.PhiAccrualFailureDetector
import akka.util.Helpers.ConfigOps
import akka.actor.Address
@ -41,7 +45,8 @@ class ClusterConfigSpec extends AkkaSpec {
DownRemovalMargin should ===(Duration.Zero)
MinNrOfMembers should ===(1)
MinNrOfMembersOfRole should ===(Map.empty[String, Int])
Roles should ===(Set.empty[String])
Team should ===("default")
Roles should ===(Set("team-default"))
JmxEnabled should ===(true)
UseDispatcher should ===(Dispatchers.DefaultDispatcherId)
GossipDifferentViewProbability should ===(0.8 +- 0.0001)
@ -49,5 +54,20 @@ class ClusterConfigSpec extends AkkaSpec {
SchedulerTickDuration should ===(33 millis)
SchedulerTicksPerWheel should ===(512)
}
"be able to parse non-default cluster config elements" in {
val settings = new ClusterSettings(ConfigFactory.parseString(
"""
|akka {
| cluster {
| roles = [ "hamlet" ]
| team = "blue"
| }
|}
""".stripMargin).withFallback(ConfigFactory.load()), system.name)
import settings._
Roles should ===(Set("hamlet", "team-blue"))
Team should ===("blue")
}
}
}

View file

@ -0,0 +1 @@
../scala/cluster-team.md

View file

@ -0,0 +1,15 @@
# Cluster Team
@@@ note
Cluster teams are a work-in-progress feature, and behavior is still expected to change.
@@@
Teams are used to define islands of the cluster that are colocated.
They can be used to make the cluster "dc-aware", run the cluster in multiple availability zones or regions.
Cluster nodes can be assigned to a team by setting the `akka.cluster.team` setting.
When no team is specified, a node will belong to the 'default' team.
The team is added to the list of roles of the node with the prefix "team-".