Skip to content
Snippets Groups Projects
Commit bb3b8593 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 379 additions and 0 deletions
# Extracted from https://github.com/ulrich/macaron-factory/blob/master/.gitignore
# Ignore all dotfiles...
.*
# except for .gitignore
!.gitignore
# Ignore Play! working directory #
db
eclipse
lib
log
logs
modules
precompiled
project/project
project/target
target
tmp
test-result
server.pid
*.iml
*.eml
activator-*.sbt
node_modules
module.exports = function(grunt) {
grunt.initConfig({
clean: {
dist: {
src: ['_site/dist']
}
},
watch: {
scripts: {
files: ['src/**/*.*', 'src/*.*'],
tasks: ['build'],
options: {
spawn: false
}
}
},
copy: {
main: {
files: [
]
}
},
concat: {
vendorjs: {
src: [
],
dest: 'public/lib.js'
},
vendorcss: {
src: [
],
dest: 'public/css/lib.css'
},
appjs: {
src: [
'src/main.js',
'src/*/*.js'
],
dest: 'public/app.js'
},
},
jshint: {
cerebro: {
src: [
]
}
},
qunit: {
all: []
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks("grunt-jscs");
grunt.registerTask('dev', ['watch'])
grunt.registerTask('build',
['clean', 'copy', 'concat' ]);
};
package controllers
import play.api.mvc.{Action, Controller}
import play.api.http.MimeTypes
object Application extends Controller {
def index = Action {
Ok(views.html.Index())
}
}
package controllers
import elastic.ElasticClient._
import models.overview.ClusterOverview
import play.api.mvc.{Action, Controller}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object ClusterOverviewController extends Controller {
def index = Action.async {
request => {
val host = request.queryString.getOrElse("host", Seq("http://localhost:9200")).head
try {
val response = Future.sequence(
Seq(clusterState(host), nodesStats(host), indicesStats(host), clusterSettings(host), aliases(host), clusterHealth(host), nodes(host), main(host))
).map { f =>
new ClusterOverview(f(0).body, f(1).body, f(2).body, f(3).body, f(4).body, f(5).body, f(6).body, f(7).body).json
}.recover {
case e =>
throw e
}
response.map(Ok(_))
} catch {
case _ => Future.successful(Status(500)(s"Cannot connect to $host"))
}
}
}
}
package controllers
import play.api.Play
import play.api.libs.json.{JsArray, JsString}
import play.api.mvc.{Action, Controller}
class HostsController extends Controller {
def index = Action {
request => {
val hosts = Play.current.configuration.getConfigSeq("hosts") match {
case Some(a) => a.map { b => b.getString("host").get }
case None => Seq()
}
Ok(JsArray(hosts.map(JsString(_))))
}
}
}
package controllers
import controllers.elasticsearch.ElasticsearchController
import elastic.ElasticClient
object Main extends ElasticsearchController {
def index = processRequest(ElasticClient.main(_))
}
package controllers.elasticsearch
import elastic.ElasticClient
class ClearIndexCacheController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.clearIndexCache(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class CloseIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.closeIndex(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class DeleteIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.deleteIndex(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class DisableShardAllocationController extends ElasticsearchController {
def index() = processRequest(ElasticClient.disableShardAllocation(_))
}
package controllers.elasticsearch
import elastic.ElasticResponse
import play.api.Logger
import play.api.mvc.{Action, Controller}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
trait ElasticsearchController extends Controller {
protected val logger = Logger("elastic")
def processRequest(f: (String => Future[ElasticResponse])) = Action.async {
request =>
val host = request.queryString.getOrElse("host", Seq("http://localhost:9200")).head
try {
val response = f(host)
response.map { r =>
Status(r.status)(r.body)
}
} catch {
case _ => Future.successful(Status(500)(s"Cannot connect to $host"))
}
}
}
package controllers.elasticsearch
import elastic.ElasticClient
class EnableShardAllocationController extends ElasticsearchController {
def index() = processRequest(ElasticClient.enableShardAllocation(_))
}
package controllers.elasticsearch
import elastic.ElasticClient
class GetIndexMapping extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.getIndexMapping(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class GetIndexSettings extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.getIndexSettings(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class NodeStatsController extends ElasticsearchController {
def index(nodes: String) = processRequest(ElasticClient.nodesStats(nodes, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class OpenIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.openIndex(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
import play.api.mvc.{Action, Controller}
import scala.concurrent.ExecutionContext.Implicits.global
class OptimizeIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.optimizeIndex(indices, _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class PutClusterSettings extends ElasticsearchController {
def index = processRequest(ElasticClient.putClusterSettings("", _))
}
package controllers.elasticsearch
import elastic.ElasticClient
class RefreshIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.refreshIndex(indices, _))
}
package elastic
import play.api.Play.current
import play.api.libs.ws.WS
import play.api.mvc.Results.EmptyContent
trait ElasticClient {
def main(host: String) =
ElasticResponse(WS.url(s"$host").get())
def clusterState(host: String) =
ElasticResponse(WS.url(s"$host/_cluster/state/master_node,routing_table,routing_nodes,blocks").get())
def indicesStats(host: String) =
ElasticResponse(WS.url(s"$host/_stats/docs,store").get())
def nodesStats(host: String) =
ElasticResponse(WS.url(s"$host/_nodes/stats/jvm,fs,os,process").get())
def nodesStats(node: String, host: String) =
ElasticResponse(WS.url(s"$host/_nodes/$node/stats?human").get())
def clusterSettings(host: String) =
ElasticResponse(WS.url(s"$host/_cluster/settings").get())
def aliases(host: String) =
ElasticResponse(WS.url(s"$host/_aliases").get())
def clusterHealth(host: String) =
ElasticResponse(WS.url(s"$host/_cluster/health").get())
def nodes(host: String) =
ElasticResponse(WS.url(s"$host/_nodes/_all/os,jvm").get())
def closeIndex(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_close").post(EmptyContent()))
def openIndex(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_open").post(EmptyContent()))
def refreshIndex(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_refresh").post(EmptyContent()))
def optimizeIndex(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_optimize").post(EmptyContent()))
def clearIndexCache(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_cache/clear").post(EmptyContent()))
def deleteIndex(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index").delete())
def getIndexSettings(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_settings").get())
def getIndexMapping(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_mapping").get())
def putClusterSettings(settings: String, host: String) =
ElasticResponse(WS.url(s"$host/_cluster/settings").put(settings))
private def allocationSettings(value: String) =
s"""{"transient": {"cluster": {"routing": {"allocation": {"enable": \"$value\"}}}}}"""
def enableShardAllocation(host: String) =
putClusterSettings(allocationSettings("all"), host)
def disableShardAllocation(host: String) =
putClusterSettings(allocationSettings("none"), host)
}
object ElasticClient extends ElasticClient
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment