1<?php 2 3namespace Elastica\Cluster\Health; 4 5/** 6 * Wraps status information for a shard. 7 * 8 * @author Ray Ward <ray.ward@bigcommerce.com> 9 * 10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html 11 */ 12class Shard 13{ 14 /** 15 * @var int the shard index/number 16 */ 17 protected $_shardNumber; 18 19 /** 20 * @var array the shard health data 21 */ 22 protected $_data; 23 24 /** 25 * @param int $shardNumber the shard index/number 26 * @param array $data the shard health data 27 */ 28 public function __construct(int $shardNumber, array $data) 29 { 30 $this->_shardNumber = $shardNumber; 31 $this->_data = $data; 32 } 33 34 /** 35 * Gets the index/number of this shard. 36 * 37 * @return int 38 */ 39 public function getShardNumber(): int 40 { 41 return $this->_shardNumber; 42 } 43 44 /** 45 * Gets the status of this shard. 46 * 47 * @return string green, yellow or red 48 */ 49 public function getStatus(): string 50 { 51 return $this->_data['status']; 52 } 53 54 /** 55 * Is the primary active? 56 * 57 * @return bool 58 */ 59 public function isPrimaryActive(): bool 60 { 61 return $this->_data['primary_active']; 62 } 63 64 /** 65 * Is this shard active? 66 * 67 * @return bool 68 */ 69 public function isActive(): bool 70 { 71 return 1 === $this->_data['active_shards']; 72 } 73 74 /** 75 * Is this shard relocating? 76 * 77 * @return bool 78 */ 79 public function isRelocating(): bool 80 { 81 return 1 === $this->_data['relocating_shards']; 82 } 83 84 /** 85 * Is this shard initialized? 86 * 87 * @return bool 88 */ 89 public function isInitialized(): bool 90 { 91 return 1 === $this->_data['initializing_shards']; 92 } 93 94 /** 95 * Is this shard unassigned? 96 * 97 * @return bool 98 */ 99 public function isUnassigned(): bool 100 { 101 return 1 === $this->_data['unassigned_shards']; 102 } 103} 104