Shard.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Elastica\Cluster\Health;
  3. /**
  4. * Wraps status information for a shard.
  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 Shard
  11. {
  12. /**
  13. * @var int the shard index/number
  14. */
  15. protected $_shardNumber;
  16. /**
  17. * @var array the shard health data
  18. */
  19. protected $_data;
  20. /**
  21. * @param int $shardNumber the shard index/number
  22. * @param array $data the shard health data
  23. */
  24. public function __construct($shardNumber, $data)
  25. {
  26. $this->_shardNumber = $shardNumber;
  27. $this->_data = $data;
  28. }
  29. /**
  30. * Gets the index/number of this shard.
  31. *
  32. * @return int
  33. */
  34. public function getShardNumber()
  35. {
  36. return $this->_shardNumber;
  37. }
  38. /**
  39. * Gets the status of this shard.
  40. *
  41. * @return string green, yellow or red
  42. */
  43. public function getStatus()
  44. {
  45. return $this->_data['status'];
  46. }
  47. /**
  48. * Is the primary active?
  49. *
  50. * @return bool
  51. */
  52. public function isPrimaryActive()
  53. {
  54. return $this->_data['primary_active'];
  55. }
  56. /**
  57. * Is this shard active?
  58. *
  59. * @return bool
  60. */
  61. public function isActive()
  62. {
  63. return 1 == $this->_data['active_shards'];
  64. }
  65. /**
  66. * Is this shard relocating?
  67. *
  68. * @return bool
  69. */
  70. public function isRelocating()
  71. {
  72. return 1 == $this->_data['relocating_shards'];
  73. }
  74. /**
  75. * Is this shard initialized?
  76. *
  77. * @return bool
  78. */
  79. public function isInitialized()
  80. {
  81. return 1 == $this->_data['initializing_shards'];
  82. }
  83. /**
  84. * Is this shard unassigned?
  85. *
  86. * @return bool
  87. */
  88. public function isUnassigned()
  89. {
  90. return 1 == $this->_data['unassigned_shards'];
  91. }
  92. }