From 7b879545dde3f56c372f771a46f5f3984a658b12 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 1 Apr 2016 13:15:22 -0400 Subject: [PATCH] Add Ingest namespace and endpoints --- src/Elasticsearch/Client.php | 17 +++++ src/Elasticsearch/Endpoints/Tasks/Cancel.php | 71 ++++++++++++++++++ src/Elasticsearch/Endpoints/Tasks/Get.php | 74 ++++++++++++++++++ .../Namespaces/TasksNamespace.php | 75 +++++++++++++++++++ 4 files changed, 237 insertions(+) create mode 100644 src/Elasticsearch/Endpoints/Tasks/Cancel.php create mode 100644 src/Elasticsearch/Endpoints/Tasks/Get.php create mode 100644 src/Elasticsearch/Namespaces/TasksNamespace.php diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index 1283df021..c09007121 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -12,6 +12,7 @@ use Elasticsearch\Namespaces\NodesNamespace; use Elasticsearch\Namespaces\SnapshotNamespace; use Elasticsearch\Namespaces\BooleanRequestWrapper; +use Elasticsearch\Namespaces\TasksNamespace; /** * Class Client @@ -64,6 +65,11 @@ class Client */ protected $ingest; + /** + * @var TasksNamespace + */ + protected $tasks; + /** @var callback */ protected $endpoints; @@ -83,6 +89,7 @@ public function __construct(Transport $transport, callable $endpoint) $this->snapshot = new SnapshotNamespace($transport, $endpoint); $this->cat = new CatNamespace($transport, $endpoint); $this->ingest = new IngestNamespace($transport, $endpoint); + $this->tasks = new TasksNamespace($transport, $endpoint); } /** @@ -1430,6 +1437,16 @@ public function ingest() return $this->ingest; } + /** + * Operate on the Tasks namespace of commands + * + * @return TasksNamespace + */ + public function tasks() + { + return $this->tasks; + } + /** * @param array $params * @param string $arg diff --git a/src/Elasticsearch/Endpoints/Tasks/Cancel.php b/src/Elasticsearch/Endpoints/Tasks/Cancel.php new file mode 100644 index 000000000..0486fafc6 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Tasks/Cancel.php @@ -0,0 +1,71 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ +class Cancel extends AbstractEndpoint +{ + private $taskId; + + /** + * @param string $taskId + * + * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException + * @return $this + */ + public function setTaskId($taskId) + { + if (isset($taskId) !== true) { + return $this; + } + + $this->taskId = $taskId; + + return $this; + } + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + protected function getURI() + { + if (isset($this->id) === true) { + return "/_tasks/{$this->taskId}/_cancel"; + } + + return "/_tasks/_cancel"; + } + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array( + 'node_id', + 'actions', + 'parent_node', + 'parent_task', + ); + } + + /** + * @return string + */ + protected function getMethod() + { + return 'POST'; + } +} diff --git a/src/Elasticsearch/Endpoints/Tasks/Get.php b/src/Elasticsearch/Endpoints/Tasks/Get.php new file mode 100644 index 000000000..77f17a01e --- /dev/null +++ b/src/Elasticsearch/Endpoints/Tasks/Get.php @@ -0,0 +1,74 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ +class Get extends AbstractEndpoint +{ + private $taskId; + + /** + * @param string $taskId + * + * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException + * @return $this + */ + public function setTaskId($taskId) + { + if (isset($taskId) !== true) { + return $this; + } + + $this->taskId = $taskId; + + return $this; + } + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + protected function getURI() + { + if (isset($this->id) === true) { + return "/_tasks/{$this->taskId}"; + } + + return "/_tasks"; + } + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array( + 'node_id', + 'actions', + 'detailed', + 'parent_node', + 'parent_task', + 'wait_for_completion', + 'group_by' + ); + } + + /** + * @return string + */ + protected function getMethod() + { + return 'GET'; + } +} diff --git a/src/Elasticsearch/Namespaces/TasksNamespace.php b/src/Elasticsearch/Namespaces/TasksNamespace.php new file mode 100644 index 000000000..36e8624f0 --- /dev/null +++ b/src/Elasticsearch/Namespaces/TasksNamespace.php @@ -0,0 +1,75 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ +class TasksNamespace extends AbstractNamespace +{ + /** + * $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. + * ['parent_node'] = (string) Cancel tasks with specified parent node + * ['parent_task'] = (string) Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all. + * ['detailed'] = (bool) Return detailed task information (default: false) + * ['wait_for_completion'] = (bool) Wait for the matching tasks to complete (default: false) + * ['group_by'] = (enum) Group tasks by nodes or parent/child relationships + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function get($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); + $response = $endpoint->performRequest(); + + return $endpoint->resultOrFuture($response); + } + + /** + * $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. + * ['parent_node'] = (string) Cancel tasks with specified parent node + * ['parent_task'] = (string) Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all. + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function cancel($params = array()) + { + $id = $this->extractArgument($params, 'id'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->endpoints; + + /** @var Cancel $endpoint */ + $endpoint = $endpointBuilder('Tasks\Cancel'); + $endpoint->setTaskId($id) + ->setParams($params); + $response = $endpoint->performRequest(); + + return $endpoint->resultOrFuture($response); + } + + +}