Introduce cluster 'team' setting and add to Member (#23234)

* 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.

* Less abbreviations, more reliable test
This commit is contained in:
Arnout Engelen 2017-06-26 07:28:06 -07:00 committed by Patrik Nordwall
parent f591bedfbb
commit 9f78cd12c4
9 changed files with 54 additions and 5 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. This can be used
# to make the cluster aware that it is running across 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

@ -154,7 +154,7 @@ private[akka] class ClusterJmx(cluster: Cluster, log: LoggingAdapter) {
val members = clusterView.members.toSeq.sorted(Member.ordering).map { m
s"""{
| "address": "${m.address}",
| "roles": [${if (m.roles.isEmpty) "" else m.roles.map("\"" + _ + "\"").mkString("\n ", ",\n ", "\n ")}],
| "roles": [${if (m.roles.isEmpty) "" else m.roles.toList.sorted.map("\"" + _ + "\"").mkString("\n ", ",\n ", "\n ")}],
| "status": "${m.status}"
| }""".stripMargin
} mkString (",\n ")

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: String = 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,6 +120,7 @@ abstract class MBeanSpec
| {
| "address": "${sortedNodes(0)}",
| "roles": [
| "team-default",
| "testNode"
| ],
| "status": "Up"
@ -127,6 +128,7 @@ abstract class MBeanSpec
| {
| "address": "${sortedNodes(1)}",
| "roles": [
| "team-default",
| "testNode"
| ],
| "status": "Up"
@ -134,6 +136,7 @@ abstract class MBeanSpec
| {
| "address": "${sortedNodes(2)}",
| "roles": [
| "team-default",
| "testNode"
| ],
| "status": "Up"
@ -141,6 +144,7 @@ abstract class MBeanSpec
| {
| "address": "${sortedNodes(3)}",
| "roles": [
| "team-default",
| "testNode"
| ],
| "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")
}
}
}