summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Cluster/Health/Shard.php
blob: a5da08ae72fa36a31a59f86ef4622f67c343df08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

namespace Elastica\Cluster\Health;

/**
 * Wraps status information for a shard.
 *
 * @package Elastica
 * @author Ray Ward <ray.ward@bigcommerce.com>
 * @link http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html
 */
class Shard
{
    /**
     * The shard index/number.
     *
     * @var int
     */
    protected $_shardNumber;

    /**
     * The shard health data.
     *
     * @var array
     */
    protected $_data;

    /**
     * @param int   $shardNumber The shard index/number.
     * @param array $data        The shard health data.
     */
    public function __construct($shardNumber, $data)
    {
        $this->_shardNumber = $shardNumber;
        $this->_data = $data;
    }

    /**
     * Gets the index/number of this shard.
     *
     * @return int
     */
    public function getShardNumber()
    {
        return $this->_shardNumber;
    }

    /**
     * Gets the status of this shard.
     *
     * @return string green, yellow or red.
     */
    public function getStatus()
    {
        return $this->_data['status'];
    }

    /**
     * Is the primary active?
     *
     * @return bool
     */
    public function isPrimaryActive()
    {
        return $this->_data['primary_active'];
    }

    /**
     * Is this shard active?
     *
     * @return bool
     */
    public function isActive()
    {
        return $this->_data['active_shards'] == 1;
    }

    /**
     * Is this shard relocating?
     *
     * @return bool
     */
    public function isRelocating()
    {
        return $this->_data['relocating_shards'] == 1;
    }

    /**
     * Is this shard initialized?
     *
     * @return bool
     */
    public function isInitialized()
    {
        return $this->_data['initializing_shards'] == 1;
    }

    /**
     * Is this shard unassigned?
     *
     * @return bool
     */
    public function isUnassigned()
    {
        return $this->_data['unassigned_shards'] == 1;
    }
}