]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
12520e41b4e68b8d1b199ce686bfb6a9e841a321
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { FormGroup } from '@angular/forms';
3
4 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import * as _ from 'lodash';
6 import { BsModalRef } from 'ngx-bootstrap/modal';
7
8 import { OsdService } from '../../../../shared/api/osd.service';
9 import { NotificationType } from '../../../../shared/enum/notification-type.enum';
10 import { Permissions } from '../../../../shared/models/permissions';
11 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
12 import { NotificationService } from '../../../../shared/services/notification.service';
13
14 @Component({
15   selector: 'cd-osd-flags-modal',
16   templateUrl: './osd-flags-modal.component.html',
17   styleUrls: ['./osd-flags-modal.component.scss']
18 })
19 export class OsdFlagsModalComponent implements OnInit {
20   permissions: Permissions;
21
22   osdFlagsForm = new FormGroup({});
23
24   allFlags = {
25     noin: {
26       code: 'noin',
27       name: this.i18n('No In'),
28       value: false,
29       description: this.i18n(
30         'OSDs that were previously marked out will not be marked back in when they start'
31       )
32     },
33     noout: {
34       code: 'noout',
35       name: this.i18n('No Out'),
36       value: false,
37       description: this.i18n(
38         'OSDs will not automatically be marked out after the configured interval'
39       )
40     },
41     noup: {
42       code: 'noup',
43       name: this.i18n('No Up'),
44       value: false,
45       description: this.i18n('OSDs are not allowed to start')
46     },
47     nodown: {
48       code: 'nodown',
49       name: this.i18n('No Down'),
50       value: false,
51       description: this.i18n(
52         'OSD failure reports are being ignored, such that the monitors will not mark OSDs down'
53       )
54     },
55     pause: {
56       code: 'pause',
57       name: this.i18n('Pause'),
58       value: false,
59       description: this.i18n('Pauses reads and writes')
60     },
61     noscrub: {
62       code: 'noscrub',
63       name: this.i18n('No Scrub'),
64       value: false,
65       description: this.i18n('Scrubbing is disabled')
66     },
67     'nodeep-scrub': {
68       code: 'nodeep-scrub',
69       name: this.i18n('No Deep Scrub'),
70       value: false,
71       description: this.i18n('Deep Scrubbing is disabled')
72     },
73     nobackfill: {
74       code: 'nobackfill',
75       name: this.i18n('No Backfill'),
76       value: false,
77       description: this.i18n('Backfilling of PGs is suspended')
78     },
79     norebalance: {
80       code: 'norebalance',
81       name: this.i18n('No Rebalance'),
82       value: false,
83       description: this.i18n('OSD will choose not to backfill unless PG is also degraded')
84     },
85     norecover: {
86       code: 'norecover',
87       name: this.i18n('No Recover'),
88       value: false,
89       description: this.i18n('Recovery of PGs is suspended')
90     },
91     sortbitwise: {
92       code: 'sortbitwise',
93       name: this.i18n('Bitwise Sort'),
94       value: false,
95       description: this.i18n('Use bitwise sort'),
96       disabled: true
97     },
98     purged_snapdirs: {
99       code: 'purged_snapdirs',
100       name: this.i18n('Purged Snapdirs'),
101       value: false,
102       description: this.i18n('OSDs have converted snapsets'),
103       disabled: true
104     },
105     recovery_deletes: {
106       code: 'recovery_deletes',
107       name: this.i18n('Recovery Deletes'),
108       value: false,
109       description: this.i18n('Deletes performed during recovery instead of peering'),
110       disabled: true
111     },
112     pglog_hardlimit: {
113       code: 'pglog_hardlimit',
114       name: this.i18n('PG Log Hard Limit'),
115       value: false,
116       description: this.i18n('Puts a hard limit on pg log length'),
117       disabled: true
118     }
119   };
120   flags: any[];
121   unknownFlags: string[] = [];
122
123   constructor(
124     public bsModalRef: BsModalRef,
125     private authStorageService: AuthStorageService,
126     private osdService: OsdService,
127     private notificationService: NotificationService,
128     private i18n: I18n
129   ) {
130     this.permissions = this.authStorageService.getPermissions();
131   }
132
133   ngOnInit() {
134     this.osdService.getFlags().subscribe((res: string[]) => {
135       res.forEach((value) => {
136         if (this.allFlags[value]) {
137           this.allFlags[value].value = true;
138         } else {
139           this.unknownFlags.push(value);
140         }
141       });
142       this.flags = _.toArray(this.allFlags);
143     });
144   }
145
146   submitAction() {
147     const newFlags = this.flags
148       .filter((flag) => flag.value)
149       .map((flag) => flag.code)
150       .concat(this.unknownFlags);
151
152     this.osdService.updateFlags(newFlags).subscribe(
153       () => {
154         this.notificationService.show(NotificationType.success, this.i18n('Updated OSD Flags'));
155         this.bsModalRef.hide();
156       },
157       () => {
158         this.bsModalRef.hide();
159       }
160     );
161   }
162 }