1 import { HttpClient } from '@angular/common/http';
2 import { Injectable, NgZone } from '@angular/core';
4 import { BehaviorSubject, Subscription } from 'rxjs';
6 import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
7 import { ApiModule } from './api.module';
13 export class RbdMirroringService {
15 private summaryDataSource = new BehaviorSubject(null);
18 summaryData$ = this.summaryDataSource.asObservable();
20 constructor(private http: HttpClient, private ngZone: NgZone) {
21 this.refreshAndSchedule();
25 this.http.get('api/block/mirroring/summary').subscribe((data) => {
26 this.summaryDataSource.next(data);
30 refreshAndSchedule() {
33 this.ngZone.runOutsideAngular(() => {
35 this.ngZone.run(() => {
36 this.refreshAndSchedule();
43 * Returns the current value of summaryData
45 getCurrentSummary(): { [key: string]: any; executing_tasks: object[] } {
46 return this.summaryDataSource.getValue();
50 * Subscribes to the summaryData,
51 * which is updated once every 30 seconds or when a new task is created.
53 subscribeSummary(next: (summary: any) => void, error?: (error: any) => void): Subscription {
54 return this.summaryData$.subscribe(next, error);
57 getPool(poolName: string) {
58 return this.http.get(`api/block/mirroring/pool/${poolName}`);
61 updatePool(poolName: string, request: any) {
62 return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
66 return this.http.get(`api/block/mirroring/site_name`);
69 setSiteName(@cdEncodeNot siteName: string) {
71 `api/block/mirroring/site_name`,
72 { site_name: siteName },
73 { observe: 'response' }
77 createBootstrapToken(poolName: string) {
78 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/token`, {});
83 @cdEncodeNot direction: string,
84 @cdEncodeNot token: string
90 return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/peer`, request, {
95 getPeer(poolName: string, peerUUID: string) {
96 return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
99 addPeer(poolName: string, request: any) {
100 return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
105 updatePeer(poolName: string, peerUUID: string, request: any) {
106 return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
111 deletePeer(poolName: string, peerUUID: string) {
112 return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {