Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indices Recovery : provides insight into on-going index shard recoveries #1537

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file based on the

* Added a transport class for mocking a HTTP 403 error codes, useful for testing response failures in inheriting clients
* [Field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) param for `Elastica\Query\FunctionScore::addRandomScoreFunction`
* [Index Recovery](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html) : the indices recovery API provides insight into on-going index shard recoveries. It was never been implemented into Elastica. [#1537](https://github.com/ruflin/Elastica/pull/1537)

### Improvements

Expand Down
11 changes: 11 additions & 0 deletions lib/Elastica/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Elastica\Exception\ResponseException;
use Elastica\Index\Settings as IndexSettings;
use Elastica\Index\Stats as IndexStats;
use Elastica\Index\Recovery as IndexRecovery;
use Elastica\ResultSet\BuilderInterface;
use Elastica\Script\AbstractScript;
use Elasticsearch\Endpoints\AbstractEndpoint;
Expand Down Expand Up @@ -87,6 +88,16 @@ public function getStats()
return new IndexStats($this);
}

/**
* Return Index Recovery.
*
* @return \Elastica\Index\Recovery
*/
public function getRecovery()
{
return new IndexRecovery($this);
}

/**
* Gets all the type mappings for an index.
*
Expand Down
100 changes: 100 additions & 0 deletions lib/Elastica/Index/Recovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
namespace Elastica\Index;

use Elastica\Index as BaseIndex;

/**
* Elastica index recovery object.
*
* @author Federico Panini <[email protected]>
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html
*/
class Recovery
{
/**
* Response.
*
* @var \Elastica\Response Response object
*/
protected $_response;

/**
* Recovery info.
*
* @var array Recovery info
*/
protected $_data = [];

/**
* Index.
*
* @var \Elastica\Index Index object
*/
protected $_index;

/**
* Construct.
*
* @param \Elastica\Index $index Index object
*/
public function __construct(BaseIndex $index)
{
$this->_index = $index;
$this->refresh();
}

/**
* Returns the index object.
*
* @return \Elastica\Index Index object
*/
public function getIndex()
{
return $this->_index;
}

/**
* Returns response object.
*
* @return \Elastica\Response Response object
*/
public function getResponse()
{
return $this->_response;
}

/**
* Returns the raw recovery info.
*
* @return array Recovery info
*/
public function getData()
{
return $this->_data;
}

/**
* @return mixed
*/
protected function getRecoveryData()
{
$endpoint = new \Elasticsearch\Endpoints\Indices\Recovery();

$this->_response = $this->getIndex()->requestEndpoint($endpoint);

return $this->getResponse()->getData();
}

/**
* Retrieve the Recovery data
*
* @return $this
*/
public function refresh()
{
$this->_data = $this->getRecoveryData();

return $this;
}
}
24 changes: 24 additions & 0 deletions test/Elastica/Index/RecoveryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace Elastica\Test\Index;

use Elastica\Index\Recovery;
use Elastica\Test\Base as BaseTest;

class RecoveryTest extends BaseTest
{
/**
* @group functional
*/
public function testGetSettings()
{
$indexName = 'test';

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$recovery = $index->getRecovery();
$this->assertInstanceOf(Recovery::class, $recovery);

$this->assertTrue($recovery->getResponse()->isOk());
}
}