fix: update onceMaxRequest field

This commit is contained in:
jialin
2026-05-28 15:51:51 +08:00
committed by jialin
parent ef61134b8b
commit b590aa746b
10 changed files with 44 additions and 42 deletions
@@ -183,20 +183,20 @@ const parseQuantity = (value?: string | null): number => {
};
// Returns the slider max for the accelerator count: the largest
// tier.onceMaxRequest across all acceleratorTiers (not from candidates).
// tier.onceMaxRequest.accelerator across all acceleratorTiers (not from candidates).
export const getAcceleratorMax = (
tiers?: { onceMaxRequest: string }[] | null
tiers?: { onceMaxRequest: { accelerator?: string } }[] | null
) => {
if (!tiers?.length) return 0;
return tiers.reduce((acc, tier) => {
const n = parseQuantity(tier.onceMaxRequest);
const n = parseQuantity(tier.onceMaxRequest?.accelerator);
return n > acc ? n : acc;
}, 0);
};
// Picks the candidate (cluster + type name) that should fulfill a requested
// accelerator count: the first candidate of the smallest tier whose
// onceMaxRequest is >= the requested count and whose cpu/ram/localStorage
// onceMaxRequest.accelerator is >= the requested count and whose cpu/ram/localStorage
// remaining are all > 0.
export const pickCandidateForAccelerator = <
C extends {
@@ -208,7 +208,10 @@ export const pickCandidateForAccelerator = <
}
>(
tiers:
| { onceMaxRequest: string; candidates?: C[] | null }[]
| {
onceMaxRequest: { accelerator?: string };
candidates?: C[] | null;
}[]
| undefined
| null,
count: number
@@ -221,12 +224,14 @@ export const pickCandidateForAccelerator = <
parseQuantity(c.localStorage?.remaining) > 0;
const sorted = [...tiers].sort(
(a, b) => parseQuantity(a.onceMaxRequest) - parseQuantity(b.onceMaxRequest)
(a, b) =>
parseQuantity(a.onceMaxRequest?.accelerator) -
parseQuantity(b.onceMaxRequest?.accelerator)
);
// count === 0 ? parseQuantity(tier.onceMaxRequest) > count; this is CPU-only case.
// count === 0 ? parseQuantity(tier.onceMaxRequest.accelerator) > count; this is CPU-only case.
for (const tier of sorted) {
const fits = parseQuantity(tier.onceMaxRequest) >= count;
const fits = parseQuantity(tier.onceMaxRequest?.accelerator) >= count;
if (!fits) continue;
const candidate = tier.candidates?.find(hasResources);
if (candidate) return candidate;
+10 -11
View File
@@ -28,9 +28,6 @@ export interface FormData {
cpu?: string;
ram?: string;
localStorage?: string;
// Stored in the form as a number so NumberSelection's strict
// equality picks up the active item. Serialized to a string at the
// API boundary in handleFinish.
accelerator?: number | string;
};
volume: {
@@ -101,12 +98,19 @@ export interface InstanceTypeCandidate {
localStorage: InstanceTypeResource;
}
export interface InstanceTypeTierOnceMaxRequestResource {
accelerator?: string;
cpu: string;
ram: string;
localStorage: string;
}
export interface InstanceTypeTier {
onceMaxRequest: string;
onceMaxRequest: InstanceTypeTierOnceMaxRequestResource;
candidates?: InstanceTypeCandidate[] | null;
}
export interface InstanceTypeRemainingResource {
export interface InstanceTypeOnceMaxRequestResource {
accelerator?: string | null;
cpu: string;
ram: string;
@@ -125,7 +129,7 @@ export interface InstanceTypeSpec {
}
export interface InstanceTypeStatus {
remaining: InstanceTypeRemainingResource;
onceMaxRequest: InstanceTypeOnceMaxRequestResource;
acceleratorTiers?: InstanceTypeTier[] | null;
}
@@ -137,11 +141,6 @@ export interface InstanceTypeItem {
status: InstanceTypeStatus;
}
// =========== Events / logs (placeholder) ===========
// The /v2/gpu-instances API does not yet expose log/event endpoints. These
// shapes are retained as minimal placeholders so disabled UI continues to
// compile until backend support lands.
export interface InstanceEventItem {
type?: string;
reason?: string;