Skip to content

Commit

Permalink
Merge branch 'development_2.6' into development_2.6_ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama committed Jun 25, 2024
2 parents a545262 + af86453 commit 945ab1b
Show file tree
Hide file tree
Showing 71 changed files with 527 additions and 413 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"npmClient": "yarn"
}
2 changes: 1 addition & 1 deletion packages/UI/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@threefold/ui",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"private": false,
"main": "dist/threefold-ui.umd.js",
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql_client/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@threefold/graphql_client",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@threefold/types": "^2.5.0-rc2",
"@threefold/types": "^2.5.0-rc3",
"ts-mixer": "^6.0.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/grid_client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@threefold/grid_client",
"author": "Ahmed Hanafy",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"license": "ISC",
"homepage": "https://github.com/threefoldtech/tfgrid-sdk-ts/tree/development/packages/grid_client/README.md",
"repository": {
Expand All @@ -14,9 +14,9 @@
"dependencies": {
"@jimber/pkid": "1.0.4",
"@noble/secp256k1": "^1.7.1",
"@threefold/rmb_direct_client": "^2.5.0-rc2",
"@threefold/tfchain_client": "^2.5.0-rc2",
"@threefold/types": "^2.5.0-rc2",
"@threefold/rmb_direct_client": "^2.5.0-rc3",
"@threefold/tfchain_client": "^2.5.0-rc3",
"@threefold/types": "^2.5.0-rc3",
"algosdk": "^1.19.0",
"appdata-path": "^1.0.0",
"await-lock": "^2.2.2",
Expand Down
16 changes: 9 additions & 7 deletions packages/grid_client/scripts/single_vm.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { MachinesModel } from "../src";
import { GridClient, MachinesModel } from "../src";
import { type ZmachineData } from "../src/helpers/types";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
async function deploy(client: GridClient, vms: MachinesModel) {
const res = await client.machines.deploy(vms);
log("================= Deploying VM =================");
log(res);
log("================= Deploying VM =================");
}

async function getDeployment(client, vms) {
const res = await client.machines.getObj(vms);
async function getDeployment(client: GridClient, name: string): Promise<ZmachineData[]> {
const res = await client.machines.getObj(name);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
return res;
}

async function cancel(client, vms) {
const res = await client.machines.delete(vms);
async function cancel(client: GridClient, name: string) {
const res = await client.machines.delete({ name: name });
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
Expand Down Expand Up @@ -69,7 +71,7 @@ async function main() {
await getDeployment(grid3, name);

//Uncomment the line below to cancel the deployment
// await cancel(grid3, { name });
// await cancel(grid3, name);

await grid3.disconnect();
}
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./events";
export * from "./validator";
export * from "./expose";
export * from "./migration";
export * from "./root_fs";
39 changes: 39 additions & 0 deletions packages/grid_client/src/helpers/root_fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Decimal } from "decimal.js";

const GB = 1024;

interface RootFSOptions {
/** The machine CPU, should be in cores e.g. 5 cores*/
CPUCores: number;
/** The machine memory, should be in megabytes e.g. 1024 or 2048 MG*/
RAMInMegaBytes: number;
}

/**
* Calculate the root filesystem size (CU - Compute Units) based on provided options.
*
* This function calculates the compute units (CU) required based on the CPU cores and RAM in megabytes.
* If both CPU cores and RAM are provided in the `options` parameter, it calculates CU by multiplying
* the CPU cores with RAM and dividing by 8 * GB, then converting the result to an integer. If the
* calculated CU is zero, it returns 500 / GB; otherwise, it returns 2.
*
* @param {RootFSOptions} [options] - Optional configuration object.
* @param {number} [options.CPUCores] - The number of CPU cores.
* @param {number} [options.RAMInMegaBytes] - The RAM size in megabytes.
*
* @returns {number} - The calculated compute units (CU) based on the provided options.
*/
function calculateRootFileSystem(options?: RootFSOptions): number {
let cu = 0;

if (options && options.CPUCores && options.RAMInMegaBytes) {
cu = new Decimal(options.CPUCores)
.mul(options.RAMInMegaBytes)
.divToInt(8 * GB)
.toNumber();
}

return cu === 0 ? 500 / GB : 2;
}

export { calculateRootFileSystem, RootFSOptions };
91 changes: 91 additions & 0 deletions packages/grid_client/src/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { PublicIPResult, ResultStates } from "../zos";

interface NetworkInterface {
/** The network identifier */
network: string;
/** The IP address of the interface */
ip: string;
}

interface ComputeCapacity {
/** Number of CPU cores allocated */
cpu: number;
/** Amount of memory allocated in MB */
memory: number;
}

interface BaseMountData {
/** The name of the mount */
name: string;
/** The mount point in the filesystem */
mountPoint: string;
}

interface ExtendedMountData extends BaseMountData {
/** The size of the mount (optional) */
size?: number;
/** The state of the mount result (optional) */
state?: ResultStates;
/** Message providing additional information about the mount result (optional) */
message?: string;
/** Cache information (optional) */
cache?: any;
/** Prefix information (optional) */
prefix?: any;
/** Minimal shards (optional) */
minimal_shards?: number;
/** Expected shards (optional) */
expected_shards?: number;
/** QSFS ZDBs name (optional) */
qsfs_zdbs_name?: string;
/** Metrics endpoint (optional) */
metricsEndpoint?: string;
}

// Union type for the mount data
type MountData = BaseMountData | ExtendedMountData;

export interface ZmachineData {
/** The version of the workload */
version: number;
/** The contract ID associated with the workload */
contractId: number;
/** The node ID where the workload is deployed */
nodeId: string;
/** The name of the workload */
name: string;
/** The creation timestamp of the workload result */
created: number;
/** The current state of the workload */
status: string;
/** Message providing additional information about the workload state */
message: string;
/** The flist (file list) used by the workload */
flist: string;
/** The public IP address obtained by the machine */
publicIP: PublicIPResult;
/** The planetary IP address of the machine */
planetary: string;
/** The Mycelium IP address of the machine, if applicable */
myceliumIP: string;
/** List of network interfaces */
interfaces: NetworkInterface[];
/** The compute capacity (CPU and memory) allocated to the machine */
capacity: ComputeCapacity;
/** List of mounts associated with the machine */
mounts: MountData[];
/** Environment variables set for the workload */
env: Record<string, unknown>;
/** The entrypoint command for the workload */
entrypoint: string;
/** Metadata associated with the workload */
metadata: string;
/** Description of the workload */
description: string;
/** Size of the root filesystem */
rootfs_size: number;
/** Indicates if corex is enabled */
corex: boolean;
/** The list of the GPUs */
gpu: string[] | undefined;
}
7 changes: 7 additions & 0 deletions packages/grid_client/src/high_level/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GridClientErrors, ValidationError } from "@threefold/types";
import { Addr } from "netaddr";

import { events } from "../helpers/events";
import { calculateRootFileSystem } from "../helpers/root_fs";
import { randomChoice, zeroPadding } from "../helpers/utils";
import { validateHexSeed } from "../helpers/validator";
import { DiskModel, MyceliumNetworkModel, QSFSDiskModel } from "../modules/models";
Expand Down Expand Up @@ -53,6 +54,12 @@ class VMHL extends HighLevelBase {
zlogsOutput?: string,
gpus: string[] = [],
): Promise<[TwinDeployment[], string]> {
if (!rootfs_size) {
rootfs_size = calculateRootFileSystem({
CPUCores: cpu,
RAMInMegaBytes: memory,
});
}
const deployments: TwinDeployment[] = [];
const workloads: Workload[] = [];
let totalDisksSize = rootfs_size;
Expand Down
3 changes: 2 additions & 1 deletion packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GqlNodeContract, RMB } from "../clients";
import { TFClient } from "../clients/tf-grid/client";
import { GridClientConfig } from "../config";
import { formatErrorMessage } from "../helpers";
import { type ZmachineData } from "../helpers/types";
import { HighLevelBase } from "../high_level/base";
import { KubernetesHL } from "../high_level/kubernetes";
import { VMHL } from "../high_level/machine";
Expand Down Expand Up @@ -306,7 +307,7 @@ class BaseModule {
return null;
}

async _getZmachineData(deploymentName: string, deployments, workload: Workload): Promise<Record<string, unknown>> {
async _getZmachineData(deploymentName: string, deployments, workload: Workload): Promise<ZmachineData> {
const data = workload.data as Zmachine;
const resultData = workload.result.data as ZmachineResult;
return {
Expand Down
13 changes: 7 additions & 6 deletions packages/grid_client/tests/modules/compute_capacity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ beforeEach(() => {
computeCapacity = new ComputeCapacity();
});
describe("Compute Capacity module", () => {
test("Compute Capacity instance is of type ComputeCapacity.", () => {
test.skip("Compute Capacity instance is of type ComputeCapacity.", () => {
expect(computeCapacity).toBeInstanceOf(ComputeCapacity);
});

test("Min values for cpu & memory.", () => {
// The following tests are skipped as there's an issue w input validation. Should be returned once validation is fixed here: https://github.com/threefoldtech/tfgrid-sdk-ts/issues/2821
test.skip("Min values for cpu & memory.", () => {
const cpu = 0;
const mem = 255 * 1024 ** 2;

Expand All @@ -22,7 +23,7 @@ describe("Compute Capacity module", () => {
expect(result).toThrow();
});

test("Max values for cpu & memory.", () => {
test.skip("Max values for cpu & memory.", () => {
const cpu = 33;
const mem = 255 * 1024 ** 4;

Expand All @@ -34,7 +35,7 @@ describe("Compute Capacity module", () => {
expect(result).toThrow();
});

test("cpu & memory doesn't accept decimal values.", () => {
test.skip("cpu & memory doesn't accept decimal values.", () => {
const cpu = 1.5;
const mem = 1.2;

Expand All @@ -46,13 +47,13 @@ describe("Compute Capacity module", () => {
expect(result).toThrow();
});

test("cpu & memory empty values.", () => {
test.skip("cpu & memory empty values.", () => {
const result = () => computeCapacity.challenge();

expect(result).toThrow();
});

test("An error should be thrown if cpu & memory negative values.", () => {
test.skip("An error should be thrown if cpu & memory negative values.", () => {
const negative_cpu = -1;
const negative_mem = -1;

Expand Down
15 changes: 15 additions & 0 deletions packages/grid_client/tests/unittests/root_fs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { calculateRootFileSystem } from "../../src/helpers/root_fs";

describe("Calculate the rootFS size based on the machine specs", () => {
it("should return 2GB when the options are provided", () => {
const options = { CPUCores: 5, RAMInMegaBytes: 2048 };
const result = calculateRootFileSystem(options);
expect(result).toEqual(2);
});

it("should return 0.48828125 when CPU cores and RAM are zero", () => {
const options = { CPUCores: 0, RAMInMegaBytes: 0 };
const result = calculateRootFileSystem(options);
expect(result).toEqual(0.48828125);
});
});
4 changes: 2 additions & 2 deletions packages/grid_http_server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@threefold/grid_http_server",
"author": "Ahmed Hanafy",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"license": "ISC",
"homepage": "https://github.com/threefoldtech/tfgrid-sdk-ts/blob/development/packages/grid_http_server/README.md",
"repository": {
Expand All @@ -12,7 +12,7 @@
"access": "public"
},
"dependencies": {
"@threefold/grid_client": "^2.5.0-rc2",
"@threefold/grid_client": "^2.5.0-rc3",
"express": "^4.18.1",
"http-server": "^14.1.1",
"typescript": "^4.7.4"
Expand Down
8 changes: 4 additions & 4 deletions packages/grid_rmb_server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@threefold/grid_rmb_server",
"author": "Ahmed Hanafy",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"license": "ISC",
"homepage": "https://github.com/threefoldtech/tfgrid-sdk-ts/blob/development/packages/grid_rmb_server/README.md",
"repository": {
Expand All @@ -12,12 +12,12 @@
"access": "public"
},
"dependencies": {
"@threefold/grid_client": "^2.5.0-rc2",
"@threefold/rmb_peer_server": "^2.5.0-rc2",
"@threefold/grid_client": "^2.5.0-rc3",
"@threefold/rmb_peer_server": "^2.5.0-rc3",
"typescript": "^4.7.4"
},
"devDependencies": {
"@threefold/rmb_peer_client": "^2.5.0-rc2",
"@threefold/rmb_peer_client": "^2.5.0-rc3",
"ts-node": "^10.9.1"
},
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/gridproxy_client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@threefold/gridproxy_client",
"version": "2.5.0-rc2",
"version": "2.5.0-rc3",
"description": "gridproxy_client help to interact with gridproxy based on network",
"main": "dist/public_api.js",
"types": "dist/public_api.d.ts",
Expand Down
Loading

0 comments on commit 945ab1b

Please sign in to comment.