1 import { Component, OnInit, TemplateRef, ViewChild, inject } from '@angular/core';
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';
18 } from '~/app/shared/models/cephfs.model';
21 selector: 'cd-cephfs-filesystem-selector',
22 templateUrl: './cephfs-filesystem-selector.component.html',
24 styleUrls: ['./cephfs-filesystem-selector.component.scss']
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();
35 mdsStatusLabels: Record<MdsStatus, string> = {
36 Active: $localize`Active`,
37 Warning: $localize`Warning`,
38 Inactive: $localize`Inactive`
40 mirroringStatusLabels: Record<MirroringStatus, string> = {
41 Enabled: $localize`Enabled`,
42 Disabled: $localize`Disabled`
45 private cephfsService = inject(CephfsService);
46 private dimlessBinaryPipe = inject(DimlessBinaryPipe);
50 { name: $localize`Filesystem name`, prop: 'name', flexGrow: 2 },
51 { name: $localize`Usage`, prop: 'used', flexGrow: 1, pipe: this.dimlessBinaryPipe },
53 prop: $localize`pools`,
55 cellTransformation: CellTemplate.tag,
56 customTemplateConfig: {
57 class: 'tag-background-primary'
61 { name: $localize`Status`, prop: 'mdsStatus', flexGrow: 0.8, cellTemplate: this.mdsStatus },
64 name: $localize`Mirroring status`,
65 prop: 'mirroringStatus',
67 cellTemplate: this.mirroringStatus
71 this.filesystems$ = this.cephfsService.list().pipe(
72 switchMap((listResponse: Array<CephfsDetail>) => {
73 if (!listResponse?.length) {
76 const detailRequests = listResponse.map(
77 (fs): Observable<CephfsDetail | null> =>
78 this.cephfsService.getCephfs(fs.id).pipe(catchError(() => of(null)))
80 return forkJoin(detailRequests).pipe(
81 map((details: Array<CephfsDetail | null>) =>
83 .map((detail, index) => {
84 if (!detail?.cephfs) {
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;
96 name: detail.cephfs.name,
99 mdsStatus: mdsStateToStatus(mdsState),
100 mirroringStatus: listItem?.mirror_info
101 ? MIRRORING_STATUS.Enabled
102 : MIRRORING_STATUS.Disabled
105 .filter((row): row is FilesystemRow => row !== null)
112 updateSelection(selection: CdTableSelection) {
113 this.selection = selection;