1
|
|
|
<?php |
2
|
|
|
namespace Elastica; |
3
|
|
|
|
4
|
|
|
use Elastica\Node\Info; |
5
|
|
|
use Elastica\Node\Stats; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Elastica cluster node object. |
9
|
|
|
* |
10
|
|
|
* @author Nicolas Ruflin <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Node |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Client. |
16
|
|
|
* |
17
|
|
|
* @var \Elastica\Client |
18
|
|
|
*/ |
19
|
|
|
protected $_client; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string Unique node id |
23
|
|
|
*/ |
24
|
|
|
protected $_id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Node name. |
28
|
|
|
* |
29
|
|
|
* @var string Node name |
30
|
|
|
*/ |
31
|
|
|
protected $_name; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Node stats. |
35
|
|
|
* |
36
|
|
|
* @var \Elastica\Node\Stats|null Node Stats |
37
|
|
|
*/ |
38
|
|
|
protected $_stats; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Node info. |
42
|
|
|
* |
43
|
|
|
* @var \Elastica\Node\Info|null Node info |
44
|
|
|
*/ |
45
|
|
|
protected $_info; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a new node object. |
49
|
|
|
* |
50
|
|
|
* @param string $id Node id or name |
51
|
|
|
* @param \Elastica\Client $client Node object |
52
|
|
|
*/ |
53
|
|
|
public function __construct($id, Client $client) |
54
|
|
|
{ |
55
|
|
|
$this->_client = $client; |
56
|
|
|
$this->setId($id); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string Unique node id. Can also be name if id not exists. |
61
|
|
|
*/ |
62
|
|
|
public function getId() |
63
|
|
|
{ |
64
|
|
|
return $this->_id; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $id Node id |
69
|
|
|
* |
70
|
|
|
* @return $this Refreshed object |
71
|
|
|
*/ |
72
|
|
|
public function setId($id) |
73
|
|
|
{ |
74
|
|
|
$this->_id = $id; |
75
|
|
|
|
76
|
|
|
return $this->refresh(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the name of the node. |
81
|
|
|
* |
82
|
|
|
* @return string Node name |
83
|
|
|
*/ |
84
|
|
|
public function getName() |
85
|
|
|
{ |
86
|
|
|
if (empty($this->_name)) { |
87
|
|
|
$this->_name = $this->getInfo()->getName(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->_name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the current client object. |
95
|
|
|
* |
96
|
|
|
* @return \Elastica\Client Client |
97
|
|
|
*/ |
98
|
|
|
public function getClient() |
99
|
|
|
{ |
100
|
|
|
return $this->_client; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Return stats object of the current node. |
105
|
|
|
* |
106
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html |
107
|
|
|
* |
108
|
|
|
* @return \Elastica\Node\Stats Node stats |
109
|
|
|
*/ |
110
|
|
|
public function getStats() |
111
|
|
|
{ |
112
|
|
|
if (!$this->_stats) { |
113
|
|
|
$this->_stats = new Stats($this); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->_stats; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return info object of the current node. |
121
|
|
|
* |
122
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html |
123
|
|
|
* |
124
|
|
|
* @return \Elastica\Node\Info Node info object |
125
|
|
|
*/ |
126
|
|
|
public function getInfo() |
127
|
|
|
{ |
128
|
|
|
if (!$this->_info) { |
129
|
|
|
$this->_info = new Info($this); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this->_info; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Refreshes all node information. |
137
|
|
|
* |
138
|
|
|
* This should be called after updating a node to refresh all information |
139
|
|
|
*/ |
140
|
|
|
public function refresh() |
141
|
|
|
{ |
142
|
|
|
$this->_stats = null; |
143
|
|
|
$this->_info = null; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|