Permalink
Browse files

Merge #264

  • Loading branch information...
ruflin committed Nov 10, 2012
2 parents 087a6b9 + a879d6e commit 3122a5cd93963443e92306c9f5d2bbf38be4b49f
View
@@ -1,5 +1,11 @@
CHANGES
+2012-11-10
+- Added Elastica_Cluster_Health, Elastica_Cluster_Health_Index and Elastica_Cluster_Health_Shard which wrap the _cluster/health endpoint.
+- Added Elastica_Document::setId()
+- Added options parameter to Elastica_Type::getDocument()
+- Added Elastica_Query_Filtered::getFilter()
+
2012-10-30
- Elastica_Search implement Elastica_Searchable interface
View
@@ -16,6 +16,20 @@ class Elastica_Cluster
*/
protected $_client = null;
+ /**
+ * Cluster state response.
+ *
+ * @var Elastica_Response
+ */
+ protected $_response;
+
+ /**
+ * Cluster state data.
+ *
+ * @var array
+ */
+ protected $_data;
+
/**
* Creates a cluster object
*
@@ -126,12 +140,12 @@ public function getInfo(array $args)
/**
* Return Cluster health
*
- * @param array $args OPTIONAL
- * @link http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/cluster/health/
+ * @return Elastica_Cluster_Health
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html
*/
- public function getHealth($args = array())
+ public function getHealth()
{
- throw new Exception('not implemented yet');
+ return new Elastica_Cluster_Health($this->getClient());
}
/**
@@ -0,0 +1,183 @@
+<?php
+
+/**
+ * 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 Elastica_Cluster_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(Elastica_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, Elastica_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 array Array of Elastica_Cluster_Health_Index objects.
+ */
+ public function getIndices()
+ {
+ $indices = array();
+ foreach ($this->_data['indices'] as $indexName => $index) {
+ $indices[] = new Elastica_Cluster_Health_Index($indexName, $index);
+ }
+
+ return $indices;
+ }
+}
+
@@ -0,0 +1,140 @@
+<?php
+
+/**
+ * Wraps status information for an index.
+ *
+ * @package Elastica
+ * @author Ray Ward <ray.ward@bigcommerce.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html
+ */
+class Elastica_Cluster_Health_Index
+{
+ /**
+ * The name of the index.
+ *
+ * @var string
+ */
+ protected $_name;
+
+ /**
+ * The index health data.
+ *
+ * @var array
+ */
+ protected $_data;
+
+ /**
+ * @param string $name The name of the index.
+ * @param array $data The index health data.
+ */
+ public function __construct($name, $data)
+ {
+ $this->_name = $name;
+ $this->_data = $data;
+ }
+
+ /**
+ * Gets the name of the index.
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * Gets the status of the index.
+ *
+ * @return string green, yellow or red.
+ */
+ public function getStatus()
+ {
+ return $this->_data['status'];
+ }
+
+ /**
+ * Gets the number of nodes in the index.
+ *
+ * @return int
+ */
+ public function getNumberOfShards()
+ {
+ return $this->_data['number_of_shards'];
+ }
+
+ /**
+ * Gets the number of data nodes in the index.
+ *
+ * @return int
+ */
+ public function getNumberOfReplicas()
+ {
+ return $this->_data['number_of_replicas'];
+ }
+
+ /**
+ * 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 health of the shards in this index.
+ *
+ * @return array Array of Elastica_Cluster_Health_Shard objects.
+ */
+ public function getShards()
+ {
+ $shards = array();
+ foreach ($this->_data['shards'] as $shardNumber => $shard) {
+ $shards[] = new Elastica_Cluster_Health_Shard($shardNumber, $shard);
+ }
+
+ return $shards;
+ }
+}
Oops, something went wrong.

0 comments on commit 3122a5c

Please sign in to comment.