Index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace Elastica\Cluster\Health;
  3. /**
  4. * Wraps status information for an index.
  5. *
  6. * @author Ray Ward <ray.ward@bigcommerce.com>
  7. *
  8. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html
  9. */
  10. class Index
  11. {
  12. /**
  13. * @var string the name of the index
  14. */
  15. protected $_name;
  16. /**
  17. * @var array the index health data
  18. */
  19. protected $_data;
  20. /**
  21. * @param string $name the name of the index
  22. * @param array $data the index health data
  23. */
  24. public function __construct($name, $data)
  25. {
  26. $this->_name = $name;
  27. $this->_data = $data;
  28. }
  29. /**
  30. * Gets the name of the index.
  31. *
  32. * @return string
  33. */
  34. public function getName()
  35. {
  36. return $this->_name;
  37. }
  38. /**
  39. * Gets the status of the index.
  40. *
  41. * @return string green, yellow or red
  42. */
  43. public function getStatus()
  44. {
  45. return $this->_data['status'];
  46. }
  47. /**
  48. * Gets the number of nodes in the index.
  49. *
  50. * @return int
  51. */
  52. public function getNumberOfShards()
  53. {
  54. return $this->_data['number_of_shards'];
  55. }
  56. /**
  57. * Gets the number of data nodes in the index.
  58. *
  59. * @return int
  60. */
  61. public function getNumberOfReplicas()
  62. {
  63. return $this->_data['number_of_replicas'];
  64. }
  65. /**
  66. * Gets the number of active primary shards.
  67. *
  68. * @return int
  69. */
  70. public function getActivePrimaryShards()
  71. {
  72. return $this->_data['active_primary_shards'];
  73. }
  74. /**
  75. * Gets the number of active shards.
  76. *
  77. * @return int
  78. */
  79. public function getActiveShards()
  80. {
  81. return $this->_data['active_shards'];
  82. }
  83. /**
  84. * Gets the number of relocating shards.
  85. *
  86. * @return int
  87. */
  88. public function getRelocatingShards()
  89. {
  90. return $this->_data['relocating_shards'];
  91. }
  92. /**
  93. * Gets the number of initializing shards.
  94. *
  95. * @return int
  96. */
  97. public function getInitializingShards()
  98. {
  99. return $this->_data['initializing_shards'];
  100. }
  101. /**
  102. * Gets the number of unassigned shards.
  103. *
  104. * @return int
  105. */
  106. public function getUnassignedShards()
  107. {
  108. return $this->_data['unassigned_shards'];
  109. }
  110. /**
  111. * Gets the health of the shards in this index.
  112. *
  113. * @return \Elastica\Cluster\Health\Shard[]
  114. */
  115. public function getShards()
  116. {
  117. $shards = [];
  118. foreach ($this->_data['shards'] as $shardNumber => $shard) {
  119. $shards[] = new Shard($shardNumber, $shard);
  120. }
  121. return $shards;
  122. }
  123. }