From 752d5a23305589c9f9f57af025b747e09d49a70c Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 25 Oct 2016 13:56:46 -0400 Subject: [PATCH] Tasks/List and Tasks/Get are now separate endpoints --- src/Elasticsearch/Endpoints/Tasks/Get.php | 11 +--- .../Endpoints/Tasks/TasksList.php | 53 +++++++++++++++++++ .../Namespaces/TasksNamespace.php | 30 +++++++++-- tests/Elasticsearch/Tests/YamlRunnerTest.php | 2 +- 4 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 src/Elasticsearch/Endpoints/Tasks/TasksList.php diff --git a/src/Elasticsearch/Endpoints/Tasks/Get.php b/src/Elasticsearch/Endpoints/Tasks/Get.php index 8652e39f2..4e7318d06 100644 --- a/src/Elasticsearch/Endpoints/Tasks/Get.php +++ b/src/Elasticsearch/Endpoints/Tasks/Get.php @@ -41,7 +41,7 @@ public function setTaskId($taskId) */ public function getURI() { - if (isset($this->id) === true) { + if (isset($this->taskId) === true) { return "/_tasks/{$this->taskId}"; } @@ -54,14 +54,7 @@ public function getURI() public function getParamWhitelist() { return array( - 'node_id', - 'actions', - 'detailed', - 'parent_node', - 'parent_task', - 'wait_for_completion', - 'group_by', - 'task_id' + 'wait_for_completion' ); } diff --git a/src/Elasticsearch/Endpoints/Tasks/TasksList.php b/src/Elasticsearch/Endpoints/Tasks/TasksList.php new file mode 100644 index 000000000..b45f20628 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Tasks/TasksList.php @@ -0,0 +1,53 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elastic.co + */ +class TasksList extends AbstractEndpoint +{ + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + public function getURI() + { + return "/_tasks"; + } + + /** + * @return string[] + */ + public function getParamWhitelist() + { + return array( + 'node_id', + 'actions', + 'detailed', + 'parent_node', + 'parent_task', + 'wait_for_completion', + 'group_by', + 'task_id' + ); + } + + /** + * @return string + */ + public function getMethod() + { + return 'GET'; + } +} diff --git a/src/Elasticsearch/Namespaces/TasksNamespace.php b/src/Elasticsearch/Namespaces/TasksNamespace.php index cbe40bbba..6782292e2 100644 --- a/src/Elasticsearch/Namespaces/TasksNamespace.php +++ b/src/Elasticsearch/Namespaces/TasksNamespace.php @@ -16,6 +16,28 @@ */ class TasksNamespace extends AbstractNamespace { + /** + * $params['wait_for_completion'] = (bool) Wait for the matching tasks to complete (default: false) + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function get($params = array()) + { + $id = $this->extractArgument($params, 'task_id'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->endpoints; + + /** @var Get $endpoint */ + $endpoint = $endpointBuilder('Tasks\Get'); + $endpoint->setTaskId($id) + ->setParams($params); + + return $this->performRequest($endpoint); + } + /** * $params['node_id'] = (list) A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes * ['actions'] = (list) A comma-separated list of actions that should be cancelled. Leave empty to cancel all. @@ -29,17 +51,15 @@ class TasksNamespace extends AbstractNamespace * * @return array */ - public function get($params = array()) + public function tasksList($params = array()) { - $id = $this->extractArgument($params, 'id'); /** @var callback $endpointBuilder */ $endpointBuilder = $this->endpoints; /** @var Get $endpoint */ - $endpoint = $endpointBuilder('Tasks\Get'); - $endpoint->setTaskId($id) - ->setParams($params); + $endpoint = $endpointBuilder('Tasks\TasksList'); + $endpoint->setParams($params); return $this->performRequest($endpoint); } diff --git a/tests/Elasticsearch/Tests/YamlRunnerTest.php b/tests/Elasticsearch/Tests/YamlRunnerTest.php index 4de47ba25..29a35318c 100644 --- a/tests/Elasticsearch/Tests/YamlRunnerTest.php +++ b/tests/Elasticsearch/Tests/YamlRunnerTest.php @@ -48,7 +48,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase /** @var array A mapping for endpoint when there is a reserved keywords for the method / namespace name */ private static $endpointMapping = [ 'tasks' => [ - 'list' => ['get', 'tasks'], + 'list' => ['tasksList', 'tasks'], ], ];