summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.ts
blob: 9cc72ac96ad7501cb48bd685f8f9e665f42c3228 (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
import { Pipe, PipeTransform } from '@angular/core';

import _ from 'lodash';

@Pipe({
  name: 'mdsSummary'
})
export class MdsSummaryPipe implements PipeTransform {
  transform(value: any): any {
    if (!value) {
      return '';
    }

    let contentLine1 = '';
    let contentLine2 = '';
    let standbys = 0;
    let active = 0;
    let standbyReplay = 0;
    _.each(value.standbys, () => {
      standbys += 1;
    });

    if (value.standbys && !value.filesystems) {
      contentLine1 = `${standbys} ${$localize`up`}`;
      contentLine2 = $localize`no filesystems`;
    } else if (value.filesystems.length === 0) {
      contentLine1 = $localize`no filesystems`;
    } else {
      _.each(value.filesystems, (fs) => {
        _.each(fs.mdsmap.info, (mds) => {
          if (mds.state === 'up:standby-replay') {
            standbyReplay += 1;
          } else {
            active += 1;
          }
        });
      });

      contentLine1 = `${active} ${$localize`active`}`;
      contentLine2 = `${standbys + standbyReplay} ${$localize`standby`}`;
    }
    const standbyHoverText = value.standbys.map((s: any): string => s.name).join(', ');
    const standbyTitleText = !standbyHoverText
      ? ''
      : `${$localize`standby daemons`}: ${standbyHoverText}`;
    const fsLength = value.filesystems ? value.filesystems.length : 0;
    const infoObject = fsLength > 0 ? value.filesystems[0].mdsmap.info : {};
    const activeHoverText = Object.values(infoObject)
      .map((info: any): string => info.name)
      .join(', ');
    let activeTitleText = !activeHoverText ? '' : `${$localize`active daemon`}: ${activeHoverText}`;
    // There is always one standbyreplay to replace active daemon, if active one is down
    if (!active && fsLength > 0) {
      activeTitleText = `${standbyReplay} ${$localize`standbyReplay`}`;
    }
    const mgrSummary = [
      {
        content: contentLine1,
        class: 'popover-info',
        titleText: activeTitleText
      }
    ];
    if (contentLine2) {
      mgrSummary.push({
        content: '',
        class: 'card-text-line-break',
        titleText: ''
      });
      mgrSummary.push({
        content: contentLine2,
        class: 'popover-info',
        titleText: standbyTitleText
      });
    }

    return mgrSummary;
  }
}