]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Improve RbdMirroringService's subscribe methods 35705/head
authorTiago Melo <tmelo@suse.com>
Thu, 14 May 2020 16:01:57 +0000 (16:01 +0000)
committerTiago Melo <tmelo@suse.com>
Wed, 24 Jun 2020 11:19:21 +0000 (11:19 +0000)
Signed-off-by: Tiago Melo <tmelo@suse.com>
(cherry picked from commit b599a5db7b5c162e6e1c4a68df5efea725b6d381)

Modified nfs-list.component.spec.ts:134 to be able to pass the unit tests.

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/bootstrap-create-modal/bootstrap-create-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/bootstrap-import-modal/bootstrap-import-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/daemon-list/daemon-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/image-list/image-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/overview/overview.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/pool-edit-mode-modal/pool-edit-mode-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/pool-list/pool-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/models/mirroring-summary.ts [new file with mode: 0644]

index b2130f8b515760b6c947655bce509b3a318a05e2..63ccdc71175c0e9b04da5f8fd718e6c7fe933358 100644 (file)
@@ -55,11 +55,7 @@ export class BootstrapCreateModalComponent implements OnDestroy, OnInit {
       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({
index 0e7d56d408730123709b17103010a780a69da23f..ca6c833631202f1a49a39b7de2a02bc86aaaaa5e 100644 (file)
@@ -62,11 +62,7 @@ export class BootstrapImportModalComponent implements OnInit, OnDestroy {
       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({
index 62826028d75dec3e3753abf3434de7d876cdf4bf..7eaae7aa0243717f619289c9a745d77eb4b50f19 100644 (file)
@@ -45,10 +45,7 @@ export class DaemonListComponent implements OnInit, OnDestroy {
       }
     ];
 
-    this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
-      if (!data) {
-        return;
-      }
+    this.subs = this.rbdMirroringService.subscribeSummary((data) => {
       this.data = data.content_data.daemons;
     });
   }
index 5acdd1ea29d21cfb123b2d5d298c375c59a57078..3867da7db92a5deafaa055729a1002c5cfa58628 100644 (file)
@@ -77,10 +77,7 @@ export class ImageListComponent implements OnInit, OnDestroy {
       }
     ];
 
-    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;
index 682ed68c8bc3177598add8d28582c4623b6263fa..a73db2f62fafa7acb8fec31a5ff39297db849347 100644 (file)
@@ -67,10 +67,7 @@ export class OverviewComponent implements OnInit, OnDestroy {
   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;
 
index 3a393170b87f59ab540954f8a593039cbffc780d..64054aabb0838a6101ee3b391a3eb0fdc50fec3b 100644 (file)
@@ -59,12 +59,8 @@ export class PoolEditModeModalComponent implements OnInit, OnDestroy {
       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;
index efa0beba8c75be31743f18ef7de94249afa87fa8..2cb0bfd46a67346c60600d3db2ca06e81e6edc5c 100644 (file)
@@ -94,10 +94,7 @@ export class PoolListComponent implements OnInit, OnDestroy {
       }
     ];
 
-    this.subs = this.rbdMirroringService.subscribeSummary((data: any) => {
-      if (!data) {
-        return;
-      }
+    this.subs = this.rbdMirroringService.subscribeSummary((data) => {
       this.data = data.content_data.pools;
     });
   }
index 8ad7e0d4e249d2d0814a2803128dc2eff1f1c68a..a62f28a19f5e961926850a066a997dea5de951ae 100644 (file)
@@ -131,7 +131,7 @@ describe('NfsListComponent', () => {
       addExport('b');
       addExport('c');
       component.exports = exports;
-      refresh(new Summary());
+      refresh({ executing_tasks: [] });
       spyOn(nfsService, 'list').and.callFake(() => of(exports));
       fixture.detectChanges();
 
index 37be86346dd0cca9112bf8facdb5fa2adc7fc086..34eb6282526a0e18b719fce3269f21040a29f0ca 100644 (file)
@@ -62,7 +62,7 @@ describe('RbdMirroringService', () => {
     const subs = service.startPolling();
     tick();
     const calledWith: any[] = [];
-    service.subscribeSummary((data: any) => {
+    service.subscribeSummary((data) => {
       calledWith.push(data);
     });
     tick(service.REFRESH_INTERVAL * 2);
@@ -70,23 +70,11 @@ describe('RbdMirroringService', () => {
 
     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();
 
index c1f069323be2480efcd39cd5380acb08679b7e95..6a378b359971a691d3f03be0de060f6a5edd3562 100644 (file)
@@ -2,8 +2,10 @@ import { HttpClient } from '@angular/common/http';
 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';
 
@@ -14,7 +16,7 @@ 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();
 
@@ -30,29 +32,25 @@ export class RbdMirroringService {
     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) {
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/mirroring-summary.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/mirroring-summary.ts
new file mode 100644 (file)
index 0000000..95327ed
--- /dev/null
@@ -0,0 +1,4 @@
+export interface MirroringSummary {
+  content_data?: any;
+  site_name?: any;
+}