forked from filodb/FiloDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter of valid nodes and sort Akka Cluster seed nodes and modify…
… failure handling of any invalid seeds (filodb#64) * Added sort, eager parsing of configured seed addresses and fail fast to bootstrapper. * Made all suggested changes from code review.
- Loading branch information
Helena Edelson
committed
Oct 23, 2017
1 parent
2d6206e
commit 2b2b292
Showing
12 changed files
with
257 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
akka-bootstrapper/src/main/scala/filodb/akkabootstrapper/SeedValidator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package filodb.akkabootstrapper | ||
|
||
import akka.actor.Address | ||
import akka.cluster.Cluster | ||
|
||
/** Collects invalid and valid seed nodes from configuration. | ||
* Allows the user to decide error handling if any invalid are found. | ||
* | ||
* Can be extended for further validation behavior. | ||
*/ | ||
trait SeedValidator { | ||
self: ClusterSeedDiscovery => | ||
|
||
def cluster: Cluster | ||
|
||
def settings: AkkaBootstrapperSettings | ||
|
||
/** Collects invalid seed nodes. */ | ||
def invalidSeedNodes: List[String] | ||
|
||
/** Collects valid seed nodes. */ | ||
def validSeedNodes: List[Address] | ||
|
||
} |
25 changes: 0 additions & 25 deletions
25
...otstrapper/src/main/scala/filodb/akkabootstrapper/WhitelistAkkaClusterSeedDiscovery.scala
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
akka-bootstrapper/src/main/scala/filodb/akkabootstrapper/WhitelistClusterSeedDiscovery.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package filodb.akkabootstrapper | ||
|
||
import java.net.MalformedURLException | ||
|
||
import scala.collection.immutable | ||
|
||
import akka.actor.{Address, AddressFromURIString} | ||
import akka.cluster.{Cluster, Member} | ||
|
||
/** | ||
* This implementation of discovery allows clients to whitelist nodes that form the | ||
* cluster seeds. Essentially, this is just an adapter that allows for the simple | ||
* implementation of `akka.cluster.Cluster.joinSeedNodes`. | ||
* | ||
* Collects invalid and valid seed nodes from configuration. | ||
* Allows the user to decide error handling if any invalid are found. | ||
*/ | ||
class WhitelistClusterSeedDiscovery(cluster: Cluster, settings: AkkaBootstrapperSettings) | ||
extends ClusterSeedDiscovery(cluster, settings) | ||
with SeedValidator { self: ClusterSeedDiscovery => | ||
|
||
/** Attempts to create addresses from a whitelist seed config. */ | ||
private val validate = (s: String) => | ||
try AddressFromURIString(s) catch { case e: MalformedURLException => | ||
logger.error("MalformedURLException: invalid cluster seed node [{}]", s) | ||
s | ||
} | ||
|
||
private val validated = settings.seedsWhitelist.map(validate) | ||
|
||
/** Collects invalid seed nodes. */ | ||
override val invalidSeedNodes: List[String] = | ||
validated collect { case a: String => a } | ||
|
||
/** Collects valid seed nodes. */ | ||
override val validSeedNodes: List[Address] = | ||
validated collect { case a: Address => a } | ||
|
||
/** Removes cluster self node unless it is in the head of the sorted list. | ||
* First logs all invalid seeds first during validation, for full auditing, | ||
* in `filodb.akkabootstrapper.WhitelistSeedValidator.validate`. | ||
* Then raises exception to fail fast. | ||
*/ | ||
override protected lazy val discoverPeersForNewCluster: immutable.Seq[Address] = { | ||
|
||
if (invalidSeedNodes.nonEmpty) throw new MalformedURLException( | ||
s"Detected ${invalidSeedNodes.size} invalid 'whitelist' seed node configurations.") | ||
|
||
import Member.addressOrdering | ||
|
||
val headOpt = validSeedNodes.headOption | ||
val selfAddress = cluster.selfAddress | ||
validSeedNodes | ||
.filter(address => address != selfAddress || headOpt.contains(address)) | ||
.sorted | ||
} | ||
} |
Oops, something went wrong.