Skip to content

Commit f9c297c

Browse files
committed
Add Cluster/AllocationExplain endpoint
1 parent 76e621c commit f9c297c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints\Cluster;
4+
5+
use Elasticsearch\Endpoints\AbstractEndpoint;
6+
7+
/**
8+
* Class AllocationExplain
9+
*
10+
* @category Elasticsearch
11+
* @package Elasticsearch\Endpoints\Cluster
12+
* @author Zachary Tong <zachary.tong@elasticsearch.com>
13+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
14+
* @link http://elasticsearch.org
15+
*/
16+
class AllocationExplain extends AbstractEndpoint
17+
{
18+
19+
/**
20+
* @param array $body
21+
*
22+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
23+
* @return $this
24+
*/
25+
public function setBody($body)
26+
{
27+
if (isset($body) !== true) {
28+
return $this;
29+
}
30+
31+
$this->body = $body;
32+
33+
return $this;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
protected function getURI()
40+
{
41+
return "/_cluster/allocation/explain";
42+
}
43+
44+
/**
45+
* @return string[]
46+
*/
47+
protected function getParamWhitelist()
48+
{
49+
return array(
50+
'include_yes_decisions'
51+
);
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
protected function getMethod()
58+
{
59+
return 'GET';
60+
}
61+
}

src/Elasticsearch/Namespaces/ClusterNamespace.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,27 @@ public function pendingTasks($params = array())
187187

188188
return $endpoint->resultOrFuture($response);
189189
}
190+
191+
/**
192+
* $params['include_yes_decisions'] = (bool) Return 'YES' decisions in explanation (default: false)
193+
*
194+
* @param $params array Associative array of parameters
195+
*
196+
* @return array
197+
*/
198+
public function allocationExplain($params = array())
199+
{
200+
$body = $this->extractArgument($params, 'body');
201+
202+
/** @var callback $endpointBuilder */
203+
$endpointBuilder = $this->endpoints;
204+
205+
/** @var \Elasticsearch\Endpoints\Cluster\AllocationExplain $endpoint */
206+
$endpoint = $endpointBuilder('Cluster\AllocationExplain');
207+
$endpoint->setBody($body)
208+
->setParams($params);
209+
$response = $endpoint->performRequest();
210+
211+
return $endpoint->resultOrFuture($response);
212+
}
190213
}

0 commit comments

Comments
 (0)