+import _ from 'lodash';
import { Component, OnInit } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
-import { ListenerRequest, NvmeofService } from '~/app/shared/api/nvmeof.service';
+import { GatewayGroup, ListenerRequest, NvmeofService } from '~/app/shared/api/nvmeof.service';
import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
import { FinishedTask } from '~/app/shared/models/finished-task';
import { HostService } from '~/app/shared/api/host.service';
import { map } from 'rxjs/operators';
import { forkJoin } from 'rxjs';
-import { CephServiceSpec } from '~/app/shared/models/service.interface';
+import { Host } from '~/app/shared/models/host.interface';
@Component({
selector: 'cd-nvmeof-listeners-form',
this.pageURL = 'block/nvmeof/subsystems';
}
+ filterHostsByLabel(allHosts: Host[], gwNodesLabel: string | string[]) {
+ return allHosts.filter((host: Host) => {
+ const hostLabels: string[] = host?.labels;
+ if (typeof gwNodesLabel === 'string') {
+ return hostLabels.includes(gwNodesLabel);
+ }
+ return hostLabels?.length === gwNodesLabel?.length && _.isEqual(hostLabels, gwNodesLabel);
+ });
+ }
+
+ filterHostsByHostname(allHosts: Host[], gwNodes: string[]) {
+ return allHosts.filter((host: Host) => gwNodes.includes(host.hostname));
+ }
+
+ getGwGroupPlacement(gwGroups: GatewayGroup[][]) {
+ return (
+ gwGroups?.[0]?.find((gwGroup: GatewayGroup) => gwGroup?.spec?.group === this.group)
+ ?.placement || { hosts: [], label: [] }
+ );
+ }
+
setHosts() {
forkJoin({
gwGroups: this.nvmeofService.listGatewayGroups(),
- hosts: this.hostService.getAllHosts()
+ allHosts: this.hostService.getAllHosts()
})
.pipe(
- map(({ gwGroups, hosts }) => {
- // Find the gateway hosts in current group
- const selectedGwGroup: CephServiceSpec = gwGroups?.[0]?.find(
- (gwGroup: CephServiceSpec) => gwGroup?.spec?.group === this.group
- );
- const gatewayHosts: string[] = selectedGwGroup?.placement?.hosts;
- // Return the gateway hosts in current group with their metadata
- return gatewayHosts
- ? hosts.filter((host: any) => gatewayHosts.includes(host.hostname))
- : [];
+ map(({ gwGroups, allHosts }) => {
+ const { hosts, label } = this.getGwGroupPlacement(gwGroups);
+ if (hosts?.length) return this.filterHostsByHostname(allHosts, hosts);
+ else if (label?.length) return this.filterHostsByLabel(allHosts, label);
+ return [];
})
)
- .subscribe((nvmeofHosts: any[]) => {
- this.hosts = nvmeofHosts.map((h) => ({ hostname: h.hostname, addr: h.addr }));
+ .subscribe((nvmeofGwNodes: Host[]) => {
+ this.hosts = nvmeofGwNodes.map((h) => ({ hostname: h.hostname, addr: h.addr }));
});
}
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
import { CdValidators } from '~/app/shared/forms/cd-validators';
import { FinishedTask } from '~/app/shared/models/finished-task';
+import { Host } from '~/app/shared/models/host.interface';
import { CephServiceSpec } from '~/app/shared/models/service.interface';
import { ModalService } from '~/app/shared/services/modal.service';
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
});
- this.hostService.getAllHosts().subscribe((resp: object[]) => {
+ this.hostService.getAllHosts().subscribe((resp: Host[]) => {
const options: SelectOption[] = [];
- _.forEach(resp, (host: object) => {
+ _.forEach(resp, (host: Host) => {
if (_.get(host, 'sources.orchestrator', false)) {
const option = new SelectOption(false, _.get(host, 'hostname'), '');
options.push(option);
import { UpperFirstPipe } from '~/app/shared/pipes/upper-first.pipe';
import { CLUSTER_PATH } from '../smb-cluster-list/smb-cluster-list.component';
import { USERSGROUPS_PATH } from '../smb-usersgroups-list/smb-usersgroups-list.component';
+import { Host } from '~/app/shared/models/host.interface';
@Component({
selector: 'cd-smb-cluster-form',
labels: this.hostService.getLabels()
}).pipe(
map(({ hosts, labels }) => ({
- hosts: hosts.map((host: any) => ({ content: host['hostname'] })),
+ hosts: hosts.map((host: Host) => ({ content: host['hostname'] })),
labels: labels.map((label: string) => ({ content: label }))
}))
);
labels: this.hostService.getLabels()
}).pipe(
map(({ hosts, labels }) => ({
- hosts: hosts.map((host: any) => ({ content: host['hostname'] })),
+ hosts: hosts.map((host: Host) => ({ content: host['hostname'] })),
labels: labels.map((label: string) => ({ content: label }))
}))
);