Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-128601 / 25.04 / Use undefined instead of EMPTY #10851

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/app/pages/vm/vm-edit-form/vm-edit-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { MatButton } from '@angular/material/button';
import { MatCard, MatCardContent } from '@angular/material/card';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import {
Observable, forkJoin, of, switchMap,
} from 'rxjs';
import { forkJoin, of, switchMap } from 'rxjs';
import { MiB } from 'app/constants/bytes.constant';
import { RequiresRolesDirective } from 'app/directives/requires-roles/requires-roles.directive';
import { Role } from 'app/enums/role.enum';
Expand Down Expand Up @@ -104,6 +102,7 @@ export class VmEditFormComponent implements OnInit {
gpuOptions$ = this.gpuService.getGpuOptions();

readonly helptext = helptextVmWizard;
previouslySetGpuPciIds: string[] = [];

constructor(
private formBuilder: FormBuilder,
Expand Down Expand Up @@ -163,20 +162,13 @@ export class VmEditFormComponent implements OnInit {
}

const gpusIds = this.form.value.gpus;
let updateVmRequest$: Observable<unknown>;

if (gpusIds.length) {
updateVmRequest$ = this.gpuService.addIsolatedGpuPciIds(gpusIds).pipe(
switchMap(() => forkJoin([
this.ws.call('vm.update', [this.existingVm.id, vmPayload as VirtualMachineUpdate]),
this.vmGpuService.updateVmGpus(this.existingVm, gpusIds),
])),
);
} else {
updateVmRequest$ = this.ws.call('vm.update', [this.existingVm.id, vmPayload as VirtualMachineUpdate]);
}

updateVmRequest$.pipe(untilDestroyed(this)).subscribe({
this.gpuService.addIsolatedGpuPciIds(gpusIds).pipe(
switchMap(() => forkJoin([
this.ws.call('vm.update', [this.existingVm.id, vmPayload as VirtualMachineUpdate]),
this.vmGpuService.updateVmGpus(this.existingVm, gpusIds),
])),
untilDestroyed(this),
).subscribe({
next: () => {
this.isLoading = false;
this.cdr.markForCheck();
Expand All @@ -200,6 +192,7 @@ export class VmEditFormComponent implements OnInit {
const vmGpus = allGpus.filter(byVmPciSlots(vmPciSlots));

const vmGpuPciSlots = vmGpus.map((gpu) => gpu.addr.pci_slot);
this.previouslySetGpuPciIds = vmGpuPciSlots;
this.form.controls.gpus.setValue(vmGpuPciSlots, { emitEvent: false });
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/gpu/gpu-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('GpuService', () => {
const call$ = spectator.service.addIsolatedGpuPciIds(['0000:02:00.0']);

expect(spectator.inject(WebSocketService).call).not.toHaveBeenCalled();
expectObservable(call$).toBe('(|)');
expectObservable(call$).toBe('(a|)', { a: undefined });
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions src/app/services/gpu/gpu.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import {
combineLatest, EMPTY, Observable,
combineLatest, Observable,
of,
} from 'rxjs';
import {
map, shareReplay, switchMap, take,
Expand Down Expand Up @@ -81,7 +82,7 @@ export class GpuService {
...idsToIsolate,
]);
if (newIsolatedGpuIds.size === oldIsolatedGpuIds.length) {
return EMPTY;
return of(undefined);
}

return this.ws.call('system.advanced.update_gpu_pci_ids', [Array.from(newIsolatedGpuIds)]).pipe(
Expand Down
Loading