]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: service form hosts selection only show up to 10 entries 59760/head
authorSuper User <root@li-ff83bccc-26af-11b2-a85c-a4b04bfb1003.ibm.com>
Tue, 3 Sep 2024 08:46:45 +0000 (14:16 +0530)
committerNaman Munet <namanmunet@li-ff83bccc-26af-11b2-a85c-a4b04bfb1003.ibm.com>
Thu, 12 Sep 2024 09:30:36 +0000 (15:00 +0530)
exposed new UIRouter API to get all hosts

Fixes: https://tracker.ceph.com/issues/67413
Signed-off-by: Naman Munet <nmunet@redhat.com>
(cherry picked from commit ec3e4abeeb7feebd996681a7d8d4e950de5cf518)

src/pybind/mgr/dashboard/controllers/host.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-listeners-form/nvmeof-listeners-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-import/rgw-multisite-import.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts

index c0062b94d705e4c0950d48a7aaa95e2870a27d13..645fc4cc44c551d84446c2c840a9de233ab08cbd 100644 (file)
@@ -512,3 +512,16 @@ class HostUi(BaseController):
     @handle_orchestrator_error('host')
     def inventory(self, refresh=None):
         return get_inventories(None, refresh)
+
+    @Endpoint('GET')
+    @ReadPermission
+    @raise_if_no_orchestrator([OrchFeature.HOST_LIST])
+    @handle_orchestrator_error('host')
+    def list(self):
+        """
+        Get all hosts.
+        This endpoint is introduced to get all the available hosts in cases where
+        service instance is not needed (ex: hosts selection in forms), and also
+        get_hosts method helps in caching the response which makes it performant.
+        """
+        return get_hosts()
index bc02ea99c98e67475b1bea994b13f1b1e04810f1..412286bda2098087ea94304d6a1c8968a41ba486 100644 (file)
@@ -13,7 +13,10 @@ import { FormatterService } from '~/app/shared/services/formatter.service';
 import { CdValidators } from '~/app/shared/forms/cd-validators';
 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
 import { HostService } from '~/app/shared/api/host.service';
-import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
+import { DaemonService } from '~/app/shared/api/daemon.service';
+import { map } from 'rxjs/operators';
+import { forkJoin } from 'rxjs';
+
 @Component({
   selector: 'cd-nvmeof-listeners-form',
   templateUrl: './nvmeof-listeners-form.component.html',
@@ -39,7 +42,8 @@ export class NvmeofListenersFormComponent implements OnInit {
     private route: ActivatedRoute,
     public activeModal: NgbActiveModal,
     public formatterService: FormatterService,
-    public dimlessBinaryPipe: DimlessBinaryPipe
+    public dimlessBinaryPipe: DimlessBinaryPipe,
+    private daemonService: DaemonService
   ) {
     this.permission = this.authStorageService.getPermissions().nvmeof;
     this.hostPermission = this.authStorageService.getPermissions().hosts;
@@ -48,13 +52,19 @@ export class NvmeofListenersFormComponent implements OnInit {
   }
 
   setHosts() {
-    const hostContext = new CdTableFetchDataContext(() => undefined);
-    this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: any[]) => {
-      const nvmeofHosts = resp.filter((r) =>
-        r.service_instances.some((si: any) => si.type === 'nvmeof')
-      );
-      this.hosts = nvmeofHosts.map((h) => ({ hostname: h.hostname, addr: h.addr }));
-    });
+    forkJoin({
+      daemons: this.daemonService.list(['nvmeof']),
+      hosts: this.hostService.getAllHosts()
+    })
+      .pipe(
+        map(({ daemons, hosts }) => {
+          const hostNamesFromDaemon = daemons.map((daemon: any) => daemon.hostname);
+          return hosts.filter((host: any) => hostNamesFromDaemon.includes(host.hostname));
+        })
+      )
+      .subscribe((nvmeofHosts: any[]) => {
+        this.hosts = nvmeofHosts.map((h) => ({ hostname: h.hostname, addr: h.addr }));
+      });
   }
 
   ngOnInit() {
index 0506c4c77341fbe8fc0aa8f978ace62c3da1928f..5f6860b2ffdd036b03d6366f6656d6fce8b39479 100644 (file)
@@ -21,7 +21,6 @@ import { CdValidators } from '~/app/shared/forms/cd-validators';
 import { FinishedTask } from '~/app/shared/models/finished-task';
 import { Permission } from '~/app/shared/models/permissions';
 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
-import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
 
 @Component({
   selector: 'cd-cephfs-form',
@@ -127,8 +126,7 @@ export class CephfsVolumeFormComponent extends CdForm implements OnInit {
         }
       });
     } else {
-      const hostContext = new CdTableFetchDataContext(() => undefined);
-      this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
+      this.hostService.getAllHosts().subscribe((resp: object[]) => {
         const options: SelectOption[] = [];
         _.forEach(resp, (host: object) => {
           if (_.get(host, 'sources.orchestrator', false)) {
index 9602c856aed81af9897ff5c0aaff567cd5f943ff..bada177f735b46de7da27250c3c2185d62622ed8 100644 (file)
@@ -30,7 +30,6 @@ import { CdForm } from '~/app/shared/forms/cd-form';
 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
 import { CdValidators } from '~/app/shared/forms/cd-validators';
-import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
 import { FinishedTask } from '~/app/shared/models/finished-task';
 import { CephServiceSpec } from '~/app/shared/models/service.interface';
 import { ModalService } from '~/app/shared/services/modal.service';
@@ -470,8 +469,7 @@ export class ServiceFormComponent extends CdForm implements OnInit {
 
       this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
     });
-    const hostContext = new CdTableFetchDataContext(() => undefined);
-    this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
+    this.hostService.getAllHosts().subscribe((resp: object[]) => {
       const options: SelectOption[] = [];
       _.forEach(resp, (host: object) => {
         if (_.get(host, 'sources.orchestrator', false)) {
index deda890167077499c6cb4ad269c0e164695d6449..6a3edfbf59a132721d073553cc438f74f9968222 100644 (file)
@@ -11,7 +11,6 @@ import { RgwZone } from '../models/rgw-multisite';
 import _ from 'lodash';
 import { SelectMessages } from '~/app/shared/components/select/select-messages.model';
 import { HostService } from '~/app/shared/api/host.service';
-import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
 import { SelectOption } from '~/app/shared/components/select/select-option.model';
 import { Observable, Subject, merge } from 'rxjs';
 import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators';
@@ -62,8 +61,7 @@ export class RgwMultisiteImportComponent implements OnInit {
     this.zoneNames = this.zoneList.map((zone) => {
       return zone['name'];
     });
-    const hostContext = new CdTableFetchDataContext(() => undefined);
-    this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
+    this.hostService.getAllHosts().subscribe((resp: object[]) => {
       const options: SelectOption[] = [];
       _.forEach(resp, (host: object) => {
         if (_.get(host, 'sources.orchestrator', false)) {
index 3bb569575836e4aec8d3f41b5fd7bf3ee3d3e824..ce23302ba26de19a21b02c7a7d65c485a4234980 100644 (file)
@@ -162,4 +162,8 @@ export class HostService extends ApiClient {
       })
     );
   }
+
+  getAllHosts(): Observable<object[]> {
+    return this.http.get<object[]>(`${this.baseUIURL}/list`);
+  }
 }