Skip to content

Commit

Permalink
/Cluster/Nodes endpoints should extend a base, abstract class
Browse files Browse the repository at this point in the history
All endpoints use a NodeID, extending from an abstract class minimizes code
copy/paste
  • Loading branch information
polyfractal committed Jan 24, 2014
1 parent c386538 commit e60bca2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* User: zach
* Date: 1/23/14
* Time: 6:03 PM
*/

namespace Elasticsearch\Endpoints\Cluster\Nodes;


use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Elasticsearch\Endpoints\AbstractEndpoint;

abstract class AbstractNodesEndpoint extends AbstractEndpoint
{
/** @var string A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you&#039;re connecting to, leave empty to get information from all nodes */
protected $nodeID;


/**
* @param $nodeID
*
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
*
* @return $this
*/
public function setNodeID($nodeID)
{
if (isset($nodeID) !== true) {
return $this;
}

if (!(is_array($nodeID) === true || is_string($nodeID) === true)) {
throw new InvalidArgumentException("invalid node_id");
}

if (is_array($nodeID) === true) {
$nodeID = implode(',', $nodeID);
}

$this->nodeID = $nodeID;
return $this;
}
}
23 changes: 2 additions & 21 deletions src/Elasticsearch/Endpoints/Cluster/Nodes/HotThreads.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,15 @@
* @link http://elasticsearch.org
*/

class HotThreads extends AbstractEndpoint
class HotThreads extends AbstractNodesEndpoint
{
// A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you&#039;re connecting to, leave empty to get information from all nodes
private $node_id;


/**
* @param $node_id
*
* @return $this
*/
public function setNodeID($node_id)
{
if (isset($node_id) !== true) {
return $this;
}

$this->node_id = $node_id;
return $this;
}


/**
* @return string
*/
protected function getURI()
{
$node_id = $this->node_id;
$node_id = $this->nodeID;
$uri = "/_cluster/nodes/hotthreads";

if (isset($node_id) === true) {
Expand Down
24 changes: 2 additions & 22 deletions src/Elasticsearch/Endpoints/Cluster/Nodes/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,12 @@
* @link http://elasticsearch.org
*/

class Info extends AbstractEndpoint
class Info extends AbstractNodesEndpoint
{
// A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you&#039;re connecting to, leave empty to get information from all nodes
private $node_id;


// A comma-separated list of metrics you wish returned. Leave empty to return all.
private $metric;


/**
* @param $node_id
*
* @return $this
*/
public function setNodeID($node_id)
{
if (isset($node_id) !== true) {
return $this;
}

$this->node_id = $node_id;
return $this;
}


/**
* @param $metric
*
Expand All @@ -71,7 +51,7 @@ public function setMetric($metric)
*/
protected function getURI()
{
$node_id = $this->node_id;
$node_id = $this->nodeID;
$metric = $this->metric;
$uri = "/_nodes";

Expand Down
23 changes: 2 additions & 21 deletions src/Elasticsearch/Endpoints/Cluster/Nodes/Shutdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,15 @@
* @link http://elasticsearch.org
*/

class Shutdown extends AbstractEndpoint
class Shutdown extends AbstractNodesEndpoint
{
// A comma-separated list of node IDs or names to perform the operation on; use `_local` to perform the operation on the node you&#039;re connected to, leave empty to perform the operation on all nodes
private $node_id;


/**
* @param $node_id
*
* @return $this
*/
public function setNodeID($node_id)
{
if (isset($node_id) !== true) {
return $this;
}

$this->node_id = $node_id;
return $this;
}


/**
* @return string
*/
protected function getURI()
{
$node_id = $this->node_id;
$node_id = $this->nodeID;
$uri = "/_shutdown";

if (isset($node_id) === true) {
Expand Down
25 changes: 2 additions & 23 deletions src/Elasticsearch/Endpoints/Cluster/Nodes/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @link http://elasticsearch.org
*/

class Stats extends AbstractEndpoint
class Stats extends AbstractNodesEndpoint
{
// Limit the information returned to the specified metrics
private $metric;
Expand All @@ -29,11 +29,6 @@ class Stats extends AbstractEndpoint
// Limit the information returned for `indices` metric to the specific index metrics. Isn&#039;t used if `indices` (or `all`) metric isn&#039;t specified.
private $indexMetric;


// A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you&#039;re connecting to, leave empty to get information from all nodes
private $node_id;


/**
* @param $metric
*
Expand Down Expand Up @@ -74,30 +69,14 @@ public function setIndexMetric($indexMetric)
}


/**
* @param $node_id
*
* @return $this
*/
public function setNodeID($node_id)
{
if (isset($node_id) !== true) {
return $this;
}

$this->node_id = $node_id;
return $this;
}


/**
* @return string
*/
protected function getURI()
{
$metric = $this->metric;
$index_metric = $this->indexMetric;
$node_id = $this->node_id;
$node_id = $this->nodeID;
$uri = "/_nodes/stats";

if (isset($node_id) === true && isset($metric) === true && isset($index_metric) === true) {
Expand Down

0 comments on commit e60bca2

Please sign in to comment.