]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/pool-list/pool-list.component.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / pool-list / pool-list.component.ts
CommitLineData
11fdf7f2 1import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
2a845540 2import { Router } from '@angular/router';
11fdf7f2 3
f67539c2 4import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
11fdf7f2
TL
5import { Observable, Subscriber, Subscription } from 'rxjs';
6
f67539c2
TL
7import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
8import { TableStatusViewCache } from '~/app/shared/classes/table-status-view-cache';
9import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
2a845540 10import { URLVerbs } from '~/app/shared/constants/app.constants';
f67539c2
TL
11import { Icons } from '~/app/shared/enum/icons.enum';
12import { CdTableAction } from '~/app/shared/models/cd-table-action';
13import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
14import { FinishedTask } from '~/app/shared/models/finished-task';
15import { Permission } from '~/app/shared/models/permissions';
16import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
17import { ModalService } from '~/app/shared/services/modal.service';
18import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11fdf7f2
TL
19import { PoolEditPeerModalComponent } from '../pool-edit-peer-modal/pool-edit-peer-modal.component';
20
2a845540 21const BASE_URL = '/block/mirroring';
11fdf7f2
TL
22@Component({
23 selector: 'cd-mirroring-pools',
24 templateUrl: './pool-list.component.html',
25 styleUrls: ['./pool-list.component.scss']
26})
27export class PoolListComponent implements OnInit, OnDestroy {
9f95a23c 28 @ViewChild('healthTmpl', { static: true })
11fdf7f2
TL
29 healthTmpl: TemplateRef<any>;
30
31 subs: Subscription;
32
33 permission: Permission;
34 tableActions: CdTableAction[];
35 selection = new CdTableSelection();
36
f67539c2 37 modalRef: NgbModalRef;
11fdf7f2
TL
38
39 data: [];
40 columns: {};
41
f67539c2
TL
42 tableStatus = new TableStatusViewCache();
43
11fdf7f2
TL
44 constructor(
45 private authStorageService: AuthStorageService,
46 private rbdMirroringService: RbdMirroringService,
f67539c2 47 private modalService: ModalService,
2a845540
TL
48 private taskWrapper: TaskWrapperService,
49 private router: Router
11fdf7f2
TL
50 ) {
51 this.data = [];
52 this.permission = this.authStorageService.getPermissions().rbdMirroring;
53
54 const editModeAction: CdTableAction = {
55 permission: 'update',
9f95a23c 56 icon: Icons.edit,
11fdf7f2 57 click: () => this.editModeModal(),
f67539c2 58 name: $localize`Edit Mode`,
11fdf7f2
TL
59 canBePrimary: () => true
60 };
61 const addPeerAction: CdTableAction = {
62 permission: 'create',
9f95a23c 63 icon: Icons.add,
f67539c2 64 name: $localize`Add Peer`,
11fdf7f2
TL
65 click: () => this.editPeersModal('add'),
66 disable: () => !this.selection.first() || this.selection.first().mirror_mode === 'disabled',
67 visible: () => !this.getPeerUUID(),
68 canBePrimary: () => false
69 };
70 const editPeerAction: CdTableAction = {
71 permission: 'update',
9f95a23c 72 icon: Icons.exchange,
f67539c2 73 name: $localize`Edit Peer`,
11fdf7f2
TL
74 click: () => this.editPeersModal('edit'),
75 visible: () => !!this.getPeerUUID()
76 };
77 const deletePeerAction: CdTableAction = {
78 permission: 'delete',
9f95a23c 79 icon: Icons.destroy,
f67539c2 80 name: $localize`Delete Peer`,
11fdf7f2
TL
81 click: () => this.deletePeersModal(),
82 visible: () => !!this.getPeerUUID()
83 };
84 this.tableActions = [editModeAction, addPeerAction, editPeerAction, deletePeerAction];
85 }
86
87 ngOnInit() {
88 this.columns = [
f67539c2
TL
89 { prop: 'name', name: $localize`Name`, flexGrow: 2 },
90 { prop: 'mirror_mode', name: $localize`Mode`, flexGrow: 2 },
91 { prop: 'leader_id', name: $localize`Leader`, flexGrow: 2 },
92 { prop: 'image_local_count', name: $localize`# Local`, flexGrow: 2 },
93 { prop: 'image_remote_count', name: $localize`# Remote`, flexGrow: 2 },
11fdf7f2
TL
94 {
95 prop: 'health',
f67539c2 96 name: $localize`Health`,
11fdf7f2
TL
97 cellTemplate: this.healthTmpl,
98 flexGrow: 1
99 }
100 ];
101
f6b5b4d7 102 this.subs = this.rbdMirroringService.subscribeSummary((data) => {
11fdf7f2 103 this.data = data.content_data.pools;
f67539c2 104 this.tableStatus = new TableStatusViewCache(data.status);
11fdf7f2
TL
105 });
106 }
107
108 ngOnDestroy(): void {
109 this.subs.unsubscribe();
110 }
111
112 refresh() {
113 this.rbdMirroringService.refresh();
114 }
115
116 editModeModal() {
2a845540
TL
117 this.router.navigate([
118 BASE_URL,
119 { outlets: { modal: [URLVerbs.EDIT, this.selection.first().name] } }
120 ]);
11fdf7f2
TL
121 }
122
9f95a23c 123 editPeersModal(mode: string) {
11fdf7f2
TL
124 const initialState = {
125 poolName: this.selection.first().name,
126 mode: mode
127 };
128 if (mode === 'edit') {
129 initialState['peerUUID'] = this.getPeerUUID();
130 }
f67539c2 131 this.modalRef = this.modalService.show(PoolEditPeerModalComponent, initialState);
11fdf7f2
TL
132 }
133
134 deletePeersModal() {
135 const poolName = this.selection.first().name;
136 const peerUUID = this.getPeerUUID();
137
138 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
f67539c2
TL
139 itemDescription: $localize`mirror peer`,
140 itemNames: [`${poolName} (${peerUUID})`],
141 submitActionObservable: () =>
142 new Observable((observer: Subscriber<any>) => {
143 this.taskWrapper
144 .wrapTaskAroundCall({
145 task: new FinishedTask('rbd/mirroring/peer/delete', {
146 pool_name: poolName
147 }),
148 call: this.rbdMirroringService.deletePeer(poolName, peerUUID)
149 })
150 .subscribe({
151 error: (resp) => observer.error(resp),
152 complete: () => {
153 this.rbdMirroringService.refresh();
154 observer.complete();
155 }
156 });
157 })
11fdf7f2
TL
158 });
159 }
160
9f95a23c 161 getPeerUUID(): any {
11fdf7f2
TL
162 const selection = this.selection.first();
163 const pool = this.data.find((o) => selection && selection.name === o['name']);
164 if (pool && pool['peer_uuids']) {
165 return pool['peer_uuids'][0];
166 }
9f95a23c
TL
167
168 return undefined;
11fdf7f2
TL
169 }
170
171 updateSelection(selection: CdTableSelection) {
172 this.selection = selection;
173 }
174}