Skip to content

Commit

Permalink
Upgrade to Play 2.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
patelh committed Dec 15, 2015
1 parent b02109a commit b070255
Show file tree
Hide file tree
Showing 61 changed files with 322 additions and 257 deletions.
29 changes: 0 additions & 29 deletions app/GlobalKafkaManager.scala

This file was deleted.

10 changes: 5 additions & 5 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
package controllers

import features.ApplicationFeatures
import kafka.manager.features.ClusterFeatures
import models.navigation.Menus
import play.api.i18n.{MessagesApi, I18nSupport}
import play.api.mvc._

/**
* @author hiral
*/
object Application extends Controller {
class Application (val messagesApi: MessagesApi, val kafkaManagerContext: KafkaManagerContext)
(implicit af: ApplicationFeatures, menus: Menus) extends Controller with I18nSupport {

import play.api.libs.concurrent.Execution.Implicits.defaultContext

private[this] val kafkaManager = KafkaManagerContext.getKafkaManager

private[this] implicit val af: ApplicationFeatures = ApplicationFeatures.features
private[this] val kafkaManager = kafkaManagerContext.getKafkaManager

def index = Action.async {
kafkaManager.getClusterList.map { errorOrClusterList =>
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/Cluster.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import kafka.manager.model.{KafkaVersion, ClusterConfig}
import kafka.manager.ApiError
import models.FollowLink
import models.form._
import models.navigation.Menus
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.validation.{Valid, Invalid, Constraint}
import play.api.data.validation.Constraints._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc._

import scala.concurrent.Future
Expand All @@ -23,11 +25,11 @@ import scalaz.{-\/, \/-}
/**
* @author hiral
*/
object Cluster extends Controller {
class Cluster (val messagesApi: MessagesApi, val kafkaManagerContext: KafkaManagerContext)
(implicit af: ApplicationFeatures, menus: Menus) extends Controller with I18nSupport {
import play.api.libs.concurrent.Execution.Implicits.defaultContext

private[this] val kafkaManager = KafkaManagerContext.getKafkaManager
private[this] implicit val af: ApplicationFeatures = ApplicationFeatures.features
private[this] val kafkaManager = kafkaManagerContext.getKafkaManager

val validateName : Constraint[String] = Constraint("validate name") { name =>
Try {
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/Consumer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
package controllers

import features.ApplicationFeatures
import models.navigation.Menus
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc._

/**
* @author cvcal
*/
object Consumer extends Controller{
class Consumer (val messagesApi: MessagesApi, val kafkaManagerContext: KafkaManagerContext)
(implicit af: ApplicationFeatures, menus: Menus) extends Controller with I18nSupport {

import play.api.libs.concurrent.Execution.Implicits.defaultContext

private[this] val kafkaManager = KafkaManagerContext.getKafkaManager
private[this] implicit val af: ApplicationFeatures = ApplicationFeatures.features
private[this] val kafkaManager = kafkaManagerContext.getKafkaManager

def consumers(cluster: String) = Action.async {
kafkaManager.getConsumerListExtended(cluster).map { errorOrConsumerList =>
Expand Down
83 changes: 83 additions & 0 deletions app/controllers/KMWebJarAssets.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package controllers

import play.api.http.{LazyHttpErrorHandler, HttpErrorHandler}
import play.api.mvc.Action
import play.api.mvc.AnyContent
import scala.util.matching.Regex
import play.api.{Configuration, Play}
import org.webjars.WebJarAssetLocator

import javax.inject.{ Inject, Singleton }

/**
* A Play framework controller that is able to resolve WebJar paths.
* <p>org.webjars.play.webJarFilterExpr can be used to declare a regex for the
* files that should be looked for when searching within WebJars. By default
* all files are searched for.
*/
@Singleton
class KMWebJarAssets @Inject() (errorHandler: HttpErrorHandler, configuration: Configuration) extends AssetsBuilder(errorHandler) {

val WebjarFilterExprDefault = """.*"""
val WebjarFilterExprProp = "org.webjars.play.webJarFilterExpr"

val webJarFilterExpr = configuration.getString(WebjarFilterExprProp).getOrElse(WebjarFilterExprDefault)

import play.api.Play.current
lazy val webJarAssetLocator = new WebJarAssetLocator(
WebJarAssetLocator.getFullPathIndex(
new Regex(webJarFilterExpr).pattern, Play.application.classloader))

/**
* Controller Method to serve a WebJar asset
*
* @param file the file to serve
* @return the Action that serves the file
*/
def at(file: String): Action[AnyContent] = {
this.at("/" + WebJarAssetLocator.WEBJARS_PATH_PREFIX, file)
}

/**
* Locate a file in a WebJar
*
* @example Passing in `jquery.min.js` will return `jquery/1.8.2/jquery.min.js` assuming the jquery WebJar version 1.8.2 is on the classpath
*
* @param file the file or partial path to find
* @return the path to the file (sans-the webjars prefix)
*
*/
def locate(file: String): String = {
webJarAssetLocator.getFullPath(file).stripPrefix(WebJarAssetLocator.WEBJARS_PATH_PREFIX + "/")
}

/**
* Locate a file in a WebJar
*
* @param webjar the WebJar artifactId
* @param file the file or partial path to find
* @return the path to the file (sans-the webjars prefix)
*
*/
def locate(webjar: String, file: String): String = {
webJarAssetLocator.getFullPath(webjar, file).stripPrefix(WebJarAssetLocator.WEBJARS_PATH_PREFIX + "/")
}

/**
* Get the full path to a file in a WebJar without validating that the file actually exists
*
* @example Calling fullPath("react", "react.js") will return the full path to the file in the WebJar because react.js exists at the root of the WebJar
*
* @param webjar the WebJar artifactId
* @param path the full path to a file in the WebJar
* @return the path to the file (sans-the webjars prefix)
*
*/
def fullPath(webjar: String, path: String): String = {
val version = webJarAssetLocator.getWebJars.get(webjar)
s"$webjar/$version/$path"
}

}

object KMWebJarAssets extends KMWebJarAssets(LazyHttpErrorHandler, play.api.Play.current.configuration)
16 changes: 10 additions & 6 deletions app/controllers/KafkaManagerContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
package controllers

import kafka.manager.KafkaManager
import play.api.Configuration
import play.api.inject.ApplicationLifecycle

import scala.concurrent.Future

/**
* @author hiral
*/
object KafkaManagerContext {
class KafkaManagerContext (lifecycle: ApplicationLifecycle, configuration: Configuration) {

import play.api.Play.current
private[this] val kafkaManager : KafkaManager = new KafkaManager(configuration.underlying)

lifecycle.addStopHook { () =>
Future.successful(kafkaManager.shutdown())
}

private[this] val kafkaManager : KafkaManager = new KafkaManager(play.api.Play.configuration.underlying)
def getKafkaManager : KafkaManager = kafkaManager
def shutdown() : Unit = {
kafkaManager.shutdown()
}
}
17 changes: 9 additions & 8 deletions app/controllers/Logkafka.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import play.api.data.Form
import play.api.data.Forms._
import play.api.data.validation.{Valid, Invalid, Constraint}
import play.api.data.validation.Constraints._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc._

import scala.concurrent.Future
Expand All @@ -29,11 +30,11 @@ import scalaz.{\/-, -\/}
/**
* @author hiral
*/
object Logkafka extends Controller{
class Logkafka (val messagesApi: MessagesApi, val kafkaManagerContext: KafkaManagerContext)
(implicit af: ApplicationFeatures, menus: Menus) extends Controller with I18nSupport {
import play.api.libs.concurrent.Execution.Implicits.defaultContext

implicit private[this] val kafkaManager = KafkaManagerContext.getKafkaManager
private[this] implicit val af: ApplicationFeatures = ApplicationFeatures.features
implicit private[this] val kafkaManager = kafkaManagerContext.getKafkaManager

val validateLogkafkaId: Constraint[String] = Constraint("validate logkafka id") { id =>
Try {
Expand Down Expand Up @@ -144,7 +145,7 @@ object Logkafka extends Controller{
cl.configs.filter(_.value.isDefined).foreach(c => props.setProperty(c.name, c.value.get))
kafkaManager.createLogkafka(clusterName, cl.logkafka_id, cl.log_path, props).map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Create", Menus.clusterMenus(clusterName)),
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Create", menus.clusterMenus(clusterName)),
models.navigation.BreadCrumbs.withNamedViewAndCluster("Logkafkas", clusterName, "Create Logkafka"),
errorOrSuccess,
"Create Logkafka",
Expand All @@ -170,7 +171,7 @@ object Logkafka extends Controller{
deleteLogkafka => {
kafkaManager.deleteLogkafka(clusterName, deleteLogkafka.logkafka_id, deleteLogkafka.log_path).map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", Menus.clusterMenus(clusterName)),
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", menus.clusterMenus(clusterName)),
models.navigation.BreadCrumbs.withNamedViewAndClusterAndLogkafka("Logkafka View", clusterName, logkafka_id, log_path, "Delete Logkafka"),
errorOrSuccess,
"Delete Logkafka",
Expand Down Expand Up @@ -226,7 +227,7 @@ object Logkafka extends Controller{
updateLogkafkaConfig.configs.filter(_.value.isDefined).foreach(c => props.setProperty(c.name, c.value.get))
kafkaManager.updateLogkafkaConfig(clusterName, updateLogkafkaConfig.logkafka_id, updateLogkafkaConfig.log_path, props).map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", Menus.clusterMenus(clusterName)),
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", menus.clusterMenus(clusterName)),
models.navigation.BreadCrumbs.withNamedViewAndClusterAndLogkafka("Logkafka View", clusterName, logkafka_id, log_path, "Update Config"),
errorOrSuccess,
"Update Config",
Expand All @@ -246,7 +247,7 @@ object Logkafka extends Controller{
props.put("valid", true.toString);
kafkaManager.updateLogkafkaConfig(clusterName, logkafka_id, log_path, props, false).map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", Menus.clusterMenus(clusterName)),
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", menus.clusterMenus(clusterName)),
models.navigation.BreadCrumbs.withNamedViewAndClusterAndLogkafka("Logkafka View", clusterName, logkafka_id, log_path, "Update Config"),
errorOrSuccess,
"Enable Config",
Expand All @@ -264,7 +265,7 @@ object Logkafka extends Controller{
props.put("valid", false.toString);
kafkaManager.updateLogkafkaConfig(clusterName, logkafka_id, log_path, props, false).map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", Menus.clusterMenus(clusterName)),
views.html.navigation.clusterMenu(clusterName, "Logkafka", "Logkafka View", menus.clusterMenus(clusterName)),
models.navigation.BreadCrumbs.withNamedViewAndClusterAndLogkafka("Logkafka View", clusterName, logkafka_id, log_path, "Update Config"),
errorOrSuccess,
"Disable Config",
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/PreferredReplicaElection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import models.form.{UnknownPREO, RunElection, PreferredReplicaElectionOperation}
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.validation.{Valid, Invalid, Constraint}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc._

import scala.concurrent.Future
Expand All @@ -22,11 +23,11 @@ import scalaz.-\/
/**
* @author hiral
*/
object PreferredReplicaElection extends Controller{
class PreferredReplicaElection (val messagesApi: MessagesApi, val kafkaManagerContext: KafkaManagerContext)
(implicit af: ApplicationFeatures, menus: Menus) extends Controller with I18nSupport {
import play.api.libs.concurrent.Execution.Implicits.defaultContext

private[this] val kafkaManager = KafkaManagerContext.getKafkaManager
private[this] implicit val af: ApplicationFeatures = ApplicationFeatures.features
private[this] val kafkaManager = kafkaManagerContext.getKafkaManager
private[this] implicit val cf: ClusterFeatures = ClusterFeatures.default


Expand Down Expand Up @@ -63,7 +64,7 @@ object PreferredReplicaElection extends Controller{
}
errorOrSuccessFuture.map { errorOrSuccess =>
Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(c, "Preferred Replica Election", "", navigation.Menus.clusterMenus(c)),
views.html.navigation.clusterMenu(c, "Preferred Replica Election", "", menus.clusterMenus(c)),
models.navigation.BreadCrumbs.withViewAndCluster("Run Election", c),
errorOrSuccess,
"Run Election",
Expand All @@ -73,7 +74,7 @@ object PreferredReplicaElection extends Controller{
}
case UnknownPREO(opString) =>
Future.successful(Ok(views.html.common.resultOfCommand(
views.html.navigation.clusterMenu(c, "Preferred Replica Election", "", Menus.clusterMenus(c)),
views.html.navigation.clusterMenu(c, "Preferred Replica Election", "", menus.clusterMenus(c)),
models.navigation.BreadCrumbs.withNamedViewAndCluster("Preferred Replica Election", c, "Unknown Operation"),
-\/(ApiError(s"Unknown operation $opString")),
"Unknown Preferred Replica Election Operation",
Expand Down
Loading

0 comments on commit b070255

Please sign in to comment.