]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.ts
d32b09487e867db48dcb383bf0c751b08789a446
[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, NgZone } from '@angular/core';
3
4 import { BehaviorSubject, Subscription } from 'rxjs';
5
6 import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
7 import { ApiModule } from './api.module';
8
9 @cdEncode
10 @Injectable({
11 providedIn: ApiModule
12 })
13 export class RbdMirroringService {
14 // Observable sources
15 private summaryDataSource = new BehaviorSubject(null);
16
17 // Observable streams
18 summaryData$ = this.summaryDataSource.asObservable();
19
20 constructor(private http: HttpClient, private ngZone: NgZone) {
21 this.refreshAndSchedule();
22 }
23
24 refresh() {
25 this.http.get('api/block/mirroring/summary').subscribe((data) => {
26 this.summaryDataSource.next(data);
27 });
28 }
29
30 refreshAndSchedule() {
31 this.refresh();
32
33 this.ngZone.runOutsideAngular(() => {
34 setTimeout(() => {
35 this.ngZone.run(() => {
36 this.refreshAndSchedule();
37 });
38 }, 30000);
39 });
40 }
41
42 /**
43 * Returns the current value of summaryData
44 */
45 getCurrentSummary(): { [key: string]: any; executing_tasks: object[] } {
46 return this.summaryDataSource.getValue();
47 }
48
49 /**
50 * Subscribes to the summaryData,
51 * which is updated once every 30 seconds or when a new task is created.
52 */
53 subscribeSummary(next: (summary: any) => void, error?: (error: any) => void): Subscription {
54 return this.summaryData$.subscribe(next, error);
55 }
56
57 getPool(poolName: string) {
58 return this.http.get(`api/block/mirroring/pool/${poolName}`);
59 }
60
61 updatePool(poolName: string, request: any) {
62 return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
63 }
64
65 getSiteName() {
66 return this.http.get(`api/block/mirroring/site_name`);
67 }
68
69 setSiteName(@cdEncodeNot siteName: string) {
70 return this.http.put(
71 `api/block/mirroring/site_name`,
72 { site_name: siteName },
73 { observe: 'response' }
74 );
75 }
76
77 createBootstrapToken(poolName: string) {
78 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/token`, {});
79 }
80
81 importBootstrapToken(
82 poolName: string,
83 @cdEncodeNot direction: string,
84 @cdEncodeNot token: string
85 ) {
86 const request = {
87 direction: direction,
88 token: token
89 };
90 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/peer`, request, {
91 observe: 'response'
92 });
93 }
94
95 getPeer(poolName: string, peerUUID: string) {
96 return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
97 }
98
99 addPeer(poolName: string, request: any) {
100 return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
101 observe: 'response'
102 });
103 }
104
105 updatePeer(poolName: string, peerUUID: string, request: any) {
106 return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
107 observe: 'response'
108 });
109 }
110
111 deletePeer(poolName: string, peerUUID: string) {
112 return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {
113 observe: 'response'
114 });
115 }
116 }