Skip to content

Commit

Permalink
Add Indices/Rollover endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jul 6, 2016
1 parent 6a315e0 commit 1ba8299
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/Elasticsearch/Endpoints/Indices/Rollover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Elasticsearch\Endpoints\Indices;

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

/**
* Class Rollover
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Indices
* @author Zachary Tong <zach@elastic.co>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elastic.co
*/
class Rollover extends AbstractEndpoint
{
private $alias;
private $newIndex;

/**
* @param string $alias
*
* @return $this
*/
public function setAlias($alias)
{
if ($alias === null) {
return $this;
}

$this->alias = urlencode($alias);
return $this;
}

/**
* @param string $newIndex
*
* @return $this
*/
public function setNewIndex($newIndex)
{
if ($newIndex === null) {
return $this;
}

$this->newIndex = urlencode($newIndex);
return $this;
}

/**
* @param array $body
*
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}

$this->body = $body;

return $this;
}

/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
protected function getURI()
{
if (isset($this->alias) !== true) {
throw new Exceptions\RuntimeException(
'alias name is required for Rollover'
);
}

$uri = "/{$this->alias}/_rollover";

if (isset($this->newIndex) === true) {
$uri .= "/{$this->newIndex}";
}

return $uri;
}

/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array(
'timeout',
'master_timeout'
);
}

/**
* @return string
*/
protected function getMethod()
{
return 'POST';
}
}
30 changes: 30 additions & 0 deletions src/Elasticsearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -1166,4 +1166,34 @@ public function shardStores($params)

return $endpoint->resultOrFuture($response);
}

/**
* $params['newIndex'] = (string) The name of the rollover index
* ['alias'] = (string) The name of the alias to rollover
* ['timeout'] = (time) Explicit operation timeout
* ['master_timeout'] = (time) Specify timeout for connection to master
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function rollover($params)
{
$newIndex = $this->extractArgument($params, 'newIndex');
$alias = $this->extractArgument($params, 'alias');
$body = $this->extractArgument($params, 'body');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->endpoints;

/** @var \Elasticsearch\Endpoints\Indices\Rollover $endpoint */
$endpoint = $endpointBuilder('Indices\Rollover');
$endpoint->setNewIndex($newIndex)
->setAlias($alias)
->setParams($params)
->setBody($body);
$response = $endpoint->performRequest();

return $endpoint->resultOrFuture($response);
}
}

0 comments on commit 1ba8299

Please sign in to comment.