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