Skip to content

Commit 5a1bbdd

Browse files
authored
Merge pull request ceph#64131 from afreen23/wip-71805-tentacle
tentacle: mgr/dashboard: Allow host with labels in listener form Reviewed-by: Aashish Sharma <[email protected]>
2 parents 13b1d28 + 60c21b7 commit 5a1bbdd

File tree

9 files changed

+61
-25
lines changed

9 files changed

+61
-25
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-listeners-form/nvmeof-listeners-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<label class="cd-col-form-label"
1313
for="host">
1414
<span class="required"
15-
i18n>Host Name</span>
15+
i18n>Hostname</span>
1616
</label>
1717
<div class="cd-col-form-input">
1818
<select id="host"

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-listeners-form/nvmeof-listeners-form.component.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import _ from 'lodash';
12
import { Component, OnInit } from '@angular/core';
23
import { UntypedFormControl, Validators } from '@angular/forms';
34
import { ActivatedRoute, Router } from '@angular/router';
45
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5-
import { ListenerRequest, NvmeofService } from '~/app/shared/api/nvmeof.service';
6+
import { GatewayGroup, ListenerRequest, NvmeofService } from '~/app/shared/api/nvmeof.service';
67
import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
78
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
89
import { FinishedTask } from '~/app/shared/models/finished-task';
@@ -15,7 +16,7 @@ import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
1516
import { HostService } from '~/app/shared/api/host.service';
1617
import { map } from 'rxjs/operators';
1718
import { forkJoin } from 'rxjs';
18-
import { CephServiceSpec } from '~/app/shared/models/service.interface';
19+
import { Host } from '~/app/shared/models/host.interface';
1920

