summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Node
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
commit7e85254903c7c0cb49e381f16b18441ea7b058cc (patch)
treeb22328fcf4c8408fc25a7acb73d1cb1089cd82ac /vendor/ruflin/elastica/lib/Elastica/Node
parent1de335ad3f395ca6861085393ba366a9e3fb4a0d (diff)
parent1a365e77dfb8825136626202b1df462731b42060 (diff)
Merge commit '1a365e'
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Node')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Node/Info.php196
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Node/Stats.php115
2 files changed, 311 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Node/Info.php b/vendor/ruflin/elastica/lib/Elastica/Node/Info.php
new file mode 100644
index 00000000..1d04e53d
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Node/Info.php
@@ -0,0 +1,196 @@
+<?php
+
+namespace Elastica\Node;
+
+use Elastica\Node as BaseNode;
+use Elastica\Request;
+
+/**
+ * Elastica cluster node object
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-status.html
+ */
+class Info
+{
+ /**
+ * Response
+ *
+ * @var \Elastica\Response Response object
+ */
+ protected $_response = null;
+
+ /**
+ * Stats data
+ *
+ * @var array stats data
+ */
+ protected $_data = array();
+
+ /**
+ * Node
+ *
+ * @var \Elastica\Node Node object
+ */
+ protected $_node = null;
+
+ /**
+ * Query parameters
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * Create new info object for node
+ *
+ * @param \Elastica\Node $node Node object
+ * @param array $params List of params to return. Can be: settings, os, process, jvm, thread_pool, network, transport, http
+ */
+ public function __construct(BaseNode $node, array $params = array())
+ {
+ $this->_node = $node;
+ $this->refresh($params);
+ }
+
+ /**
+ * Returns the entry in the data array based on the params.
+ * Several params possible.
+ *
+ * Example 1: get('os', 'mem', 'total') returns total memory of the system the
+ * node is running on
+ * Example 2: get('os', 'mem') returns an array with all mem infos
+ *
+ * @return mixed Data array entry or null if not found
+ */
+ public function get()
+ {
+ $data = $this->getData();
+
+ foreach (func_get_args() as $arg) {
+ if (isset($data[$arg])) {
+ $data = $data[$arg];
+ } else {
+ return null;
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Return port of the node
+ *
+ * @return string Returns Node port
+ */
+ public function getPort()
+ {
+ // Returns string in format: inet[/192.168.1.115:9201]
+ $data = $this->get('http_address');
+ $data = substr($data, 6, strlen($data) - 7);
+ $data = explode(':', $data);
+
+ return $data[1];
+ }
+
+ /**
+ * Return IP of the node
+ *
+ * @return string Returns Node ip address
+ */
+ public function getIp()
+ {
+ // Returns string in format: inet[/192.168.1.115:9201]
+ $data = $this->get('http_address');
+ $data = substr($data, 6, strlen($data) - 7);
+ $data = explode(':', $data);
+
+ return $data[0];
+ }
+
+ /**
+ * Return data regarding plugins installed on this node
+ * @return array plugin data
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/
+ */
+ public function getPlugins()
+ {
+ if(!in_array('plugins', $this->_params)) {
+ //Plugin data was not retrieved when refresh() was called last. Get it now.
+ $this->_params[] = 'plugins';
+ $this->refresh($this->_params);
+ }
+ return $this->get('plugins');
+ }
+
+ /**
+ * Check if the given plugin is installed on this node
+ * @param string $name plugin name
+ * @return bool true if the plugin is installed, false otherwise
+ */
+ public function hasPlugin($name)
+ {
+ foreach($this->getPlugins() as $plugin) {
+ if($plugin['name'] == $name) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return all info data
+ *
+ * @return array Data array
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * Return node object
+ *
+ * @return \Elastica\Node Node object
+ */
+ public function getNode()
+ {
+ return $this->_node;
+ }
+
+ /**
+ * Returns response object
+ *
+ * @return \Elastica\Response Response object
+ */
+ public function getResponse()
+ {
+ return $this->_response;
+ }
+
+ /**
+ * Reloads all nodes information. Has to be called if informations changed
+ *
+ * @param array $params Params to return (default none). Possible options: settings, os, process, jvm, thread_pool, network, transport, http, plugin
+ * @return \Elastica\Response Response object
+ */
+ public function refresh(array $params = array())
+ {
+ $this->_params = $params;
+
+ $path = '_nodes/' . $this->getNode()->getName();
+
+ if (!empty($params)) {
+ $path .= '?';
+ foreach ($params as $param) {
+ $path .= $param . '=true&';
+ }
+ }
+
+ $this->_response = $this->getNode()->getClient()->request($path, Request::GET);
+ $data = $this->getResponse()->getData();
+ $this->_data = reset($data['nodes']);
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Node/Stats.php b/vendor/ruflin/elastica/lib/Elastica/Node/Stats.php
new file mode 100644
index 00000000..d918e686
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Node/Stats.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Elastica\Node;
+
+use Elastica\Node as BaseNode;
+use Elastica\Request;
+
+/**
+ * Elastica cluster node object
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-status.html
+ */
+class Stats
+{
+ /**
+ * Response
+ *
+ * @var \Elastica\Response Response object
+ */
+ protected $_response = null;
+
+ /**
+ * Stats data
+ *
+ * @var array stats data
+ */
+ protected $_data = array();
+
+ /**
+ * Node
+ *
+ * @var \Elastica\Node Node object
+ */
+ protected $_node = null;
+
+ /**
+ * Create new stats for node
+ *
+ * @param \Elastica\Node $node Elastica node object
+ */
+ public function __construct(BaseNode $node)
+ {
+ $this->_node = $node;
+ $this->refresh();
+ }
+
+ /**
+ * Returns all node stats as array based on the arguments
+ *
+ * Several arguments can be use
+ * get('index', 'test', 'example')
+ *
+ * @return array Node stats for the given field or null if not found
+ */
+ public function get()
+ {
+ $data = $this->getData();
+
+ foreach (func_get_args() as $arg) {
+ if (isset($data[$arg])) {
+ $data = $data[$arg];
+ } else {
+ return null;
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Returns all stats data
+ *
+ * @return array Data array
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * Returns node object
+ *
+ * @return \Elastica\Node Node object
+ */
+ public function getNode()
+ {
+ return $this->_node;
+ }
+
+ /**
+ * Returns response object
+ *
+ * @return \Elastica\Response Response object
+ */
+ public function getResponse()
+ {
+ return $this->_response;
+ }
+
+ /**
+ * Reloads all nodes information. Has to be called if informations changed
+ *
+ * @return \Elastica\Response Response object
+ */
+ public function refresh()
+ {
+ $path = '_nodes/' . $this->getNode()->getName() . '/stats';
+ $this->_response = $this->getNode()->getClient()->request($path, Request::GET);
+ $data = $this->getResponse()->getData();
+ $this->_data = reset($data['nodes']);
+ }
+}