From 8319165e9da19f885ab0cec7a578796bf831e2f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Wed, 17 Nov 2021 09:29:38 +0100 Subject: [PATCH] mgr/dashboard: rgw daemon list: add realm column MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Some refactoring and cleanup. Fixes: https://tracker.ceph.com/issues/53301 Signed-off-by: Alfonso Martínez --- .../rgw-daemon-list.component.spec.ts | 31 ++++++++++++++++++- .../rgw-daemon-list.component.ts | 28 +++++++++-------- .../rgw-user-list/rgw-user-list.component.ts | 1 - .../app/shared/api/rgw-daemon.service.spec.ts | 2 +- .../src/app/shared/api/rgw-daemon.service.ts | 16 +++++----- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts index 4278b0c0d3a59..ecf0bedf961d0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts @@ -1,5 +1,6 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; @@ -7,6 +8,8 @@ import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; import { of } from 'rxjs'; import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module'; +import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon'; +import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service'; import { RgwSiteService } from '~/app/shared/api/rgw-site.service'; import { Permissions } from '~/app/shared/models/permissions'; import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; @@ -20,7 +23,18 @@ describe('RgwDaemonListComponent', () => { let fixture: ComponentFixture; let getPermissionsSpy: jasmine.Spy; let getRealmsSpy: jasmine.Spy; + let listDaemonsSpy: jest.SpyInstance; const permissions = new Permissions({ grafana: ['read'] }); + const daemon: RgwDaemon = { + id: '8000', + service_map_id: '4803', + version: 'ceph version', + server_hostname: 'ceph', + realm_name: 'realm1', + zonegroup_name: 'zg1-realm1', + zone_name: 'zone1-zg1-realm1', + default: true + }; const expectTabsAndHeading = (length: number, heading: string) => { const tabs = TabHelper.getTextContents(fixture); @@ -45,6 +59,9 @@ describe('RgwDaemonListComponent', () => { getPermissionsSpy.and.returnValue(new Permissions({})); getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get'); getRealmsSpy.and.returnValue(of([])); + listDaemonsSpy = jest + .spyOn(TestBed.inject(RgwDaemonService), 'list') + .mockReturnValue(of([daemon])); fixture = TestBed.createComponent(RgwDaemonListComponent); component = fixture.componentInstance; }); @@ -54,6 +71,18 @@ describe('RgwDaemonListComponent', () => { expect(component).toBeTruthy(); }); + it('should show a row with daemon info', fakeAsync(() => { + fixture.detectChanges(); + tick(); + expect(listDaemonsSpy).toHaveBeenCalledTimes(1); + expect(component.daemons).toEqual([daemon]); + expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain( + 'total 1' + ); + + fixture.destroy(); + })); + it('should only show Daemons List tab', () => { fixture.detectChanges(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts index 96a7938942c33..c620843fb8acd 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts @@ -1,7 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { take } from 'rxjs/operators'; - import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon'; import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service'; import { RgwSiteService } from '~/app/shared/api/rgw-site.service'; @@ -19,7 +17,7 @@ import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; }) export class RgwDaemonListComponent extends ListWithDetails implements OnInit { columns: CdTableColumn[] = []; - daemons: object[] = []; + daemons: RgwDaemon[] = []; grafanaPermission: Permission; isMultiSite: boolean; @@ -45,14 +43,19 @@ export class RgwDaemonListComponent extends ListWithDetails implements OnInit { prop: 'server_hostname', flexGrow: 2 }, + { + name: $localize`Zone`, + prop: 'zone_name', + flexGrow: 2 + }, { name: $localize`Zone Group`, prop: 'zonegroup_name', flexGrow: 2 }, { - name: $localize`Zone`, - prop: 'zone_name', + name: $localize`Realm`, + prop: 'realm_name', flexGrow: 2 }, { @@ -68,13 +71,12 @@ export class RgwDaemonListComponent extends ListWithDetails implements OnInit { } getDaemonList(context: CdTableFetchDataContext) { - this.rgwDaemonService.daemons$.pipe(take(1)).subscribe( - (resp: RgwDaemon[]) => { - this.daemons = resp; - }, - () => { - context.error(); - } - ); + this.rgwDaemonService.list().subscribe(this.updateDaemons, () => { + context.error(); + }); } + + private updateDaemons = (daemons: RgwDaemon[]) => { + this.daemons = daemons; + }; } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts index e48aaa7c40640..34cccb9409d6b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts @@ -1,6 +1,5 @@ import { Component, NgZone, OnInit, TemplateRef, ViewChild } from '@angular/core'; -import _ from 'lodash'; import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs'; import { RgwUserService } from '~/app/shared/api/rgw-user.service'; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts index 6f96c6ab51a59..93ef337869367 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts @@ -50,7 +50,7 @@ describe('RgwDaemonService', () => { expect(service['daemons'].getValue()).toEqual(daemonList); }); - it('should get daemon ', () => { + it('should call "get daemon"', () => { service.get('foo').subscribe(); const req = httpTesting.expectOne('api/rgw/daemon/foo'); expect(req.request.method).toBe('GET'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts index bc81dacf47e0c..c947f3ed45597 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import _ from 'lodash'; import { BehaviorSubject, Observable, of, throwError } from 'rxjs'; -import { mergeMap, retryWhen, take, tap } from 'rxjs/operators'; +import { mergeMap, take, tap } from 'rxjs/operators'; import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon'; import { cdEncode } from '~/app/shared/decorators/cd-encode'; @@ -59,17 +59,15 @@ export class RgwDaemonService { request(next: (params: HttpParams) => Observable) { return this.selectedDaemon.pipe( mergeMap((daemon: RgwDaemon) => - // If there is no selected daemon, retrieve daemon list (default daemon will be selected) - // and try again if daemon list is not empty. + // If there is no selected daemon, retrieve daemon list so default daemon will be selected. _.isEmpty(daemon) - ? this.list().pipe(mergeMap((daemons) => throwError(!_.isEmpty(daemons)))) + ? this.list().pipe( + mergeMap((daemons) => + _.isEmpty(daemons) ? throwError('No RGW daemons found!') : this.selectedDaemon$ + ) + ) : of(daemon) ), - retryWhen((error) => - error.pipe( - mergeMap((hasToRetry) => (hasToRetry ? error : throwError('No RGW daemons found!'))) - ) - ), take(1), mergeMap((daemon: RgwDaemon) => { let params = new HttpParams(); -- 2.39.5