]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cephfs / cephfs-tabs / cephfs-tabs.component.ts
CommitLineData
9f95a23c
TL
1import { Component, Input, NgZone, OnChanges, OnDestroy } from '@angular/core';
2
3import * as _ from 'lodash';
4import { Subscription, timer } from 'rxjs';
5
6import { CephfsService } from '../../../shared/api/cephfs.service';
7import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
9f95a23c
TL
8import { Permission } from '../../../shared/models/permissions';
9import { AuthStorageService } from '../../../shared/services/auth-storage.service';
10
11@Component({
12 selector: 'cd-cephfs-tabs',
13 templateUrl: './cephfs-tabs.component.html',
14 styleUrls: ['./cephfs-tabs.component.scss']
15})
16export class CephfsTabsComponent implements OnChanges, OnDestroy {
17 @Input()
e306af50 18 selection: any;
9f95a23c
TL
19
20 // Grafana tab
21 grafanaId: any;
22 grafanaPermission: Permission;
23
24 // Client tab
25 id: number;
26 clients: Record<string, any> = {
27 data: [],
28 status: ViewCacheStatus.ValueNone
29 };
30
31 // Details tab
32 details: Record<string, any> = {
33 standbys: '',
34 pools: [],
35 ranks: [],
36 mdsCounters: {},
37 name: ''
38 };
39
40 // Directories
41 directoriesSelected = false;
42
43 private data: any;
44 private reloadSubscriber: Subscription;
45
46 constructor(
47 private ngZone: NgZone,
48 private authStorageService: AuthStorageService,
49 private cephfsService: CephfsService
50 ) {
51 this.grafanaPermission = this.authStorageService.getPermissions().grafana;
52 }
53
54 ngOnChanges() {
e306af50 55 if (!this.selection) {
9f95a23c
TL
56 this.unsubscribeInterval();
57 return;
58 }
e306af50
TL
59 if (this.selection.id !== this.id) {
60 this.setupSelected(this.selection.id, this.selection.mdsmap.info);
9f95a23c
TL
61 }
62 }
63
64 private setupSelected(id: number, mdsInfo: any) {
65 this.id = id;
66 const firstMds: any = _.first(Object.values(mdsInfo));
67 this.grafanaId = firstMds && firstMds['name'];
68 this.details = {
69 standbys: '',
70 pools: [],
71 ranks: [],
72 mdsCounters: {},
73 name: ''
74 };
75 this.clients = {
76 data: [],
77 status: ViewCacheStatus.ValueNone
78 };
79 this.updateInterval();
80 }
81
82 private updateInterval() {
83 this.unsubscribeInterval();
84 this.subscribeInterval();
85 }
86
87 private unsubscribeInterval() {
88 if (this.reloadSubscriber) {
89 this.reloadSubscriber.unsubscribe();
90 }
91 }
92
93 private subscribeInterval() {
94 this.ngZone.runOutsideAngular(
95 () =>
96 (this.reloadSubscriber = timer(0, 5000).subscribe(() =>
97 this.ngZone.run(() => this.refresh())
98 ))
99 );
100 }
101
102 refresh() {
103 this.cephfsService.getTabs(this.id).subscribe(
104 (data: any) => {
105 this.data = data;
106 this.softRefresh();
107 },
108 () => {
109 this.clients.status = ViewCacheStatus.ValueException;
110 }
111 );
112 }
113
114 softRefresh() {
115 const data = _.cloneDeep(this.data); // Forces update of tab tables on tab switch
116 // Clients tab
117 this.clients = data.clients;
118 // Details tab
119 this.details = {
120 standbys: data.standbys,
121 pools: data.pools,
122 ranks: data.ranks,
123 mdsCounters: data.mds_counters,
124 name: data.name
125 };
126 }
127
128 ngOnDestroy() {
129 this.unsubscribeInterval();
130 }
131}