From 2b005395818700185e2c0f7713fae0c321471b2d Mon Sep 17 00:00:00 2001 From: Sarthak0702 Date: Fri, 3 Jun 2022 04:28:31 +0530 Subject: [PATCH] mgr/dashboard: rbd force resync from fornt-end Signed-off-by: Sarthak0702 --- .../block/rbd-list/rbd-list.component.spec.ts | 7 ++-- .../ceph/block/rbd-list/rbd-list.component.ts | 41 +++++++++++++++++++ .../src/app/shared/constants/app.constants.ts | 3 +- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.spec.ts index a63ac2379fd59..c6dde029233d6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.spec.ts @@ -319,6 +319,7 @@ describe('RbdListComponent', () => { 'Edit', 'Copy', 'Flatten', + 'Resync', 'Delete', 'Move to Trash', 'Remove Scheduling' @@ -326,7 +327,7 @@ describe('RbdListComponent', () => { primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' } }, 'create,update': { - actions: ['Create', 'Edit', 'Copy', 'Flatten', 'Remove Scheduling'], + actions: ['Create', 'Edit', 'Copy', 'Flatten', 'Resync', 'Remove Scheduling'], primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' } }, 'create,delete': { @@ -338,11 +339,11 @@ describe('RbdListComponent', () => { primary: { multiple: 'Create', executing: 'Copy', single: 'Copy', no: 'Create' } }, 'update,delete': { - actions: ['Edit', 'Flatten', 'Delete', 'Move to Trash', 'Remove Scheduling'], + actions: ['Edit', 'Flatten', 'Resync', 'Delete', 'Move to Trash', 'Remove Scheduling'], primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' } }, update: { - actions: ['Edit', 'Flatten', 'Remove Scheduling'], + actions: ['Edit', 'Flatten', 'Resync', 'Remove Scheduling'], primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' } }, delete: { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts index c77a627324eed..215f7f6f874ac 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts @@ -153,6 +153,13 @@ export class RbdListComponent extends ListWithDetails implements OnInit { name: this.actionLabels.DELETE, disable: (selection: CdTableSelection) => this.getDeleteDisableDesc(selection) }; + const resyncAction: CdTableAction = { + permission: 'update', + icon: Icons.refresh, + click: () => this.resyncRbdModal(), + name: this.actionLabels.RESYNC, + disable: (selection: CdTableSelection) => this.getResyncDisableDesc(selection) + }; const copyAction: CdTableAction = { permission: 'create', canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection, @@ -200,6 +207,7 @@ export class RbdListComponent extends ListWithDetails implements OnInit { editAction, copyAction, flattenAction, + resyncAction, deleteAction, moveAction, removeSchedulingAction @@ -411,6 +419,26 @@ export class RbdListComponent extends ListWithDetails implements OnInit { }); } + resyncRbdModal() { + const poolName = this.selection.first().pool_name; + const namespace = this.selection.first().namespace; + const imageName = this.selection.first().name; + const imageSpec = new ImageSpec(poolName, namespace, imageName); + + this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, { + itemDescription: 'RBD', + itemNames: [imageSpec], + actionDescription: 'resync', + submitActionObservable: () => + this.taskWrapper.wrapTaskAroundCall({ + task: new FinishedTask('rbd/edit', { + image_spec: imageSpec.toString() + }), + call: this.rbdService.update(imageSpec, { resync: true }) + }) + }); + } + trashRbdModal() { const initialState = { poolName: this.selection.first().pool_name, @@ -533,6 +561,19 @@ export class RbdListComponent extends ListWithDetails implements OnInit { return this.getInvalidNameDisable(selection) || this.hasClonedSnapshots(selection.first()); } + getResyncDisableDesc(selection: CdTableSelection): string | boolean { + const first = selection.first(); + + if (first && this.imageIsPrimary(first)) { + return $localize`Primary RBD images cannot be resynced`; + } + + return this.getInvalidNameDisable(selection); + } + + imageIsPrimary(image: object) { + return image['primary']; + } getInvalidNameDisable(selection: CdTableSelection): string | boolean { const first = selection.first(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/constants/app.constants.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/constants/app.constants.ts index 9e1c42963bdf9..d78620a89b2d7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/constants/app.constants.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/constants/app.constants.ts @@ -134,6 +134,7 @@ export class ActionLabelsI18n { STOP: string; REDEPLOY: string; RESTART: string; + RESYNC: string; constructor() { /* Create a new item */ @@ -190,7 +191,7 @@ export class ActionLabelsI18n { this.START_DRAIN = $localize`Start Drain`; this.STOP_DRAIN = $localize`Stop Drain`; - + this.RESYNC = $localize`Resync`; /* Prometheus wording */ this.RECREATE = $localize`Recreate`; this.EXPIRE = $localize`Expire`; -- 2.39.5