Completed
Push — master ( 808702...a941cc )
by Nicolas
03:27
created

Health::getTaskMaxWaitingInQueueMillis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Elastica\Cluster;
3
4
use Elastica\Client;
5
use Elastica\Cluster\Health\Index;
6
7
/**
8
 * Elastic cluster health.
9
 *
10
 * @author Ray Ward <[email protected]>
11
 *
12
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html
13
 */
14
class Health
15
{
16
    /**
17
     * @var \Elastica\Client Client object.
18
     */
19
    protected $_client;
20
21
    /**
22
     * @var array The cluster health data.
23
     */
24
    protected $_data;
25
26
    /**
27
     * @param \Elastica\Client $client The Elastica client.
28
     */
29
    public function __construct(Client $client)
30
    {
31
        $this->_client = $client;
32
        $this->refresh();
33
    }
34
35
    /**
36
     * Retrieves the health data from the cluster.
37
     *
38
     * @return array
39
     */
40
    protected function _retrieveHealthData()
41
    {
42
        $endpoint = new \Elasticsearch\Endpoints\Cluster\Health();
43
        $endpoint->setParams(['level' => 'shards']);
44
45
        $response = $this->_client->requestEndpoint($endpoint);
46
47
        return $response->getData();
48
    }
49
50
    /**
51
     * Gets the health data.
52
     *
53
     * @return array
54
     */
55
    public function getData()
56
    {
57
        return $this->_data;
58
    }
59
60
    /**
61
     * Refreshes the health data for the cluster.
62
     *
63
     * @return $this
64
     */
65
    public function refresh()
66
    {
67
        $this->_data = $this->_retrieveHealthData();
68
69
        return $this;
70
    }
71
72
    /**
73
     * Gets the name of the cluster.
74
     *
75
     * @return string
76
     */
77
    public function getClusterName()
78
    {
79
        return $this->_data['cluster_name'];
80
    }
81
82
    /**
83
     * Gets the status of the cluster.
84
     *
85
     * @return string green, yellow or red.
86
     */
87
    public function getStatus()
88
    {
89
        return $this->_data['status'];
90
    }
91
92
    /**
93
     * TODO determine the purpose of this.
94
     *
95
     * @return bool
96
     */
97
    public function getTimedOut()
98
    {
99
        return $this->_data['timed_out'];
100
    }
101
102
    /**
103
     * Gets the number of nodes in the cluster.
104
     *
105
     * @return int
106
     */
107
    public function getNumberOfNodes()
108
    {
109
        return $this->_data['number_of_nodes'];
110
    }
111
112
    /**
113
     * Gets the number of data nodes in the cluster.
114
     *
115
     * @return int
116
     */
117
    public function getNumberOfDataNodes()
118
    {
119
        return $this->_data['number_of_data_nodes'];
120
    }
121
122
    /**
123
     * Gets the number of active primary shards.
124
     *
125
     * @return int
126
     */
127
    public function getActivePrimaryShards()
128
    {
129
        return $this->_data['active_primary_shards'];
130
    }
131
132
    /**
133
     * Gets the number of active shards.
134
     *
135
     * @return int
136
     */
137
    public function getActiveShards()
138
    {
139
        return $this->_data['active_shards'];
140
    }
141
142
    /**
143
     * Gets the number of relocating shards.
144
     *
145
     * @return int
146
     */
147
    public function getRelocatingShards()
148
    {
149
        return $this->_data['relocating_shards'];
150
    }
151
152
    /**
153
     * Gets the number of initializing shards.
154
     *
155
     * @return int
156
     */
157
    public function getInitializingShards()
158
    {
159
        return $this->_data['initializing_shards'];
160
    }
161
162
    /**
163
     * Gets the number of unassigned shards.
164
     *
165
     * @return int
166
     */
167
    public function getUnassignedShards()
168
    {
169
        return $this->_data['unassigned_shards'];
170
    }
171
172
    /**
173
     * get the number of delayed unassined shards
174
     *
175
     * @return int
176
     */
177
    public function getDelayedUnassignedShards()
178
    {
179
        return $this->_data['delayed_unassigned_shards'];
180
    }
181
182
    /**
183
     * @return int
184
     */
185
    public function getNumberOfPendingTasks()
186
    {
187
        return $this->_data['number_of_pending_tasks'];
188
    }
189
190
    /**
191
     * @return int
192
     */
193
    public function getNumberOfInFlightFetch()
194
    {
195
        return $this->_data['number_of_in_flight_fetch'];
196
    }
197
198
    /**
199
     * @return int
200
     */
201
    public function getTaskMaxWaitingInQueueMillis()
202
    {
203
        return $this->_data['task_max_waiting_in_queue_millis'];
204
    }
205
206
    /**
207
     * @return int
208
     */
209
    public function getActiveShardsPercentAsNumber()
210
    {
211
        return $this->_data['active_shards_percent_as_number'];
212
    }
213
214
    /**
215
     * Gets the status of the indices.
216
     *
217
     * @return \Elastica\Cluster\Health\Index[]
218
     */
219
    public function getIndices()
220
    {
221
        $indices = [];
222
        foreach ($this->_data['indices'] as $indexName => $index) {
223
            $indices[$indexName] = new Index($indexName, $index);
224
        }
225
226
        return $indices;
227
    }
228
}
229