From: Volker Theile Date: Thu, 26 Apr 2018 12:33:24 +0000 (+0200) Subject: mgr/dashboard: Refactor performance counter service X-Git-Tag: v14.0.0~200^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9ed646109778e482e34ba303d5f648b1624e80d9;p=ceph.git mgr/dashboard: Refactor performance counter service - Rename performance counter service - Return an Observable instead of a Promise object Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts index e4c6ddcc1d515..d6ff1b54878ce 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts @@ -4,8 +4,8 @@ import { RouterTestingModule } from '@angular/router/testing'; import { BsDropdownModule } from 'ngx-bootstrap'; import { - TablePerformanceCounterService -} from '../../../shared/api/table-performance-counter.service'; + PerformanceCounterService +} from '../../../shared/api/performance-counter.service'; import { PerformanceCounterModule } from '../performance-counter.module'; import { PerformanceCounterComponent } from './performance-counter.component'; @@ -30,7 +30,7 @@ describe('PerformanceCounterComponent', () => { async(() => { TestBed.configureTestingModule({ imports: [PerformanceCounterModule, BsDropdownModule.forRoot(), RouterTestingModule], - providers: [{ provide: TablePerformanceCounterService, useValue: fakeService }] + providers: [{ provide: PerformanceCounterService, useValue: fakeService }] }).compileComponents(); }) ); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts index 30c283e3231ed..833417904aa1d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts @@ -1,8 +1,8 @@ import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { - TablePerformanceCounterService -} from '../../../shared/api/table-performance-counter.service'; + PerformanceCounterService +} from '../../../shared/api/performance-counter.service'; import { CdTableColumn } from '../../../shared/models/cd-table-column'; /** @@ -30,7 +30,7 @@ export class TablePerformanceCounterComponent implements OnInit { */ @Input() serviceId: string; - constructor(private performanceCounterService: TablePerformanceCounterService) { } + constructor(private performanceCounterService: PerformanceCounterService) { } ngOnInit() { this.columns = [ @@ -54,7 +54,7 @@ export class TablePerformanceCounterComponent implements OnInit { getCounters() { this.performanceCounterService.get(this.serviceType, this.serviceId) - .then((resp) => { + .subscribe((resp: object[]) => { this.counters = resp; }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts index 26656cdd0a03a..4e63dc17692bc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts @@ -8,13 +8,13 @@ import { DashboardService } from './dashboard.service'; import { HostService } from './host.service'; import { MonitorService } from './monitor.service'; import { OsdService } from './osd.service'; +import { PerformanceCounterService } from './performance-counter.service'; import { PoolService } from './pool.service'; import { RbdMirroringService } from './rbd-mirroring.service'; import { RbdService } from './rbd.service'; import { RgwBucketService } from './rgw-bucket.service'; import { RgwDaemonService } from './rgw-daemon.service'; import { RgwUserService } from './rgw-user.service'; -import { TablePerformanceCounterService } from './table-performance-counter.service'; import { TcmuIscsiService } from './tcmu-iscsi.service'; @NgModule({ @@ -34,7 +34,7 @@ import { TcmuIscsiService } from './tcmu-iscsi.service'; RgwBucketService, RgwDaemonService, RgwUserService, - TablePerformanceCounterService, + PerformanceCounterService, TcmuIscsiService ] }) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.spec.ts new file mode 100644 index 0000000000000..6cee171b1d27a --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.spec.ts @@ -0,0 +1,27 @@ +import { HttpClientModule } from '@angular/common/http'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { inject, TestBed } from '@angular/core/testing'; + +import { BsDropdownModule } from 'ngx-bootstrap'; + +import { PerformanceCounterService } from './performance-counter.service'; + +describe('PerformanceCounterService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [PerformanceCounterService], + imports: [ + HttpClientTestingModule, + BsDropdownModule.forRoot(), + HttpClientModule + ] + }); + }); + + it( + 'should be created', + inject([PerformanceCounterService], (service: PerformanceCounterService) => { + expect(service).toBeTruthy(); + }) + ); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.ts new file mode 100644 index 0000000000000..d4ae1fecdfee9 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.ts @@ -0,0 +1,25 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; + +import 'rxjs/add/observable/of'; +import { Observable } from 'rxjs/Observable'; + +@Injectable() +export class PerformanceCounterService { + + private url = 'api/perf_counters'; + + constructor(private http: HttpClient) {} + + list() { + return this.http.get(this.url); + } + + get(service_type: string, service_id: string) { + const serviceType = service_type.replace('-', '_'); + return this.http.get(`${this.url}/${serviceType}/${service_id}`) + .flatMap((resp) => { + return Observable.of(resp['counters']); + }); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.spec.ts deleted file mode 100644 index 6f0af94e4b603..0000000000000 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { HttpClientModule } from '@angular/common/http'; -import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { inject, TestBed } from '@angular/core/testing'; - -import { BsDropdownModule } from 'ngx-bootstrap'; - -import { TablePerformanceCounterService } from './table-performance-counter.service'; - -describe('TablePerformanceCounterService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [TablePerformanceCounterService], - imports: [ - HttpClientTestingModule, - BsDropdownModule.forRoot(), - HttpClientModule - ] - }); - }); - - it( - 'should be created', - inject([TablePerformanceCounterService], (service: TablePerformanceCounterService) => { - expect(service).toBeTruthy(); - }) - ); -}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.ts deleted file mode 100644 index b6ac5d5fe3e67..0000000000000 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; - -@Injectable() -export class TablePerformanceCounterService { - - private url = 'api/perf_counters'; - - constructor(private http: HttpClient) { } - - list() { - return this.http.get(this.url) - .toPromise() - .then((resp: object): object => { - return resp; - }); - } - - get(service_type: string, service_id: string) { - const serviceType = service_type.replace('-', '_'); - - return this.http.get(`${this.url}/${serviceType}/${service_id}`) - .toPromise() - .then((resp: object): Array => { - return resp['counters']; - }); - } -}