2021
@Component({
2122
selector: 'cd-nvmeof-listeners-form',
@@ -51,26 +52,42 @@ export class NvmeofListenersFormComponent implements OnInit {
5152
this.pageURL = 'block/nvmeof/subsystems';
5253
}
5354

55+
filterHostsByLabel(allHosts: Host[], gwNodesLabel: string | string[]) {
56+
return allHosts.filter((host: Host) => {
57+
const hostLabels: string[] = host?.labels;
58+
if (typeof gwNodesLabel === 'string') {
59+
return hostLabels.includes(gwNodesLabel);
60+
}
61+
return hostLabels?.length === gwNodesLabel?.length && _.isEqual(hostLabels, gwNodesLabel);
62+
});
63+
}
64+
65+
filterHostsByHostname(allHosts: Host[], gwNodes: string[]) {
66+
return allHosts.filter((host: Host) => gwNodes.includes(host.hostname));
67+
}
68+
69+
getGwGroupPlacement(gwGroups: GatewayGroup[][]) {
70+
return (
71+
gwGroups?.[0]?.find((gwGroup: GatewayGroup) => gwGroup?.spec?.group === this.group)
72+
?.placement || { hosts: [], label: [] }
73+
);
74+
}
75+
5476
setHosts() {
5577
forkJoin({
5678
gwGroups: this.nvmeofService.listGatewayGroups(),
57-
hosts: this.hostService.getAllHosts()
79+
allHosts: this.hostService.getAllHosts()
5880
})
5981
.pipe(
60-
map(({ gwGroups, hosts }) => {
61-
// Find the gateway hosts in current group
62-
const selectedGwGroup: CephServiceSpec = gwGroups?.[0]?.find(
63-
(gwGroup: CephServiceSpec) => gwGroup?.spec?.group === this.group
64-
);
65-
const gatewayHosts: string[] = selectedGwGroup?.placement?.hosts;
66-
// Return the gateway hosts in current group with their metadata
67-
return gatewayHosts
68-
? hosts.filter((host: any) => gatewayHosts.includes(host.hostname))
69-
: [];
82+
map(({ gwGroups, allHosts }) => {
83+
const { hosts, label } = this.getGwGroupPlacement(gwGroups);
84+
if (hosts?.length) return this.filterHostsByHostname(allHosts, hosts);
85+
else if (label?.length) return this.filterHostsByLabel(allHosts, label);
86+
return [];
7087
})
7188
)
72-
.subscribe((nvmeofHosts: any[]) => {
73-
this.hosts = nvmeofHosts.map((h) => ({ hostname: h.hostname, addr: h.addr }));
89+
.subscribe((nvmeofGwNodes: Host[]) => {
90+
this.hosts = nvmeofGwNodes.map((h) => ({ hostname: h.hostname, addr: h.addr }));
7491
});
7592
}
7693

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Permission } from '~/app/shared/models/permissions';
2121
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
2222
import { PoolService } from '~/app/shared/api/pool.service';
2323
import { Pool } from '../../pool/pool';
24+
import { Host } from '~/app/shared/models/host.interface';
2425

2526
@Component({
2627
selector: 'cd-cephfs-form',
@@ -176,7 +177,7 @@ export class CephfsVolumeFormComponent extends CdForm implements OnInit {
176177
labels: this.hostService.getLabels()
177178
}).pipe(
178179
map(({ hosts, labels }) => ({
179-
hosts: hosts.map((host: any) => ({ content: host['hostname'] })),
180+
hosts: hosts.map((host: Host) => ({ content: host['hostname'] })),
180181
labels: labels.map((label: string) => ({ content: label }))
181182
}))
182183
);

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
3434
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
3535
import { CdValidators } from '~/app/shared/forms/cd-validators';
3636
import { FinishedTask } from '~/app/shared/models/finished-task';
37+
import { Host } from '~/app/shared/models/host.interface';
3738
import { CephServiceSpec } from '~/app/shared/models/service.interface';
3839
import { ModalService } from '~/app/shared/services/modal.service';
3940
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
@@ -636,9 +637,9 @@ export class ServiceFormComponent extends CdForm implements OnInit {
636637

637638
this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
638639
});
639-
this.hostService.getAllHosts().subscribe((resp: object[]) => {
640+
this.hostService.getAllHosts().subscribe((resp: Host[]) => {
640641
const options: SelectOption[] = [];
641-
_.forEach(resp, (host: object) => {
642+
_.forEach(resp, (host: Host) => {
642643
if (_.get(host, 'sources.orchestrator', false)) {
643644
const option = new SelectOption(false, _.get(host, 'hostname'), '');
644645
options.push(option);

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { CephServicePlacement } from '~/app/shared/models/service.interface';
3737
import { UpperFirstPipe } from '~/app/shared/pipes/upper-first.pipe';
3838
import { CLUSTER_PATH } from '../smb-cluster-list/smb-cluster-list.component';
3939
import { USERSGROUPS_PATH } from '../smb-usersgroups-list/smb-usersgroups-list.component';
40+
import { Host } from '~/app/shared/models/host.interface';
4041

4142
@Component({
4243
selector: 'cd-smb-cluster-form',
@@ -95,7 +96,7 @@ export class SmbClusterFormComponent extends CdForm implements OnInit {
9596
labels: this.hostService.getLabels()
9697
}).pipe(
9798
map(({ hosts, labels }) => ({
98-
hosts: hosts.map((host: any) => ({ content: host['hostname'] })),
99+
hosts: hosts.map((host: Host) => ({ content: host['hostname'] })),
99100
labels: labels.map((label: string) => ({ content: label }))
100101
}))
101102
);
@@ -169,7 +170,7 @@ export class SmbClusterFormComponent extends CdForm implements OnInit {
169170
labels: this.hostService.getLabels()
170171
}).pipe(
171172
map(({ hosts, labels }) => ({
172-
hosts: hosts.map((host: any) => ({ content: host['hostname'] })),
173+
hosts: hosts.map((host: Host) => ({ content: host['hostname'] })),
173174
labels: labels.map((label: string) => ({ content: label }))
174175
}))
175176
);

src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Daemon } from '../models/daemon.interface';
1313
import { CdDevice } from '../models/devices';
1414
import { SmartDataResponseV1 } from '../models/smart';
1515
import { DeviceService } from '../services/device.service';
16+
import { Host } from '../models/host.interface';
1617

1718
@Injectable({
1819
providedIn: 'root'
@@ -163,7 +164,7 @@ export class HostService extends ApiClient {
163164
);
164165
}
165166

166-
getAllHosts(): Observable<object[]> {
167-
return this.http.get<object[]>(`${this.baseUIURL}/list`);
167+
getAllHosts(): Observable<Host[]> {
168+
return this.http.get<Host[]>(`${this.baseUIURL}/list`);
168169
}
169170
}

src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { CephServiceSpec } from '../models/service.interface';
88

99
export const MAX_NAMESPACE = 1024;
1010

11+
export type GatewayGroup = CephServiceSpec;
12+
1113
export type GroupsComboboxItem = {
1214
content: string;
1315
serviceName?: string;
@@ -71,7 +73,7 @@ export class NvmeofService {
7173

7274
// Gateway groups
7375
listGatewayGroups() {
74-
return this.http.get(`${API_PATH}/gateway/group`);
76+
return this.http.get<GatewayGroup[][]>(`${API_PATH}/gateway/group`);
7577
}
7678

7779
// Gateways
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface Host {
2+
ceph_version: string;
3+
services: Array<{ type: string; id: string }>;
4+
sources: {
5+
ceph: boolean;
6+
orchestrator: boolean;
7+
};
8+
hostname: string;
9+
addr: string;
10+
labels: string[];
11+
status: any;
12+
service_instances: Array<{ type: string; count: number }>;
13+
}

src/pybind/mgr/dashboard/frontend/src/app/shared/models/service.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ export interface CephServicePlacement {
6868
count?: number;
6969
placement?: string;
7070
hosts?: string[];
71-
label?: string;
71+
label?: string | string[];
7272
}

0 commit comments

Comments
 (0)