Skip to content

Commit

Permalink
Add Cluster/AllocationExplain endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Mar 31, 2016
1 parent 76e621c commit f9c297c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/Elasticsearch/Endpoints/Cluster/AllocationExplain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Elasticsearch\Endpoints\Cluster;

use Elasticsearch\Endpoints\AbstractEndpoint;

/**
* Class AllocationExplain
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Cluster
* @author Zachary Tong <zachary.tong@elasticsearch.com>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/
class AllocationExplain extends AbstractEndpoint
{

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

$this->body = $body;

return $this;
}

/**
* @return string
*/
protected function getURI()
{
return "/_cluster/allocation/explain";
}

/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array(
'include_yes_decisions'
);
}

/**
* @return string
*/
protected function getMethod()
{
return 'GET';
}
}
23 changes: 23 additions & 0 deletions src/Elasticsearch/Namespaces/ClusterNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,27 @@ public function pendingTasks($params = array())

return $endpoint->resultOrFuture($response);
}

/**
* $params['include_yes_decisions'] = (bool) Return 'YES' decisions in explanation (default: false)
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function allocationExplain($params = array())
{
$body = $this->extractArgument($params, 'body');

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

/** @var \Elasticsearch\Endpoints\Cluster\AllocationExplain $endpoint */
$endpoint = $endpointBuilder('Cluster\AllocationExplain');
$endpoint->setBody($body)
->setParams($params);
$response = $endpoint->performRequest();

return $endpoint->resultOrFuture($response);
}
}

0 comments on commit f9c297c

Please sign in to comment.