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

GridClient types and docstrings #3024

Merged
merged 45 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5984fcf
chore: WIP:: Thinking about creating a base types module for each mod…
Mahmoud-Emad Jun 25, 2024
0b48b73
style: Write docstrings for all GridClient functions to clarify their…
Mahmoud-Emad Jun 26, 2024
3e98ca0
docs: Documented the networks module.
Mahmoud-Emad Jun 26, 2024
d4d1f4d
docs: Documented the GridClient module.
Mahmoud-Emad Jun 26, 2024
534ff31
docs: Documented the client loader:
Mahmoud-Emad Jun 26, 2024
9cb0ca3
Merge branch 'development_2.6' into development_2.6_gridclient_types
Mahmoud-Emad Jun 26, 2024
fc3fb2e
docs: Documented the machines module
Mahmoud-Emad Jun 26, 2024
bf3c723
docs: Documented the Algorand module
Mahmoud-Emad Jun 26, 2024
c714dd3
docs: Documented the BackendStorage module
Mahmoud-Emad Jun 26, 2024
4425500
fix: Fix the build workflow.
Mahmoud-Emad Jun 27, 2024
a8ea7ae
docs: Documented the BlockChain module
Mahmoud-Emad Jun 27, 2024
e67a4f7
docs: Documented the BlockChain, Calculator modules
Mahmoud-Emad Jun 27, 2024
4cd8e60
Merge branch 'development_2.6_gridclient_types' of https://github.com…
Mahmoud-Emad Jun 27, 2024
68bb435
docs: Documented the ZOS module
Mahmoud-Emad Jun 27, 2024
103c17b
docs: Documented the TFChain module
Mahmoud-Emad Jun 27, 2024
8622e14
Merge branch 'development_2.6' into development_2.6_gridclient_types
Mahmoud-Emad Jul 1, 2024
5575ac9
docs: Documented the Contracts module
Mahmoud-Emad Jul 1, 2024
9f55b43
docs: Documented the Balance module
Mahmoud-Emad Jul 1, 2024
f2eb051
chore: WIP:: Documented the base module:
Mahmoud-Emad Jul 1, 2024
50bc24a
docs: Documented the Bridge module.
Mahmoud-Emad Jul 1, 2024
1b15eb4
chore: Reduce the import size.
Mahmoud-Emad Jul 1, 2024
1d6814a
docs: Documented the Capacity module.
Mahmoud-Emad Jul 1, 2024
5261a23
docs: Documented the Currency module.
Mahmoud-Emad Jul 1, 2024
f18ff5e
docs: Documented the DAO, FarmerBot modules.
Mahmoud-Emad Jul 1, 2024
075d4ca
docs: Documented the Farm module.
Mahmoud-Emad Jul 2, 2024
262edfb
docs: Documented the Gateway module.
Mahmoud-Emad Jul 2, 2024
520b4ad
docs: Documented the K8S module.
Mahmoud-Emad Jul 2, 2024
b8075d6
docs: Documented the TFKVStore module.
Mahmoud-Emad Jul 2, 2024
9ae80aa
docs: Documented the Nodes/TFChain.contracts modules.
Mahmoud-Emad Jul 2, 2024
f18b36d
docs: Documented the QSFSZdbs module.
Mahmoud-Emad Jul 2, 2024
3750110
docs: Documented the Stellar module.
Mahmoud-Emad Jul 2, 2024
b4e1cd6
docs: Documented the Twin module.
Mahmoud-Emad Jul 2, 2024
d65984d
docs: Documented the Utils module.
Mahmoud-Emad Jul 2, 2024
2ee97d4
docs: Documented the ZDB module.
Mahmoud-Emad Jul 2, 2024
692575f
Merge branch 'development' into development_2.6_gridclient_types
Mahmoud-Emad Jul 3, 2024
4fedf32
Merge branch 'development' into development_2.6_gridclient_types
Mahmoud-Emad Jul 3, 2024
93d29c4
feat: Added the test-report into the gitignore.
Mahmoud-Emad Jul 3, 2024
0640514
feat: Added the addAccess attr to the network interface in the kubern…
Mahmoud-Emad Jul 3, 2024
bcd26b1
fix: Applied changes:
Mahmoud-Emad Jul 10, 2024
21bae53
Merge branch 'development' into development_2.6_gridclient_types
Mahmoud-Emad Jul 16, 2024
9e462ba
Merge branch 'development' into development_2.6_gridclient_types
Mahmoud-Emad Aug 4, 2024
841a243
style: Apply the comments.
Mahmoud-Emad Aug 4, 2024
c96ecb5
chore: Remove the secret
Mahmoud-Emad Aug 7, 2024
40196ea
chore: Remove the test script
Mahmoud-Emad Aug 7, 2024
f9383b3
chore: Apply comments:
Mahmoud-Emad Aug 7, 2024
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
Prev Previous commit
Next Next commit
docs: Documented the ZOS module
  • Loading branch information
