summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/DeploymentLogTable.php
blob: 48492188531a510ec1d5ab9a1ba7c79bc5d51c65 (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
<?php

namespace Icinga\Module\Director\Web\Table;

use gipfl\IcingaWeb2\Link;
use Icinga\Date\DateFormatter;

class DeploymentLogTable extends IntlZfQueryBasedTable
{
    use DbHelper;

    protected $activeStageName;

    public function setActiveStageName($name)
    {
        $this->activeStageName = $name;
        return $this;
    }

    public function assemble()
    {
        $this->getAttributes()->add('class', 'deployment-log');
    }

    public function renderRow($row)
    {
        $this->splitByDay($row->start_time);

        $shortSum = $this->getShortChecksum($row->config_checksum);
        $tr = $this::tr([
            $this::td(Link::create(
                $shortSum === null ? $row->peer_identity : [$row->peer_identity, " ($shortSum)"],
                'director/deployment',
                ['id' => $row->id]
            )),
            $this::td(DateFormatter::formatTime($row->start_time))
        ])->addAttributes(['class' => $this->getMyRowClasses($row)]);

        return $tr;
    }

    protected function getMyRowClasses($row)
    {
        if ($row->startup_succeeded === 'y') {
            $classes = ['succeeded'];
        } elseif ($row->startup_succeeded === 'n') {
            $classes = ['failed'];
        } elseif ($row->stage_collected === null) {
            $classes = ['pending'];
        } elseif ($row->dump_succeeded === 'y') {
            $classes = ['sent'];
        } else {
            // TODO: does this ever be stored?
            $classes = ['notsent'];
        }

        if ($this->activeStageName !== null
            && $row->stage_name === $this->activeStageName
        ) {
            $classes[] = 'running';
        }

        return $classes;
    }

    public function getColumns()
    {
        $columns = [
            'id'                => 'l.id',
            'peer_identity'     => 'l.peer_identity',
            'start_time'        => 'UNIX_TIMESTAMP(l.start_time)',
            'stage_collected'   => 'l.stage_collected',
            'dump_succeeded'    => 'l.dump_succeeded',
            'stage_name'        => 'l.stage_name',
            'startup_succeeded' => 'l.startup_succeeded',
            'config_checksum'   => 'l.config_checksum',
        ];

        return $columns;
    }

    public function prepareQuery()
    {
        return $this->db()->select()->from(
            array('l' => 'director_deployment_log'),
            $this->getColumns()
        )->order('l.start_time DESC')->limit(100);
    }
}