]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
56d3bbb204cfcaa30b944e319fab467e72e9ca13
[ceph.git] /
1 import { Component, OnInit, TemplateRef, ViewChild, inject } from '@angular/core';
2
3 import { CephfsService } from '~/app/shared/api/cephfs.service';
4 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
5 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
6 import { Icons } from '~/app/shared/enum/icons.enum';
7 import { catchError, map, switchMap } from 'rxjs/operators';
8 import { forkJoin, of, Observable } from 'rxjs';
9 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
10 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
11 import {
12   CephfsDetail,
13   FilesystemRow,
14   MdsStatus,
15   MirroringStatus,
16   MIRRORING_STATUS,
17   mdsStateToStatus
18 } from '~/app/shared/models/cephfs.model';
19
20 @Component({
21   selector: 'cd-cephfs-filesystem-selector',
22   templateUrl: './cephfs-filesystem-selector.component.html',
23   standalone: false,
24   styleUrls: ['./cephfs-filesystem-selector.component.scss']
25 })
26 export class CephfsFilesystemSelectorComponent implements OnInit {
27   @ViewChild('mdsStatus', { static: true })
28   mdsStatus: TemplateRef<any>;
29   @ViewChild('mirroringStatus', { static: true })
30   mirroringStatus: TemplateRef<any>;
31   columns: CdTableColumn[] = [];
32   filesystems$: Observable<FilesystemRow[]> = of([]);
33   selection = new CdTableSelection();
34   icons = Icons;
35   mdsStatusLabels: Record<MdsStatus, string> = {
36     Active: $localize`Active`,
37     Warning: $localize`Warning`,
38     Inactive: $localize`Inactive`
39   };
40   mirroringStatusLabels: Record<MirroringStatus, string> = {
41     Enabled: $localize`Enabled`,
42     Disabled: $localize`Disabled`
43   };
44
45   private cephfsService = inject(CephfsService);
46   private dimlessBinaryPipe = inject(DimlessBinaryPipe);
47
48   ngOnInit(): void {
49     this.columns = [
50       { name: $localize`Filesystem name`, prop: 'name', flexGrow: 2 },
51       { name: $localize`Usage`, prop: 'used', flexGrow: 1, pipe: this.dimlessBinaryPipe },
52       {
53         prop: $localize`pools`,
54         name: 'Pools used',
55         cellTransformation: CellTemplate.tag,
56         customTemplateConfig: {
57           class: 'tag-background-primary'
58         },
59         flexGrow: 1.3
60       },
61       { name: $localize`Status`, prop: 'mdsStatus', flexGrow: 0.8, cellTemplate: this.mdsStatus },
62
63       {
64         name: $localize`Mirroring status`,
65         prop: 'mirroringStatus',
66         flexGrow: 0.8,
67         cellTemplate: this.mirroringStatus
68       }
69     ];
70
71     this.filesystems$ = this.cephfsService.list().pipe(
72       switchMap((listResponse: Array<CephfsDetail>) => {
73         if (!listResponse?.length) {
74           return of([]);
75         }
76         const detailRequests = listResponse.map(
77           (fs): Observable<CephfsDetail | null> =>
78             this.cephfsService.getCephfs(fs.id).pipe(catchError(() => of(null)))
79         );
80         return forkJoin(detailRequests).pipe(
81           map((details: Array<CephfsDetail | null>) =>
82             details
83               .map((detail, index) => {
84                 if (!detail?.cephfs) {
85                   return null;
86                 }
87                 const listItem = listResponse[index];
88                 const pools = detail.cephfs.pools || [];
89                 const poolNames = pools.map((p) => p.pool);
90                 const totalUsed = pools.reduce((sum, p) => sum + p.used, 0);
91                 const mdsInfo = listItem?.mdsmap?.info ?? {};
92                 const firstMdsGid = Object.keys(mdsInfo)[0];
93                 const mdsState = firstMdsGid ? mdsInfo[firstMdsGid]?.state : undefined;
94                 return {
95                   id: detail.cephfs.id,
96                   name: detail.cephfs.name,
97                   pools: poolNames,
98                   used: `${totalUsed}`,
99                   mdsStatus: mdsStateToStatus(mdsState),
100                   mirroringStatus: listItem?.mirror_info
101                     ? MIRRORING_STATUS.Enabled
102                     : MIRRORING_STATUS.Disabled
103                 } as FilesystemRow;
104               })
105               .filter((row): row is FilesystemRow => row !== null)
106           )
107         );
108       })
109     );
110   }
111
112   updateSelection(selection: CdTableSelection) {
113     this.selection = selection;
114   }
115 }