# All files / src/app/ceph/dashboard mds-summary.pipe.ts

100% Statements 29/29
80% Branches 4/5
100% Functions 5/5
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    676x

    6x
    6x

    6x
    25x

    6x

    3x

    12x
    12x
    12x
    12x
    12x
    12x
    4x

    1x
    1x

    9x

    2x
    2x

    1x

    1x

    2x
    2x

    3x

    3x

    12x

    6x
     import { Pipe, PipeTransform } from '@angular/core';

    import { I18n } from '@ngx-translate/i18n-polyfill';
    import * as _ from 'lodash';

    @Pipe({
      name: 'mdsSummary'
    })
    export class MdsSummaryPipe implements PipeTransform {
      constructor(private i18n: I18n) {}

      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} ${this.i18n('up')}`;
          contentLine2 = this.i18n('no filesystems');
        } else if (value.filesystems.length === 0) {
          contentLine1 = this.i18n('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} ${this.i18n('active')}`;
          contentLine2 = `${standbys + standbyReplay} ${this.i18n('standby')}`;
        }

        const mgrSummary = [
          {
            content: contentLine1,
            class: ''
          }
        ];

        if (contentLine2) {
          mgrSummary.push({
            content: '',
            class: 'card-text-line-break'
          });
          mgrSummary.push({
            content: contentLine2,
            class: ''
          });
        }

        return mgrSummary;
      }
    }