File

src/app/shared/api/rbd-mirroring.service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient, ngZone: NgZone)
Parameters :
Name Type Optional
http HttpClient No
ngZone NgZone No

Methods

addPeer
addPeer(poolName, request)
Parameters :
Name Optional
poolName No
request No
Returns : any
deletePeer
deletePeer(poolName, peerUUID)
Parameters :
Name Optional
poolName No
peerUUID No
Returns : any
getCurrentSummary
getCurrentSummary()

Returns the current value of summaryData

Returns : literal type
getPeer
getPeer(poolName, peerUUID)
Parameters :
Name Optional
poolName No
peerUUID No
Returns : any
getPool
getPool(poolName)
Parameters :
Name Optional
poolName No
Returns : any
refresh
refresh()
Returns : void
refreshAndSchedule
refreshAndSchedule()
Returns : void
subscribeSummary
subscribeSummary(next: (summary: any) => void, error?: (error?: any) => void)

Subscribes to the summaryData, which is updated once every 30 seconds or when a new task is created.

Parameters :
Name Type Optional
next function No
error function Yes
Returns : Subscription
updatePeer
updatePeer(poolName, peerUUID, request)
Parameters :
Name Optional
poolName No
peerUUID No
request No
Returns : any
updatePool
updatePool(poolName, request)
Parameters :
Name Optional
poolName No
request No
Returns : any

Properties

summaryData$
Default value : this.summaryDataSource.asObservable()
Private summaryDataSource
Default value : new BehaviorSubject(null)
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';

import { BehaviorSubject, Subscription } from 'rxjs';

import { ApiModule } from './api.module';

@Injectable({
  providedIn: ApiModule
})
export class RbdMirroringService {
  // Observable sources
  private summaryDataSource = new BehaviorSubject(null);

  // Observable streams
  summaryData$ = this.summaryDataSource.asObservable();

  constructor(private http: HttpClient, private ngZone: NgZone) {
    this.refreshAndSchedule();
  }

  refresh() {
    this.http.get('api/block/mirroring/summary').subscribe((data) => {
      this.summaryDataSource.next(data);
    });
  }

  refreshAndSchedule() {
    this.refresh();

    this.ngZone.runOutsideAngular(() => {
      setTimeout(() => {
        this.ngZone.run(() => {
          this.refreshAndSchedule();
        });
      }, 30000);
    });
  }

  /**
   * Returns the current value of summaryData
   */
  getCurrentSummary(): { [key: string]: any; executing_tasks: object[] } {
    return this.summaryDataSource.getValue();
  }

  /**
   * Subscribes to the summaryData,
   * which is updated once every 30 seconds or when a new task is created.
   */
  subscribeSummary(next: (summary: any) => void, error?: (error: any) => void): Subscription {
    return this.summaryData$.subscribe(next, error);
  }

  getPool(poolName) {
    return this.http.get(`api/block/mirroring/pool/${poolName}`);
  }

  updatePool(poolName, request) {
    return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
  }

  getPeer(poolName, peerUUID) {
    return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
  }

  addPeer(poolName, request) {
    return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
      observe: 'response'
    });
  }

  updatePeer(poolName, peerUUID, request) {
    return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
      observe: 'response'
    });
  }

  deletePeer(poolName, peerUUID) {
    return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {
      observe: 'response'
    });
  }
}

result-matching ""

    No results matching ""