Skip to content

Commit 446a327

Browse files
authored
Enhance capacity pool fn (#4435)
* Edit checkNodeCapacityPool to include node twinId, fall back to graphql get node twinId only in case it's undefined, update CapacityPoolCheckModel * Remove unnecessary gql twinId query on node manual selection
1 parent f76736b commit 446a327

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

packages/grid_client/src/modules/capacity.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class Capacity {
267267
@expose
268268
@validateInput
269269
async getNodeFreeResources(options?: NodeFreeResourcesModel): Promise<NodeResources> {
270-
return await this.nodes.getNodeFreeResources(options!.nodeId);
270+
return await this.nodes.getNodeFreeResources(options!.nodeId, "proxy", "", options?.nodeTwinId);
271271
}
272272

273273
/**
@@ -306,6 +306,7 @@ class Capacity {
306306
options.hddDisks,
307307
options.rootfsDisks,
308308
options.nodeId,
309+
options.nodeTwinId,
309310
);
310311
}
311312

packages/grid_client/src/modules/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ class ContractState {
591591

592592
class NodeFreeResourcesModel {
593593
@Expose() @IsInt() @Min(1) nodeId: number;
594+
@Expose() @IsOptional() @IsInt() @Min(1) nodeTwinId?: number;
594595
}
595596

596597
class FarmIdFromFarmNameModel {
@@ -605,6 +606,7 @@ class CapacityPoolCheckModel {
605606
@Expose() @IsInt({ each: true }) @Min(0, { each: true }) rootfsDisks: number[]; //Byte
606607
@Expose() @IsInt({ each: true }) @Min(250 * 1024 ** 2, { each: true }) ssdDisks: number[]; //Byte
607608
@Expose() @IsInt({ each: true }) @Min(250 * 1024 ** 2, { each: true }) hddDisks: number[]; //Byte
609+
@Expose() @IsOptional() @IsInt() @Min(1) nodeTwinId?: number;
608610
}
609611

610612
class PingNodeOptionsModel {

packages/grid_client/src/primitives/nodes.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,17 @@ class Nodes {
287287
});
288288
}
289289

290-
async getNodeFreeResources(nodeId: number, source: "proxy" | "zos" = "proxy", url = ""): Promise<NodeResources> {
290+
async getNodeFreeResources(
291+
nodeId: number,
292+
source: "proxy" | "zos" = "proxy",
293+
url = "",
294+
nodeTwinId?: number,
295+
): Promise<NodeResources> {
291296
if (source == "zos") {
292-
const node_twin_id = await this.getNodeTwinId(nodeId);
297+
const twinId = nodeTwinId ?? (await this.getNodeTwinId(nodeId));
293298

294299
return this.rmb
295-
.request([node_twin_id], "zos.statistics.get", "")
300+
.request([twinId], "zos.statistics.get", "")
296301
.then(res => {
297302
const node: RMBNodeCapacity = res;
298303
const ret: NodeResources = {
@@ -519,8 +524,8 @@ class Nodes {
519524
return convertObjectToQueryString(params);
520525
}
521526

522-
async nodeHasResources(nodeId: number, options: FilterOptions): Promise<boolean> {
523-
const resources = await this.getNodeFreeResources(nodeId, "zos");
527+
async nodeHasResources(nodeId: number, options: FilterOptions, nodeTwinId?: number): Promise<boolean> {
528+
const resources = await this.getNodeFreeResources(nodeId, "zos", "", nodeTwinId);
524529
if (
525530
(options.mru && options.mru > 0 && resources.mru < this._g2b(options.mru)) ||
526531
(options.sru && options.sru > 0 && resources.sru < this._g2b(options.sru)) ||
@@ -609,17 +614,16 @@ class Nodes {
609614
hddDisks: number[],
610615
rootFileSystemDisks: number[],
611616
nodeId: number,
617+
nodeTwinId?: number,
612618
): Promise<boolean> {
613619
const ssdPools: number[] = [];
614620
const hddPools: number[] = [];
615621

616622
try {
617-
const nodeTwinId = await this.getNodeTwinId(nodeId);
618-
((await this.rmb.request([nodeTwinId], "zos.storage.pools", "")) as StoragePool[]).forEach(
619-
(disk: StoragePool) => {
620-
disk.type === DiskTypes.SSD ? ssdPools.push(disk.size - disk.used) : hddPools.push(disk.size - disk.used);
621-
},
622-
);
623+
const twinId = nodeTwinId ?? (await this.getNodeTwinId(nodeId));
624+
((await this.rmb.request([twinId], "zos.storage.pools", "")) as StoragePool[]).forEach((disk: StoragePool) => {
625+
disk.type === DiskTypes.SSD ? ssdPools.push(disk.size - disk.used) : hddPools.push(disk.size - disk.used);
626+
});
623627
} catch (e) {
624628
(e as Error).message = formatErrorMessage(`Error getting node ${nodeId}`, e);
625629
throw e;

packages/playground/src/components/node_selector/TfManualNodeSelector.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
"
2626
/>
2727

28-
<input-tooltip
29-
tooltip="Node ID to deploy on."
30-
align-center
31-
>
28+
<input-tooltip tooltip="Node ID to deploy on." align-center>
3229
<VTextField
3330
v-model.number="nodeId"
3431
label="Node ID"
@@ -40,9 +37,9 @@
4037
:disabled="!validFilters"
4138
:persistent-hint="
4239
(nodeId && !validationTask.initialized) ||
43-
!validFilters ||
44-
validationTask.loading ||
45-
(validationTask.initialized && validationTask.data === true)
40+
!validFilters ||
41+
validationTask.loading ||
42+
(validationTask.initialized && validationTask.data === true)
4643
"
4744
:hint="
4845
!validFilters
@@ -199,7 +196,7 @@ export default {
199196
} Feature${missingFeatures.length > 1 ? "s" : ""}. Please check compatibility or upgrade the node.`;
200197
}
201198
202-
const args = [nodeId, "proxy", gridStore.client.config.proxyURL] as const;
199+
const args = [nodeId, "proxy", gridStore.client.config.proxyURL, node.twinId] as const;
203200
const [resources, e2] = await resolveAsync(gridStore.client.capacity.nodes.getNodeFreeResources(...args));
204201
if (e2) {
205202
throw normalizeError(e2, _defaultError);

packages/playground/src/utils/nodeSelector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ export async function checkNodeCapacityPool(
530530
ssdDisks: [filters.solutionDisk ?? 0, ...(filters.ssdDisks || [])].filter(Boolean).map(disk => disk * 1024 ** 3),
531531
rootfsDisks: [(filters.rootFilesystemSize ?? 0) * 1024 ** 3],
532532
hddDisks: filters.hddDisks || [],
533+
nodeTwinId: node.twinId,
533534
});
534535
return true;
535536
} catch (error) {

0 commit comments

Comments
 (0)