]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Use task wrapper in RBD list
authorStephan Müller <smueller@suse.com>
Wed, 30 May 2018 13:22:31 +0000 (15:22 +0200)
committerStephan Müller <smueller@suse.com>
Thu, 14 Jun 2018 14:46:35 +0000 (16:46 +0200)
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts

index 0c5c979ab47dce8da0aeec03948d4618aba15791..1f5b842f32eead42b067c9cac650a7612d1c11de 100644 (file)
@@ -1,21 +1,17 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
 import { ToastModule } from 'ng2-toastr';
 import {
   AlertModule,
   BsDropdownModule,
-  BsModalRef,
   ModalModule,
   TabsModule,
   TooltipModule
 } from 'ngx-bootstrap';
-import { throwError as observableThrowError } from 'rxjs';
 
-import { RbdService } from '../../../shared/api/rbd.service';
 import { ComponentsModule } from '../../../shared/components/components.module';
-import { NotificationService } from '../../../shared/services/notification.service';
 import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
 import { RbdDetailsComponent } from '../rbd-details/rbd-details.component';
@@ -51,41 +47,4 @@ describe('RbdListComponent', () => {
   it('should create', () => {
     expect(component).toBeTruthy();
   });
-
-  describe('api delete request', () => {
-    let called;
-    let rbdService: RbdService;
-    let notificationService: NotificationService;
-
-    beforeEach(() => {
-      called = false;
-      rbdService = new RbdService(null);
-      notificationService = new NotificationService(null, null);
-      component = new RbdListComponent(
-        rbdService,
-        null,
-        null,
-        null,
-        null,
-        notificationService,
-        null,
-        null
-      );
-      spyOn(rbdService, 'delete').and.returnValue(observableThrowError({ status: 500 }));
-      spyOn(notificationService, 'notifyTask').and.stub();
-      component.modalRef = new BsModalRef();
-      component.modalRef.content = {
-        stopLoadingSpinner: () => (called = true)
-      };
-    });
-
-    it('should make sure that if the deletion fails stopLoadingSpinner is called', <any>fakeAsync(
-      () => {
-        expect(called).toBe(false);
-        component.deleteRbd('sth', 'test');
-        tick(500);
-        expect(called).toBe(true);
-      }
-    ));
-  });
 });
index f60089219daffa3e185d1812e8ba7dd05c478ffe..e31f15c9e034b4d05736b464e9c9da7a8faa372c 100644 (file)
@@ -8,7 +8,6 @@ import {
   DeletionModalComponent
 } from '../../../shared/components/deletion-modal/deletion-modal.component';
 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
-import { NotificationType } from '../../../shared/enum/notification-type.enum';
 import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
@@ -16,12 +15,8 @@ import { ExecutingTask } from '../../../shared/models/executing-task';
 import { FinishedTask } from '../../../shared/models/finished-task';
 import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe';
 import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
-import {
-  NotificationService
-} from '../../../shared/services/notification.service';
 import { SummaryService } from '../../../shared/services/summary.service';
-import { TaskManagerMessageService } from '../../../shared/services/task-manager-message.service';
-import { TaskManagerService } from '../../../shared/services/task-manager.service';
+import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
 import {
   FlattenConfirmationModalComponent
 } from '../flatten-confirmation-modal/flatten-confimation-modal.component';
@@ -55,9 +50,7 @@ export class RbdListComponent implements OnInit, OnDestroy {
               private dimlessPipe: DimlessPipe,
               private summaryService: SummaryService,
               private modalService: BsModalService,
-              private notificationService: NotificationService,
-              private taskManagerMessageService: TaskManagerMessageService,
-              private taskManagerService: TaskManagerService) {
+              private taskWrapper: TaskWrapperService) {
   }
 
   ngOnInit() {
@@ -241,35 +234,6 @@ export class RbdListComponent implements OnInit, OnDestroy {
     this.selection = selection;
   }
 
-  deleteRbd(poolName: string, imageName: string) {
-    const finishedTask = new FinishedTask();
-    finishedTask.name = 'rbd/delete';
-    finishedTask.metadata = {'pool_name': poolName, 'image_name': imageName};
-    this.rbdService.delete(poolName, imageName)
-      .toPromise().then((resp) => {
-        if (resp.status === 202) {
-          this.notificationService.show(NotificationType.info,
-            `RBD deletion in progress...`,
-            this.taskManagerMessageService.getDescription(finishedTask));
-          const executingTask = new ExecutingTask();
-          executingTask.name = finishedTask.name;
-          executingTask.metadata = finishedTask.metadata;
-          this.executingTasks.push(executingTask);
-          this.taskManagerService.subscribe(executingTask.name, executingTask.metadata,
-            (asyncFinishedTask: FinishedTask) => {
-              this.notificationService.notifyTask(asyncFinishedTask);
-            });
-        } else {
-          finishedTask.success = true;
-          this.notificationService.notifyTask(finishedTask);
-        }
-        this.modalRef.hide();
-        this.loadImages(null);
-      }).catch((resp) => {
-        this.modalRef.content.stopLoadingSpinner();
-      });
-  }
-
   deleteRbdModal() {
     const poolName = this.selection.first().pool_name;
     const imageName = this.selection.first().name;
@@ -277,36 +241,35 @@ export class RbdListComponent implements OnInit, OnDestroy {
     this.modalRef.content.setUp({
       metaType: 'RBD',
       pattern: `${poolName}/${imageName}`,
-      deletionMethod: () => this.deleteRbd(poolName, imageName),
+      deletionObserver: () =>
+        this.taskWrapper.wrapTaskAroundCall({
+          task: new FinishedTask('rbd/delete', {
+            pool_name: poolName,
+            image_name: imageName
+          }),
+          tasks: this.executingTasks,
+          call: this.rbdService.delete(poolName, imageName)
+        }),
       modalRef: this.modalRef
     });
   }
 
   flattenRbd(poolName, imageName) {
-    const finishedTask = new FinishedTask();
-    finishedTask.name = 'rbd/flatten';
-    finishedTask.metadata = {'pool_name': poolName, 'image_name': imageName};
-    this.rbdService.flatten(poolName, imageName)
-      .toPromise().then((resp) => {
-        if (resp.status === 202) {
-          this.notificationService.show(NotificationType.info,
-            `RBD flatten in progress...`,
-            this.taskManagerMessageService.getDescription(finishedTask));
-          const executingTask = new ExecutingTask();
-          executingTask.name = finishedTask.name;
-          executingTask.metadata = finishedTask.metadata;
-          this.executingTasks.push(executingTask);
-          this.taskManagerService.subscribe(executingTask.name, executingTask.metadata,
-            (asyncFinishedTask: FinishedTask) => {
-              this.notificationService.notifyTask(asyncFinishedTask);
-            });
-        } else {
-          finishedTask.success = true;
-          this.notificationService.notifyTask(finishedTask);
-        }
+    this.taskWrapper.wrapTaskAroundCall({
+      task: new FinishedTask('rbd/flatten', {
+        pool_name: poolName,
+        image_name: imageName
+      }),
+      tasks: this.executingTasks,
+      call: this.rbdService.flatten(poolName, imageName)
+    }).subscribe(
+      undefined,
+      undefined,
+      () => {
         this.modalRef.hide();
         this.loadImages(null);
-      });
+      }
+    );
   }
 
   flattenRbdModal() {