]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd-mirroring.service.ts
CommitLineData
11fdf7f2 1import { HttpClient } from '@angular/common/http';
1911f103 2import { Injectable } from '@angular/core';
11fdf7f2 3
1911f103 4import { BehaviorSubject, Observable, Subscription } from 'rxjs';
f6b5b4d7 5import { filter } from 'rxjs/operators';
11fdf7f2 6
9f95a23c 7import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
f6b5b4d7 8import { MirroringSummary } from '../models/mirroring-summary';
1911f103 9import { TimerService } from '../services/timer.service';
11fdf7f2 10
9f95a23c 11@cdEncode
11fdf7f2 12@Injectable({
f67539c2 13 providedIn: 'root'
11fdf7f2
TL
14})
15export class RbdMirroringService {
1911f103 16 readonly REFRESH_INTERVAL = 30000;
11fdf7f2 17 // Observable sources
f6b5b4d7 18 private summaryDataSource = new BehaviorSubject<MirroringSummary>(null);
11fdf7f2
TL
19 // Observable streams
20 summaryData$ = this.summaryDataSource.asObservable();
21
1911f103
TL
22 constructor(private http: HttpClient, private timerService: TimerService) {}
23
24 startPolling(): Subscription {
25 return this.timerService
26 .get(() => this.retrieveSummaryObservable(), this.REFRESH_INTERVAL)
27 .subscribe(this.retrieveSummaryObserver());
11fdf7f2
TL
28 }
29
1911f103
TL
30 refresh(): Subscription {
31 return this.retrieveSummaryObservable().subscribe(this.retrieveSummaryObserver());
11fdf7f2
TL
32 }
33
f6b5b4d7 34 private retrieveSummaryObservable(): Observable<MirroringSummary> {
1911f103
TL
35 return this.http.get('api/block/mirroring/summary');
36 }
11fdf7f2 37
f6b5b4d7 38 private retrieveSummaryObserver(): (data: MirroringSummary) => void {
1911f103
TL
39 return (data: any) => {
40 this.summaryDataSource.next(data);
41 };
11fdf7f2
TL
42 }
43
11fdf7f2
TL
44 /**
45 * Subscribes to the summaryData,
1911f103 46 * which is updated periodically or when a new task is created.
11fdf7f2 47 */
f6b5b4d7
TL
48 subscribeSummary(
49 next: (summary: MirroringSummary) => void,
50 error?: (error: any) => void
51 ): Subscription {
52 return this.summaryData$.pipe(filter((value) => !!value)).subscribe(next, error);
11fdf7f2
TL
53 }
54
9f95a23c 55 getPool(poolName: string) {
11fdf7f2
TL
56 return this.http.get(`api/block/mirroring/pool/${poolName}`);
57 }
58
9f95a23c 59 updatePool(poolName: string, request: any) {
11fdf7f2
TL
60 return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
61 }
62
9f95a23c
TL
63 getSiteName() {
64 return this.http.get(`api/block/mirroring/site_name`);
65 }
66
67 setSiteName(@cdEncodeNot siteName: string) {
68 return this.http.put(
69 `api/block/mirroring/site_name`,
70 { site_name: siteName },
71 { observe: 'response' }
72 );
73 }
74
75 createBootstrapToken(poolName: string) {
76 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/token`, {});
77 }
78
79 importBootstrapToken(
80 poolName: string,
81 @cdEncodeNot direction: string,
82 @cdEncodeNot token: string
83 ) {
84 const request = {
85 direction: direction,
86 token: token
87 };
88 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/peer`, request, {
89 observe: 'response'
90 });
91 }
92
93 getPeer(poolName: string, peerUUID: string) {
11fdf7f2
TL
94 return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
95 }
96
39ae355f
TL
97 getPeerForPool(poolName: string) {
98 return this.http.get(`api/block/mirroring/pool/${poolName}/peer`);
99 }
100
9f95a23c 101 addPeer(poolName: string, request: any) {
11fdf7f2
TL
102 return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
103 observe: 'response'
104 });
105 }
106
9f95a23c 107 updatePeer(poolName: string, peerUUID: string, request: any) {
11fdf7f2
TL
108 return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
109 observe: 'response'
110 });
111 }
112
9f95a23c 113 deletePeer(poolName: string, peerUUID: string) {
11fdf7f2
TL
114 return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {
115 observe: 'response'
116 });
117 }
118}