Skip to content

Commit

Permalink
Add Ingest namespace and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Apr 1, 2016
1 parent 3fa1c51 commit 7b87954
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Elasticsearch/Client.php
Expand Up @@ -12,6 +12,7 @@
use Elasticsearch\Namespaces\NodesNamespace;
use Elasticsearch\Namespaces\SnapshotNamespace;
use Elasticsearch\Namespaces\BooleanRequestWrapper;
use Elasticsearch\Namespaces\TasksNamespace;

/**
* Class Client
Expand Down Expand Up @@ -64,6 +65,11 @@ class Client
*/
protected $ingest;

/**
* @var TasksNamespace
*/
protected $tasks;

/** @var callback */
protected $endpoints;

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

/**
Expand Down Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions src/Elasticsearch/Endpoints/Tasks/Cancel.php
@@ -0,0 +1,71 @@
<?php

namespace Elasticsearch\Endpoints\Tasks;

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

/**
* Class Cancel
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Tasks
* @author Zachary Tong <zachary.tong@elasticsearch.com>
* @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';
}
}
74 changes: 74 additions & 0 deletions src/Elasticsearch/Endpoints/Tasks/Get.php
@@ -0,0 +1,74 @@
<?php

namespace Elasticsearch\Endpoints\Tasks;

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

/**
* Class Get
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Tasks
* @author Zachary Tong <zachary.tong@elasticsearch.com>
* @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';
}
}
75 changes: 75 additions & 0 deletions src/Elasticsearch/Namespaces/TasksNamespace.php
@@ -0,0 +1,75 @@
<?php

namespace Elasticsearch\Namespaces;
use Elasticsearch\Endpoints\Tasks\Cancel;
use Elasticsearch\Endpoints\Tasks\Get;


/**
* Class TasksNamespace
*
* @category Elasticsearch
* @package Elasticsearch\Namespaces\TasksNamespace
* @author Zachary Tong <zachary.tong@elasticsearch.com>
* @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);
}


}

0 comments on commit 7b87954

Please sign in to comment.