blob: 18c77cfcdea6dc1e78c882d71b20c2c1d82e21d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
<?php
namespace Elastica\Cluster;
use Elastica\Client;
use Elastica\Cluster\Health\Index;
use Elastica\Request;
/**
* Elastic cluster health.
*
* @package Elastica
* @author Ray Ward <ray.ward@bigcommerce.com>
* @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html
*/
class Health
{
/**
* Elastica client.
*
* @var \Elastica\Client Client object
*/
protected $_client = null;
/**
* The cluster health data.
*
* @var array
*/
protected $_data = null;
/**
* @param \Elastica\Client $client The Elastica client.
*/
public function __construct(Client $client)
{
$this->_client = $client;
$this->refresh();
}
/**
* Retrieves the health data from the cluster.
*
* @return array
*/
protected function _retrieveHealthData()
{
$path = '_cluster/health?level=shards';
$response = $this->_client->request($path, Request::GET);
return $response->getData();
}
/**
* Gets the health data.
*
* @return array
*/
public function getData()
{
return $this->_data;
}
/**
* Refreshes the health data for the cluster.
*
* @return \Elastica\Cluster\Health
*/
public function refresh()
{
$this->_data = $this->_retrieveHealthData();
return $this;
}
/**
* Gets the name of the cluster.
*
* @return string
*/
public function getClusterName()
{
return $this->_data['cluster_name'];
}
/**
* Gets the status of the cluster.
*
* @return string green, yellow or red.
*/
public function getStatus()
{
return $this->_data['status'];
}
/**
* TODO determine the purpose of this.
*
* @return bool
*/
public function getTimedOut()
{
return $this->_data['timed_out'];
}
/**
* Gets the number of nodes in the cluster.
*
* @return int
*/
public function getNumberOfNodes()
{
return $this->_data['number_of_nodes'];
}
/**
* Gets the number of data nodes in the cluster.
*
* @return int
*/
public function getNumberOfDataNodes()
{
return $this->_data['number_of_data_nodes'];
}
/**
* Gets the number of active primary shards.
*
* @return int
*/
public function getActivePrimaryShards()
{
return $this->_data['active_primary_shards'];
}
/**
* Gets the number of active shards.
*
* @return int
*/
public function getActiveShards()
{
return $this->_data['active_shards'];
}
/**
* Gets the number of relocating shards.
*
* @return int
*/
public function getRelocatingShards()
{
return $this->_data['relocating_shards'];
}
/**
* Gets the number of initializing shards.
*
* @return int
*/
public function getInitializingShards()
{
return $this->_data['initializing_shards'];
}
/**
* Gets the number of unassigned shards.
*
* @return int
*/
public function getUnassignedShards()
{
return $this->_data['unassigned_shards'];
}
/**
* Gets the status of the indices.
*
* @return \Elastica\Cluster\Health\Index[]
*/
public function getIndices()
{
$indices = array();
foreach ($this->_data['indices'] as $indexName => $index) {
$indices[] = new Index($indexName, $index);
}
return $indices;
}
}
|