-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leonardo Menezes
committed
Apr 3, 2016
0 parents
commit bb3b859
Showing
69 changed files
with
6,681 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 |
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,65 @@ | ||
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' ]); | ||
}; |
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,12 @@ | ||
package controllers | ||
|
||
import play.api.mvc.{Action, Controller} | ||
import play.api.http.MimeTypes | ||
|
||
object Application extends Controller { | ||
|
||
def index = Action { | ||
Ok(views.html.Index()) | ||
} | ||
|
||
} |
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,33 @@ | ||
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")) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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,20 @@ | ||
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(_)))) | ||
} | ||
} | ||
|
||
} |
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,10 @@ | ||
package controllers | ||
|
||
import controllers.elasticsearch.ElasticsearchController | ||
import elastic.ElasticClient | ||
|
||
object Main extends ElasticsearchController { | ||
|
||
def index = processRequest(ElasticClient.main(_)) | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/controllers/elasticsearch/ClearIndexCacheController.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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class ClearIndexCacheController extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.clearIndexCache(indices, _)) | ||
|
||
} |
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,10 @@ | ||
package controllers.elasticsearch | ||
|
||
|
||
import elastic.ElasticClient | ||
|
||
class CloseIndexController extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.closeIndex(indices, _)) | ||
|
||
} |
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,10 @@ | ||
package controllers.elasticsearch | ||
|
||
|
||
import elastic.ElasticClient | ||
|
||
class DeleteIndexController extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.deleteIndex(indices, _)) | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/controllers/elasticsearch/DisableShardAllocationController.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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class DisableShardAllocationController extends ElasticsearchController { | ||
|
||
def index() = processRequest(ElasticClient.disableShardAllocation(_)) | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/controllers/elasticsearch/ElasticsearchController.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,27 @@ | ||
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")) | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/controllers/elasticsearch/EnableShardAllocationController.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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class EnableShardAllocationController extends ElasticsearchController { | ||
|
||
def index() = processRequest(ElasticClient.enableShardAllocation(_)) | ||
|
||
} |
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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class GetIndexMapping extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.getIndexMapping(indices, _)) | ||
|
||
} |
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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class GetIndexSettings extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.getIndexSettings(indices, _)) | ||
|
||
} |
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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class NodeStatsController extends ElasticsearchController { | ||
|
||
def index(nodes: String) = processRequest(ElasticClient.nodesStats(nodes, _)) | ||
|
||
} |
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,10 @@ | ||
package controllers.elasticsearch | ||
|
||
|
||
import elastic.ElasticClient | ||
|
||
class OpenIndexController extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.openIndex(indices, _)) | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
app/controllers/elasticsearch/OptimizeIndexController.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,12 @@ | ||
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, _)) | ||
|
||
} |
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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class PutClusterSettings extends ElasticsearchController { | ||
|
||
def index = processRequest(ElasticClient.putClusterSettings("", _)) | ||
|
||
} |
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,9 @@ | ||
package controllers.elasticsearch | ||
|
||
import elastic.ElasticClient | ||
|
||
class RefreshIndexController extends ElasticsearchController { | ||
|
||
def index(indices: String) = processRequest(ElasticClient.refreshIndex(indices, _)) | ||
|
||
} |
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,74 @@ | ||
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 |
Oops, something went wrong.