summaryrefslogtreecommitdiffstats
path: root/webapp/components/admin_console/cluster_table.jsx
blob: 34df047102a02d321a58e50276732ea6455b28e2 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import {FormattedMessage} from 'react-intl';
import * as Utils from 'utils/utils.jsx';

import statusGreen from 'images/status_green.png';
import statusRed from 'images/status_red.png';

export default class ClusterTable extends React.Component {
    static propTypes = {
        clusterInfos: React.PropTypes.array.isRequired,
        reload: React.PropTypes.func.isRequired
    }

    render() {
        var versionMismatch = (
            <img
                className='cluster-status'
                src={statusGreen}
            />
        );

        var configMismatch = (
            <img
                className='cluster-status'
                src={statusGreen}
            />
        );

        var version = '';
        var configHash = '';

        if (this.props.clusterInfos.length) {
            version = this.props.clusterInfos[0].version;
            configHash = this.props.clusterInfos[0].config_hash;
        }

        this.props.clusterInfos.map((clusterInfo) => {
            if (clusterInfo.version !== version) {
                versionMismatch = (
                    <img
                        className='cluster-status'
                        src={statusRed}
                    />
                );
            }

            if (clusterInfo.config_hash !== configHash) {
                configMismatch = (
                    <img
                        className='cluster-status'
                        src={statusRed}
                    />
                );
            }

            return null;
        });

        var items = this.props.clusterInfos.map((clusterInfo) => {
            var status = null;

            if (clusterInfo.hostname === '') {
                clusterInfo.hostname = Utils.localizeMessage('admin.cluster.unknown', 'unknown');
            }

            if (clusterInfo.version === '') {
                clusterInfo.version = Utils.localizeMessage('admin.cluster.unknown', 'unknown');
            }

            if (clusterInfo.config_hash === '') {
                clusterInfo.config_hash = Utils.localizeMessage('admin.cluster.unknown', 'unknown');
            }

            if (clusterInfo.id === '') {
                clusterInfo.id = Utils.localizeMessage('admin.cluster.unknown', 'unknown');
            }

            if (clusterInfo.is_alive > 0) {
                status = (
                    <img
                        className='cluster-status'
                        src={statusGreen}
                    />
                );
            } else {
                status = (
                    <img
                        className='cluster-status'
                        src={statusRed}
                    />
                );
            }

            return (
                <tr key={clusterInfo.id}>
                    <td style={{whiteSpace: 'nowrap'}}>{status}</td>
                    <td style={{whiteSpace: 'nowrap'}}>{clusterInfo.hostname}</td>
                    <td style={{whiteSpace: 'nowrap'}}>{versionMismatch} {clusterInfo.version}</td>
                    <td style={{whiteSpace: 'nowrap'}}><div className='config-hash'>{configMismatch} {clusterInfo.config_hash}</div></td>
                    <td style={{whiteSpace: 'nowrap'}}>{clusterInfo.internode_url}</td>
                    <td style={{whiteSpace: 'nowrap'}}><div className='config-hash'>{clusterInfo.id}</div></td>
                </tr>
            );
        });

        return (
            <div
                className='cluster-panel__table'
                style={{
                    margin: '10px',
                    marginBottom: '30px'
                }}
            >
                <div className='text-right'>
                    <button
                        type='submit'
                        className='btn btn-link'
                        onClick={this.props.reload}
                    >
                        <i className='fa fa-refresh'/>
                        <FormattedMessage
                            id='admin.cluster.status_table.reload'
                            defaultMessage=' Reload Cluster Status'
                        />
                    </button>
                </div>
                <table className='table'>
                    <thead>
                        <tr>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.status'
                                    defaultMessage='Status'
                                />
                            </th>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.hostname'
                                    defaultMessage='Hostname'
                                />
                            </th>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.version'
                                    defaultMessage='Version'
                                />
                            </th>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.config_hash'
                                    defaultMessage='Config File MD5'
                                />
                            </th>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.url'
                                    defaultMessage='Inter-Node URL'
                                />
                            </th>
                            <th>
                                <FormattedMessage
                                    id='admin.cluster.status_table.id'
                                    defaultMessage='Node ID'
                                />
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {items}
                    </tbody>
                </table>
            </div>
        );
    }
}