protected function populateNodes()
{
$node = reset($this->nodes);
$host = $node['http_address'];
$protocol = isset($node['protocol']) ? $node['protocol'] : $this->defaultProtocol;
if (strncmp($host, 'inet[/', 6) === 0) {
$host = substr($host, 6, -1);
}
$response = $this->httpRequest('GET', "{$protocol}://{$host}/_nodes");
if (!empty($response['nodes'])) {
$nodes = $response['nodes'];
} else {
$nodes = [];
}
foreach ($nodes as $key => &$node) {
// Make sure that nodes have an 'http_address' property, which is not the case if you're using AWS
// Elasticsearch service (at least as of Oct., 2015). - TO BE VERIFIED
// Temporary workaround - simply ignore all invalid nodes
if (!isset($node['http_address'])) {
unset($nodes[$key]);
}
//Protocol is not a standard ES node property, so we add it manually
$node['protocol'] = $this->defaultProtocol;
}
if (!empty($nodes)) {
$this->nodes = array_values($nodes);
} else {
curl_close($this->_curl);
throw new Exception('Cluster autodetection did not find any active nodes.');
}
}