1 | <?php |
||
8 | final class ServerGroup extends \SimpleSAML\Module\monitor\TestCaseFactory |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $tests = array(); |
||
14 | |||
15 | /** |
||
16 | * @var string|null |
||
17 | */ |
||
18 | private $group = null; |
||
19 | |||
20 | /** |
||
21 | * @param TestData $testData |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | protected function initialize($testData) |
||
26 | { |
||
27 | $this->tests = \SimpleSAML\Utils\Array::Arrayize($testData->getInput('tests')); |
||
|
|||
28 | $this->group = $testData->getInput('group'); |
||
29 | |||
30 | parent::initialize($testData); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @return void |
||
35 | */ |
||
36 | protected function invokeTest() |
||
37 | { |
||
38 | $states = array(); |
||
39 | foreach ($this->tests as $server) { |
||
40 | $states[] = $server->getState(); |
||
41 | } |
||
42 | $state = min($states); |
||
43 | $this->setState($state); |
||
44 | |||
45 | if ($state === State::OK) { |
||
46 | $this->addMessage(State::OK, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is healthy'); |
||
47 | } elseif ($state === State::WARNING) { |
||
48 | $this->addMessage(State::WARNING, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is crippled'); |
||
49 | } else { |
||
50 | $this->addMessage(State::ERROR, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is down'); |
||
51 | } |
||
52 | |||
53 | foreach ($this->tests as $server) { |
||
54 | $this->addOutput($server->getOutput()); |
||
55 | $this->setMessages(array_merge($this->getMessages(), $server->getMessages())); |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 |