]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Refactor performance counter service 21673/head
authorVolker Theile <vtheile@suse.com>
Thu, 26 Apr 2018 12:33:24 +0000 (14:33 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 26 Apr 2018 14:07:37 +0000 (16:07 +0200)
- Rename performance counter service
- Return an Observable instead of a Promise object

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.spec.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/api/performance-counter.service.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.spec.ts [deleted file]
src/pybind/mgr/dashboard/frontend/src/app/shared/api/table-performance-counter.service.ts [deleted file]

index e4c6ddcc1d5157b0f4ed8ef200b9fd28f56155d3..d6ff1b54878ce5ae968be38f5784f7c5faaaf34a 100644 (file)
@@ -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();
     })
   );
index 30c283e3231ed116adf796682698ca28b7ff9e22..833417904aa1dee81b38e95fa882d58c56d92712 100644 (file)
@@ -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;
       });
   }
index 26656cdd0a03a706c1ae6db8d7ee8dae7e128636..4e63dc17692bce62633df80e852d9420ff58f5ff 100644 (file)
@@ -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 (file)
index 0000000..6cee171
--- /dev/null
@@ -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 (file)
index 0000000..d4ae1fe
--- /dev/null
@@ -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 (file)
index 6f0af94..0000000
+++ /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 (file)
index b6ac5d5..0000000
+++ /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<object> => {
-        return resp['counters'];
-      });
-  }
-}