Loading app/controllers/RestController.scala +18 −10 Original line number Diff line number Diff line package controllers import java.sql.Date import javax.inject.Inject import controllers.auth.AuthenticationModule import dao.{RestHistoryDAO, RestRequest} import elastic.{ElasticClient, Error, Success} import models.{CerebroResponse, ClusterMapping, Hosts} import play.api.libs.json.{JsArray, Json} import scala.concurrent.ExecutionContext.Implicits.global class RestController @Inject()(val authentication: AuthenticationModule, val hosts: Hosts, client: ElasticClient) extends BaseController { client: ElasticClient, restHistoryDAO: RestHistoryDAO) extends BaseController { def request = process { request => client.executeRequest( request.get("method"), request.get("path"), request.getObjOpt("data"), request.target ).map { response => CerebroResponse(response.status, response.body) val method = request.get("method") val path = request.get("path") val body = request.getObjOpt("data") client.executeRequest(method, path, body, request.target).map { case s: Success => val bodyAsString = body.map(_.toString).getOrElse("{}") val username = request.user.map(_.name).getOrElse("") restHistoryDAO.save(RestRequest(path, method, bodyAsString, username, new Date(System.currentTimeMillis))) CerebroResponse(s.status, s.body) case e: Error => CerebroResponse(e.status, e.body) } } def getClusterMapping = process { request => def index = process { request => client.getClusterMapping(request.target).map { case Success(status, mapping) => CerebroResponse(status, ClusterMapping(mapping)) case Success(status, body) => CerebroResponse(status, ClusterMapping(body)) case Error(status, error) => CerebroResponse(status, error) } } Loading conf/routes +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ POST /aliases/update_aliases controllers.AliasesControl # Rest module POST /rest/request controllers.RestController.request POST /rest/get_cluster_mapping controllers.RestController.getClusterMapping POST /rest controllers.RestController.index # Overview module POST /overview controllers.ClusterOverviewController.index Loading public/js/app.js +27 −16 Original line number Diff line number Diff line Loading @@ -1108,9 +1108,9 @@ angular.module('cerebro').factory('RepositoriesDataService', ['DataService', ]); angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', '$sce', 'RestDataService', 'AlertService', 'ModalService', 'AceEditorService', 'ClipboardService', function($scope, $http, $sce, DataService, AlertService, ModalService, function($scope, $http, $sce, RestDataService, AlertService, ModalService, AceEditorService, ClipboardService) { $scope.editor = undefined; Loading @@ -1132,14 +1132,15 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.execute = function() { var data = $scope.editor.getValue(); var method = $scope.method; $scope.response = undefined; DataService.execute($scope.method, $scope.path, data, success, failure); RestDataService.execute(method, $scope.path, data, success, failure); }; $scope.setup = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue('{}'); DataService.getClusterMapping( RestDataService.load( function(response) { $scope.mappings = response; $scope.updateOptions($scope.path); Loading @@ -1159,7 +1160,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.copyAsCURLCommand = function() { var method = $scope.method; var host = DataService.getHost(); var host = RestDataService.getHost(); var path = encodeURI($scope.path); if (path.substring(0, 1) !== '/') { path = '/' + path; Loading @@ -1183,6 +1184,27 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', }] ); angular.module('cerebro').factory('RestDataService', ['DataService', function(DataService) { this.load = function(success, error) { DataService.send('/rest', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; DataService.send('/rest/request', requestData, success, error); }; this.getHost = function() { return DataService.getHost(); }; return this; } ]); angular.module('cerebro').controller('SnapshotController', ['$scope', 'SnapshotsDataService', 'AlertService', 'ModalService', function($scope, SnapshotsDataService, AlertService, ModalService) { Loading Loading @@ -2494,17 +2516,6 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout', request(config, success, error); }; // ---------- Rest ---------- this.getClusterMapping = function(success, error) { clusterRequest('/rest/get_cluster_mapping', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; clusterRequest('/rest/request', requestData, success, error); }; // ---------- External API ---------- this.send = function(path, data, success, error) { Loading src/app/components/rest/controller.js +6 −5 Original line number Diff line number Diff line angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', '$sce', 'RestDataService', 'AlertService', 'ModalService', 'AceEditorService', 'ClipboardService', function($scope, $http, $sce, DataService, AlertService, ModalService, function($scope, $http, $sce, RestDataService, AlertService, ModalService, AceEditorService, ClipboardService) { $scope.editor = undefined; Loading @@ -23,14 +23,15 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.execute = function() { var data = $scope.editor.getValue(); var method = $scope.method; $scope.response = undefined; DataService.execute($scope.method, $scope.path, data, success, failure); RestDataService.execute(method, $scope.path, data, success, failure); }; $scope.setup = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue('{}'); DataService.getClusterMapping( RestDataService.load( function(response) { $scope.mappings = response; $scope.updateOptions($scope.path); Loading @@ -50,7 +51,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.copyAsCURLCommand = function() { var method = $scope.method; var host = DataService.getHost(); var host = RestDataService.getHost(); var path = encodeURI($scope.path); if (path.substring(0, 1) !== '/') { path = '/' + path; Loading src/app/components/rest/data.js 0 → 100644 +20 −0 Original line number Diff line number Diff line angular.module('cerebro').factory('RestDataService', ['DataService', function(DataService) { this.load = function(success, error) { DataService.send('/rest', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; DataService.send('/rest/request', requestData, success, error); }; this.getHost = function() { return DataService.getHost(); }; return this; } ]); Loading
app/controllers/RestController.scala +18 −10 Original line number Diff line number Diff line package controllers import java.sql.Date import javax.inject.Inject import controllers.auth.AuthenticationModule import dao.{RestHistoryDAO, RestRequest} import elastic.{ElasticClient, Error, Success} import models.{CerebroResponse, ClusterMapping, Hosts} import play.api.libs.json.{JsArray, Json} import scala.concurrent.ExecutionContext.Implicits.global class RestController @Inject()(val authentication: AuthenticationModule, val hosts: Hosts, client: ElasticClient) extends BaseController { client: ElasticClient, restHistoryDAO: RestHistoryDAO) extends BaseController { def request = process { request => client.executeRequest( request.get("method"), request.get("path"), request.getObjOpt("data"), request.target ).map { response => CerebroResponse(response.status, response.body) val method = request.get("method") val path = request.get("path") val body = request.getObjOpt("data") client.executeRequest(method, path, body, request.target).map { case s: Success => val bodyAsString = body.map(_.toString).getOrElse("{}") val username = request.user.map(_.name).getOrElse("") restHistoryDAO.save(RestRequest(path, method, bodyAsString, username, new Date(System.currentTimeMillis))) CerebroResponse(s.status, s.body) case e: Error => CerebroResponse(e.status, e.body) } } def getClusterMapping = process { request => def index = process { request => client.getClusterMapping(request.target).map { case Success(status, mapping) => CerebroResponse(status, ClusterMapping(mapping)) case Success(status, body) => CerebroResponse(status, ClusterMapping(body)) case Error(status, error) => CerebroResponse(status, error) } } Loading
conf/routes +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ POST /aliases/update_aliases controllers.AliasesControl # Rest module POST /rest/request controllers.RestController.request POST /rest/get_cluster_mapping controllers.RestController.getClusterMapping POST /rest controllers.RestController.index # Overview module POST /overview controllers.ClusterOverviewController.index Loading
public/js/app.js +27 −16 Original line number Diff line number Diff line Loading @@ -1108,9 +1108,9 @@ angular.module('cerebro').factory('RepositoriesDataService', ['DataService', ]); angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', '$sce', 'RestDataService', 'AlertService', 'ModalService', 'AceEditorService', 'ClipboardService', function($scope, $http, $sce, DataService, AlertService, ModalService, function($scope, $http, $sce, RestDataService, AlertService, ModalService, AceEditorService, ClipboardService) { $scope.editor = undefined; Loading @@ -1132,14 +1132,15 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.execute = function() { var data = $scope.editor.getValue(); var method = $scope.method; $scope.response = undefined; DataService.execute($scope.method, $scope.path, data, success, failure); RestDataService.execute(method, $scope.path, data, success, failure); }; $scope.setup = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue('{}'); DataService.getClusterMapping( RestDataService.load( function(response) { $scope.mappings = response; $scope.updateOptions($scope.path); Loading @@ -1159,7 +1160,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.copyAsCURLCommand = function() { var method = $scope.method; var host = DataService.getHost(); var host = RestDataService.getHost(); var path = encodeURI($scope.path); if (path.substring(0, 1) !== '/') { path = '/' + path; Loading @@ -1183,6 +1184,27 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', }] ); angular.module('cerebro').factory('RestDataService', ['DataService', function(DataService) { this.load = function(success, error) { DataService.send('/rest', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; DataService.send('/rest/request', requestData, success, error); }; this.getHost = function() { return DataService.getHost(); }; return this; } ]); angular.module('cerebro').controller('SnapshotController', ['$scope', 'SnapshotsDataService', 'AlertService', 'ModalService', function($scope, SnapshotsDataService, AlertService, ModalService) { Loading Loading @@ -2494,17 +2516,6 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout', request(config, success, error); }; // ---------- Rest ---------- this.getClusterMapping = function(success, error) { clusterRequest('/rest/get_cluster_mapping', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; clusterRequest('/rest/request', requestData, success, error); }; // ---------- External API ---------- this.send = function(path, data, success, error) { Loading
src/app/components/rest/controller.js +6 −5 Original line number Diff line number Diff line angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', '$sce', 'RestDataService', 'AlertService', 'ModalService', 'AceEditorService', 'ClipboardService', function($scope, $http, $sce, DataService, AlertService, ModalService, function($scope, $http, $sce, RestDataService, AlertService, ModalService, AceEditorService, ClipboardService) { $scope.editor = undefined; Loading @@ -23,14 +23,15 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.execute = function() { var data = $scope.editor.getValue(); var method = $scope.method; $scope.response = undefined; DataService.execute($scope.method, $scope.path, data, success, failure); RestDataService.execute(method, $scope.path, data, success, failure); }; $scope.setup = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue('{}'); DataService.getClusterMapping( RestDataService.load( function(response) { $scope.mappings = response; $scope.updateOptions($scope.path); Loading @@ -50,7 +51,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', $scope.copyAsCURLCommand = function() { var method = $scope.method; var host = DataService.getHost(); var host = RestDataService.getHost(); var path = encodeURI($scope.path); if (path.substring(0, 1) !== '/') { path = '/' + path; Loading
src/app/components/rest/data.js 0 → 100644 +20 −0 Original line number Diff line number Diff line angular.module('cerebro').factory('RestDataService', ['DataService', function(DataService) { this.load = function(success, error) { DataService.send('/rest', {}, success, error); }; this.execute = function(method, path, data, success, error) { var requestData = {method: method, data: data, path: path}; DataService.send('/rest/request', requestData, success, error); }; this.getHost = function() { return DataService.getHost(); }; return this; } ]);