Skip to content

Commit

Permalink
Merge pull request #2882 from threefoldtech/development_CRU_sorting
Browse files Browse the repository at this point in the history
Sort solutions nodes by free CRU
  • Loading branch information
samaradel authored Jun 5, 2024
2 parents 7014fb3 + 3e8f5c5 commit 10b2b62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions packages/grid_client/src/primitives/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SortBy, SortOrder } from "@threefold/gridproxy_client";
import { Client as RMBClient } from "@threefold/rmb_direct_client";
import { QueryClient } from "@threefold/tfchain_client";
import {
Expand Down Expand Up @@ -135,13 +136,22 @@ class Nodes {
let nodes: NodeInfo[] = [];
let page = 1;
do {
nodes = await this.filterNodes({ accessNodeV4: true, accessNodeV6: true, availableFor, page });
nodes = await this.filterNodes({
accessNodeV4: true,
accessNodeV6: true,
availableFor,
page,
});
for (const node of nodes) {
const ipv4 = node.publicConfig.ipv4;
const ipv6 = node.publicConfig.ipv6;
const domain = node.publicConfig.domain;
if (PrivateIp(ipv4.split("/")[0]) === false) {
accessNodes[+node.nodeId] = { ipv4: ipv4, ipv6: ipv6, domain: domain };
accessNodes[+node.nodeId] = {
ipv4: ipv4,
ipv6: ipv6,
domain: domain,
};
}
}
page++;
Expand Down Expand Up @@ -279,7 +289,13 @@ class Nodes {
.request([node_twin_id], "zos.statistics.get", "")
.then(res => {
const node: RMBNodeCapacity = res;
const ret: NodeResources = { cru: 0, mru: 0, hru: 0, sru: 0, ipv4u: 0 };
const ret: NodeResources = {
cru: 0,
mru: 0,
hru: 0,
sru: 0,
ipv4u: 0,
};

ret.cru = +node.total.cru;
ret.mru = +node.total.mru - +node.used.mru;
Expand Down Expand Up @@ -408,6 +424,8 @@ class Nodes {
ret_count: options.ret_count,
region: options.region,
healthy: options.healthy,
sort_by: SortBy.FreeCRU,
sort_order: SortOrder.Desc,
};

if (options.gateway) {
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/src/views/nodes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ export default {
domain: filters.value.gateway || undefined,
freeIps: +filters.value.publicIPs || undefined,
dedicated: filters.value.dedicated || undefined,
sortBy: SortBy.FreeCRU,
sortOrder: SortOrder.Desc,
sortBy: SortBy.Status,
sortOrder: SortOrder.Asc,
numGpu: +filters.value.numGpu || undefined,
rentable: filters.value.rentable && profileManager.profile ? filters.value.rentable : undefined,
availableFor: filters.value.rentable && profileManager.profile ? profileManager.profile.twinId : undefined,
Expand Down

0 comments on commit 10b2b62

Please sign in to comment.