]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
1c7ca0a3b88fcd1575b8000392559ea8186d0e49
[ceph-ci.git] /
1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs';
3 import { catchError, map, switchMap } from 'rxjs/operators';
4 import { GatewayGroup, NvmeofService } from '~/app/shared/api/nvmeof.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { TableComponent } from '~/app/shared/datatable/table/table.component';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
9 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
10 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
11 import { Permission } from '~/app/shared/models/permissions';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { Icons, IconSize } from '~/app/shared/enum/icons.enum';
14 import { NvmeofGatewayGroup } from '~/app/shared/models/nvmeof';
15 import { CephServiceSpec } from '~/app/shared/models/service.interface';
16
17 @Component({
18   selector: 'cd-nvmeof-gateway-group',
19   templateUrl: './nvmeof-gateway-group.component.html',
20   styleUrls: ['./nvmeof-gateway-group.component.scss'],
21   standalone: false
22 })
23 export class NvmeofGatewayGroupComponent implements OnInit {
24   @ViewChild(TableComponent, { static: true })
25   table: TableComponent;
26
27   @ViewChild('dateTpl', { static: true })
28   dateTpl: TemplateRef<any>;
29
30   @ViewChild('gatewayStatusTpl', { static: true })
31   gatewayStatusTpl: TemplateRef<any>;
32
33   permission: Permission;
34   tableActions: CdTableAction[];
35   columns: CdTableColumn[] = [];
36   selection: CdTableSelection = new CdTableSelection();
37   gatewayGroup$: Observable<CephServiceSpec[]>;
38   subject = new BehaviorSubject<CephServiceSpec[]>([]);
39   context: CdTableFetchDataContext;
40   gatewayGroupName: string;
41   subsystemCount: number;
42   gatewayCount: number;
43
44   icons = Icons;
45
46   iconSize = IconSize;
47
48   constructor(
49     public actionLabels: ActionLabelsI18n,
50     private authStorageService: AuthStorageService,
51     private nvmeofService: NvmeofService
52   ) {}
53
54   ngOnInit(): void {
55     this.permission = this.authStorageService.getPermissions().nvmeof;
56
57     this.columns = [
58       {
59         name: $localize`Name`,
60         prop: 'name'
61       },
62       {
63         name: $localize`Gateways`,
64         prop: 'statusCount',
65         cellTemplate: this.gatewayStatusTpl
66       },
67       {
68         name: $localize`Subsystems`,
69         prop: 'subSystemCount'
70       },
71       {
72         name: $localize`Created on`,
73         prop: 'created',
74         cellTemplate: this.dateTpl
75       }
76     ];
77
78     this.gatewayGroup$ = this.subject.pipe(
79       switchMap(() =>
80         this.nvmeofService.listGatewayGroups().pipe(
81           switchMap((gatewayGroups: GatewayGroup[][]) => {
82             const groups = gatewayGroups?.[0] ?? [];
83             return forkJoin(
84               groups.map((group: NvmeofGatewayGroup) =>
85                 this.nvmeofService.listSubsystems(group.spec.group).pipe(
86                   catchError(() => of([])),
87                   map((subs) => ({
88                     ...group,
89                     name: group.spec?.group,
90                     statusCount: {
91                       running: group.status?.running ?? 0,
92                       error: (group.status?.size ?? 0) - (group.status?.running ?? 0)
93                     },
94
95                     subSystemCount: Array.isArray(subs) ? subs.length : 0,
96                     gateWayNode: group.placement?.hosts?.length ?? 0,
97                     created: group.status?.created ? new Date(group.status.created) : null
98                   }))
99                 )
100               )
101             );
102           }),
103           catchError((error) => {
104             this.context?.error?.(error);
105             return of([]);
106           })
107         )
108       )
109     );
110   }
111
112   fetchData(): void {
113     this.subject.next([]);
114   }
115
116   updateSelection(selection: CdTableSelection): void {
117     this.selection = selection;
118   }
119 }