]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.ts
4958382e27982a1a1f06aeaafbbe6a1775e28e78
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd-mirroring.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { BehaviorSubject, Observable, Subscription } from 'rxjs';
5 import { filter } from 'rxjs/operators';
6
7 import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
8 import { MirroringSummary } from '../models/mirroring-summary';
9 import { TimerService } from '../services/timer.service';
10
11 @cdEncode
12 @Injectable({
13 providedIn: 'root'
14 })
15 export class RbdMirroringService {
16 readonly REFRESH_INTERVAL = 30000;
17 // Observable sources
18 private summaryDataSource = new BehaviorSubject<MirroringSummary>(null);
19 // Observable streams
20 summaryData$ = this.summaryDataSource.asObservable();
21
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());
28 }
29
30 refresh(): Subscription {
31 return this.retrieveSummaryObservable().subscribe(this.retrieveSummaryObserver());
32 }
33
34 private retrieveSummaryObservable(): Observable<MirroringSummary> {
35 return this.http.get('api/block/mirroring/summary');
36 }
37
38 private retrieveSummaryObserver(): (data: MirroringSummary) => void {
39 return (data: any) => {
40 this.summaryDataSource.next(data);
41 };
42 }
43
44 /**
45 * Subscribes to the summaryData,
46 * which is updated periodically or when a new task is created.
47 */
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);
53 }
54
55 getPool(poolName: string) {
56 return this.http.get(`api/block/mirroring/pool/${poolName}`);
57 }
58
59 updatePool(poolName: string, request: any) {
60 return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
61 }
62
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) {
94 return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
95 }
96
97 addPeer(poolName: string, request: any) {
98 return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
99 observe: 'response'
100 });
101 }
102
103 updatePeer(poolName: string, peerUUID: string, request: any) {
104 return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
105 observe: 'response'
106 });
107 }
108
109 deletePeer(poolName: string, peerUUID: string) {
110 return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {
111 observe: 'response'
112 });
113 }
114 }