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 { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
10 import { Flag } from '~/app/shared/models/flag';
11 import { Permissions } from '~/app/shared/models/permissions';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { NotificationService } from '~/app/shared/services/notification.service';
16 selector: 'cd-osd-flags-indiv-modal',
17 templateUrl: './osd-flags-indiv-modal.component.html',
18 styleUrls: ['./osd-flags-indiv-modal.component.scss']
20 export class OsdFlagsIndivModalComponent implements OnInit {
21 permissions: Permissions;
23 initialSelection: Flag[] = [];
24 osdFlagsForm = new FormGroup({});
28 name: $localize`No Up`,
29 description: $localize`OSDs are not allowed to start`,
36 name: $localize`No Down`,
37 description: $localize`OSD failure reports are being ignored, such that the monitors will not mark OSDs down`,
44 name: $localize`No In`,
45 description: $localize`OSDs that were previously marked out will not be marked back in when they start`,
52 name: $localize`No Out`,
53 description: $localize`OSDs will not automatically be marked out after the configured interval`,
59 clusterWideTooltip: string = $localize`The flag has been enabled for the entire cluster.`;
62 public activeModal: NgbActiveModal,
63 public actionLabels: ActionLabelsI18n,
64 private authStorageService: AuthStorageService,
65 private osdService: OsdService,
66 private notificationService: NotificationService
68 this.permissions = this.authStorageService.getPermissions();
72 const osdCount = this.selected.length;
73 this.osdService.getFlags().subscribe((clusterWideFlags: string[]) => {
74 const activatedIndivFlags = this.getActivatedIndivFlags();
75 this.flags.forEach((flag) => {
76 const flagCount = activatedIndivFlags[flag.code];
77 if (clusterWideFlags.includes(flag.code)) {
78 flag.clusterWide = true;
81 if (flagCount === osdCount) {
83 } else if (flagCount > 0) {
84 flag.indeterminate = true;
87 this.initialSelection = _.cloneDeep(this.flags);
91 getActivatedIndivFlags(): { [flag: string]: number } {
92 const flagsCount = {};
93 this.flags.forEach((flag) => {
94 flagsCount[flag.code] = 0;
97 [].concat(...this.selected.map((osd) => osd['state'])).map((activatedFlag) => {
98 if (Object.keys(flagsCount).includes(activatedFlag)) {
99 flagsCount[activatedFlag] = flagsCount[activatedFlag] + 1;
105 changeValue(flag: Flag) {
106 flag.value = !flag.value;
107 flag.indeterminate = false;
111 this.flags = _.cloneDeep(this.initialSelection);
115 const activeFlags = {};
116 this.flags.forEach((flag) => {
117 if (flag.indeterminate) {
118 activeFlags[flag.code] = null;
120 activeFlags[flag.code] = flag.value;
123 const selectedIds = this.selected.map((selection) => selection['osd']);
124 this.osdService.updateIndividualFlags(activeFlags, selectedIds).subscribe(
126 this.notificationService.show(NotificationType.success, $localize`Updated OSD Flags`);
127 this.activeModal.close();
130 this.activeModal.close();