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

C2D refactor #818

Open
wants to merge 14 commits into
base: feature/c2d_docker
Choose a base branch
from
80 changes: 45 additions & 35 deletions src/@types/C2D/C2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,64 @@ export interface C2DClusterInfo {
tempFolder?: string
}

export type ComputeResourceType = 'cpu' | 'memory' | 'storage'
export type ComputeResourceType = 'cpu' | 'ram' | 'disk' | any

export interface ComputeResourcesPricingInfo {
type: ComputeResourceType
price: number
id: ComputeResourceType
price: number // price per unit
}

export interface ComputeResource {
id: ComputeResourceType
type?: string
alexcos20 marked this conversation as resolved.
Show resolved Hide resolved
kind?: string
total: number // total number of specific resource
min: number // min number of resource needed for a job
max: number // max number of resource for a job
inUse?: number // for display purposes
}
export interface ComputeResourceRequest {
id: string
amount: number
}

export interface ComputeEnvFees {
feeToken: string
prices: ComputeResourcesPricingInfo[]
}
export interface ComputeEnvFeesStructure {
[chainId: string]: ComputeEnvFees
[chainId: string]: ComputeEnvFees[]
}

export interface RunningPlatform {
architecture: string
os: string
os?: string
}

export interface ComputeEnvironmentFreeOptions {
// only if a compute env exposes free jobs
storageExpiry?: number
maxJobDuration?: number
maxJobs?: number // maximum number of simultaneous free jobs
resources?: ComputeResource[]
}
export interface ComputeEnvironmentBaseConfig {
// cpuNumber: number
// ramGB: number
// diskGB: number
description: string // v1
// maxJobs: number
storageExpiry: number // v1
maxJobDuration: number // v1 max seconds for a job
// chainId?: number
// feeToken: string
// priceMin: number
totalCpu: number // total cpu available for jobs
maxCpu: number // max cpu for a single job. Imagine a K8 cluster with two nodes, each node with 10 cpus. Total=20, but at most you can allocate 10 cpu for a job
totalRam: number // total gb of RAM
maxRam: number // max allocatable GB RAM for a single job.
maxDisk: number // max GB of disck allocatable for a single job
description?: string // v1
storageExpiry?: number // amount of seconds for storage
minJobDuration?: number // min billable seconds for a paid job
maxJobDuration?: number // max duration in seconds for a paid job
maxJobs?: number // maximum number of simultaneous paid jobs
fees: ComputeEnvFeesStructure
resources?: ComputeResource[]
free?: ComputeEnvironmentFreeOptions
platform: RunningPlatform
}

export interface ComputeEnvironment extends ComputeEnvironmentBaseConfig {
id: string // v1
// arch: string => part of platform bellow
// cpuType?: string
// gpuNumber?: number
// gpuType?: string
chainId?: number // it can be useful to keep the chain id (optional)
currentJobs: number
runningJobs: number
runningfreeJobs?: number
consumerAddress: string // v1
// lastSeen?: number
free: boolean
platform?: RunningPlatform[] // array due to k8 support
}

export interface C2DDockerConfig {
Expand All @@ -80,12 +88,12 @@ export interface C2DDockerConfig {
caPath: string
certPath: string
keyPath: string
environments: ComputeEnvironment[]
freeComputeOptions?: ComputeEnvironment
}

export interface ComputeEnvByChain {
[chainId: number]: ComputeEnvironment[]
storageExpiry?: number
maxJobDuration?: number
maxJobs?: number
fees: ComputeEnvFeesStructure
resources?: ComputeResource[] // optional, owner can overwrite
free?: ComputeEnvironmentFreeOptions
}

export type ComputeResultType =
Expand Down Expand Up @@ -165,6 +173,8 @@ export interface DBComputeJob extends ComputeJob {
isRunning: boolean
isStarted: boolean
containerImage: string
resources: ComputeResourceRequest[]
isFree: boolean
}

// make sure we keep them both in sync
Expand Down
11 changes: 10 additions & 1 deletion src/@types/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ValidateParams } from '../components/httpRoutes/validateCommands.js'
import { DDO } from './DDO/DDO'
import { P2PCommandResponse } from './OceanNode'
import type { ComputeAsset, ComputeAlgorithm, ComputeOutput } from './C2D/C2D.js'
import type {
ComputeAsset,
ComputeAlgorithm,
ComputeOutput,
ComputeResourceRequest
} from './C2D/C2D.js'
import {
ArweaveFileObject,
FileObjectType,
Expand Down Expand Up @@ -166,14 +171,18 @@ export interface ComputeStartCommand extends Command {
algorithm: ComputeAlgorithm
datasets?: ComputeAsset[]
output?: ComputeOutput
resources?: ComputeResourceRequest[]
chainId?: number // network used by payment
}
export interface FreeComputeStartCommand extends Command {
consumerAddress: string
signature: string
nonce: string
environment: string
alexcos20 marked this conversation as resolved.
Show resolved Hide resolved
algorithm: ComputeAlgorithm
datasets?: ComputeAsset[]
output?: ComputeOutput
resources?: ComputeResourceRequest[]
alexcos20 marked this conversation as resolved.
Show resolved Hide resolved
}

export interface ComputeStopCommand extends Command {
Expand Down
1 change: 1 addition & 0 deletions src/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class OceanNode {
return
}
this.c2dEngines = new C2DEngines(_config, this.db.c2d)
await this.c2dEngines.startAllEngines()
}
}

Expand Down
Loading
Loading