]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
652c9afa58b1c864bbcebb5de948ad1045dec9b4
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { FormGroup } from '@angular/forms';
3
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5 import _ from 'lodash';
6
7 import { OsdService } from '~/app/shared/api/osd.service';
8 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
9 import { Flag } from '~/app/shared/models/flag';
10 import { Permissions } from '~/app/shared/models/permissions';
11 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
12 import { NotificationService } from '~/app/shared/services/notification.service';
13
14 @Component({
15   selector: 'cd-osd-flags-indiv-modal',
16   templateUrl: './osd-flags-indiv-modal.component.html',
17   styleUrls: ['./osd-flags-indiv-modal.component.scss']
18 })
19 export class OsdFlagsIndivModalComponent implements OnInit {
20   permissions: Permissions;
21   selected: object[];
22   initialSelection: Flag[] = [];
23   osdFlagsForm = new FormGroup({});
24   flags: Flag[] = [
25     {
26       code: 'noup',
27       name: $localize`No Up`,
28       description: $localize`OSDs are not allowed to start`,
29       value: false,
30       clusterWide: false,
31       indeterminate: false
32     },
33     {
34       code: 'nodown',
35       name: $localize`No Down`,
36       description: $localize`OSD failure reports are being ignored, such that the monitors will not mark OSDs down`,
37       value: false,
38       clusterWide: false,
39       indeterminate: false
40     },
41     {
42       code: 'noin',
43       name: $localize`No In`,
44       description: $localize`OSDs that were previously marked out will not be marked back in when they start`,
45       value: false,
46       clusterWide: false,
47       indeterminate: false
48     },
49     {
50       code: 'noout',
51       name: $localize`No Out`,
52       description: $localize`OSDs will not automatically be marked out after the configured interval`,
53       value: false,
54       clusterWide: false,
55       indeterminate: false
56     }
57   ];
58   clusterWideTooltip: string = $localize`The flag has been enabled for the entire cluster.`;
59
60   constructor(
61     public activeModal: NgbActiveModal,
62     private authStorageService: AuthStorageService,
63     private osdService: OsdService,
64     private notificationService: NotificationService
65   ) {
66     this.permissions = this.authStorageService.getPermissions();
67   }
68
69   ngOnInit() {
70     const osdCount = this.selected.length;
71     this.osdService.getFlags().subscribe((clusterWideFlags: string[]) => {
72       const activatedIndivFlags = this.getActivatedIndivFlags();
73       this.flags.forEach((flag) => {
74         const flagCount = activatedIndivFlags[flag.code];
75         if (clusterWideFlags.includes(flag.code)) {
76           flag.clusterWide = true;
77         }
78
79         if (flagCount === osdCount) {
80           flag.value = true;
81         } else if (flagCount > 0) {
82           flag.indeterminate = true;
83         }
84       });
85       this.initialSelection = _.cloneDeep(this.flags);
86     });
87   }
88
89   getActivatedIndivFlags(): { [flag: string]: number } {
90     const flagsCount = {};
91     this.flags.forEach((flag) => {
92       flagsCount[flag.code] = 0;
93     });
94
95     [].concat(...this.selected.map((osd) => osd['state'])).map((activatedFlag) => {
96       if (Object.keys(flagsCount).includes(activatedFlag)) {
97         flagsCount[activatedFlag] = flagsCount[activatedFlag] + 1;
98       }
99     });
100     return flagsCount;
101   }
102
103   changeValue(flag: Flag) {
104     flag.value = !flag.value;
105     flag.indeterminate = false;
106   }
107
108   resetSelection() {
109     this.flags = _.cloneDeep(this.initialSelection);
110   }
111
112   submitAction() {
113     const activeFlags = {};
114     this.flags.forEach((flag) => {
115       if (flag.indeterminate) {
116         activeFlags[flag.code] = null;
117       } else {
118         activeFlags[flag.code] = flag.value;
119       }
120     });
121     const selectedIds = this.selected.map((selection) => selection['osd']);
122     this.osdService.updateIndividualFlags(activeFlags, selectedIds).subscribe(
123       () => {
124         this.notificationService.show(NotificationType.success, $localize`Updated OSD Flags`);
125         this.activeModal.close();
126       },
127       () => {
128         this.activeModal.close();
129       }
130     );
131   }
132 }