• This repository has been archived on 15/Apr/2018
  • Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Coordinated (etcd, ...) cluster construction for dynamic (cloud, containers) environments

ConstructR

Join the chat at https://gitter.im/hseeberger/constructr

ConstructR is for bootstrapping (construction) an Akka cluster by using a coordination service.

Disambiguation: Despite the similar name, ConstructR is not related to Lightbend ConductR.

ConstructR utilizes a key-value coordination service like etcd to automate bootstrapping or joining a cluster. It stores each member node under the key /constructr/$clusterName/nodes/$address where $clusterName is for disambiguating multiple clusters and $address is a Base64 encoded Akka Address. These keys expire after a configurable time in order to avoid stale information. Therefore ConstructR refreshes each key periodically.

In a nutshell, ConstructR is a state machine which first tries to get the nodes from the coordination service. If none are available it tries to acquire a lock, e.g. via a CAS write for etcd, and uses itself or retries getting the nodes. Then it joins using these nodes as seed nodes. After that it adds its address to the nodes and starts the refresh loop:

                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”Œβ”€β”€β–Άβ”‚   GettingNodes    │◀─────────────│BeforeGettingNodes β”‚
              β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    delayed   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚             β”‚     β”‚                            β–²
  join-failed β”‚   non-empty β”‚     └──────────────────────┐     β”‚ failure
              β”‚             β–Ό               empty        β–Ό     β”‚
              β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              └───│      Joining      │◀─────────────│      Locking      β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    success   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
              member-joined β”‚
                            β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚    AddingSelf     β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚     β”‚                            β”‚
                            β–Ό     β–Ό                            β”‚
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚ RefreshScheduled  │─────────────▢│    Refreshing     β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

If something goes finally wrong when interacting with the coordination service, e.g. a permanent timeout after a configurable number of retries, ConstructR terminates its ActorSystem in the spirit of "fail fast".

// All releases including intermediate ones are published here,
// final ones are also published to Maven Central.
resolvers += Resolver.bintrayRepo("hseeberger", "maven")

libraryDependencies ++= Vector(
  "de.heikoseeberger" %% "constructr" % "0.19.0",
  "de.heikoseeberger" %% "constructr-coordination-etcd" % "0.19.0", // in case of using etcd for coordination
  ...
)

Simply add the ConstructrExtension to the extensions configuration setting:

akka.extensions = [de.heikoseeberger.constructr.ConstructrExtension]

This will start the Constructr actor as a system actor. Alternatively start it yourself as early as possible if you feel so inclined.

The following listing shows the available configuration settings with their defaults:

constructr {
  coordination {
    host = localhost
    port = 2379
  }

  coordination-timeout    = 3 seconds  // Maximum response time for coordination service (e.g. etcd)
  join-timeout            = 15 seconds // Might depend on cluster size and network properties
  abort-on-join-timeout   = false      // Abort the attempt to join if true; otherwise restart the process from scratch
  max-nr-of-seed-nodes    = 0          // Any nonpositive value means Int.MaxValue
  nr-of-retries           = 2          // Nr. of tries are nr. of retries + 1
  refresh-interval        = 30 seconds // TTL is refresh-interval * ttl-factor
  retry-delay             = 3 seconds  // Give coordination service (e.g. etcd) some delay before retrying
  ttl-factor              = 2.0        // Must be greater or equal 1 + ((coordination-timeout * (1 + nr-of-retries) + retry-delay * nr-of-retries)/ refresh-interval)!
  ignore-refresh-failures = false      // Ignore failures once machine is already in "Refreshing" state. It prevents from FSM being terminated due to exhausted number of retries.

}

Coordination

ConstructR comes with out-of-the-box support for etcd: simply depend on the "constructr-coordination-etcd" module. If you want to use some other coordination backend, e.g. Consul, simply implement the Coordination trait from the "constructr-coordination" module and make sure to provide the fully qualified class name via the constructr.coordination.class-name configuration setting.

Community Coordination Implementations

There are some implementations for other coordination backends than etcd:

Testing

etcd must be running, e.g.:

docker run \
  --detach \
  --name etcd \
  --publish 2379:2379 \
  quay.io/coreos/etcd:v2.3.8 \
  --listen-client-urls http://0.0.0.0:2379 \
  --advertise-client-urls http://192.168.99.100:2379

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

Please make sure to follow these conventions:

  • For each contribution there must be a ticket (GitHub issue) with a short descriptive name, e.g. "Respect seed-nodes configuration setting"
  • Work should happen in a branch named "ISSUE-DESCRIPTION", e.g. "32-respect-seed-nodes"
  • Before a PR can be merged, all commits must be squashed into one with its message made up from the ticket name and the ticket id, e.g. "Respect seed-nodes configuration setting (closes #32)"

License

This code is open source software licensed under the Apache 2.0 License.

More Repositories

1

akka-http-json

Integrate some of the best JSON libs in Scala with Akka HTTP
Scala
587
star
2

akka-sse

Akka HTTP now includes Akka SSE, this project is at EOL
Scala
181
star
3

reactive-flows

Reactive web app with Akka and AngularJS
Scala
80
star
4

eventsourced

Event sourced entities in Rust.
Rust
28
star
5

akka-log4j

Logging backend for Akka based on Log4j
Scala
28
star
6

whirlwind-tour-akka-typed

Demo code for my Scala Exchange workshop "Whirlwind Tour of Akka Typed"
Scala
25
star
7

accessus

Access log for Akka HTTP based servers
Scala
25
star
8

demo-phantom-types

Demo of phantom types in Scala
Scala
13
star
9

lyas

Learn you Akka Streams for great Good!
Scala
10
star
10

welcome-akka-typed

Demo code for my "Farewell Any => Unit, welcome Akka Typed!" talk
Scala
10
star
11

akkluster

Demo application to visualize the status of the member nodes
Scala
9
star
12

log4dotty

Experimental (just for learning) logging library powered by Dotty / Scala 3 macros
Scala
6
star
13

demo-equality

Demos for type-safe equality with Scala implicits
Scala
6
star
14

slf4s

Scala 3 sugar for efficient logging
Scala
5
star
15

xtream

Demo code for my Akka Streams to the Extreme talk
Scala
5
star
16

game-of-life

Simple and idiomatic Scala 3 implementation of the famous Conway's Game of Life
Scala
3
star
17

deck-akka-cluster-coreos

Slide deck of Akka Cluster on CoreOS talk
JavaScript
3
star
18

bayer-akka

the Boarische Webserver with Scala and Akka
Scala
1
star
19

hseeberger.github.io

Stylus
1
star
20

bayer-cli

Rust CLI for the Boarische Webserver (bayer-warp, bayer-akka, ...)
Rust
1
star
21

hello-rs

Simple dockerized Rust/Axum based HTTP server for demo purposes.
Rust
1
star
22

scala-train

Begleitende Fallstudie zum Buch "Durchstarten mit Scala"
Scala
1
star
23

deck-reactive-apps

JavaScript
1
star
24

echo

Simple gRPC example with an Scala/Akka server and a Rust/tonic client.
Scala
1
star
25

waltz

Experimental actor framework
Rust
1
star
26

log4scala

Scala 3 sugar for logging
Scala
1
star
27

rusty-bank

Example application using eventsourced.
Rust
1
star