]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
fbe7dd9d48d0a35723e430ec94b4938b57ed8f33
[ceph-ci.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((tier) => ({
128             ...tier,
129             tier_type: this.mapTierTypeDisplay(tier.tier_type)
130           }));
131
132           this.transformTierData(tierConfig);
133           this.storageClassList.push(...tierConfig);
134           resolve();
135         },
136         (error) => {
137           reject(error);
138         }
139       );
140     });
141   }
142
143   private mapTierTypeDisplay(tierType: string): string {
144     switch (tierType?.toLowerCase()) {
145       case TIER_TYPE.CLOUD_TIER:
146         return TIER_TYPE_DISPLAY.CLOUD_TIER;
147       case TIER_TYPE.LOCAL:
148         return TIER_TYPE_DISPLAY.LOCAL;
149       case TIER_TYPE.GLACIER:
150         return TIER_TYPE_DISPLAY.GLACIER;
151       default:
152         return tierType;
153     }
154   }
155
156   transformTierData(tierConfig: any[]) {
157     tierConfig.forEach((item, index) => {
158       const zone_group = item?.zone_group;
159       const storageClass = item?.storage_class;
160       const uniqueId = `${zone_group}-${storageClass}-${index}`;
161       item.uniqueId = uniqueId;
162     });
163     return tierConfig;
164   }
165
166   removeStorageClassModal() {
167     const storage_class = this.selection.first().storage_class;
168     const placement_target = this.selection.first().placement_target;
169     this.cdsModalService.show(DeleteConfirmationModalComponent, {
170       itemDescription: $localize`Tiering Storage Class`,
171       itemNames: [storage_class],
172       actionDescription: 'remove',
173       submitActionObservable: () =>
174         this.taskWrapper.wrapTaskAroundCall({
175           task: new FinishedTask('rgw/zonegroup/storage-class', {
176             placement_target: placement_target,
177             storage_class: storage_class
178           }),
179           call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
180         })
181     });
182   }
183
184   updateSelection(selection: CdTableSelection) {
185     this.selection = selection;
186   }
187
188   setExpandedRow(expandedRow: any) {
189     super.setExpandedRow(expandedRow);
190   }
191 }