this.createBootstrapForm.get('siteName').setValue(response.site_name);
});
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
-
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
const pools = data.content_data.pools;
this.pools = pools.reduce((acc: any[], pool: Pool) => {
acc.push({
this.importBootstrapForm.get('siteName').setValue(response.site_name);
});
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
-
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
const pools = data.content_data.pools;
this.pools = pools.reduce((acc: any[], pool: Pool) => {
acc.push({
}
];
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
this.data = data.content_data.daemons;
});
}
}
];
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
this.image_error.data = data.content_data.image_error;
this.image_syncing.data = data.content_data.image_syncing;
this.image_ready.data = data.content_data.image_ready;
ngOnInit() {
this.subs.add(this.rbdMirroringService.startPolling());
this.subs.add(
- this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
+ this.rbdMirroringService.subscribeSummary((data) => {
this.status = data.content_data.status;
this.siteName = data.site_name;
this.setResponse(resp);
});
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
this.peerExists = false;
- if (!data) {
- return;
- }
-
const poolData = data.content_data.pools;
const pool = poolData.find((o: any) => this.poolName === o['name']);
this.peerExists = pool && pool['peer_uuids'].length;
}
];
- this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
- if (!data) {
- return;
- }
+ this.subs = this.rbdMirroringService.subscribeSummary((data) => {
this.data = data.content_data.pools;
});
}
addExport('b');
addExport('c');
component.exports = exports;
- refresh(new Summary());
+ refresh({ executing_tasks: [] });
spyOn(nfsService, 'list').and.callFake(() => of(exports));
fixture.detectChanges();
const subs = service.startPolling();
tick();
const calledWith: any[] = [];
- service.subscribeSummary((data: any) => {
+ service.subscribeSummary((data) => {
calledWith.push(data);
});
tick(service.REFRESH_INTERVAL * 2);
expect(calls.length).toEqual(3);
calls.forEach((call: TestRequest) => flushCalls(call));
- expect(calledWith).toEqual([null, summary]);
+ expect(calledWith).toEqual([summary]);
subs.unsubscribe();
}));
- it('should get current summary', () => {
- service.refresh();
- const calledWith: any[] = [];
- service.subscribeSummary((data: any) => {
- calledWith.push(data);
- });
- const calls = getMirroringSummaryCalls();
- calls.forEach((call: TestRequest) => flushCalls(call));
-
- expect(service.getCurrentSummary()).toEqual(summary);
- });
-
it('should get pool config', () => {
service.getPool('poolName').subscribe();
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
+import { filter } from 'rxjs/operators';
import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
+import { MirroringSummary } from '../models/mirroring-summary';
import { TimerService } from '../services/timer.service';
import { ApiModule } from './api.module';
export class RbdMirroringService {
readonly REFRESH_INTERVAL = 30000;
// Observable sources
- private summaryDataSource = new BehaviorSubject(null);
+ private summaryDataSource = new BehaviorSubject<MirroringSummary>(null);
// Observable streams
summaryData$ = this.summaryDataSource.asObservable();
return this.retrieveSummaryObservable().subscribe(this.retrieveSummaryObserver());
}
- private retrieveSummaryObservable(): Observable<Object> {
+ private retrieveSummaryObservable(): Observable<MirroringSummary> {
return this.http.get('api/block/mirroring/summary');
}
- private retrieveSummaryObserver(): (data: any) => void {
+ private retrieveSummaryObserver(): (data: MirroringSummary) => void {
return (data: any) => {
this.summaryDataSource.next(data);
};
}
- /**
- * Returns the current value of summaryData
- */
- getCurrentSummary(): { [key: string]: any; executing_tasks: object[] } {
- return this.summaryDataSource.getValue();
- }
-
/**
* Subscribes to the summaryData,
* which is updated periodically or when a new task is created.
*/
- subscribeSummary(next: (summary: any) => void, error?: (error: any) => void): Subscription {
- return this.summaryData$.subscribe(next, error);
+ subscribeSummary(
+ next: (summary: MirroringSummary) => void,
+ error?: (error: any) => void
+ ): Subscription {
+ return this.summaryData$.pipe(filter((value) => !!value)).subscribe(next, error);
}
getPool(poolName: string) {
--- /dev/null
+export interface MirroringSummary {
+ content_data?: any;
+ site_name?: any;
+}