Skip to content

Commit

Permalink
Tasks/List and Tasks/Get are now separate endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Oct 25, 2016
1 parent 9eb573a commit 752d5a2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
11 changes: 2 additions & 9 deletions src/Elasticsearch/Endpoints/Tasks/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}

Expand All @@ -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'
);
}

Expand Down
53 changes: 53 additions & 0 deletions src/Elasticsearch/Endpoints/Tasks/TasksList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Elasticsearch\Endpoints\Tasks;

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

/**
* Class TasksLists
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Tasks
* @author Zachary Tong <[email protected]>
* @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';
}
}
30 changes: 25 additions & 5 deletions src/Elasticsearch/Namespaces/TasksNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand 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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
],
];

Expand Down

0 comments on commit 752d5a2

Please sign in to comment.