Skip to content

Commit

Permalink
added rest client section
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Menezes committed May 5, 2016
1 parent ce716d6 commit 1ed0a17
Show file tree
Hide file tree
Showing 24 changed files with 907 additions and 9 deletions.
13 changes: 13 additions & 0 deletions app/controllers/GetClusterMappingController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package controllers


import models.ClusterMapping
import scala.concurrent.ExecutionContext.Implicits.global

class GetClusterMappingController extends BaseController {

def processRequest = (request, client) => client.getClusterMapping(request.host).map { response =>
Ok(ClusterMapping(response.body))
}

}
14 changes: 14 additions & 0 deletions app/controllers/RestController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controllers

class RestController extends ElasticActionController {

def processElasticRequest = (request, client) => {
client.executeRequest(
request.get("method"),
request.get("path"),
request.getOpt("data"),
request.host
)
}

}
5 changes: 5 additions & 0 deletions app/elastic/ElasticClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ trait ElasticClient {
def getIndexRecovery(index: String, host: String) =
ElasticResponse(WS.url(s"$host/$index/_recovery?active_only=true&human=true").get())

def getClusterMapping(host: String) =
ElasticResponse(WS.url(s"$host/_mapping").get())

def executeRequest(method: String, path: String, data: Option[String], host: String) =
ElasticResponse(data.foldLeft(WS.url(s"$host/$path"))(_ withBody _).execute(method))

}

Expand Down
2 changes: 2 additions & 0 deletions app/models/CerebroRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CerebroRequest(val host: String, body: JsValue) {

def getArray(name: String) = (body \ name).asOpt[Array[String]].getOrElse(throw MissingRequiredParamException(name))

def getOpt(name: String) =
(body \ name).asOpt[String]
}

object CerebroRequest {
Expand Down
12 changes: 12 additions & 0 deletions app/models/ClusterMapping.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package models

import play.api.libs.json.{Json, JsString, JsObject, JsValue}

object ClusterMapping {

def apply(mappings: JsValue) = JsObject(mappings.as[JsObject].value.map {
case (index, indexMappings) =>
(index -> Json.obj("types" -> (indexMappings \ "mappings").as[JsObject].keys.map(JsString(_))))
})

}
2 changes: 1 addition & 1 deletion app/views/Index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="container-fluid main">
<div class="row">
<div class="col-sm-12">
<div class="content" ng-view></div>
<div class="content" ng-view onload="initializeController()"></div>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ POST /apis/get_node_stats @controllers.GetNodeStatsController
POST /apis/disable_shard_allocation @controllers.DisableShardAllocationController.execute
POST /apis/enable_shard_allocation @controllers.EnableShardAllocationController.execute
POST /apis/get_shard_stats @controllers.GetShardStatsController.execute
POST /apis/rest @controllers.RestController.execute
POST /apis/get_cluster_mapping @controllers.GetClusterMappingController.execute

GET /apis/hosts @controllers.HostsController.index

Expand Down
Loading

0 comments on commit 1ed0a17

Please sign in to comment.