4831: Rearrange some files.
[arvados.git] / apps / backstage / app / component.arv-api-status.js
1 module.exports = ArvApiStatusComponent;
2
3 var m = require('mithril')
4 , util = require('app/util');
5
6 function ArvApiStatusComponent(connection) {
7     var apistatus = {};
8     apistatus.vm = (function() {
9         var vm = {};
10         vm.connection = connection;
11         vm.dd = connection.discoveryDoc;
12         vm.dirty = true;
13         vm.init = function() {
14             if (vm.dirty)
15                 vm.refresh();
16             vm.dirty = false;
17         };
18         vm.keepServices = m.prop();
19         vm.nodes = m.prop();
20         vm.refresh = function() {
21             vm.connection.api(
22                 'KeepService', 'list', {}).then(vm.keepServices);
23             vm.connection.api(
24                 'Node', 'list', {}).then(vm.nodes);
25         };
26         vm.logout = function() {
27             vm.connection.token(undefined);
28         };
29         vm.ddSummary = function() {
30             return !vm.dd() ? {} : {
31                 apiVersion: vm.dd().version + ' (' + vm.dd().revision + ')',
32                 sourceVersion: m('a', {
33                     href: 'https://arvados.org/projects/arvados/repository/changes?rev=' + vm.dd().source_version
34                 }, vm.dd().source_version),
35                 generatedAt: vm.dd().generatedAt,
36                 websocket: util.choose(vm.connection.webSocket().readyState, {
37                     0: m('span.label.label-warning', ['connecting']),
38                     1: m('span.label.label-success', ['OK']),
39                     2: m('span.label.label-danger', ['closing']),
40                     3: m('span.label.label-danger', ['closed']),
41                 }) || m('span.label.label-danger',
42                         {title: ('advertised websocketUrl: ' +
43                                  vm.dd().websocketUrl)}, ['none'])
44             }
45         };
46         return vm;
47     })();
48     apistatus.controller = function() {
49         apistatus.vm.init();
50     };
51     apistatus.view = function() {
52         var vm = apistatus.vm;
53         var ddSummary = vm.ddSummary();
54         return m('.panel.panel-info.arv-bs-api-status', [
55             m('.panel-heading', [
56                 vm.connection.apiPrefix(),
57                 !vm.dd() ? '' : m('.pull-right', [
58                     util.choose(!!vm.connection.token(), {
59                         true: [function() {
60                             return m('a.btn.btn-xs.btn-default',
61                                      {onclick: vm.logout}, 'Log out');
62                         }],
63                         false: [function() {
64                             return m('a.btn.btn-xs.btn-primary',
65                                      {href: vm.connection.loginLink()}, 'Log in');
66                         }]
67                     }),
68                 ]),
69             ]),
70             m('.panel-body', !vm.dd() ? [vm.connection.state()] : [
71                 m('.row', [
72                     m('.col-md-4',
73                       Object.keys(ddSummary).map(function(key) {
74                           return m('.row', [
75                               m('.col-sm-4.lighten', key),
76                               m('.col-sm-8', ddSummary[key]),
77                           ]);
78                       })),
79                     m('.col-md-4', [
80                         !vm.keepServices() ? '' : m('ul', [
81                             '' + vm.keepServices().length + ' Keep services',
82                             vm.keepServices().map(function(keepService) {
83                                 return m('li', [
84                                     m('span.label.label-default',
85                                       keepService().service_type),
86                                     ' ',
87                                     m('a',
88                                       {href: '/show/'+keepService().uuid,
89                                        config: m.route}, [
90                                            keepService().service_host,
91                                            ':',
92                                            keepService().service_port,
93                                        ]),
94                                 ]);
95                             }),
96                         ]),
97                     ]),
98                     m('.col-md-4', [
99                         !vm.nodes() ? '' : m('ul', [
100                             '' + vm.nodes().length + ' worker nodes',
101                             vm.nodes().filter(function(node) {
102                                 return node().crunch_worker_state != 'down';
103                             }).map(function(node) {
104                                 return m('li', [
105                                     m('span.label.label-default', [
106                                         node().crunch_worker_state,
107                                     ]),
108                                     ' ',
109                                     m('a', {href: '/show/'+node().uuid,
110                                             config: m.route},
111                                       node().hostname),
112                                     ' ',
113                                     m('span.label.label-info', {title: 'time since last ping'}, [
114                                         ((new Date() - Date.parse(node().last_ping_at))/1000).toFixed(),
115                                         's'
116                                     ]),
117                                 ]);
118                             }),
119                         ]),
120                     ]),
121                 ]),
122                 m('.row', 'Collection Job PipelineInstance'.split(' ').map(function(arvModelName) {
123                     return m('.col-sm-2', [
124                         m('a.btn.btn-xs.btn-default', {
125                             style: 'width: 100%',
126                             href: '/list/'+vm.connection.apiPrefix()+'/'+arvModelName,
127                             config: m.route
128                         }, arvModelName+'s'),
129                     ]);
130                 })),
131             ]),
132         ]);
133     };
134     return apistatus;
135 }