Skip to content

Commit

Permalink
Add Cat Namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 10, 2014
1 parent 343fa38 commit b069b40
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Elasticsearch\Common\Exceptions\RoutingMissingException;
use Elasticsearch\Common\Exceptions\UnexpectedValueException;
use Elasticsearch\Endpoints;
use Elasticsearch\Namespaces\CatNamespace;
use Elasticsearch\Namespaces\ClusterNamespace;
use Elasticsearch\Namespaces\IndicesNamespace;
use Elasticsearch\Namespaces\NodesNamespace;
Expand Down Expand Up @@ -64,6 +65,11 @@ class Client
*/
protected $snapshot;

/**
* @var CatNamespace
*/
protected $cat;

/** @var callback */
protected $dicEndpoints;

Expand Down Expand Up @@ -987,6 +993,17 @@ public function snapshot()
}


/**
* Operate on the Cat namespace of commands
*
* @return SnapshotNamespace
*/
public function cat()
{
return $this->cat;
}


/**
* Sets up the DIC parameter object
*
Expand Down
12 changes: 12 additions & 0 deletions src/Elasticsearch/Common/DICBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Elasticsearch\Common\Exceptions\RuntimeException;
use Elasticsearch\Endpoints;
use Elasticsearch\Namespaces\CatNamespace;
use Elasticsearch\Namespaces\ClusterNamespace;
use Elasticsearch\Namespaces\IndicesNamespace;
use Elasticsearch\Namespaces\NodesNamespace;
Expand Down Expand Up @@ -171,6 +172,7 @@ private function setSharedDICObjects($hosts)
$this->setClusterNamespaceObj();
$this->setIndicesNamespaceObj();
$this->setNodesNamespaceObj();
$this->setCatNamespaceObj();
$this->setSnapshotNamespaceObj();
$this->setSharedConnectionParamsObj();
$this->setCurlMultihandle();
Expand Down Expand Up @@ -289,6 +291,16 @@ function ($dicParams) {
);
}

private function setCatNamespaceObj()
{
$this->dic['catNamespace'] = $this->dic->share(
function ($dicParams) {
/** @var Pimple $dicParams */
return new CatNamespace($dicParams['transport'], $dicParams['endpoint']);
}
);
}


private function setSharedConnectionParamsObj()
{
Expand Down
321 changes: 321 additions & 0 deletions src/Elasticsearch/Namespaces/CatNamespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
<?php
/**
* User: zach
* Date: 5/9/13
* Time: 5:13 PM
*/

namespace Elasticsearch\Namespaces;

/**
* Class CatNamespace
*
* @category Elasticsearch
* @package Elasticsearch\Namespaces\CatNamespace
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/
class CatNamespace extends AbstractNamespace
{

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function aliases($params = array())
{
$name = $this->extractArgument($params, 'name');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Aliases $endpoint */
$endpoint = $endpointBuilder('Cat\Aliases');
$endpoint->setName($name);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
* ['bytes'] = (enum) The unit in which to display byte values
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function allocation($params = array())
{
$nodeID = $this->extractArgument($params, 'nodeID');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Allocation $endpoint */
$endpoint = $endpointBuilder('Cat\Allocation');
$endpoint->setNodeID($nodeID);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function count($params = array())
{
$index = $this->extractArgument($params, 'index');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Count $endpoint */
$endpoint = $endpointBuilder('Cat\Count');
$endpoint->setIndex($index);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
* ['ts'] = (bool) Set to false to disable timestamping
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function health($params = array())
{
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Health $endpoint */
$endpoint = $endpointBuilder('Cat\Health');
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['help'] = (bool) Return help information
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function help($params = array())
{
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Help $endpoint */
$endpoint = $endpointBuilder('Cat\Help');
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
* ['bytes'] = (enum) The unit in which to display byte values
* ['pri'] = (bool) Set to true to return stats only for primary shards
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function indices($params = array())
{
$index = $this->extractArgument($params, 'index');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Indices $endpoint */
$endpoint = $endpointBuilder('Cat\Indices');
$endpoint->setIndex($index);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function master($params = array())
{
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Master $endpoint */
$endpoint = $endpointBuilder('Cat\Master');
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function nodes($params = array())
{
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Nodes $endpoint */
$endpoint = $endpointBuilder('Cat\Nodes');
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function pendingTasks($params = array())
{
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\PendingTasks $endpoint */
$endpoint = $endpointBuilder('Cat\PendingTasks');
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
* ['bytes'] = (enum) The unit in which to display byte values
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function recovery($params = array())
{
$index = $this->extractArgument($params, 'index');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Recovery $endpoint */
$endpoint = $endpointBuilder('Cat\Recovery');
$endpoint->setIndex($index);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function shards($params = array())
{
$index = $this->extractArgument($params, 'index');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\Shards $endpoint */
$endpoint = $endpointBuilder('Cat\Shards');
$endpoint->setIndex($index);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['local'] = (bool) Return local information, do not retrieve the state from master node (default: false)
* ['master_timeout'] = (time) Explicit operation timeout for connection to master node
* ['h'] = (list) Comma-separated list of column names to display
* ['help'] = (bool) Return help information
* ['v'] = (bool) Verbose mode. Display column headers
* ['full_id'] = (bool) Enables displaying the complete node ids
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function threadPool($params = array())
{
$index = $this->extractArgument($params, 'index');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Cat\ThreadPool $endpoint */
$endpoint = $endpointBuilder('Cat\ThreadPool');
$endpoint->setIndex($index);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

}

0 comments on commit b069b40

Please sign in to comment.