Skip to content

Commit 7fc86e0

Browse files
p365labsruflin
authored andcommitted
Indices Recovery : provides insight into on-going index shard recoveries (#1537)
1 parent d45df9f commit 7fc86e0

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file based on the
1717

1818
* Added a transport class for mocking a HTTP 403 error codes, useful for testing response failures in inheriting clients
1919
* [Field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) param for `Elastica\Query\FunctionScore::addRandomScoreFunction`
20+
* [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)
2021

2122
### Improvements
2223

lib/Elastica/Index.php

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Elastica\Exception\ResponseException;
66
use Elastica\Index\Settings as IndexSettings;
77
use Elastica\Index\Stats as IndexStats;
8+
use Elastica\Index\Recovery as IndexRecovery;
89
use Elastica\ResultSet\BuilderInterface;
910
use Elastica\Script\AbstractScript;
1011
use Elasticsearch\Endpoints\AbstractEndpoint;
@@ -87,6 +88,16 @@ public function getStats()
8788
return new IndexStats($this);
8889
}
8990

91+
/**
92+
* Return Index Recovery.
93+
*
94+
* @return \Elastica\Index\Recovery
95+
*/
96+
public function getRecovery()
97+
{
98+
return new IndexRecovery($this);
99+
}
100+
90101
/**
91102
* Gets all the type mappings for an index.
92103
*

lib/Elastica/Index/Recovery.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
namespace Elastica\Index;
3+
4+
use Elastica\Index as BaseIndex;
5+
6+
/**
7+
* Elastica index recovery object.
8+
*
9+
* @author Federico Panini <[email protected]>
10+
*
11+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html
12+
*/
13+
class Recovery
14+
{
15+
/**
16+
* Response.
17+
*
18+
* @var \Elastica\Response Response object
19+
*/
20+
protected $_response;
21+
22+
/**
23+
* Recovery info.
24+
*
25+
* @var array Recovery info
26+
*/
27+
protected $_data = [];
28+
29+
/**
30+
* Index.
31+
*
32+
* @var \Elastica\Index Index object
33+
*/
34+
protected $_index;
35+
36+
/**
37+
* Construct.
38+
*
39+
* @param \Elastica\Index $index Index object
40+
*/
41+
public function __construct(BaseIndex $index)
42+
{
43+
$this->_index = $index;
44+
$this->refresh();
45+
}
46+
47+
/**
48+
* Returns the index object.
49+
*
50+
* @return \Elastica\Index Index object
51+
*/
52+
public function getIndex()
53+
{
54+
return $this->_index;
55+
}
56+
57+
/**
58+
* Returns response object.
59+
*
60+
* @return \Elastica\Response Response object
61+
*/
62+
public function getResponse()
63+
{
64+
return $this->_response;
65+
}
66+
67+
/**
68+
* Returns the raw recovery info.
69+
*
70+
* @return array Recovery info
71+
*/
72+
public function getData()
73+
{
74+
return $this->_data;
75+
}
76+
77+
/**
78+
* @return mixed
79+
*/
80+
protected function getRecoveryData()
81+
{
82+
$endpoint = new \Elasticsearch\Endpoints\Indices\Recovery();
83+
84+
$this->_response = $this->getIndex()->requestEndpoint($endpoint);
85+
86+
return $this->getResponse()->getData();
87+
}
88+
89+
/**
90+
* Retrieve the Recovery data
91+
*
92+
* @return $this
93+
*/
94+
public function refresh()
95+
{
96+
$this->_data = $this->getRecoveryData();
97+
98+
return $this;
99+
}
100+
}

test/Elastica/Index/RecoveryTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace Elastica\Test\Index;
3+
4+
use Elastica\Index\Recovery;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class RecoveryTest extends BaseTest
8+
{
9+
/**
10+
* @group functional
11+
*/
12+
public function testGetSettings()
13+
{
14+
$indexName = 'test';
15+
16+
$client = $this->_getClient();
17+
$index = $client->getIndex($indexName);
18+
$index->create([], true);
19+
$recovery = $index->getRecovery();
20+
$this->assertInstanceOf(Recovery::class, $recovery);
21+
22+
$this->assertTrue($recovery->getResponse()->isOk());
23+
}
24+
}

0 commit comments

Comments
 (0)