Mahmoud-Emad committed Jun 27, 2024
commit 68bb435f313f07065a887d69c74ec931e9cbc5a8
6 changes: 3 additions & 3 deletions packages/grid_client/scripts/checkNodeAlive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PingNodeOptionsModel } from "../src";
import { GridClient, PingNodeOptionsModel } from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";

async function pingNode(client, nodeId) {
const res = await client.zos.pingNode(nodeId);
async function pingNode(client: GridClient, node: PingNodeOptionsModel) {
const res = await client.zos.pingNode(node);
log("================= Ping result =================");
log(res);
log("================= Ping result =================");
Expand Down
153 changes: 143 additions & 10 deletions packages/grid_client/src/modules/zos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RMB } from "../clients/rmb/client";
import { GridClientConfig } from "../config";
import { expose } from "../helpers/expose";
import { validateInput } from "../helpers/validator";
import { Operations, TwinDeployment } from "../high_level/models";
import { DeploymentResultContracts, Operations, TwinDeployment } from "../high_level/models";
import { TwinDeploymentHandler } from "../high_level/twinDeploymentHandler";
import { DeploymentFactory } from "../primitives/deployment";
import { Nodes } from "../primitives/nodes";
Expand All @@ -22,15 +22,31 @@ import { checkBalance } from "./utils";
class Zos {
rmb: RMB;
capacity: Nodes;

/**
* Class representing the ZOS functionality.
*
* @param {GridClientConfig} config - The configuration object for initializing the client.
*/
constructor(public config: GridClientConfig) {
this.rmb = new RMB(config.rmbClient);
this.capacity = new Nodes(this.config.graphqlURL, this.config.proxyURL, this.config.rmbClient);
}

/**
* Deploy a workload on a node.
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {ZOSModel} options - The options for the deployment.
* @returns {Promise<DeploymentResultContracts>} - The result of the deployment.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
* - `@checkBalance`: Checks the balance before proceeding.
*/
@expose
@validateInput
@checkBalance
async deploy(options: ZOSModel) {
async deploy(options: ZOSModel): Promise<DeploymentResultContracts> {
// get node_id from the deployment
const node_id = options.node_id;
delete options.node_id;
Expand All @@ -50,78 +66,177 @@ class Zos {
return await twinDeploymentHandler.handle([twinDeployment]);
}

/**
* Ping a node to check its availability.
*
* @param {PingNodeOptionsModel} options - The options for pinging the node.
* @returns {Promise<boolean>} - A boolean indicating if the node is reachable.
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async pingNode(options: PingNodeOptionsModel): Promise<boolean> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.system.version", "", 10, 1);
}

/**
* Get deployment information based on the contract ID.
*
* @param {ZOSGetDeploymentModel} options - The options for getting deployment information.
* @returns {Promise<any>} - A promise that resolves with the deployment information.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getDeployment(options: ZOSGetDeploymentModel) {
async getDeployment(options: ZOSGetDeploymentModel): Promise<any> {
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
const nodeId = await this.capacity.getNodeIdFromContractId(options.contractId, this.config.substrateURL);
const nodeTwinId = await this.capacity.getNodeTwinId(nodeId);
const payload = JSON.stringify({ contract_id: options.contractId });
return await this.rmb.request([nodeTwinId], "zos.deployment.get", payload);
}

/**
* Get statistics for a specific node.
*
* @param {ZOSNodeModel} options - The options for getting node statistics.
* @returns {Promise<any>} - A promise that resolves with the node statistics.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodeStatistics(options: ZOSNodeModel) {
async getNodeStatistics(options: ZOSNodeModel): Promise<any> {
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.statistics.get", "");
}

/**
* Check if a node has a public IPv6 address.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the node has a public IPv6 address.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async hasPublicIPv6(options: ZOSNodeModel) {
async hasPublicIPv6(options: ZOSNodeModel): Promise<boolean> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.network.has_ipv6", "");
}

/**
* List network interfaces for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<any>} - A promise that resolves with the network interfaces information.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async listNetworkInterfaces(options: ZOSNodeModel) {
async listNetworkInterfaces(options: ZOSNodeModel): Promise<any> {
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.network.interfaces", "");
}

/**
* List the public IP addresses associated with a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<any>} - A promise that resolves with the list of public IP addresses.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async listNetworkPublicIPs(options: ZOSNodeModel) {
async listNetworkPublicIPs(options: ZOSNodeModel): Promise<any> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.network.list_public_ips", "");
}

/**
* Get the public network configuration for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<any>} - A promise that resolves with the public network configuration.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNetworkPublicConfig(options: ZOSNodeModel) {
async getNetworkPublicConfig(options: ZOSNodeModel): Promise<any> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.network.public_config_get", "");
}

/**
* Get the storage pools information for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<any>} - A promise that resolves with the storage pools information.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getStoragePools(options: ZOSNodeModel) {
async getStoragePools(options: ZOSNodeModel): Promise<any> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.storage.pools", "");
}

/**
* Get GPU information for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<GPUCardInfo[]>} - A promise that resolves with an array of GPU card information.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodeGPUInfo(options: ZOSNodeModel): Promise<GPUCardInfo[]> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.gpu.list", "");
}

/**
* Get performance tests for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<any>} - A promise that resolves with the performance test results.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodePerfTests(options: ZOSNodeModel) {
async getNodePerfTests(options: ZOSNodeModel): Promise<any> {
const nodeTwinId = await this.capacity.getNodeTwinId(options.nodeId);
return await this.rmb.request([nodeTwinId], "zos.perf.get_all", "");
}

/**
* Get the IPerf test results for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<NodeIPerf>} - A promise that resolves with the IPerf test results.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodeIPerfTest(options: ZOSNodeModel): Promise<NodeIPerf> {
Expand All @@ -130,6 +245,15 @@ class Zos {
return await this.rmb.request([nodeTwinId], "zos.perf.get", payload);
}

/**
* Get the IP validation test results for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<NodeIPValidation>} - A promise that resolves with the IP validation test results.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodeIPValidation(options: ZOSNodeModel): Promise<NodeIPValidation> {
Expand All @@ -138,6 +262,15 @@ class Zos {
return await this.rmb.request([nodeTwinId], "zos.perf.get", payload);
}

/**
* Get CPU test results for a specific node.
*
* @param {ZOSNodeModel} options - The options containing the node ID.
* @returns {Promise<NodeCPUTest>} - A promise that resolves with the CPU test results.
* @decorators
* - `@expose`: Exposes the method for external use.
* - `@validateInput`: Validates the input options.
*/
@expose
@validateInput
async getNodeCPUTest(options: ZOSNodeModel): Promise<NodeCPUTest> {
Expand Down
Loading