Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed add clusters and modify cluster #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ dist
activator*
RUNNING_PID
.DS_Store
/bin
.cache
.classpath
.project
.sbtserver/
.tmpBin
project/.sbtserver
project/.sbtserver.lock
project/play-fork-run.sbt
project/sbt-ui.sbt
41 changes: 39 additions & 2 deletions app/GlobalKafkaManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,64 @@
* See accompanying LICENSE file.
*/

import collection.JavaConversions._
import controllers.KafkaManagerContext
import kafka.manager.KafkaManager
import play.api._
import com.typesafe.config.ConfigException
import models.navigation.BreadCrumbs

/**
* @author hiral
*/
object GlobalKafkaManager extends GlobalSettings {
object Global extends GlobalSettings {

private[this] var kafkaManager: KafkaManager = null
val ClusterZks = "managed-kafka-clusters"

override def beforeStart(app: Application): Unit = {
Logger.info("Init kafka manager...")
KafkaManagerContext.getKafkaManger
kafkaManager = KafkaManagerContext.getKafkaManger
initialize_with_clusters_from_conf()
Thread.sleep(5000)
}

override def onStop(app: Application) {
KafkaManagerContext.shutdown()
Logger.info("Application shutdown...")
}


def initialize_with_clusters_from_conf() {
Logger.info("initialize_with_clusters_from_conf(): Going to read kafka list from config and initialize")

val configWithDefaults = kafkaManager.getConfigWithDefaults

var member_zkhosts_list = List[String]()
try {
member_zkhosts_list = configWithDefaults.getStringList(ClusterZks).toList
} catch {
case cfge: ConfigException => Logger.error("managed-kafka-clusters param not defined in the conf or is in wrong format")
}


member_zkhosts_list.foreach{ item =>

// Each item in the list from config will be a string of format
// "clustername, version, zk1:port1, zk2:port2...."
//
val mylist = item.split(",")
val name = mylist(0)
val version = mylist(1)
val zkhosts = mylist.takeRight(mylist.size - 2).mkString(",")


kafkaManager.addCluster(name, version, zkhosts)

}
}


}


2 changes: 2 additions & 0 deletions app/kafka/manager/KafkaManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class KafkaManager(akkaConfig: Config) {
}
}

def getConfigWithDefaults = configWithDefaults

