]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
714d0234314541898ecf9a83c16bcc3ba3f27cc6
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { CdTableAction } from '~/app/shared/models/cd-table-action';
3 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
4 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
5
6 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
7 import {
8   StorageClass,
9   TIER_TYPE,
10   TIER_TYPE_DISPLAY,
11   ZoneGroupDetails
12 } from '../models/rgw-storage-class.model';
13 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
14 import { FinishedTask } from '~/app/shared/models/finished-task';
15 import { Icons } from '~/app/shared/enum/icons.enum';
16 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
17 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
18 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
19 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
20 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
21 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
22 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
23 import { Permission } from '~/app/shared/models/permissions';
24 import { BucketTieringUtils } from '../utils/rgw-bucket-tiering';
25 import { Router } from '@angular/router';
26
27 const BASE_URL = 'rgw/tiering';
28 @Component({
29   selector: 'cd-rgw-storage-class-list',
30   templateUrl: './rgw-storage-class-list.component.html',
31   styleUrls: ['./rgw-storage-class-list.component.scss'],
32   providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
33 })
34 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
35   columns: CdTableColumn[];
36   selection = new CdTableSelection();
37   permission: Permission;
38   tableActions: CdTableAction[];
39   storageClassList: StorageClass[] = [];
40
41   constructor(
42     private rgwZonegroupService: RgwZonegroupService,
43     public actionLabels: ActionLabelsI18n,
44     private cdsModalService: ModalCdsService,
45     private taskWrapper: TaskWrapperService,
46     private authStorageService: AuthStorageService,
47     private rgwStorageClassService: RgwStorageClassService,
48     private router: Router,
49     private urlBuilder: URLBuilderService
50   ) {
51     super();
52     this.permission = this.authStorageService.getPermissions().rgw;
53   }
54
55   ngOnInit() {
56     this.columns = [
57       {
58         prop: 'uniqueId',
59         isInvisible: true,
60         isHidden: true
61       },
62       {
63         name: $localize`Storage Class`,
64         prop: 'storage_class',
65         flexGrow: 2
66       },
67       {
68         name: $localize`Type`,
69         prop: 'tier_type',
70         flexGrow: 2
71       },
72       {
73         name: $localize`Zone Group`,
74         prop: 'zonegroup_name',
75         flexGrow: 2
76       },
77       {
78         name: $localize`Placement Target`,
79         prop: 'placement_target',
80         flexGrow: 2
81       },
82       {
83         name: $localize`Target Region`,
84         prop: 'region',
85         flexGrow: 2
86       },
87       {
88         name: $localize`Target Endpoint`,
89         prop: 'endpoint',
90         flexGrow: 2
91       }
92     ];
93     const getStorageUri = () =>
94       this.selection.first() &&
95       `${encodeURI(this.selection.first().zonegroup_name)}/${encodeURI(
96         this.selection.first().placement_target
97       )}/${encodeURI(this.selection.first().storage_class)}`;
98     this.tableActions = [
99       {
100         name: this.actionLabels.CREATE,
101         permission: 'create',
102         icon: Icons.add,
103         click: () => this.router.navigate([this.urlBuilder.getCreate()]),
104         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
105       },
106       {
107         name: this.actionLabels.EDIT,
108         permission: 'update',
109         icon: Icons.edit,
110         routerLink: () => [`/rgw/tiering/edit/${getStorageUri()}`]
111       },
112       {
113         name: this.actionLabels.REMOVE,
114         permission: 'delete',
115         icon: Icons.destroy,
116         click: () => this.removeStorageClassModal()
117       }
118     ];
119   }
120
121   loadStorageClass(): Promise<void> {
122     return new Promise((resolve, reject) => {
123       this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
124         (data: ZoneGroupDetails) => {
125           this.storageClassList = [];
126           const tierObj = BucketTieringUtils.filterAndMapTierTargets(data);
127           const tierConfig = tierObj.map((item) => ({
128             ...item,
129             tier_type:
130               item.tier_type?.toLowerCase() === TIER_TYPE.CLOUD_TIER
131                 ? TIER_TYPE_DISPLAY.CLOUD_TIER
132                 : item.tier_type?.toLowerCase() === TIER_TYPE.LOCAL
133                 ? TIER_TYPE_DISPLAY.LOCAL
134                 : item.tier_type
135           }));
136           this.transformTierData(tierConfig);
137           this.storageClassList.push(...tierConfig);
138           resolve();
139         },
140         (error) => {
141           reject(error);
142         }
143       );
144     });
145   }
146
147   transformTierData(tierConfig: any[]) {
148     tierConfig.forEach((item, index) => {
149       const zone_group = item?.zone_group;
150       const storageClass = item?.storage_class;
151       const uniqueId = `${zone_group}-${storageClass}-${index}`;
152       item.uniqueId = uniqueId;
153     });
154     return tierConfig;
155   }
156
157   removeStorageClassModal() {
158     const storage_class = this.selection.first().storage_class;
159     const placement_target = this.selection.first().placement_target;
160     this.cdsModalService.show(DeleteConfirmationModalComponent, {
161       itemDescription: $localize`Tiering Storage Class`,
162       itemNames: [storage_class],
163       actionDescription: 'remove',
164       submitActionObservable: () =>
165         this.taskWrapper.wrapTaskAroundCall({
166           task: new FinishedTask('rgw/zonegroup/storage-class', {
167             placement_target: placement_target,
168             storage_class: storage_class
169           }),
170           call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
171         })
172     });
173   }
174
175   updateSelection(selection: CdTableSelection) {
176     this.selection = selection;
177   }
178
179   setExpandedRow(expandedRow: any) {
180     super.setExpandedRow(expandedRow);
181   }
182 }