From f9a2ebf24ba5c032454812c9a28da0278c265fc8 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Tue, 18 Nov 2025 11:50:52 +0200 Subject: [PATCH] chore: Refactor coordinator configuration and status reporting - Update default coordinator name to 'coordinator' - Improve status reporting by using dedicated variables - Adjust `zinit.get` call to use `create: true` - Set `zinit_default` based on `args.name` when 'default' is provided - Update `coordinatorServer.name` default to 'coordinator' - Make 'coordinator' the default for `ArgsGet.name` - Use `coordinator_default` for `ArgsGet.name` if set - Adjust `CoordinatorServer.binary_path` default - Update `zinit.get` to use `create: true` - Log socket closure for debugging - Remove unused import `incubaid.herolib.core.texttools` --- examples/installers/horus/horus_start_all.vsh | 21 +++++-- lib/clients/zinit/zinit_factory_.v | 7 ++- .../horus/coordinator/coordinator_actions.v | 59 ++++++++++--------- .../horus/coordinator/coordinator_factory_.v | 13 ++-- .../horus/coordinator/coordinator_model.v | 16 ++--- lib/osal/startupmanager/startupmanager.v | 5 +- lib/schemas/jsonrpc/transport_unixsocket.v | 3 +- 7 files changed, 71 insertions(+), 53 deletions(-) diff --git a/examples/installers/horus/horus_start_all.vsh b/examples/installers/horus/horus_start_all.vsh index 6dfc8852..3b640f1e 100755 --- a/examples/installers/horus/horus_start_all.vsh +++ b/examples/installers/horus/horus_start_all.vsh @@ -14,7 +14,7 @@ println('šŸš€ Starting All Horus Services') // Step 1: Start Coordinator println('\nā–¶ļø Step 1/5: Starting Coordinator...') -mut coordinator_installer := coordinator.get()! +mut coordinator_installer := coordinator.get(name: 'ayman', create: true)! coordinator_installer.start()! if coordinator_installer.running()! { println('āœ… Coordinator is running on HTTP:${coordinator_installer.http_port} WS:${coordinator_installer.ws_port}') @@ -65,11 +65,20 @@ if sal_runner.running()! { println('šŸŽ‰ All Horus services started!') println('\nšŸ“Š Service Status:') -println(' • Coordinator: ${if coordinator_installer.running()! { "āœ… Running" } else { "āŒ Stopped" }} (http://127.0.0.1:${coordinator_installer.http_port})') -println(' • Supervisor: ${if supervisor_inst.running()! { "āœ… Running" } else { "āŒ Stopped" }} (http://127.0.0.1:${supervisor_inst.http_port})') -println(' • Hero Runner: ${if hero_runner.running()! { "āœ… Running" } else { "āŒ Stopped" }}') -println(' • Osiris Runner: ${if osiris_runner.running()! { "āœ… Running" } else { "āŒ Stopped" }}') -println(' • SAL Runner: ${if sal_runner.running()! { "āœ… Running" } else { "āŒ Stopped" }}') +coordinator_status := if coordinator_installer.running()! { 'āœ… Running' } else { 'āŒ Stopped' } +println(' • Coordinator: ${coordinator_status} (http://127.0.0.1:${coordinator_installer.http_port})') + +supervisor_status := if supervisor_inst.running()! { 'āœ… Running' } else { 'āŒ Stopped' } +println(' • Supervisor: ${supervisor_status} (http://127.0.0.1:${supervisor_inst.http_port})') + +hero_runner_status := if hero_runner.running()! { 'āœ… Running' } else { 'āŒ Stopped' } +println(' • Hero Runner: ${hero_runner_status}') + +osiris_runner_status := if osiris_runner.running()! { 'āœ… Running' } else { 'āŒ Stopped' } +println(' • Osiris Runner: ${osiris_runner_status}') + +sal_runner_status := if sal_runner.running()! { 'āœ… Running' } else { 'āŒ Stopped' } +println(' • SAL Runner: ${sal_runner_status}') println('\nšŸ’” Next Steps:') println(' To stop services, run: ./horus_stop_all.vsh') diff --git a/lib/clients/zinit/zinit_factory_.v b/lib/clients/zinit/zinit_factory_.v index 89e1b565..947059dc 100644 --- a/lib/clients/zinit/zinit_factory_.v +++ b/lib/clients/zinit/zinit_factory_.v @@ -27,8 +27,13 @@ pub fn new(args ArgsGet) !&ZinitRPC { return get(name: args.name)! } -pub fn get(args ArgsGet) !&ZinitRPC { +pub fn get(args_ ArgsGet) !&ZinitRPC { + mut args := args_ mut context := base.context()! + // If name is 'default' and zinit_default is set, use zinit_default instead + if args.name == 'default' && zinit_default != '' { + args.name = zinit_default + } zinit_default = args.name if args.fromdb || args.name !in zinit_global { mut r := context.redis()! diff --git a/lib/installers/horus/coordinator/coordinator_actions.v b/lib/installers/horus/coordinator/coordinator_actions.v index 647719cd..8351b3cb 100644 --- a/lib/installers/horus/coordinator/coordinator_actions.v +++ b/lib/installers/horus/coordinator/coordinator_actions.v @@ -2,7 +2,6 @@ module coordinator import incubaid.herolib.osal.core as osal import incubaid.herolib.ui.console -import incubaid.herolib.core.texttools import incubaid.herolib.core.pathlib import incubaid.herolib.osal.startupmanager import incubaid.herolib.installers.ulist @@ -13,7 +12,7 @@ import os fn startupcmd() ![]startupmanager.ZProcessNewArgs { mut cfg := get()! mut res := []startupmanager.ZProcessNewArgs{} - + res << startupmanager.ZProcessNewArgs{ name: 'coordinator' cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr} --api-http-port ${cfg.http_port} --api-ws-port ${cfg.ws_port}' @@ -30,7 +29,11 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs { fn running() !bool { mut cfg := get()! // Check if the process is running by checking the HTTP port - res := osal.exec(cmd: 'curl -fsSL http://127.0.0.1:${cfg.http_port} || exit 1', stdout: false, raise_error: false)! + res := osal.exec( + cmd: 'curl -fsSL http://127.0.0.1:${cfg.http_port} || exit 1' + stdout: false + raise_error: false + )! return res.exit_code == 0 } @@ -51,13 +54,13 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed() !bool { mut cfg := get()! - + // Check if the binary exists mut binary := pathlib.get(cfg.binary_path) if !binary.exists() { return false } - + return true } @@ -85,7 +88,7 @@ fn install() ! { pub fn build_coordinator() ! { console.print_header('build coordinator') println('šŸ“¦ Starting coordinator build process...\n') - + // Use default config instead of getting from factory println('āš™ļø Initializing configuration...') mut cfg := CoordinatorServer{} @@ -94,7 +97,7 @@ pub fn build_coordinator() ! { println(' - Redis address: ${cfg.redis_addr}') println(' - HTTP port: ${cfg.http_port}') println(' - WS port: ${cfg.ws_port}\n') - + // Ensure rust is installed println('Step 1/3: Checking Rust dependency...') if !osal.cmd_exists('rustc') { @@ -106,7 +109,7 @@ pub fn build_coordinator() ! { res := osal.exec(cmd: 'rustc --version', stdout: false, raise_error: false)! println('Rust is already installed: ${res.output.trim_space()}\n') } - + // Clone or get the repository println('Step 2/3: Cloning/updating horus repository...') // Use the configured repo_path or default coderoot @@ -116,42 +119,42 @@ pub fn build_coordinator() ! { pull: true reset: false )! - + // Update the path to the actual cloned repo cfg.repo_path = repo.path() println('āœ… Repository ready at: ${cfg.repo_path}\n') - + // Build the coordinator binary from the horus workspace println('Step 3/3: Building coordinator binary...') println('WARNING: This may take several minutes (compiling Rust code)...') println('Running: cargo build -p hero-coordinator --release\n') - + cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release' osal.execute_stdout(cmd)! - + println('\nāœ… Build completed successfully') - + // Ensure binary directory exists and copy the binary println('šŸ“ Preparing binary directory: ${cfg.binary_path}') mut binary_path_obj := pathlib.get(cfg.binary_path) osal.dir_ensure(binary_path_obj.path_dir())! - + // Copy the built binary to the configured location source_binary := '${cfg.repo_path}/target/release/coordinator' println('šŸ“‹ Copying binary from: ${source_binary}') println('šŸ“‹ Copying binary to: ${cfg.binary_path}') mut source_file := pathlib.get_file(path: source_binary)! source_file.copy(dest: cfg.binary_path, rsync: false)! - + println('\nšŸŽ‰ Coordinator built successfully!') println('šŸ“ Binary location: ${cfg.binary_path}') } fn build() ! { console.print_header('build coordinator') - + mut cfg := get()! - + // Ensure Redis is installed and running (required for coordinator) console.print_debug('Checking if Redis is installed and running...') redis_check := osal.exec(cmd: 'redis-cli -c -p 6379 ping', stdout: false, raise_error: false)! @@ -167,7 +170,7 @@ fn build() ! { } else { console.print_debug('Redis is already running') } - + // Ensure rust is installed console.print_debug('Checking if Rust is installed...') mut rust_installer := rust.get()! @@ -178,7 +181,7 @@ fn build() ! { } else { console.print_debug('Rust is already installed: ${res.output.trim_space()}') } - + // Clone or get the repository console.print_debug('Cloning/updating horus repository...') mut gs := gittools.new()! @@ -187,43 +190,43 @@ fn build() ! { pull: true reset: false )! - + // Update the path to the actual cloned repo cfg.repo_path = repo.path() set(cfg)! console.print_debug('Repository path: ${cfg.repo_path}') - + // Build the coordinator binary from the horus workspace console.print_header('Building coordinator binary (this may take several minutes ${cfg.repo_path})...') console.print_debug('Running: cargo build -p hero-coordinator --release') console.print_debug('Build output:') - + cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release' osal.execute_stdout(cmd)! - + console.print_debug('Build completed successfully') - + // Ensure binary directory exists and copy the binary console.print_header('Preparing binary directory: ${cfg.binary_path}') mut binary_path_obj := pathlib.get(cfg.binary_path) osal.dir_ensure(binary_path_obj.path_dir())! - + // Copy the built binary to the configured location source_binary := '${cfg.repo_path}/target/release/coordinator' console.print_debug('Copying binary from: ${source_binary}') console.print_debug('Copying binary to: ${cfg.binary_path}') mut source_file := pathlib.get_file(path: source_binary)! source_file.copy(dest: cfg.binary_path, rsync: false)! - + console.print_header('coordinator built successfully at ${cfg.binary_path}') } fn destroy() ! { mut server := get()! server.stop()! - + osal.process_kill_recursive(name: 'coordinator')! - + // Remove the built binary osal.rm(server.binary_path)! } diff --git a/lib/installers/horus/coordinator/coordinator_factory_.v b/lib/installers/horus/coordinator/coordinator_factory_.v index f091fb6c..1ce84ef2 100644 --- a/lib/installers/horus/coordinator/coordinator_factory_.v +++ b/lib/installers/horus/coordinator/coordinator_factory_.v @@ -17,7 +17,7 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string = 'default' + name string = 'coordinator' binary_path string redis_addr string http_port int @@ -38,19 +38,22 @@ pub fn new(args ArgsGet) !&CoordinatorServer { log_level: args.log_level repo_path: args.repo_path } - + // Try to set in Redis, if it fails (Redis not available), use in-memory config set(obj) or { console.print_debug('Redis not available, using in-memory configuration') set_in_mem(obj)! } - + return get(name: args.name)! } -pub fn get(args ArgsGet) !&CoordinatorServer { +pub fn get(args_ ArgsGet) !&CoordinatorServer { + mut args := args_ mut context := base.context()! - coordinator_default = args.name + if args.name == 'coordinator' && coordinator_default != '' { + args.name = coordinator_default + } if args.fromdb || args.name !in coordinator_global { mut r := context.redis()! if r.hexists('context:coordinator', args.name)! { diff --git a/lib/installers/horus/coordinator/coordinator_model.v b/lib/installers/horus/coordinator/coordinator_model.v index f3f3a9b1..c4933921 100644 --- a/lib/installers/horus/coordinator/coordinator_model.v +++ b/lib/installers/horus/coordinator/coordinator_model.v @@ -14,13 +14,13 @@ const default = true @[heap] pub struct CoordinatorServer { pub mut: - name string = 'default' - binary_path string = os.join_path(os.home_dir(), 'hero/bin/coordinator') - redis_addr string = '127.0.0.1:6379' - http_port int = 8081 - ws_port int = 9653 - log_level string = 'info' - repo_path string = '/root/code/git.ourworld.tf/herocode/horus' + name string = 'coordinator' + binary_path string = os.join_path(os.home_dir(), 'hero/bin/coordinator') + redis_addr string = '127.0.0.1:6379' + http_port int = 8081 + ws_port int = 9653 + log_level string = 'info' + repo_path string = '/root/code/git.ourworld.tf/herocode/horus' } // your checking & initialization code if needed @@ -30,7 +30,7 @@ fn obj_init(mycfg_ CoordinatorServer) !CoordinatorServer { mycfg.name = 'default' } if mycfg.binary_path == '' { - mycfg.binary_path = os.join_path(os.home_dir(),'hero/bin/coordinator') + mycfg.binary_path = os.join_path(os.home_dir(), 'hero/bin/coordinator') } if mycfg.redis_addr == '' { mycfg.redis_addr = '127.0.0.1:6379' diff --git a/lib/osal/startupmanager/startupmanager.v b/lib/osal/startupmanager/startupmanager.v index 6804e037..2d6e5626 100644 --- a/lib/osal/startupmanager/startupmanager.v +++ b/lib/osal/startupmanager/startupmanager.v @@ -18,13 +18,12 @@ pub fn get(cat StartupManagerType) !StartupManager { } match sm.cat { .zinit { - mut zinit_client_test := zinit.get()! // 'create:true' ensures a client object is initiated even if the socket isn't active. + mut zinit_client_test := zinit.get(create: true)! // 'create:true' ensures a client object is initiated even if the socket isn't active. if _ := zinit_client_test.rpc_discover() { sm.cat = .zinit } else { return error('zinit not found ${err}') } - } .auto { // Try to get a ZinitRPC client and check if it can discover RPC methods. @@ -36,7 +35,7 @@ pub fn get(cat StartupManagerType) !StartupManager { } else { sm.cat = .screen } - } + } .unknown { print_backtrace() return error("can't determine startup manager type, need to be a known one.") diff --git a/lib/schemas/jsonrpc/transport_unixsocket.v b/lib/schemas/jsonrpc/transport_unixsocket.v index ea0ec070..7912dfe8 100644 --- a/lib/schemas/jsonrpc/transport_unixsocket.v +++ b/lib/schemas/jsonrpc/transport_unixsocket.v @@ -33,8 +33,7 @@ pub fn (mut t UnixSocketTransport) send(request string, params SendParams) !stri // Close the socket explicitly unix.shutdown(socket.sock.handle) socket.close() or {} - print_backtrace() - console.print_debug('The server did not close the socket, we did timeout or there was other error.') + console.print_debug('The server closed the socket, check if closed') // We should debug this } // Set timeout if specified