All files / src/app/ceph/cluster/osd/osd-flags-modal osd-flags-modal.component.ts

100% Statements 39/39
77.27% Branches 17/22
100% Functions 10/10
100% Lines 35/35

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 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 1577x 7x   7x 7x 7x   7x 7x   7x 7x             7x     4x   4x                                                                                                                                                                                     4x     4x 4x 4x 4x 4x   4x     7x 1x 1x 3x 2x   1x     1x       7x 2x 13x 2x     2x   1x 1x     1x       7x  
import { Component, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
 
import { I18n } from '@ngx-translate/i18n-polyfill';
import * as _ from 'lodash';
import { BsModalRef } from 'ngx-bootstrap/modal';
 
import { OsdService } from '../../../../shared/api/osd.service';
import { NotificationType } from '../../../../shared/enum/notification-type.enum';
import { Permissions } from '../../../../shared/models/permissions';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../../shared/services/notification.service';
 
@Component({
  selector: 'cd-osd-flags-modal',
  template: require('./osd-flags-modal.component.html'),
  styles: []
})
export class OsdFlagsModalComponent implements OnInit {
  permissions: Permissions;
 
  osdFlagsForm = new FormGroup({});
 
  allFlags = {
    noin: {
      code: 'noin',
      name: this.i18n('No In'),
      value: false,
      description: this.i18n(
        'OSDs that were previously marked out will not be marked back in when they start'
      )
    },
    noout: {
      code: 'noout',
      name: this.i18n('No Out'),
      value: false,
      description: this.i18n(
        'OSDs will not automatically be marked out after the configured interval'
      )
    },
    noup: {
      code: 'noup',
      name: this.i18n('No Up'),
      value: false,
      description: this.i18n('OSDs are not allowed to start')
    },
    nodown: {
      code: 'nodown',
      name: this.i18n('No Down'),
      value: false,
      description: this.i18n(
        'OSD failure reports are being ignored, such that the monitors will not mark OSDs down'
      )
    },
    pause: {
      code: 'pause',
      name: this.i18n('Pause'),
      value: false,
      description: this.i18n('Pauses reads and writes')
    },
    noscrub: {
      code: 'noscrub',
      name: this.i18n('No Scrub'),
      value: false,
      description: this.i18n('Scrubbing is disabled')
    },
    'nodeep-scrub': {
      code: 'nodeep-scrub',
      name: this.i18n('No Deep Scrub'),
      value: false,
      description: this.i18n('Deep Scrubbing is disabled')
    },
    nobackfill: {
      code: 'nobackfill',
      name: this.i18n('No Backfill'),
      value: false,
      description: this.i18n('Backfilling of PGs is suspended')
    },
    norecover: {
      code: 'norecover',
      name: this.i18n('No Recover'),
      value: false,
      description: this.i18n('Recovery of PGs is suspended')
    },
    sortbitwise: {
      code: 'sortbitwise',
      name: this.i18n('Bitwise Sort'),
      value: false,
      description: this.i18n('Use bitwise sort'),
      disabled: true
    },
    purged_snapdirs: {
      code: 'purged_snapdirs',
      name: this.i18n('Purged Snapdirs'),
      value: false,
      description: this.i18n('OSDs have converted snapsets'),
      disabled: true
    },
    recovery_deletes: {
      code: 'recovery_deletes',
      name: this.i18n('Recovery Deletes'),
      value: false,
      description: this.i18n('Deletes performed during recovery instead of peering'),
      disabled: true
    },
    pglog_hardlimit: {
      code: 'pglog_hardlimit',
      name: this.i18n('PG Log Hard Limit'),
      value: false,
      description: this.i18n('Puts a hard limit on pg log length'),
      disabled: true
    }
  };
  flags: any[];
  unknownFlags: string[] = [];
 
  constructor(
    public bsModalRef: BsModalRef,
    private authStorageService: AuthStorageService,
    private osdService: OsdService,
    private notificationService: NotificationService,
    private i18n: I18n
  ) {
    this.permissions = this.authStorageService.getPermissions();
  }
 
  ngOnInit() {
    this.osdService.getFlags().subscribe((res: string[]) => {
      res.forEach((value) => {
        if (this.allFlags[value]) {
          this.allFlags[value].value = true;
        } else {
          this.unknownFlags.push(value);
        }
      });
      this.flags = _.toArray(this.allFlags);
    });
  }
 
  submitAction() {
    const newFlags = this.flags
      .filter((flag) => flag.value)
      .map((flag) => flag.code)
      .concat(this.unknownFlags);
 
    this.osdService.updateFlags(newFlags).subscribe(
      () => {
        this.notificationService.show(NotificationType.success, this.i18n('Updated OSD Flags'));
        this.bsModalRef.hide();
      },
      () => {
        this.bsModalRef.hide();
      }
    );
  }
}