Commit d283b473 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

initial version for cat module

parent d423aa75
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
package controllers

import models.analysis.{IndexAnalyzers, IndexFields, OpenIndices, Tokens}
import models.ElasticServer

import scala.concurrent.ExecutionContext.Implicits.global

class CatController extends BaseController {

  def get = process { (request, client) =>
    val api = request.get("api")
    client.catRequest(api, ElasticServer(request.host, request.authentication)).map { response =>
      Status(response.status)(response.body)
    }
  }

}
+6 −0
Original line number Diff line number Diff line
@@ -261,6 +261,12 @@ trait ElasticClient {
    execute(s"${target.host}$path", "PUT", Some(settings.toString), target.authentication)
  }

  // Cat requests
  def catRequest(api: String, target: ElasticServer) = {
    val path = s"/_cat/$api"
    execute(s"${target.host}$path?format=json", "GET", None, target.authentication)
  }

  def executeRequest(method: String, path: String, data: Option[JsValue], target: ElasticServer) =
    execute(s"${target.host}/$path", method, data.map(_.toString), target.authentication)

+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ POST /snapshots/create @controllers.SnapshotsCont
POST        /snapshots/delete                         @controllers.SnapshotsController.delete
POST        /snapshots/restore                        @controllers.SnapshotsController.restore

# Cat module
POST        /cat                                      @controllers.CatController.get

# Map the JS resource paths
GET         /public/*file                             controllers.Assets.at(path="/public", file)
GET         /*file                                    controllers.Assets.versioned(path="/public", file: Asset)

public/cat/index.html

0 → 100644
+36 −0
Original line number Diff line number Diff line
<h4>cluster settings</h4>
<div class="row">
  <div class="col-xs-12">
    <div class="form-group">
      <select ng-model="api" class="form-control" ng-options="a for a in apis">
      </select>
    </div>
  </div>
  <div class="col-xs-12">
    <button class="btn btn-success pull-right" ng-click="get(api)">
      execute
    </button>
  </div>
</div>
<div class="row">
  <div class="col-xs-12">
    <h4 class="text-center" ng-show="data.length === 0">No data available</h4>
    <table class="table">
      <thead>
      <tr>
        <th ng-repeat="col in headers track by $index" ng-show="col" ng-click="sort(col)" class="normal-action">
          {{col}}<span ng-show="col === sortCol">
          <i class="fa fa-caret-down" ng-show="sortAsc"></i>
          <i class="fa fa-caret-up" ng-hide="sortAsc"></i>
        </span>
        </th>
      </tr>
      </thead>
      <tr ng-repeat="row in data | orderBy:sortCol:sortAsc track by $index " ng-show="row">
        <td ng-repeat="col in headers track by $index" ng-show="col">
          {{row[col]}}
        </td>
      </tr>
    </table>
  </div>
</div>
+72 −0
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ angular.module('cerebro', ['ngRoute', 'ngAnimate', 'ui.bootstrap'])
          templateUrl: 'repositories/index.html',
          controller: 'RepositoriesController'
        })
        .when('/cat', {
          templateUrl: 'cat/index.html',
          controller: 'CatController'
        })
        .otherwise({
            redirectTo: '/connect'
          }
@@ -256,6 +260,74 @@ angular.module('cerebro').directive('analysisTokens', function() {
  };
});

angular.module('cerebro').controller('CatController', ['$scope',
  'CatDataService', 'AlertService',
  function($scope, CatDataService, AlertService) {

    $scope.api = undefined;

    $scope.apis = [
      'aliases',
      'allocation',
      'count',
      'fielddata',
      'health',
      'indices',
      'master',
      'nodeattrs',
      'nodes',
      'pending tasks',
      'plugins',
      'recovery',
      'repositories',
      'thread pool',
      'shards',
      'segments'
    ];

    $scope.headers = undefined;
    $scope.data = undefined;
    $scope.sortCol = undefined;
    $scope.sortAsc = true;

    $scope.get = function(api) {
      CatDataService.get(
        api.replace(/ /g, '_'), // transforms thread pool into thread_pool, for example
        function(data) {
          $scope.headers = Object.keys(data[0]);
          $scope.sort($scope.headers[0]);
          $scope.data = data;
        },
        function(error) {
          AlertService.error('Error executing request', error);
        }
      );
    };

    $scope.sort = function(col) {
      if ($scope.sortCol === col) {
        $scope.sortAsc = !$scope.sortAsc;
      } else {
        $scope.sortAsc = true;
      }
      $scope.sortCol = col;
    };

  }]
);

angular.module('cerebro').factory('CatDataService', ['DataService',
  function(DataService) {

    this.get = function(api, success, error) {
      DataService.send('/cat', {api: api}, success, error);
    };

    return this;

  }
]);

angular.module('cerebro').directive('clusterSetting', function() {
  return {
    restrict: 'EA',
Loading