def addCluster(clusterName: String, version: String, zkHosts: String) : Future[ApiError \/ Unit] = {
val cc = ClusterConfig(clusterName, version, zkHosts)
tryWithKafkaManagerActor(KMAddCluster(cc)) { result: KMCommandResult =>
Expand Down
7 changes: 4 additions & 3 deletions app/kafka/manager/KafkaManagerActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ object KafkaVersion {
val supportedVersions: Map[String,KafkaVersion] = Map(
"0.8.1.1" -> Kafka_0_8_1_1,
"0.8.2-beta" -> Kafka_0_8_2_0,
"0.8.2.0" -> Kafka_0_8_2_0)
"0.8.2.0" -> Kafka_0_8_2_0,
"0.8.2.1" -> Kafka_0_8_2_0)

val formSelectList : IndexedSeq[(String,String)] = supportedVersions.toIndexedSeq.filterNot(_._1.contains("beta")).map(t => (t._1,t._2.toString))

Expand Down Expand Up @@ -82,8 +83,8 @@ object ClusterConfig {
validateName(name)
//validate zk hosts
validateZkHosts(zkHosts)
val cleanZkHosts = zkHosts.replaceAll(" ","").toLowerCase
new ClusterConfig(name.toLowerCase, CuratorConfig(cleanZkHosts, zkMaxRetry), true, kafkaVersion)
val cleanZkHosts = zkHosts.replaceAll(" ", "")
new ClusterConfig(name, CuratorConfig(cleanZkHosts, zkMaxRetry), true, kafkaVersion)
}

def customUnapply(cc: ClusterConfig) : Option[(String, String, String, Int)] = {
Expand Down
3 changes: 1 addition & 2 deletions app/models/navigation/BreadCrumbs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ object BreadCrumbs {
import models.navigation.QuickRoutes._

val baseBreadCrumbs: Map[String, IndexedSeq[BreadCrumb]] = Map(
"Clusters" -> IndexedSeq.empty[BreadCrumb],
"Add Cluster" -> IndexedSeq("Clusters".baseRouteBreadCrumb)
"Clusters" -> IndexedSeq.empty[BreadCrumb]
)

val clusterBreadCrumbs: Map[String, IndexedSeq[BreadCrumb]] = Map(
Expand Down
6 changes: 2 additions & 4 deletions app/models/navigation/Menus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ object Menus {
def clusterMenus(cluster: String) : IndexedSeq[Menu] = IndexedSeq(
Menu("Cluster",IndexedSeq(
"Summary".clusterRouteMenuItem(cluster),
"List".baseRouteMenuItem,
"Add Cluster".baseRouteMenuItem),
"List".baseRouteMenuItem),
None),
"Brokers".clusterMenu(cluster),
Menu("Topic",IndexedSeq(
Expand All @@ -27,8 +26,7 @@ object Menus {

def indexMenu : IndexedSeq[Menu] = IndexedSeq(
Menu("Cluster",IndexedSeq(
"List".baseRouteMenuItem,
"Add Cluster".baseRouteMenuItem),
"List".baseRouteMenuItem),
None)
)
}
3 changes: 1 addition & 2 deletions app/models/navigation/QuickRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ object QuickRoutes {

val baseRoutes : Map[String, Call] = Map(
"Clusters" -> controllers.routes.Application.index(),
"List" -> controllers.routes.Application.index(),
"Add Cluster" -> controllers.routes.Cluster.addCluster()
"List" -> controllers.routes.Application.index()
)
val clusterRoutes : Map[String, String => Call] = Map(
"Update Cluster" -> controllers.routes.Cluster.updateCluster,
Expand Down
8 changes: 0 additions & 8 deletions app/views/cluster/clusterList.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<td>
<div class="btn-group-horizontal" role="group" aria-label="...">
@if(cluster.enabled) {
<a href="@routes.Cluster.updateCluster(cluster.name)" class="btn btn-default ops-button" role="button">Modify</a>
@b3.form(routes.Cluster.handleUpdateCluster(cluster.name)) {
<input type="hidden" name="name" value="@cluster.name">
<input type="hidden" name="kafkaVersion" value="@cluster.version.toString">
Expand All @@ -39,13 +38,6 @@
<input type="hidden" name="operation" value="Enable">
@b3.submit('class -> "btn btn-success ops-button"){ Enable }
}
@b3.form(routes.Cluster.handleUpdateCluster(cluster.name)) {
<input type="hidden" name="name" value="@cluster.name">
<input type="hidden" name="kafkaVersion" value="@cluster.version.toString">
<input type="hidden" name="zkHosts" value="@cluster.curatorConfig.zkConnect">
<input type="hidden" name="operation" value="Delete">
@b3.submit('class -> "btn btn-danger ops-button"){ Delete }
}
}
</div>
</td>
Expand Down
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name := """kafka-manager"""

/* For packaging purposes, -SNAPSHOT MUST contain a digit */
version := "1.1"
version := "1.2"

scalaVersion := "2.11.5"

Expand Down Expand Up @@ -82,3 +82,6 @@ rpmLicense := Some("Apache")





fork in run := true
6 changes: 6 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ kafka-manager.zkhosts=${?ZK_HOSTS}
pinned-dispatcher.type="PinnedDispatcher"
pinned-dispatcher.executor="thread-pool-executor"

# These will be added into Kafka Manager at startup
# Value of this param is a list of strings representing info about kafka clusters to be managed
# ["clusterNmae, Version, zk1:port1, zk2:port2,...", ...]
# Supported versions currently are "0.8.1.1" and "0.8.2-beta" only
# (line 38: kafka/manager/KafkaManagerActor.scala)
managed-kafka-clusters=["kmgr1,0.8.2-beta,zk1:2181,zk2:2181"]