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

use POST for all apis, and include host on body instead of url

parent bb3b8593
No related branches found
No related tags found
No related merge requests found
Showing
with 175 additions and 86 deletions
......@@ -5,6 +5,6 @@ import elastic.ElasticClient
object Main extends ElasticsearchController {
def index = processRequest(ElasticClient.main(_))
def index = processRequest { request => ElasticClient.main(request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class ClearIndexCacheController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.clearIndexCache(indices, _))
def index = processRequest { request => ElasticClient.clearIndexCache(request.get("indices"), request.host) }
}
......@@ -5,6 +5,6 @@ import elastic.ElasticClient
class CloseIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.closeIndex(indices, _))
def index = processRequest { request => ElasticClient.closeIndex(request.get("indices"), request.host) }
}
......@@ -5,6 +5,6 @@ import elastic.ElasticClient
class DeleteIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.deleteIndex(indices, _))
def index = processRequest { request => ElasticClient.deleteIndex(request.get("indices"), request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class DisableShardAllocationController extends ElasticsearchController {
def index() = processRequest(ElasticClient.disableShardAllocation(_))
def index = processRequest { request => ElasticClient.disableShardAllocation(request.host) }
}
package controllers.elasticsearch
import elastic.ElasticResponse
import models.{CerebroRequest, CerebroRequest$}
import play.api.Logger
import play.api.mvc.{Action, Controller}
......@@ -11,16 +12,15 @@ 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
def processRequest(f: (CerebroRequest => Future[ElasticResponse])) = Action.async(parse.json) { request =>
val cRequest = CerebroRequest(request.body)
try {
val response = f(host)
val response = f(cRequest)
response.map { r =>
Status(r.status)(r.body)
}
} catch {
case _ => Future.successful(Status(500)(s"Cannot connect to $host"))
case _ => Future.successful(Status(500)(s"Cannot connect to ${cRequest.host}"))
}
}
......
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class EnableShardAllocationController extends ElasticsearchController {
def index() = processRequest(ElasticClient.enableShardAllocation(_))
def index = processRequest { request => ElasticClient.enableShardAllocation(request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class GetIndexMapping extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.getIndexMapping(indices, _))
def index = processRequest { request => ElasticClient.getIndexMapping(request.get("index"), request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class GetIndexSettings extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.getIndexSettings(indices, _))
def index = processRequest { request => ElasticClient.getIndexSettings(request.get("index"), request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class NodeStatsController extends ElasticsearchController {
def index(nodes: String) = processRequest(ElasticClient.nodesStats(nodes, _))
def index = processRequest { request => ElasticClient.nodesStats(request.get("node"), request.host) }
}
......@@ -5,6 +5,6 @@ import elastic.ElasticClient
class OpenIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.openIndex(indices, _))
def index = processRequest { request => ElasticClient.openIndex(request.get("indices"), request.host) }
}
......@@ -7,6 +7,6 @@ import scala.concurrent.ExecutionContext.Implicits.global
class OptimizeIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.optimizeIndex(indices, _))
def index = processRequest { request => ElasticClient.optimizeIndex(request.get("indices"), request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class PutClusterSettings extends ElasticsearchController {
def index = processRequest(ElasticClient.putClusterSettings("", _))
def index = processRequest { request => ElasticClient.putClusterSettings(request.get("settings"), request.host) }
}
......@@ -4,6 +4,6 @@ import elastic.ElasticClient
class RefreshIndexController extends ElasticsearchController {
def index(indices: String) = processRequest(ElasticClient.refreshIndex(indices, _))
def index = processRequest { request => ElasticClient.refreshIndex(request.get("indices"), request.host) }
}
package exceptions
case class MissingRequiredParamException(name: String) extends Exception
package exceptions
object MissingTargetHostException extends Exception
package models
import exceptions.{MissingRequiredParamException, MissingTargetHostException}
import play.api.libs.json.JsValue
class CerebroRequest(val host: String, body: JsValue) {
def get(name: String) = (body \ name).asOpt[String].getOrElse(throw MissingRequiredParamException(name))
def getArray(name: String) = (body \ name).asOpt[Array[String]].getOrElse(throw MissingRequiredParamException(name))
}
object CerebroRequest {
def apply(body: JsValue) = {
val host = (body \ "host").asOpt[String].getOrElse(throw MissingTargetHostException)
new CerebroRequest(host, body)
}
}
......@@ -9,18 +9,18 @@ GET / controllers.Application.index()
#
GET /main controllers.Main.index()
GET /apis/overview controllers.ClusterOverviewController.index()
POST /apis/:indices/_close @controllers.elasticsearch.CloseIndexController.index(indices)
POST /apis/:indices/_open @controllers.elasticsearch.OpenIndexController.index(indices)
POST /apis/:indices/_optimize @controllers.elasticsearch.OptimizeIndexController.index(indices)
POST /apis/:indices/_cache/clear @controllers.elasticsearch.ClearIndexCacheController.index(indices)
POST /apis/:indices/_refresh @controllers.elasticsearch.RefreshIndexController.index(indices)
DELETE /apis/:indices/_delete @controllers.elasticsearch.DeleteIndexController.index(indices)
GET /apis/:index/_settings @controllers.elasticsearch.GetIndexSettings.index(index)
GET /apis/:index/_mapping @controllers.elasticsearch.GetIndexMapping.index(index)
PUT /apis/_cluster/settings @controllers.elasticsearch.PutClusterSettings.index
GET /apis/_nodes/:nodes/stats @controllers.elasticsearch.NodeStatsController.index(nodes)
PUT /apis/disable_allocation @controllers.elasticsearch.DisableShardAllocationController.index()
PUT /apis/enable_allocation @controllers.elasticsearch.EnableShardAllocationController.index()
POST /apis/close_indices @controllers.elasticsearch.CloseIndexController.index
POST /apis/open_indices @controllers.elasticsearch.OpenIndexController.index
POST /apis/optimize_indices @controllers.elasticsearch.OptimizeIndexController.index
POST /apis/clear_indices_cache @controllers.elasticsearch.ClearIndexCacheController.index
POST /apis/refresh_indices @controllers.elasticsearch.RefreshIndexController.index
POST /apis/delete_indices @controllers.elasticsearch.DeleteIndexController.index
POST /apis/get_index_settings @controllers.elasticsearch.GetIndexSettings.index
POST /apis/get_index_mapping @controllers.elasticsearch.GetIndexMapping.index
POST /apis/update_cluster_settings @controllers.elasticsearch.PutClusterSettings.index
POST /apis/get_node_stats @controllers.elasticsearch.NodeStatsController.index
POST /apis/disable_shard_allocation @controllers.elasticsearch.DisableShardAllocationController.index
POST /apis/enable_shard_allocation @controllers.elasticsearch.EnableShardAllocationController.index
GET /apis/hosts @controllers.HostsController.index
......
......@@ -834,8 +834,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.closeIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_close',
params: {host: host}
url: baseUrl + '/apis/close_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -845,8 +848,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.openIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_open',
params: {host: host}
url: baseUrl + '/apis/open_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -856,8 +862,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.optimizeIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_optimize',
params: {host: host}
url: baseUrl + '/apis/optimize_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -867,8 +876,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.refreshIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_refresh',
params: {host: host}
url: baseUrl + '/apis/refresh_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -878,8 +890,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.clearIndexCache = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_cache/clear',
params: {host: host}
url: baseUrl + '/apis/clear_indices_cache',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -888,9 +903,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.deleteIndex = function(index, success, error) {
var config = {
method: 'DELETE',
url: baseUrl + '/apis/' + index + '/_delete',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/delete_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -899,9 +917,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.getIndexSettings = function(index, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/' + index + '/_settings',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_index_settings',
data: {
host: host,
index: index
}
};
$http(config).
success(success).
......@@ -910,9 +931,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.getIndexMapping = function(index, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/' + index + '/_mapping',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_index_mapping',
data: {
host: host,
index: index
}
};
$http(config).
success(success).
......@@ -921,9 +945,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.nodeStats = function(node, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/_nodes/' + node + '/stats',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_node_stats',
data: {
host: host,
node: node
}
};
$http(config).
success(success).
......@@ -932,9 +959,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.enableShardAllocation = function(success, error) {
var config = {
method: 'PUT',
url: baseUrl + '/apis/enable_allocation',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/enable_shard_allocation',
data: {
host: host
}
};
$http(config).
success(success).
......@@ -943,9 +972,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.disableShardAllocation = function(success, error) {
var config = {
method: 'PUT',
url: baseUrl + '/apis/disable_allocation',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/disable_shard_allocation',
data: {
host: host
}
};
$http(config).
success(success).
......
......@@ -59,8 +59,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.closeIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_close',
params: {host: host}
url: baseUrl + '/apis/close_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -70,8 +73,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.openIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_open',
params: {host: host}
url: baseUrl + '/apis/open_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -81,8 +87,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.optimizeIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_optimize',
params: {host: host}
url: baseUrl + '/apis/optimize_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -92,8 +101,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.refreshIndex = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_refresh',
params: {host: host}
url: baseUrl + '/apis/refresh_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -103,8 +115,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.clearIndexCache = function(index, success, error) {
var config = {
method: 'POST',
url: baseUrl + '/apis/' + index + '/_cache/clear',
params: {host: host}
url: baseUrl + '/apis/clear_indices_cache',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -113,9 +128,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.deleteIndex = function(index, success, error) {
var config = {
method: 'DELETE',
url: baseUrl + '/apis/' + index + '/_delete',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/delete_indices',
data: {
host: host,
indices: index
}
};
$http(config).
success(success).
......@@ -124,9 +142,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.getIndexSettings = function(index, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/' + index + '/_settings',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_index_settings',
data: {
host: host,
index: index
}
};
$http(config).
success(success).
......@@ -135,9 +156,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.getIndexMapping = function(index, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/' + index + '/_mapping',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_index_mapping',
data: {
host: host,
index: index
}
};
$http(config).
success(success).
......@@ -146,9 +170,12 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.nodeStats = function(node, success, error) {
var config = {
method: 'GET',
url: baseUrl + '/apis/_nodes/' + node + '/stats',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/get_node_stats',
data: {
host: host,
node: node
}
};
$http(config).
success(success).
......@@ -157,9 +184,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.enableShardAllocation = function(success, error) {
var config = {
method: 'PUT',
url: baseUrl + '/apis/enable_allocation',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/enable_shard_allocation',
data: {
host: host
}
};
$http(config).
success(success).
......@@ -168,9 +197,11 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
this.disableShardAllocation = function(success, error) {
var config = {
method: 'PUT',
url: baseUrl + '/apis/disable_allocation',
params: {host: host}
method: 'POST',
url: baseUrl + '/apis/disable_shard_allocation',
data: {
host: host
}
};
$http(config).
success(success).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment