@nosana/node 1.1.84 → 1.1.86-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.env +2 -1
- package/dist/package.json +1 -1
- package/dist/packages/common/src/formatTime.d.ts +2 -2
- package/dist/packages/common/src/formatTime.js +9 -5
- package/dist/packages/job-runtime/src/host/HostClient.d.ts +20 -4
- package/dist/packages/job-runtime/src/host/HostClient.js +35 -2
- package/dist/packages/job-runtime/src/host/contract.d.ts +27 -7
- package/dist/packages/job-runtime/src/host/contract.js +43 -7
- package/dist/packages/job-runtime/src/runtime/runJob.d.ts +8 -5
- package/dist/packages/job-runtime/src/runtime/runJob.js +44 -17
- package/dist/packages/vm-orchestrator/src/CidRegistry.d.ts +67 -0
- package/dist/packages/vm-orchestrator/src/CidRegistry.js +168 -0
- package/dist/packages/vm-orchestrator/src/GpuPool.d.ts +27 -0
- package/dist/packages/vm-orchestrator/src/GpuPool.js +41 -0
- package/dist/packages/vm-orchestrator/src/Hypervisor.d.ts +66 -0
- package/dist/packages/vm-orchestrator/src/Hypervisor.js +7 -0
- package/dist/packages/vm-orchestrator/src/QemuHypervisor.d.ts +62 -0
- package/dist/packages/vm-orchestrator/src/QemuHypervisor.js +185 -0
- package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.d.ts +61 -0
- package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.js +37 -0
- package/dist/packages/vm-orchestrator/src/QemuVmInstance.d.ts +37 -0
- package/dist/packages/vm-orchestrator/src/QemuVmInstance.js +44 -0
- package/dist/packages/vm-orchestrator/src/QmpClient.d.ts +43 -0
- package/dist/packages/vm-orchestrator/src/QmpClient.js +103 -0
- package/dist/packages/vm-orchestrator/src/VmSpec.d.ts +21 -0
- package/dist/packages/vm-orchestrator/src/VmSpec.js +30 -0
- package/dist/packages/vm-orchestrator/src/VmStateManager.d.ts +16 -0
- package/dist/packages/vm-orchestrator/src/VmStateManager.js +30 -0
- package/dist/packages/vm-orchestrator/src/bootAttempt.d.ts +31 -0
- package/dist/packages/vm-orchestrator/src/bootAttempt.js +193 -0
- package/dist/packages/vm-orchestrator/src/bootErrors.d.ts +33 -0
- package/dist/packages/vm-orchestrator/src/bootErrors.js +67 -0
- package/dist/packages/vm-orchestrator/src/buildCloudInit.d.ts +33 -0
- package/dist/packages/vm-orchestrator/src/buildCloudInit.js +55 -0
- package/dist/packages/vm-orchestrator/src/buildQemuArgs.d.ts +33 -0
- package/dist/packages/vm-orchestrator/src/buildQemuArgs.js +127 -0
- package/dist/packages/vm-orchestrator/src/diskSizing.d.ts +18 -0
- package/dist/packages/vm-orchestrator/src/diskSizing.js +41 -0
- package/dist/packages/vm-orchestrator/src/firmware.d.ts +5 -0
- package/dist/packages/vm-orchestrator/src/firmware.js +18 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.d.ts +22 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.js +33 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.d.ts +3 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.js +17 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.d.ts +9 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.js +17 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.d.ts +6 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.js +42 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/index.d.ts +1 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/index.js +1 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.d.ts +6 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.js +18 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.d.ts +7 -0
- package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.js +30 -0
- package/dist/packages/vm-orchestrator/src/hostDevices.d.ts +12 -0
- package/dist/packages/vm-orchestrator/src/hostDevices.js +12 -0
- package/dist/packages/vm-orchestrator/src/hostTools.d.ts +25 -0
- package/dist/packages/vm-orchestrator/src/hostTools.js +39 -0
- package/dist/packages/vm-orchestrator/src/imageCache.d.ts +25 -0
- package/dist/packages/vm-orchestrator/src/imageCache.js +73 -0
- package/dist/packages/vm-orchestrator/src/imageDownload.d.ts +31 -0
- package/dist/packages/vm-orchestrator/src/imageDownload.js +85 -0
- package/dist/packages/vm-orchestrator/src/index.d.ts +19 -0
- package/dist/packages/vm-orchestrator/src/index.js +15 -0
- package/dist/packages/vm-orchestrator/src/memlockLimit.d.ts +5 -0
- package/dist/packages/vm-orchestrator/src/memlockLimit.js +23 -0
- package/dist/packages/vm-orchestrator/src/nvidiaHolders.d.ts +11 -0
- package/dist/packages/vm-orchestrator/src/nvidiaHolders.js +74 -0
- package/dist/packages/vm-orchestrator/src/pciNuma.d.ts +7 -0
- package/dist/packages/vm-orchestrator/src/pciNuma.js +18 -0
- package/dist/packages/vm-orchestrator/src/pciSysfs.d.ts +21 -0
- package/dist/packages/vm-orchestrator/src/pciSysfs.js +47 -0
- package/dist/packages/vm-orchestrator/src/processes.d.ts +37 -0
- package/dist/packages/vm-orchestrator/src/processes.js +102 -0
- package/dist/packages/vm-orchestrator/src/sockets.d.ts +21 -0
- package/dist/packages/vm-orchestrator/src/sockets.js +58 -0
- package/dist/packages/vm-orchestrator/src/sweepVmImageCache.d.ts +19 -0
- package/dist/packages/vm-orchestrator/src/sweepVmImageCache.js +132 -0
- package/dist/packages/vm-orchestrator/src/util.d.ts +14 -0
- package/dist/packages/vm-orchestrator/src/util.js +33 -0
- package/dist/packages/vm-orchestrator/src/vfioBinding.d.ts +27 -0
- package/dist/packages/vm-orchestrator/src/vfioBinding.js +163 -0
- package/dist/packages/vm-orchestrator/src/vmImageResolver.d.ts +20 -0
- package/dist/packages/vm-orchestrator/src/vmImageResolver.js +62 -0
- package/dist/packages/vm-orchestrator/src/vsockBridge.d.ts +20 -0
- package/dist/packages/vm-orchestrator/src/vsockBridge.js +27 -0
- package/dist/packages/vm-orchestrator/src/workDirs.d.ts +49 -0
- package/dist/packages/vm-orchestrator/src/workDirs.js +79 -0
- package/dist/src/NodeManager/configs/configs.d.ts +4 -0
- package/dist/src/NodeManager/configs/configs.js +3 -0
- package/dist/src/NodeManager/db/index.d.ts +10 -0
- package/dist/src/NodeManager/db/index.js +4 -0
- package/dist/src/NodeManager/monitoring/log/NodeLog.d.ts +2 -0
- package/dist/src/NodeManager/monitoring/log/NodeLog.js +21 -0
- package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.d.ts +8 -0
- package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.js +29 -5
- package/dist/src/NodeManager/monitoring/log/vmSetupLog.d.ts +11 -0
- package/dist/src/NodeManager/monitoring/log/vmSetupLog.js +33 -0
- package/dist/src/NodeManager/node/Node.d.ts +2 -0
- package/dist/src/NodeManager/node/Node.js +12 -5
- package/dist/src/NodeManager/node/job/ContainerJobRuntime.d.ts +141 -0
- package/dist/src/NodeManager/node/job/ContainerJobRuntime.js +419 -0
- package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.d.ts +74 -0
- package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.js +1 -0
- package/dist/src/NodeManager/node/job/JobRuntimeHost.d.ts +6 -2
- package/dist/src/NodeManager/node/job/JobRuntimeHost.js +13 -2
- package/dist/src/NodeManager/node/job/JobRuntimeSession.d.ts +12 -9
- package/dist/src/NodeManager/node/job/JobRuntimeSession.js +42 -71
- package/dist/src/NodeManager/node/job/VmJobRuntime.d.ts +109 -0
- package/dist/src/NodeManager/node/job/VmJobRuntime.js +258 -0
- package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.d.ts +33 -0
- package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.js +1 -0
- package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.d.ts +41 -0
- package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.js +25 -0
- package/dist/src/NodeManager/node/job/followFile.d.ts +14 -0
- package/dist/src/NodeManager/node/job/followFile.js +57 -0
- package/dist/src/NodeManager/node/job/jobHandler.d.ts +3 -3
- package/dist/src/NodeManager/node/job/jobHandler.js +7 -7
- package/dist/src/NodeManager/node/job/keepFailedConsole.d.ts +7 -0
- package/dist/src/NodeManager/node/job/keepFailedConsole.js +52 -0
- package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.d.ts +50 -0
- package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.js +117 -0
- package/dist/src/NodeManager/node/market/benchmark.d.ts +3 -3
- package/dist/src/NodeManager/node/market/benchmark.js +3 -3
- package/dist/src/NodeManager/node/market/marketHandler.d.ts +3 -3
- package/dist/src/NodeManager/node/market/marketHandler.js +3 -3
- package/dist/src/NodeManager/node/resource/resourceManager.d.ts +1 -1
- package/dist/src/NodeManager/node/resource/resourceManager.js +1 -1
- package/dist/src/NodeManager/provider/Provider.d.ts +3 -121
- package/dist/src/NodeManager/provider/Provider.js +3 -369
- package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.d.ts +14 -0
- package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.js +1 -0
- package/dist/src/NodeManager/provider/vmHost/capacity.d.ts +16 -0
- package/dist/src/NodeManager/provider/vmHost/capacity.js +47 -0
- package/dist/src/NodeManager/provider/vmHost/gpus.d.ts +19 -0
- package/dist/src/NodeManager/provider/vmHost/gpus.js +83 -0
- package/dist/src/NodeManager/provider/vmHost/index.d.ts +5 -0
- package/dist/src/NodeManager/provider/vmHost/index.js +4 -0
- package/dist/src/NodeManager/provider/vmHost/readVmSpec.d.ts +11 -0
- package/dist/src/NodeManager/provider/vmHost/readVmSpec.js +22 -0
- package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.d.ts +27 -0
- package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.js +25 -0
- package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.d.ts +6 -0
- package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.js +22 -0
- package/dist/src/NodeManager/provider/vmHost/setup/hostUser.d.ts +15 -0
- package/dist/src/NodeManager/provider/vmHost/setup/hostUser.js +25 -0
- package/dist/src/NodeManager/provider/vmHost/setup/index.d.ts +2 -0
- package/dist/src/NodeManager/provider/vmHost/setup/index.js +2 -0
- package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.d.ts +6 -0
- package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.js +12 -0
- package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.d.ts +17 -0
- package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.js +90 -0
- package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.d.ts +5 -0
- package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.js +35 -0
- package/dist/src/NodeManager/provider/vmHost/vmHostEnv.d.ts +20 -0
- package/dist/src/NodeManager/provider/vmHost/vmHostEnv.js +24 -0
- package/dist/src/NodeManager/provider/vmHost/workRoot.d.ts +14 -0
- package/dist/src/NodeManager/provider/vmHost/workRoot.js +84 -0
- package/dist/src/NodeManager/repository/NodeRepository.d.ts +12 -2
- package/dist/src/NodeManager/repository/NodeRepository.js +21 -1
- package/dist/src/cli/commands/prune/command.js +2 -1
- package/dist/src/cli/commands/run/action.d.ts +2 -2
- package/dist/src/cli/commands/run/action.js +15 -34
- package/dist/src/cli/commands/run/command.js +7 -2
- package/dist/src/cli/commands/sharedOptions/--config.d.ts +2 -0
- package/dist/src/cli/commands/sharedOptions/--config.js +2 -0
- package/dist/src/cli/commands/sharedOptions/--environment.d.ts +6 -0
- package/dist/src/cli/commands/sharedOptions/--environment.js +6 -0
- package/dist/src/cli/commands/sharedOptions/--gpu.js +5 -2
- package/dist/src/cli/commands/sharedOptions/--node-limits.d.ts +9 -0
- package/dist/src/cli/commands/sharedOptions/--node-limits.js +24 -0
- package/dist/src/cli/commands/sharedOptions/index.d.ts +3 -0
- package/dist/src/cli/commands/sharedOptions/index.js +3 -0
- package/dist/src/cli/commands/start/command.js +7 -2
- package/dist/src/cli/commands/vm-setup/action.d.ts +10 -0
- package/dist/src/cli/commands/vm-setup/action.js +14 -0
- package/dist/src/cli/commands/vm-setup/command.d.ts +3 -0
- package/dist/src/cli/commands/vm-setup/command.js +11 -0
- package/dist/src/cli/createNosanaCli.d.ts +1 -0
- package/dist/src/cli/createNosanaCli.js +4 -1
- package/npm-shrinkwrap.json +10 -2
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { JOB_RUNTIME_PORT, } from '../../../../packages/job-runtime/src/host/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The sidecar's environment as every runtime environment sets it (see
|
|
4
|
+
* docs/job-runtime-sidecar.md, "What the node starts"): the job, the node and what the job's
|
|
5
|
+
* containers are run with. What the sidecar's own host adds (its container runtime, its GPUs)
|
|
6
|
+
* is each environment's.
|
|
7
|
+
*/
|
|
8
|
+
export function buildJobRuntimeEnv(source) {
|
|
9
|
+
const { frp, rpc, consoleOutput } = source;
|
|
10
|
+
return {
|
|
11
|
+
JOB_ADDRESS: source.jobAddress,
|
|
12
|
+
JOB_KIND: source.kind,
|
|
13
|
+
NODE_ADDRESS: source.nodeAddress,
|
|
14
|
+
NOSANA_NETWORK: source.network,
|
|
15
|
+
...(rpc ? { SOLANA_RPC: rpc } : {}),
|
|
16
|
+
FRP_SERVER_ADDR: frp.serverAddr,
|
|
17
|
+
FRP_SERVER_PORT: frp.serverPort.toString(),
|
|
18
|
+
FRP_SERVER_IMAGE: frp.containerImage,
|
|
19
|
+
RESOURCE_MANAGER_IMAGE: source.resourceManagerImage,
|
|
20
|
+
NOSANA_NODE_VERSION: source.nodeVersion,
|
|
21
|
+
JOB_RUNTIME_PORT: JOB_RUNTIME_PORT.toString(),
|
|
22
|
+
// The entries carry their colours; the container has no terminal.
|
|
23
|
+
...(consoleOutput === 'entries' ? { JOB_RUNTIME_CONSOLE: 'entries', FORCE_COLOR: '1' } : {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** What followFile follows and how. */
|
|
2
|
+
export interface FollowFileOptions {
|
|
3
|
+
/** The file followed, from its start. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Takes the text written since the last read; a UTF-8 character split across reads comes whole. */
|
|
6
|
+
onText: (text: string) => void;
|
|
7
|
+
/** How long to wait before looking again when nothing new was written. */
|
|
8
|
+
pollMs: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Follows a file from its start as it grows, until the function it answers is called. A file
|
|
12
|
+
* not there yet is waited for; one that cannot be read is not followed further.
|
|
13
|
+
*/
|
|
14
|
+
export declare function followFile(options: FollowFileOptions): () => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import { StringDecoder } from 'string_decoder';
|
|
3
|
+
import { setTimeout as sleep } from 'timers/promises';
|
|
4
|
+
/** How much of a followed file is read at a time. */
|
|
5
|
+
const READ_CHUNK_BYTES = 64 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Follows a file from its start as it grows, until the function it answers is called. A file
|
|
8
|
+
* not there yet is waited for; one that cannot be read is not followed further.
|
|
9
|
+
*/
|
|
10
|
+
export function followFile(options) {
|
|
11
|
+
const follower = new FileFollower(options);
|
|
12
|
+
void follower.run();
|
|
13
|
+
return () => follower.stop();
|
|
14
|
+
}
|
|
15
|
+
/** One file followed: where it was read up to, and whether to go on. */
|
|
16
|
+
class FileFollower {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.isFollowing = true;
|
|
20
|
+
this.position = 0;
|
|
21
|
+
this.decoder = new StringDecoder('utf8');
|
|
22
|
+
this.buffer = Buffer.alloc(READ_CHUNK_BYTES);
|
|
23
|
+
}
|
|
24
|
+
stop() {
|
|
25
|
+
this.isFollowing = false;
|
|
26
|
+
}
|
|
27
|
+
async run() {
|
|
28
|
+
try {
|
|
29
|
+
while (this.isFollowing)
|
|
30
|
+
await this.readNext();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// A file that cannot be read is not followed further.
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await this.handle?.close().catch(() => undefined);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Hands on what was written since the last read, or waits when nothing was. */
|
|
40
|
+
async readNext() {
|
|
41
|
+
const { file, onText, pollMs } = this.options;
|
|
42
|
+
this.handle ??= await fs.open(file, 'r').catch(() => undefined);
|
|
43
|
+
const bytesRead = await this.readAtPosition();
|
|
44
|
+
if (bytesRead === 0) {
|
|
45
|
+
await sleep(pollMs);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this.position += bytesRead;
|
|
49
|
+
onText(this.decoder.write(this.buffer.subarray(0, bytesRead)));
|
|
50
|
+
}
|
|
51
|
+
async readAtPosition() {
|
|
52
|
+
if (!this.handle)
|
|
53
|
+
return 0;
|
|
54
|
+
const { bytesRead } = await this.handle.read(this.buffer, 0, this.buffer.length, this.position);
|
|
55
|
+
return bytesRead;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import { type Job, type NosanaClient, type Run } from '@nosana/kit';
|
|
3
|
-
import { Provider } from '../../provider/Provider.js';
|
|
4
3
|
import { StopReason } from '../../../../packages/job-runtime/src/host/index.js';
|
|
5
4
|
import type { NodeRepository } from '../../repository/NodeRepository.js';
|
|
5
|
+
import type { JobRuntimeEnvironment } from './JobRuntimeEnvironment.js';
|
|
6
6
|
/**
|
|
7
7
|
* The node's side of a job: claiming it, watching it onchain, and finishing
|
|
8
8
|
* it with its result. The job itself runs in its runtime sidecar, which the
|
|
@@ -12,7 +12,7 @@ import type { NodeRepository } from '../../repository/NodeRepository.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class JobHandler {
|
|
14
14
|
private kit;
|
|
15
|
-
private
|
|
15
|
+
private environment;
|
|
16
16
|
/** Keeps the last job submitted, whose run the node must not take again. */
|
|
17
17
|
private repository;
|
|
18
18
|
/** Holds each running job's directory. */
|
|
@@ -27,7 +27,7 @@ export declare class JobHandler {
|
|
|
27
27
|
private eventEmitter;
|
|
28
28
|
private finishing;
|
|
29
29
|
accountEmitter: EventEmitter;
|
|
30
|
-
constructor(kit: NosanaClient,
|
|
30
|
+
constructor(kit: NosanaClient, environment: JobRuntimeEnvironment,
|
|
31
31
|
/** Keeps the last job submitted, whose run the node must not take again. */
|
|
32
32
|
repository: Pick<NodeRepository, 'setFinishedJob'>,
|
|
33
33
|
/** Holds each running job's directory. */
|
|
@@ -20,13 +20,13 @@ const STOP_GRACE_MS = 5 * 60 * 1000;
|
|
|
20
20
|
* result, only the hash it submits.
|
|
21
21
|
*/
|
|
22
22
|
export class JobHandler {
|
|
23
|
-
constructor(kit,
|
|
23
|
+
constructor(kit, environment,
|
|
24
24
|
/** Keeps the last job submitted, whose run the node must not take again. */
|
|
25
25
|
repository,
|
|
26
26
|
/** Holds each running job's directory. */
|
|
27
27
|
dataDir) {
|
|
28
28
|
this.kit = kit;
|
|
29
|
-
this.
|
|
29
|
+
this.environment = environment;
|
|
30
30
|
this.repository = repository;
|
|
31
31
|
this.dataDir = dataDir;
|
|
32
32
|
this.finishing = false;
|
|
@@ -189,7 +189,7 @@ export class JobHandler {
|
|
|
189
189
|
const jobId = this.jobId();
|
|
190
190
|
const runtime = this.session(job);
|
|
191
191
|
try {
|
|
192
|
-
if (await this.
|
|
192
|
+
if (await this.environment.has(jobId)) {
|
|
193
193
|
await runtime.attach({ renew: true });
|
|
194
194
|
console.log(`Reattached to the runtime of job ${jobId}`);
|
|
195
195
|
}
|
|
@@ -217,7 +217,7 @@ export class JobHandler {
|
|
|
217
217
|
* it can be stopped and its result submitted; false when it has none.
|
|
218
218
|
*/
|
|
219
219
|
async attachExpired(job) {
|
|
220
|
-
if (!(await this.
|
|
220
|
+
if (!(await this.environment.has(this.jobId())))
|
|
221
221
|
return false;
|
|
222
222
|
const runtime = this.session(job);
|
|
223
223
|
await runtime.attach();
|
|
@@ -227,7 +227,7 @@ export class JobHandler {
|
|
|
227
227
|
session(job) {
|
|
228
228
|
return new JobRuntimeSession({
|
|
229
229
|
sdk: this.kit,
|
|
230
|
-
|
|
230
|
+
environment: this.environment,
|
|
231
231
|
dataDir: this.dataDir,
|
|
232
232
|
jobAddress: this.jobId(),
|
|
233
233
|
project: job.project,
|
|
@@ -240,7 +240,7 @@ export class JobHandler {
|
|
|
240
240
|
async jobRuntimeUrl(jobId) {
|
|
241
241
|
if (!this.runtime || this.id !== jobId)
|
|
242
242
|
return undefined;
|
|
243
|
-
return this.
|
|
243
|
+
return this.environment.url(jobId);
|
|
244
244
|
}
|
|
245
245
|
/** Waits out the job, until its runtime exits with its result. */
|
|
246
246
|
async runWithErrorHandling() {
|
|
@@ -343,6 +343,6 @@ export class JobHandler {
|
|
|
343
343
|
* `liveJob`'s (see JobRuntimeSession.removeLeftovers).
|
|
344
344
|
*/
|
|
345
345
|
async removeLeftoverJobs(liveJob) {
|
|
346
|
-
await JobRuntimeSession.removeLeftovers(this.dataDir, this.
|
|
346
|
+
await JobRuntimeSession.removeLeftovers(this.dataDir, this.environment, liveJob);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps the console of a job's VM that stopped before its result, which destroying the VM
|
|
3
|
+
* would delete, as `<workRoot>/logs/<job>.console.log`, and prints where with its last lines:
|
|
4
|
+
* the guest's side of why is only there. The console is moved, not copied: a reader holding
|
|
5
|
+
* it open keeps reading it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function keepFailedConsole(jobAddress: string, consoleFile: string, workRoot: string): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { describeError } from '../../../../packages/common/src/index.js';
|
|
4
|
+
/** Where the console of a VM that stopped before its result is kept, under the work root. */
|
|
5
|
+
const FAILED_CONSOLE_DIR = 'logs';
|
|
6
|
+
/** How much of that console is printed with the error. */
|
|
7
|
+
const FAILED_CONSOLE_TAIL_LINES = 30;
|
|
8
|
+
/** How much of its end is read for those lines: a console can be large. */
|
|
9
|
+
const FAILED_CONSOLE_TAIL_BYTES = 64 * 1024;
|
|
10
|
+
/**
|
|
11
|
+
* Keeps the console of a job's VM that stopped before its result, which destroying the VM
|
|
12
|
+
* would delete, as `<workRoot>/logs/<job>.console.log`, and prints where with its last lines:
|
|
13
|
+
* the guest's side of why is only there. The console is moved, not copied: a reader holding
|
|
14
|
+
* it open keeps reading it.
|
|
15
|
+
*/
|
|
16
|
+
export async function keepFailedConsole(jobAddress, consoleFile, workRoot) {
|
|
17
|
+
const stopped = `The VM of job ${jobAddress} stopped before its result`;
|
|
18
|
+
try {
|
|
19
|
+
const kept = path.join(workRoot, FAILED_CONSOLE_DIR, `${jobAddress}.console.log`);
|
|
20
|
+
await fs.mkdir(path.dirname(kept), { recursive: true });
|
|
21
|
+
await moveFile(consoleFile, kept);
|
|
22
|
+
const tail = await readLastLines(kept, FAILED_CONSOLE_TAIL_LINES);
|
|
23
|
+
console.error(`${stopped}; its console is kept at ${kept}. Its last lines:\n${tail}`);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(`${stopped}; its console could not be kept: ${describeError(error)}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Renames the file, or copies it when the target is on another filesystem. */
|
|
30
|
+
async function moveFile(from, to) {
|
|
31
|
+
try {
|
|
32
|
+
await fs.rename(from, to);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code !== 'EXDEV')
|
|
36
|
+
throw error;
|
|
37
|
+
await fs.copyFile(from, to);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The last lines of a file, read from its last FAILED_CONSOLE_TAIL_BYTES only. */
|
|
41
|
+
async function readLastLines(file, lines) {
|
|
42
|
+
const handle = await fs.open(file, 'r');
|
|
43
|
+
try {
|
|
44
|
+
const { size } = await handle.stat();
|
|
45
|
+
const length = Math.min(size, FAILED_CONSOLE_TAIL_BYTES);
|
|
46
|
+
const { buffer } = await handle.read(Buffer.alloc(length), 0, length, size - length);
|
|
47
|
+
return buffer.toString('utf8').trimEnd().split('\n').slice(-lines).join('\n');
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await handle.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ContainerOrchestrationInterface } from '../../../../packages/container-orchestrator/src/index.js';
|
|
2
|
+
import { type VmSpec } from '../../../../packages/vm-orchestrator/src/index.js';
|
|
3
|
+
import { readVmSpec, type VmNodeOptions } from '../../provider/vmHost/index.js';
|
|
4
|
+
import type { NodeRepository } from '../../repository/NodeRepository.js';
|
|
5
|
+
import type { ResourceManager } from '../resource/resourceManager.js';
|
|
6
|
+
import type { JobRuntimeEnvironment } from './JobRuntimeEnvironment.js';
|
|
7
|
+
/** The operator's choice of environment, and the VMs' limits. */
|
|
8
|
+
export interface JobRuntimeEnvironmentOptions extends VmNodeOptions {
|
|
9
|
+
/** Run each job's runtime in a VM (`--vm`), not a container beside the node. */
|
|
10
|
+
vm?: boolean;
|
|
11
|
+
/** Power cap in watts the guest applies to each GPU (`--gpu-power-limit`). */
|
|
12
|
+
gpuPowerLimit?: number;
|
|
13
|
+
}
|
|
14
|
+
/** What a `--vm` node checks of its host; injectable for tests. */
|
|
15
|
+
export interface VmHostSystem {
|
|
16
|
+
/** The host's platform. */
|
|
17
|
+
platform: NodeJS.Platform;
|
|
18
|
+
/** Whether a file exists. */
|
|
19
|
+
exists: (file: string) => boolean;
|
|
20
|
+
/** Whether an executable of that name is on PATH. */
|
|
21
|
+
isOnPath: (binary: string) => boolean;
|
|
22
|
+
/** Whether the host's QEMU can pass GPUs through (its iommufd backend, QEMU 9.0 or newer). */
|
|
23
|
+
canPassGpus: () => boolean;
|
|
24
|
+
/** Reads the VM every job boots from the node's limits and the host. */
|
|
25
|
+
readVmSpec: typeof readVmSpec;
|
|
26
|
+
/** What stops the node's user from booting the VMs under the work root; none when it can. */
|
|
27
|
+
findAccessProblems: (spec: VmSpec, workRoot: string) => string[];
|
|
28
|
+
/** Makes the VMs' work root under the node's data directory, refused on a tmpfs. */
|
|
29
|
+
makeVmWorkRoot: (dataDir: string) => string;
|
|
30
|
+
}
|
|
31
|
+
/** What either environment runs its jobs' runtimes with. */
|
|
32
|
+
export interface JobRuntimeEnvironmentDeps {
|
|
33
|
+
/** The node's container runtime. */
|
|
34
|
+
containerOrchestration: ContainerOrchestrationInterface;
|
|
35
|
+
/** The node's records. */
|
|
36
|
+
repository: NodeRepository;
|
|
37
|
+
/** The node's image and resource cache. */
|
|
38
|
+
resourceManager: ResourceManager;
|
|
39
|
+
/** The node's data directory (`--config`); a `--vm` node's VMs live under it. */
|
|
40
|
+
dataDir: string;
|
|
41
|
+
/** Overrides of what a `--vm` node checks of its host. */
|
|
42
|
+
system?: Partial<VmHostSystem>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Where this node runs its jobs' runtimes: a sidecar container beside the node by default, a
|
|
46
|
+
* golden VM per job with `--vm`. Both composition roots (the node, `nosana node run`) choose
|
|
47
|
+
* here. A `--vm` host that cannot boot a VM is refused now, with what it lacks, rather than at
|
|
48
|
+
* its first job.
|
|
49
|
+
*/
|
|
50
|
+
export declare function selectJobRuntimeEnvironment(options: JobRuntimeEnvironmentOptions, deps: JobRuntimeEnvironmentDeps): JobRuntimeEnvironment;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createVmImageResolver, findVmHostAccessProblems, KVM_DEVICE, QemuHypervisor, qemuSupportsIommufd, requiredHostTools, VM_IMAGE_CACHE_DIR, } from '../../../../packages/vm-orchestrator/src/index.js';
|
|
4
|
+
import { configs } from '../../configs/configs.js';
|
|
5
|
+
import { hasPciAddress, makeVmWorkRoot, readVmSpec, } from '../../provider/vmHost/index.js';
|
|
6
|
+
import { getKit, nodeAddress } from '../../sdk/index.js';
|
|
7
|
+
import { pkg } from '../../../static/index.js';
|
|
8
|
+
import { ContainerJobRuntime } from './ContainerJobRuntime.js';
|
|
9
|
+
import { VmJobRuntime } from './VmJobRuntime.js';
|
|
10
|
+
/**
|
|
11
|
+
* Where this node runs its jobs' runtimes: a sidecar container beside the node by default, a
|
|
12
|
+
* golden VM per job with `--vm`. Both composition roots (the node, `nosana node run`) choose
|
|
13
|
+
* here. A `--vm` host that cannot boot a VM is refused now, with what it lacks, rather than at
|
|
14
|
+
* its first job.
|
|
15
|
+
*/
|
|
16
|
+
export function selectJobRuntimeEnvironment(options, deps) {
|
|
17
|
+
const { containerOrchestration, repository, resourceManager } = deps;
|
|
18
|
+
if (!options.vm) {
|
|
19
|
+
// The container runtime selects GPUs by index.
|
|
20
|
+
if (hasPciAddress(options.gpu))
|
|
21
|
+
throw new Error('PCI addresses in --gpu need --vm');
|
|
22
|
+
return new ContainerJobRuntime(containerOrchestration, repository, resourceManager);
|
|
23
|
+
}
|
|
24
|
+
const system = {
|
|
25
|
+
platform: process.platform,
|
|
26
|
+
exists: fs.existsSync,
|
|
27
|
+
isOnPath,
|
|
28
|
+
canPassGpus: qemuSupportsIommufd,
|
|
29
|
+
readVmSpec,
|
|
30
|
+
findAccessProblems: findVmHostAccessProblems,
|
|
31
|
+
makeVmWorkRoot,
|
|
32
|
+
...deps.system,
|
|
33
|
+
};
|
|
34
|
+
assertCanRunKvm(system);
|
|
35
|
+
const settings = configs();
|
|
36
|
+
if (!settings.vm.image) {
|
|
37
|
+
throw new Error('--vm needs GOLDEN_VM_IMAGE in .env: the golden image each job’s VM boots');
|
|
38
|
+
}
|
|
39
|
+
const spec = system.readVmSpec(options);
|
|
40
|
+
assertVmToolsOnPath(spec, system);
|
|
41
|
+
assertQemuCanPassGpus(spec, system);
|
|
42
|
+
const workRoot = system.makeVmWorkRoot(deps.dataDir);
|
|
43
|
+
assertCanBootVms(spec, workRoot, system);
|
|
44
|
+
const host = { spec, workRoot, gpuPowerLimitWatts: options.gpuPowerLimit };
|
|
45
|
+
return createVmJobRuntime(host, settings, deps);
|
|
46
|
+
}
|
|
47
|
+
function isOnPath(binary) {
|
|
48
|
+
return (process.env.PATH ?? '').split(path.delimiter).some((dir) => {
|
|
49
|
+
if (!dir)
|
|
50
|
+
return false;
|
|
51
|
+
try {
|
|
52
|
+
fs.accessSync(path.join(dir, binary), fs.constants.X_OK);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function assertCanRunKvm({ platform, exists }) {
|
|
61
|
+
if (platform !== 'linux') {
|
|
62
|
+
throw new Error(`--vm needs a Linux host with KVM; this one is ${platform}`);
|
|
63
|
+
}
|
|
64
|
+
if (!exists(KVM_DEVICE)) {
|
|
65
|
+
throw new Error(`--vm needs KVM: ${KVM_DEVICE} is missing (enable virtualization in the BIOS and load kvm_intel or kvm_amd)`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** The host binaries a VM of `spec` needs (see requiredHostTools). */
|
|
69
|
+
function assertVmToolsOnPath(spec, system) {
|
|
70
|
+
const missing = requiredHostTools(spec).filter((tool) => !system.isOnPath(tool));
|
|
71
|
+
if (missing.length > 0) {
|
|
72
|
+
throw new Error(`--vm needs ${missing.join(', ')} on PATH`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** A GPU VM needs a QEMU with the iommufd backend its passthrough uses. */
|
|
76
|
+
function assertQemuCanPassGpus(spec, system) {
|
|
77
|
+
if (spec.gpus.length === 0 || system.canPassGpus())
|
|
78
|
+
return;
|
|
79
|
+
throw new Error('--vm needs QEMU 9.0 or newer to pass GPUs through (its iommufd backend); this host’s ' +
|
|
80
|
+
'qemu-system-x86_64 has no iommufd: upgrade QEMU');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The node's user must be able to boot the VMs: open QEMU's devices, use GPUs already on
|
|
84
|
+
* vfio-pci, lock the guest's RAM, and write the work root. Every gap is named at once.
|
|
85
|
+
*/
|
|
86
|
+
function assertCanBootVms(spec, workRoot, system) {
|
|
87
|
+
const problems = system.findAccessProblems(spec, workRoot);
|
|
88
|
+
if (problems.length === 0)
|
|
89
|
+
return;
|
|
90
|
+
throw new Error('--vm cannot boot VMs as this user: prepare the host for it with `sudo nosana-node ' +
|
|
91
|
+
'vm-setup --gpu <gpus>`, run the node as root, or fix:\n' +
|
|
92
|
+
problems.map((problem) => ` - ${problem}`).join('\n'));
|
|
93
|
+
}
|
|
94
|
+
function createVmJobRuntime({ spec, workRoot, gpuPowerLimitWatts }, settings, { repository, resourceManager }) {
|
|
95
|
+
const { vm, jobRuntime, frp, network } = settings;
|
|
96
|
+
const cacheDir = path.join(workRoot, VM_IMAGE_CACHE_DIR);
|
|
97
|
+
const hypervisor = new QemuHypervisor({ workRoot });
|
|
98
|
+
const rpc = getKit().config.solana.rpcEndpoint;
|
|
99
|
+
return new VmJobRuntime({
|
|
100
|
+
image: vm.image,
|
|
101
|
+
cacheDir,
|
|
102
|
+
workRoot,
|
|
103
|
+
spec,
|
|
104
|
+
gpuPowerLimitWatts,
|
|
105
|
+
runtimeImage: jobRuntime.containerImage,
|
|
106
|
+
nodeAddress: nodeAddress(),
|
|
107
|
+
network,
|
|
108
|
+
...(rpc ? { rpc } : {}),
|
|
109
|
+
frp: {
|
|
110
|
+
serverAddr: frp.serverAddr,
|
|
111
|
+
serverPort: frp.serverPort,
|
|
112
|
+
containerImage: frp.containerImage,
|
|
113
|
+
},
|
|
114
|
+
resourceManagerImage: resourceManager.volumes.resourceManagerImage,
|
|
115
|
+
nodeVersion: pkg.version,
|
|
116
|
+
}, { hypervisor, repository, resolveImage: createVmImageResolver({ cacheDir }) });
|
|
117
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JobDefinition, NosanaClient } from '@nosana/kit';
|
|
2
|
-
import {
|
|
2
|
+
import type { JobRuntimeEnvironment } from '../job/JobRuntimeEnvironment.js';
|
|
3
3
|
/**
|
|
4
4
|
* Set on the container by the start script that launched it. Absent when the
|
|
5
5
|
* node was started another way.
|
|
@@ -14,10 +14,10 @@ export declare class Benchmark {
|
|
|
14
14
|
private benchmarkId;
|
|
15
15
|
private jobDefinition;
|
|
16
16
|
private sdk;
|
|
17
|
-
private
|
|
17
|
+
private environment;
|
|
18
18
|
/** The node's data directory, where the run's directory is made. */
|
|
19
19
|
private dataDir;
|
|
20
|
-
constructor(benchmarkId: string, jobDefinition: JobDefinition, sdk: NosanaClient,
|
|
20
|
+
constructor(benchmarkId: string, jobDefinition: JobDefinition, sdk: NosanaClient, environment: JobRuntimeEnvironment,
|
|
21
21
|
/** The node's data directory, where the run's directory is made. */
|
|
22
22
|
dataDir: string);
|
|
23
23
|
run(): Promise<void>;
|
|
@@ -26,13 +26,13 @@ function emitBenchmark(method, type, payload) {
|
|
|
26
26
|
* sent back. Nothing of it is published: it is the node's own hardware data.
|
|
27
27
|
*/
|
|
28
28
|
export class Benchmark {
|
|
29
|
-
constructor(benchmarkId, jobDefinition, sdk,
|
|
29
|
+
constructor(benchmarkId, jobDefinition, sdk, environment,
|
|
30
30
|
/** The node's data directory, where the run's directory is made. */
|
|
31
31
|
dataDir) {
|
|
32
32
|
this.benchmarkId = benchmarkId;
|
|
33
33
|
this.jobDefinition = jobDefinition;
|
|
34
34
|
this.sdk = sdk;
|
|
35
|
-
this.
|
|
35
|
+
this.environment = environment;
|
|
36
36
|
this.dataDir = dataDir;
|
|
37
37
|
}
|
|
38
38
|
async run() {
|
|
@@ -51,7 +51,7 @@ export class Benchmark {
|
|
|
51
51
|
const total = this.jobDefinition.ops.length;
|
|
52
52
|
const session = new JobRuntimeSession({
|
|
53
53
|
sdk: this.sdk,
|
|
54
|
-
|
|
54
|
+
environment: this.environment,
|
|
55
55
|
dataDir: this.dataDir,
|
|
56
56
|
jobAddress: this.benchmarkId,
|
|
57
57
|
project: node,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Address, type Market, type NosanaClient } from "@nosana/kit";
|
|
2
|
-
import {
|
|
2
|
+
import type { JobRuntimeEnvironment } from "../job/JobRuntimeEnvironment.js";
|
|
3
3
|
export declare class MarketHandler {
|
|
4
4
|
private kit;
|
|
5
|
-
private
|
|
5
|
+
private environment;
|
|
6
6
|
/** The node's data directory, where a benchmark's directory is made. */
|
|
7
7
|
private dataDir;
|
|
8
8
|
private market;
|
|
@@ -12,7 +12,7 @@ export declare class MarketHandler {
|
|
|
12
12
|
private queueMonitoring;
|
|
13
13
|
private marketAccessHandler;
|
|
14
14
|
private inMarket;
|
|
15
|
-
constructor(kit: NosanaClient,
|
|
15
|
+
constructor(kit: NosanaClient, environment: JobRuntimeEnvironment,
|
|
16
16
|
/** The node's data directory, where a benchmark's directory is made. */
|
|
17
17
|
dataDir: string);
|
|
18
18
|
clear(): void;
|
|
@@ -10,11 +10,11 @@ import { sleep } from "../../utils/utils.js";
|
|
|
10
10
|
const RETEST_BUFFER_S = 60;
|
|
11
11
|
const MAX_BENCHMARK_RETRIES = 3;
|
|
12
12
|
export class MarketHandler {
|
|
13
|
-
constructor(kit,
|
|
13
|
+
constructor(kit, environment,
|
|
14
14
|
/** The node's data directory, where a benchmark's directory is made. */
|
|
15
15
|
dataDir) {
|
|
16
16
|
this.kit = kit;
|
|
17
|
-
this.
|
|
17
|
+
this.environment = environment;
|
|
18
18
|
this.dataDir = dataDir;
|
|
19
19
|
/** Moves on each stop, so a start that was stopped meanwhile knows it. */
|
|
20
20
|
this.queueMonitoring = 0;
|
|
@@ -43,7 +43,7 @@ export class MarketHandler {
|
|
|
43
43
|
}
|
|
44
44
|
// Host manager wants us to run a benchmark first
|
|
45
45
|
if (result.jobDefinition) {
|
|
46
|
-
const benchmark = new Benchmark(result.benchmarkId ?? result.jobDefinition.id, result.jobDefinition, this.kit, this.
|
|
46
|
+
const benchmark = new Benchmark(result.benchmarkId ?? result.jobDefinition.id, result.jobDefinition, this.kit, this.environment, this.dataDir);
|
|
47
47
|
await benchmark.run();
|
|
48
48
|
// Re-poll within the same request-market cycle, echoing the session the
|
|
49
49
|
// host issued so lifecycle metrics aren't re-requested on the retry.
|
|
@@ -65,7 +65,7 @@ export declare class ResourceManager {
|
|
|
65
65
|
* The one exception is `liveJob`, a job still running in its runtime while
|
|
66
66
|
* the node restarted: its sidecar is left for the node to reattach to. What
|
|
67
67
|
* the sidecar starts is not recorded here; it carries the job's label (see
|
|
68
|
-
*
|
|
68
|
+
* ContainerJobRuntime.sweep).
|
|
69
69
|
*/
|
|
70
70
|
resyncContainersDB(liveJob?: string): Promise<void>;
|
|
71
71
|
fetchMarketRequiredResources(market: Market | string): Promise<void>;
|
|
@@ -78,7 +78,7 @@ export class ResourceManager {
|
|
|
78
78
|
* The one exception is `liveJob`, a job still running in its runtime while
|
|
79
79
|
* the node restarted: its sidecar is left for the node to reattach to. What
|
|
80
80
|
* the sidecar starts is not recorded here; it carries the job's label (see
|
|
81
|
-
*
|
|
81
|
+
* ContainerJobRuntime.sweep).
|
|
82
82
|
*/
|
|
83
83
|
async resyncContainersDB(liveJob) {
|
|
84
84
|
const sidecar = liveJob && JOB_RUNTIME_CONTAINER_PREFIX + liveJob;
|