]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
16afef45d368916938cca8b53f66ec2b4c7ffbc1
[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   CLOUD_TIER,
10   ZoneGroup,
11   TierTarget,
12   Target,
13   ZoneGroupDetails
14 } from '../models/rgw-storage-class.model';
15 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
16 import { FinishedTask } from '~/app/shared/models/finished-task';
17 import { Icons } from '~/app/shared/enum/icons.enum';
18 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
19 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
20 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
21 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
22 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
23 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
24 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
25 import { Permission } from '~/app/shared/models/permissions';
26
27 import { Router } from '@angular/router';
28
29 const BASE_URL = 'rgw/tiering';
30
31 @Component({
32   selector: 'cd-rgw-storage-class-list',
33   templateUrl: './rgw-storage-class-list.component.html',
34   styleUrls: ['./rgw-storage-class-list.component.scss'],
35   providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
36 })
37 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
38   columns: CdTableColumn[];
39   selection = new CdTableSelection();
40   permission: Permission;
41   tableActions: CdTableAction[];
42   storageClassList: StorageClass[] = [];
43
44   constructor(
45     private rgwZonegroupService: RgwZonegroupService,
46     public actionLabels: ActionLabelsI18n,
47     private cdsModalService: ModalCdsService,
48     private taskWrapper: TaskWrapperService,
49     private authStorageService: AuthStorageService,
50     private rgwStorageClassService: RgwStorageClassService,
51     private router: Router,
52     private urlBuilder: URLBuilderService
53   ) {
54     super();
55     this.permission = this.authStorageService.getPermissions().rgw;
56   }
57
58   ngOnInit() {
59     this.columns = [
60       {
61         name: $localize`Zone Group`,
62         prop: 'zonegroup_name',
63         flexGrow: 2
64       },
65       {
66         name: $localize`Placement Target`,
67         prop: 'placement_target',
68         flexGrow: 2
69       },
70       {
71         name: $localize`Storage Class`,
72         prop: 'storage_class',
73         flexGrow: 2
74       },
75       {
76         name: $localize`Target Region`,
77         prop: 'region',
78         flexGrow: 2
79       },
80       {
81         name: $localize`Target Endpoint`,
82         prop: 'endpoint',
83         flexGrow: 2
84       }
85     ];
86     this.tableActions = [
87       {
88         name: this.actionLabels.CREATE,
89         permission: 'create',
90         icon: Icons.add,
91         click: () => this.router.navigate([this.urlBuilder.getCreate()]),
92         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
93       },
94       {
95         name: this.actionLabels.REMOVE,
96         permission: 'delete',
97         icon: Icons.destroy,
98         click: () => this.removeStorageClassModal()
99       }
100     ];
101   }
102
103   loadStorageClass(): Promise<void> {
104     return new Promise((resolve, reject) => {
105       this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
106         (data: ZoneGroupDetails) => {
107           this.storageClassList = [];
108
109           const tierObj = data.zonegroups.flatMap((zoneGroup: ZoneGroup) =>
110             zoneGroup.placement_targets
111               .filter((target: Target) => target.tier_targets)
112               .flatMap((target: Target) =>
113                 target.tier_targets
114                   .filter((tierTarget: TierTarget) => tierTarget.val.tier_type === CLOUD_TIER)
115                   .map((tierTarget: TierTarget) => {
116                     return this.getTierTargets(tierTarget, zoneGroup.name, target.name);
117                   })
118               )
119           );
120           this.storageClassList.push(...tierObj);
121           resolve();
122         },
123         (error) => {
124           reject(error);
125         }
126       );
127     });
128   }
129
130   getTierTargets(tierTarget: TierTarget, zoneGroup: string, targetName: string) {
131     if (tierTarget.val.tier_type !== CLOUD_TIER) return null;
132     return {
133       zonegroup_name: zoneGroup,
134       placement_target: targetName,
135       storage_class: tierTarget.val.storage_class,
136       ...tierTarget.val.s3
137     };
138   }
139
140   removeStorageClassModal() {
141     const storage_class = this.selection.first().storage_class;
142     const placement_target = this.selection.first().placement_target;
143     this.cdsModalService.show(CriticalConfirmationModalComponent, {
144       itemDescription: $localize`Tiering Storage Class`,
145       itemNames: [storage_class],
146       actionDescription: 'remove',
147       submitActionObservable: () =>
148         this.taskWrapper.wrapTaskAroundCall({
149           task: new FinishedTask('rgw/zonegroup/storage-class', {
150             placement_target: placement_target,
151             storage_class: storage_class
152           }),
153           call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
154         })
155     });
156   }
157
158   updateSelection(selection: CdTableSelection) {
159     this.selection = selection;
160   }
161
162   setExpandedRow(expandedRow: any) {
163     super.setExpandedRow(expandedRow);
164   }
165 }