]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
9cd8abf13aaedc3fe2f7c0f8a323fa747653c8fa
[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 name`,
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`Target Region`,
79         prop: 'region',
80         flexGrow: 2
81       },
82       {
83         name: $localize`Target Endpoint`,
84         prop: 'endpoint',
85         flexGrow: 2
86       }
87     ];
88     const getStorageUri = () =>
89       this.selection.first() &&
90       `${encodeURI(this.selection.first().zonegroup_name)}/${encodeURI(
91         this.selection.first().placement_target
92       )}/${encodeURI(this.selection.first().storage_class)}`;
93     this.tableActions = [
94       {
95         name: this.actionLabels.CREATE,
96         permission: 'create',
97         icon: Icons.add,
98         click: () => this.router.navigate([this.urlBuilder.getCreate()]),
99         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
100       },
101       {
102         name: this.actionLabels.EDIT,
103         permission: 'update',
104         icon: Icons.edit,
105         routerLink: () => [`/rgw/tiering/edit/${getStorageUri()}`]
106       },
107       {
108         name: this.actionLabels.REMOVE,
109         permission: 'delete',
110         icon: Icons.destroy,
111         click: () => this.removeStorageClassModal()
112       }
113     ];
114   }
115
116   loadStorageClass(): Promise<void> {
117     return new Promise((resolve, reject) => {
118       this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
119         (data: ZoneGroupDetails) => {
120           this.storageClassList = [];
121           const tierObj = BucketTieringUtils.filterAndMapTierTargets(data);
122           const tierConfig = tierObj.map((tier) => ({
123             ...tier,
124             tier_type: this.mapTierTypeDisplay(tier.tier_type)
125           }));
126
127           this.transformTierData(tierConfig);
128           this.storageClassList.push(...tierConfig);
129           resolve();
130         },
131         (error) => {
132           reject(error);
133         }
134       );
135     });
136   }
137
138   private mapTierTypeDisplay(tierType: string): string {
139     switch (tierType?.toLowerCase()) {
140       case TIER_TYPE.CLOUD_TIER:
141         return TIER_TYPE_DISPLAY.CLOUD_TIER;
142       case TIER_TYPE.LOCAL:
143         return TIER_TYPE_DISPLAY.LOCAL;
144       case TIER_TYPE.GLACIER:
145         return TIER_TYPE_DISPLAY.GLACIER;
146       default:
147         return tierType;
148     }
149   }
150
151   transformTierData(tierConfig: any[]) {
152     tierConfig.forEach((item, index) => {
153       const zone_group = item?.zone_group;
154       const storageClass = item?.storage_class;
155       const uniqueId = `${zone_group}-${storageClass}-${index}`;
156       item.uniqueId = uniqueId;
157     });
158     return tierConfig;
159   }
160
161   removeStorageClassModal() {
162     const storage_class = this.selection.first().storage_class;
163     const placement_target = this.selection.first().placement_target;
164     this.cdsModalService.show(DeleteConfirmationModalComponent, {
165       itemDescription: $localize`Tiering Storage Class`,
166       itemNames: [storage_class],
167       actionDescription: 'remove',
168       submitActionObservable: () =>
169         this.taskWrapper.wrapTaskAroundCall({
170           task: new FinishedTask('rgw/zonegroup/storage-class', {
171             placement_target: placement_target,
172             storage_class: storage_class
173           }),
174           call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
175         })
176     });
177   }
178
179   updateSelection(selection: CdTableSelection) {
180     this.selection = selection;
181   }
182
183   setExpandedRow(expandedRow: any) {
184     super.setExpandedRow(expandedRow);
185   }
186 }