Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.klout.api.models
- import com.klout.playful2.sugar.config
- /**
- * A status for a MySQL node
- */
- sealed trait MySQLNodeStatus
- /**
- * MySQL is up!
- */
- case object MySQLUp extends MySQLNodeStatus
- /**
- * MySQL is down! Ops!
- */
- case object MySQLDown extends MySQLNodeStatus
- /**
- * MySQL is up but f'ed up!
- */
- case object MySQLDegraded extends MySQLNodeStatus
- /**
- * This is the class used to identify the current state of the MySQL cluster used through Akka
- *
- * @author Felipe Oliveira [@_felipera]
- */
- case class MySQLClusterState(nodes: Map[String, MySQLNodeStatus], overrideNodes: Option[List[String]]) {
- /**
- * Define a new state taking in consideration this update
- */
- def withNodeUpdate(db: String, status: MySQLNodeStatus): MySQLClusterState = {
- this copy (nodes = nodes ++ Map(db -> status))
- }
- /**
- * Define a new state taking in consideration an update to the list of override nodes
- */
- def withOverrideNodes(overrideNodes: Option[String]): MySQLClusterState = overrideNodes match {
- case Some(value) => this copy (overrideNodes = Option(value.split(",").toList))
- case _ => this copy (overrideNodes = None)
- }
- /**
- * Get a list of healthy MySQL nodes
- */
- def getHealthyNodes: List[String] = nodes.filter(_._2 == MySQLUp).keys.toList
- /**
- * Get Current State
- */
- def currentState: Map[String, Any] = {
- val list = nodes map { node =>
- (node._1, node._2.toString)
- }
- Map("nodes" -> list, "overrideNodes" -> overrideNodes.getOrElse(List()))
- }
- }
- /**
- * Companion for the cluster state class defined above
- *
- * @author Felipe Oliveira [@_felipera]
- */
- object MySQLClusterState {
- /**
- * Return the list of all possible MySQL nodes in the cluster
- */
- lazy val allNodes: List[String] = (config string "slave.dbs" !) split "," toList
- }
Add Comment
Please, Sign In to add comment