1 import { Component, OnInit } from '@angular/core';
2 import { FormGroup } from '@angular/forms';
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5 import _ from 'lodash';
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';
15 selector: 'cd-osd-flags-indiv-modal',
16 templateUrl: './osd-flags-indiv-modal.component.html',
17 styleUrls: ['./osd-flags-indiv-modal.component.scss']
19 export class OsdFlagsIndivModalComponent implements OnInit {
20 permissions: Permissions;
22 initialSelection: Flag[] = [];
23 osdFlagsForm = new FormGroup({});
27 name: $localize`No Up`,
28 description: $localize`OSDs are not allowed to start`,
35 name: $localize`No Down`,
36 description: $localize`OSD failure reports are being ignored, such that the monitors will not mark OSDs down`,
43 name: $localize`No In`,
44 description: $localize`OSDs that were previously marked out will not be marked back in when they start`,
51 name: $localize`No Out`,
52 description: $localize`OSDs will not automatically be marked out after the configured interval`,
58 clusterWideTooltip: string = $localize`The flag has been enabled for the entire cluster.`;
61 public activeModal: NgbActiveModal,
62 private authStorageService: AuthStorageService,
63 private osdService: OsdService,
64 private notificationService: NotificationService
66 this.permissions = this.authStorageService.getPermissions();
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;
79 if (flagCount === osdCount) {
81 } else if (flagCount > 0) {
82 flag.indeterminate = true;
85 this.initialSelection = _.cloneDeep(this.flags);
89 getActivatedIndivFlags(): { [flag: string]: number } {
90 const flagsCount = {};
91 this.flags.forEach((flag) => {
92 flagsCount[flag.code] = 0;
95 [].concat(...this.selected.map((osd) => osd['state'])).map((activatedFlag) => {
96 if (Object.keys(flagsCount).includes(activatedFlag)) {
97 flagsCount[activatedFlag] = flagsCount[activatedFlag] + 1;
103 changeValue(flag: Flag) {
104 flag.value = !flag.value;
105 flag.indeterminate = false;
109 this.flags = _.cloneDeep(this.initialSelection);
113 const activeFlags = {};
114 this.flags.forEach((flag) => {
115 if (flag.indeterminate) {
116 activeFlags[flag.code] = null;
118 activeFlags[flag.code] = flag.value;
121 const selectedIds = this.selected.map((selection) => selection['osd']);
122 this.osdService.updateIndividualFlags(activeFlags, selectedIds).subscribe(
124 this.notificationService.show(NotificationType.success, $localize`Updated OSD Flags`);
125 this.activeModal.close();
128 this.activeModal.close();