Skip to content

Commit 7b87954

Browse files
committed
Add Ingest namespace and endpoints
1 parent 3fa1c51 commit 7b87954

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed

src/Elasticsearch/Client.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Elasticsearch\Namespaces\NodesNamespace;
1313
use Elasticsearch\Namespaces\SnapshotNamespace;
1414
use Elasticsearch\Namespaces\BooleanRequestWrapper;
15+
use Elasticsearch\Namespaces\TasksNamespace;
1516

1617
/**
1718
* Class Client
@@ -64,6 +65,11 @@ class Client
6465
*/
6566
protected $ingest;
6667

68+
/**
69+
* @var TasksNamespace
70+
*/
71+
protected $tasks;
72+
6773
/** @var callback */
6874
protected $endpoints;
6975

@@ -83,6 +89,7 @@ public function __construct(Transport $transport, callable $endpoint)
8389
$this->snapshot = new SnapshotNamespace($transport, $endpoint);
8490
$this->cat = new CatNamespace($transport, $endpoint);
8591
$this->ingest = new IngestNamespace($transport, $endpoint);
92+
$this->tasks = new TasksNamespace($transport, $endpoint);
8693
}
8794

8895
/**
@@ -1430,6 +1437,16 @@ public function ingest()
14301437
return $this->ingest;
14311438
}
14321439

1440+
/**
1441+
* Operate on the Tasks namespace of commands
1442+
*
1443+
* @return TasksNamespace
1444+
*/
1445+
public function tasks()
1446+
{
1447+
return $this->tasks;
1448+
}
1449+
14331450
/**
14341451
* @param array $params
14351452
* @param string $arg
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints\Tasks;
4+
5+
use Elasticsearch\Common\Exceptions;
6+
use Elasticsearch\Endpoints\AbstractEndpoint;
7+
8+
/**
9+
* Class Cancel
10+
*
11+
* @category Elasticsearch
12+
* @package Elasticsearch\Endpoints\Tasks
13+
* @author Zachary Tong <zachary.tong@elasticsearch.com>
14+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
15+
* @link http://elasticsearch.org
16+
*/
17+
class Cancel extends AbstractEndpoint
18+
{
19+
private $taskId;
20+
21+
/**
22+
* @param string $taskId
23+
*
24+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
25+
* @return $this
26+
*/
27+
public function setTaskId($taskId)
28+
{
29+
if (isset($taskId) !== true) {
30+
return $this;
31+
}
32+
33+
$this->taskId = $taskId;
34+
35+
return $this;
36+
}
37+
38+
/**
39+
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
40+
* @return string
41+
*/
42+
protected function getURI()
43+
{
44+
if (isset($this->id) === true) {
45+
return "/_tasks/{$this->taskId}/_cancel";
46+
}
47+
48+
return "/_tasks/_cancel";
49+
}
50+
51+
/**
52+
* @return string[]
53+
*/
54+
protected function getParamWhitelist()
55+
{
56+
return array(
57+
'node_id',
58+
'actions',
59+
'parent_node',
60+
'parent_task',
61+
);
62+
}
63+
64+
/**
65+
* @return string
66+
*/
67+
protected function getMethod()
68+
{
69+
return 'POST';
70+
}
71+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints\Tasks;
4+
5+
use Elasticsearch\Common\Exceptions;
6+
use Elasticsearch\Endpoints\AbstractEndpoint;
7+
8+
/**
9+
* Class Get
10+
*
11+
* @category Elasticsearch
12+
* @package Elasticsearch\Endpoints\Tasks
13+
* @author Zachary Tong <zachary.tong@elasticsearch.com>
14+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
15+
* @link http://elasticsearch.org
16+
*/
17+
class Get extends AbstractEndpoint
18+
{
19+
private $taskId;
20+
21+
/**
22+
* @param string $taskId
23+
*
24+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
25+
* @return $this
26+
*/
27+
public function setTaskId($taskId)
28+
{
29+
if (isset($taskId) !== true) {
30+
return $this;
31+
}
32+
33+
$this->taskId = $taskId;
34+
35+
return $this;
36+
}
37+
38+
/**
39+
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
40+
* @return string
41+
*/
42+
protected function getURI()
43+
{
44+
if (isset($this->id) === true) {
45+
return "/_tasks/{$this->taskId}";
46+
}
47+
48+
return "/_tasks";
49+
}
50+
51+
/**
52+
* @return string[]
53+
*/
54+
protected function getParamWhitelist()
55+
{
56+
return array(
57+
'node_id',
58+
'actions',
59+
'detailed',
60+
'parent_node',
61+
'parent_task',
62+
'wait_for_completion',
63+
'group_by'
64+
);
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
protected function getMethod()
71+
{
72+
return 'GET';
73+
}
74+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Elasticsearch\Namespaces;
4+
use Elasticsearch\Endpoints\Tasks\Cancel;
5+
use Elasticsearch\Endpoints\Tasks\Get;
6+
7+
8+
/**
9+
* Class TasksNamespace
10+
*
11+
* @category Elasticsearch
12+
* @package Elasticsearch\Namespaces\TasksNamespace
13+
* @author Zachary Tong <zachary.tong@elasticsearch.com>
14+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
15+
* @link http://elasticsearch.org
16+
*/
17+
class TasksNamespace extends AbstractNamespace
18+
{
19+
/**
20+
* $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
21+
* ['actions'] = (list) A comma-separated list of actions that should be cancelled. Leave empty to cancel all.
22+
* ['parent_node'] = (string) Cancel tasks with specified parent node
23+
* ['parent_task'] = (string) Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all.
24+
* ['detailed'] = (bool) Return detailed task information (default: false)
25+
* ['wait_for_completion'] = (bool) Wait for the matching tasks to complete (default: false)
26+
* ['group_by'] = (enum) Group tasks by nodes or parent/child relationships
27+
*
28+
* @param $params array Associative array of parameters
29+
*
30+
* @return array
31+
*/
32+
public function get($params = array())
33+
{
34+
$id = $this->extractArgument($params, 'id');
35+
36+
/** @var callback $endpointBuilder */
37+
$endpointBuilder = $this->endpoints;
38+
39+
/** @var Get $endpoint */
40+
$endpoint = $endpointBuilder('Tasks\Get');
41+
$endpoint->setTaskId($id)
42+
->setParams($params);
43+
$response = $endpoint->performRequest();
44+
45+
return $endpoint->resultOrFuture($response);
46+
}
47+
48+
/**
49+
* $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
50+
* ['actions'] = (list) A comma-separated list of actions that should be cancelled. Leave empty to cancel all.
51+
* ['parent_node'] = (string) Cancel tasks with specified parent node
52+
* ['parent_task'] = (string) Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all.
53+
*
54+
* @param $params array Associative array of parameters
55+
*
56+
* @return array
57+
*/
58+
public function cancel($params = array())
59+
{
60+
$id = $this->extractArgument($params, 'id');
61+
62+
/** @var callback $endpointBuilder */
63+
$endpointBuilder = $this->endpoints;
64+
65+
/** @var Cancel $endpoint */
66+
$endpoint = $endpointBuilder('Tasks\Cancel');
67+
$endpoint->setTaskId($id)
68+
->setParams($params);
69+
$response = $endpoint->performRequest();
70+
71+
return $endpoint->resultOrFuture($response);
72+
}
73+
74+
75+
}

0 commit comments

Comments
 (0)