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

Add volume workload #2645

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/grid_client/src/high_level/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HighLevelBase {
WorkloadTypes.ipv4, // TODO: remove deprecated
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.zdb,
WorkloadTypes.qsfs,
WorkloadTypes.gatewayfqdnproxy,
Expand Down Expand Up @@ -172,6 +173,7 @@ class HighLevelBase {
WorkloadTypes.ipv4, // TODO: remove deprecated
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.zdb,
WorkloadTypes.qsfs,
WorkloadTypes.gatewayfqdnproxy,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/high_level/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class KubernetesHL extends HighLevelBase {
return await this._delete(deployment, names, [
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.ip,
WorkloadTypes.ipv4,
WorkloadTypes.zlogs,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/high_level/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class VMHL extends HighLevelBase {
WorkloadTypes.ip,
WorkloadTypes.ipv4, // TODO: remove deprecated
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.zmachine,
WorkloadTypes.qsfs,
WorkloadTypes.zlogs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class TwinDeploymentHandler {
rootfsDisks.push(workload.data["size"]);
sru += workload.data["size"];
}
if (workload.type == WorkloadTypes.zmount) {
if (workload.type == WorkloadTypes.zmount || workload.type == WorkloadTypes.volume) {
ssdDisks.push(workload.data["size"]);
sru += workload.data["size"];
}
Expand Down
13 changes: 10 additions & 3 deletions packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { DeploymentFactory } from "../primitives/deployment";
import { Network } from "../primitives/network";
import { Nodes } from "../primitives/nodes";
import { BackendStorage, BackendStorageType } from "../storage/backend";
import { Volume, Zmount } from "../zos";
import { Deployment } from "../zos/deployment";
import { PublicIPResult } from "../zos/public_ip";
import { QuantumSafeFS, QuantumSafeFSResult } from "../zos/qsfs";
import { Workload, WorkloadTypes } from "../zos/workload";
import { Zmachine, ZmachineResult } from "../zos/zmachine";
import { Zmount } from "../zos/zmount";
import { ContractStates } from "./models";

const modulesNames = {
Expand Down Expand Up @@ -335,13 +335,20 @@ class BaseModule {
for (const deployment of deployments) {
if (deployment.contract_id !== contractId) continue;
for (const workload of deployment.workloads) {
if (workload.type === WorkloadTypes.zmount && workload.name === name) {
if (workload.name !== name) continue;
if (workload.type === WorkloadTypes.zmount) {
return {
size: (workload.data as Zmount).size,
state: workload.result.state,
message: workload.result.message,
};
} else if (workload.type === WorkloadTypes.qsfs && workload.name === name) {
} else if (workload.type === WorkloadTypes.volume) {
return {
size: (workload.data as Volume).size,
state: workload.result.state,
message: workload.result.message,
};
} else if (workload.type === WorkloadTypes.qsfs) {
const data = workload.data as QuantumSafeFS;
const metadata = JSON.parse(workload.metadata);
return {
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/modules/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class K8sModule extends BaseModule {
workloadTypes = [
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.qsfs,
WorkloadTypes.ip,
WorkloadTypes.ipv4,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/modules/machines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MachinesModule extends BaseModule {
workloadTypes = [
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.volume,
WorkloadTypes.qsfs,
WorkloadTypes.ip,
WorkloadTypes.ipv4,
Expand Down
22 changes: 11 additions & 11 deletions packages/grid_client/src/primitives/disk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Volume } from "../zos/volume";
import { Workload, WorkloadTypes } from "../zos/workload";
import { Mount } from "../zos/zmachine";
import { Zmount } from "../zos/zmount";

class DiskPrimitive {
createMount(name: string, mountpoint: string): Mount {
Expand All @@ -10,17 +10,17 @@ class DiskPrimitive {
return mount;
}
create(size: number, name: string, metadata = "", description = "", version = 0): Workload {
const zmount = new Zmount();
zmount.size = size * 1024 ** 3;
const volume = new Volume();
volume.size = size * 1024 ** 3;

const zmount_workload = new Workload();
zmount_workload.version = version;
zmount_workload.name = name;
zmount_workload.type = WorkloadTypes.zmount;
zmount_workload.data = zmount;
zmount_workload.metadata = metadata;
zmount_workload.description = description;
return zmount_workload;
const volume_workload = new Workload();
volume_workload.version = version;
volume_workload.name = name;
volume_workload.type = WorkloadTypes.volume;
volume_workload.data = volume;
volume_workload.metadata = metadata;
volume_workload.description = description;
return volume_workload;
}
update(size: number, name: string, metadata = "", description = "", old_version = 1): Workload {
return this.create(size, name, metadata, description, old_version + 1);
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/src/zos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./workload";
export * from "./zdb";
export * from "./zmachine";
export * from "./zmount";
export * from "./volume";
export * from "./znet";
export * from "./gateway";
export * from "./qsfs";
Expand Down
17 changes: 17 additions & 0 deletions packages/grid_client/src/zos/volume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Expose } from "class-transformer";
import { IsInt, Max, Min } from "class-validator";

import { WorkloadData, WorkloadDataResult } from "./workload_base";

class Volume extends WorkloadData {
@Expose() @IsInt() @Min(100 * 1024 ** 2) @Max(10 * 1024 ** 4) size: number; // in bytes

challenge(): string {
return this.size.toString();
}
}

class VolumeResult extends WorkloadDataResult {
@Expose() volume_id: string;
}
export { Volume, VolumeResult };
6 changes: 6 additions & 0 deletions packages/grid_client/src/zos/workload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GatewayFQDNProxy, GatewayNameProxy, GatewayResult } from "./gateway";
import { PublicIPv4, PublicIPv4Result } from "./ipv4"; // TODO: remove deprecated
import { PublicIP, PublicIPResult } from "./public_ip";
import { QuantumSafeFS, QuantumSafeFSResult } from "./qsfs";
import { Volume, VolumeResult } from "./volume";
import { WorkloadData, WorkloadDataResult } from "./workload_base";
import { Zdb, ZdbResult } from "./zdb";
import { Zlogs, ZlogsResult } from "./zlogs";
Expand All @@ -21,6 +22,7 @@ enum ResultStates {
enum WorkloadTypes {
zmachine = "zmachine",
zmount = "zmount",
volume = "volume",
network = "network",
zdb = "zdb",
ipv4 = "ipv4", // TODO: remove deprecated
Expand All @@ -41,6 +43,7 @@ class DeploymentResult {
property: "__type",
subTypes: [
{ value: ZmountResult, name: WorkloadTypes.zmount },
{ value: VolumeResult, name: WorkloadTypes.volume },
{ value: WorkloadDataResult, name: WorkloadTypes.network },
{ value: ZmachineResult, name: WorkloadTypes.zmachine },
{ value: ZdbResult, name: WorkloadTypes.zdb },
Expand All @@ -55,6 +58,7 @@ class DeploymentResult {
})
data:
| ZmountResult
| VolumeResult
| ZmachineResult
| ZdbResult
| PublicIPResult
Expand All @@ -79,6 +83,7 @@ class Workload {
property: "__type",
subTypes: [
{ value: Zmount, name: WorkloadTypes.zmount },
{ value: Volume, name: WorkloadTypes.volume },
{ value: Znet, name: WorkloadTypes.network },
{ value: Zmachine, name: WorkloadTypes.zmachine },
{ value: Zdb, name: WorkloadTypes.zdb },
Expand All @@ -94,6 +99,7 @@ class Workload {
// TODO: remove public IPv4 deprecated
data:
| Zmount
| Volume
| Znet
| Zmachine
| Zdb
Expand Down