From 173a6f3109ecdf0159ae511f6de75b7212d8a1b0 Mon Sep 17 00:00:00 2001 From: John Haverlack Date: Sat, 31 Jan 2026 16:56:16 -0900 Subject: [PATCH] WIP: Join Process --- sdl-mgr/app/modules/nwa-lib/index.js | 6 ++ sdl-mgr/app/modules/sdl-mgr/index.js | 72 +++++++++++++++++++++++- sdl-mgr/conf/default-sdl-mgr-config.json | 1 + sdl-wkr/app/index.js | 2 +- sdl-wkr/app/modules/nwa-lib/index.js | 3 + 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/sdl-mgr/app/modules/nwa-lib/index.js b/sdl-mgr/app/modules/nwa-lib/index.js index 3ae3a4f..a027e66 100644 --- a/sdl-mgr/app/modules/nwa-lib/index.js +++ b/sdl-mgr/app/modules/nwa-lib/index.js @@ -146,6 +146,9 @@ function load_config() { config.package = JSON.parse(fs.readFileSync(path.join(config.dirs.app, 'package.json'), 'utf8')); config.dependencies = {} + // SDL Version + config.cluster.sdl_version = config.package.version + for (let d in config.package.dependencies) { config.dependencies[d] = JSON.parse(fs.readFileSync(path.join(config.dirs.app, 'node_modules', d, 'package.json'), 'utf8')); } @@ -158,6 +161,7 @@ function load_config() { ips: [], os: { + platform: null, id: null, name: null, version: null, @@ -218,6 +222,8 @@ function load_config() { config.host.cpu.cores_logical = cpus.length; } + config.host.os.platform = os.platform(); + // ------------------------------- // OS Info from /etc/os-release (Linux) // ------------------------------- diff --git a/sdl-mgr/app/modules/sdl-mgr/index.js b/sdl-mgr/app/modules/sdl-mgr/index.js index 3fd6af4..00d2a87 100644 --- a/sdl-mgr/app/modules/sdl-mgr/index.js +++ b/sdl-mgr/app/modules/sdl-mgr/index.js @@ -1,14 +1,83 @@ const module = 'sdl-mgr'; // Module Name -import { load_config, log, ipToInt, intToIp, computeBroadcast, getUptimeDHMS } from '../nwa-lib/index.js'; +import { load_config, log, ipToInt, intToIp, computeBroadcast, getProcessStartTs, getUptimeDHMS } from '../nwa-lib/index.js'; import mqtt from 'mqtt'; import os from 'os'; import dgram from 'dgram'; +import fs from 'fs'; +import path from 'path'; + const config = load_config(); log(`Loaded module: ${module}`); // log(`${module}: Cluster Conf: ${JSON.stringify(config.cluster, null, 2)}`, true); +// log(`${module}: Dirs: ${JSON.stringify(config.dirs, null, 2)}`, true); + +function loadClusterState(config) { + const clusterDir = config.dirs.clstr; + const clusterFile = path.join(clusterDir, 'cluster.json'); + + // Ensure cluster directory exists + if (!fs.existsSync(clusterDir)) { + fs.mkdirSync(clusterDir, { recursive: true }); + } + + // If cluster.json doesn't exist, create initial state + if (!fs.existsSync(clusterFile)) { + const initialState = { + meta: { + updated: new Date().toISOString(), + started_at: new Date(getProcessStartTs()).toISOString(), + uptime: getUptimeDHMS(), + stats: { + workers: { + allocated: 0, + available: 0, + used: 0 + }, + resources: { + cpus: { + allocated: 0, + available: 0, + used: 0 + }, + memory: { + allocated: 0, + available: 0, + used: 0 + }, + gpus: { + allocated: 0, + available: 0, + used: 0 + } + } + } + }, + cluster: config.cluster, + "sdl-mgr": { + sdl_id: config.identity.sdl_id, + hostname: config.identity.hostname, + platform: config.host.os.platform, + arch: config.host.cpu.arch, + distro: config.host.os.pretty_name, + distro_name: config.host.os.name, + distro_version: config.host.os.version + }, + workers: {} + }; + + fs.writeFileSync(clusterFile, JSON.stringify(initialState, null, 2)); + return initialState; + } + + // Load existing cluster state + const data = fs.readFileSync(clusterFile, 'utf8'); + return JSON.parse(data); +} + + function startSDLStatusPub() { const sdlCfg = config.modules[module]; @@ -231,3 +300,4 @@ function startUdpBeacon() { // ------------------------------- startSDLStatusPub(); startUdpBeacon(); +loadClusterState(config); \ No newline at end of file diff --git a/sdl-mgr/conf/default-sdl-mgr-config.json b/sdl-mgr/conf/default-sdl-mgr-config.json index 966ea86..6cbcb5c 100644 --- a/sdl-mgr/conf/default-sdl-mgr-config.json +++ b/sdl-mgr/conf/default-sdl-mgr-config.json @@ -12,6 +12,7 @@ "dist": "SDLHOME/dist", "logs": "SDLHOME/logs", "data": "SDLHOME/data", + "clstr": "DATA/cluster", "proj": "DATA/proj", "jobs": "DATA/jobs", "conf": "SDLHOME/conf", diff --git a/sdl-wkr/app/index.js b/sdl-wkr/app/index.js index 7cc9cdf..a81d329 100644 --- a/sdl-wkr/app/index.js +++ b/sdl-wkr/app/index.js @@ -11,7 +11,7 @@ const config = load_config(); log('======================================================================================='); log(config.package.name + ': STARTING: ' + config.package.description + ' v' + config.package.version); // log(JSON.stringify(config, null, 2)); -log(JSON.stringify(config.dirs, null, 2), false); +// log(JSON.stringify(config.dirs, null, 2), false); for (let m in config.modules) { // log(`Loading module: ${m}`); diff --git a/sdl-wkr/app/modules/nwa-lib/index.js b/sdl-wkr/app/modules/nwa-lib/index.js index 20c7bc2..d4eb9a7 100644 --- a/sdl-wkr/app/modules/nwa-lib/index.js +++ b/sdl-wkr/app/modules/nwa-lib/index.js @@ -158,6 +158,7 @@ function load_config() { ips: [], os: { + platform: null, id: null, name: null, version: null, @@ -218,6 +219,8 @@ function load_config() { config.host.cpu.cores_logical = cpus.length; } + config.host.os.platform = os.platform(); + // ------------------------------- // OS Info from /etc/os-release (Linux) // -------------------------------