diff options
author | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-05 15:36:47 +0100 |
---|---|---|
committer | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-05 15:36:47 +0100 |
commit | f914db057a85e0fa70f319ee3af85998a551af96 (patch) | |
tree | d5a805dbc0615544d3fe1b1b538fbf2a3642a74a /src/garage/cli_v2 | |
parent | 406b6da1634a38c1b8176ff468d964e42ce5ce5d (diff) | |
download | garage-f914db057a85e0fa70f319ee3af85998a551af96.tar.gz garage-f914db057a85e0fa70f319ee3af85998a551af96.zip |
cli_v2: implement LaunchRepairOperation and remove old stuff
Diffstat (limited to 'src/garage/cli_v2')
-rw-r--r-- | src/garage/cli_v2/mod.rs | 14 | ||||
-rw-r--r-- | src/garage/cli_v2/node.rs | 48 |
2 files changed, 48 insertions, 14 deletions
diff --git a/src/garage/cli_v2/mod.rs b/src/garage/cli_v2/mod.rs index dccdc295..28c7c824 100644 --- a/src/garage/cli_v2/mod.rs +++ b/src/garage/cli_v2/mod.rs @@ -20,14 +20,10 @@ use garage_api_admin::api::*; use garage_api_admin::api_server::{AdminRpc as ProxyRpc, AdminRpcResponse as ProxyRpcResponse}; use garage_api_admin::RequestHandler; -use crate::admin::*; -use crate::cli as cli_v1; use crate::cli::structs::*; -use crate::cli::Command; pub struct Cli { pub system_rpc_endpoint: Arc<Endpoint<SystemRpc, ()>>, - pub admin_rpc_endpoint: Arc<Endpoint<AdminRpc, ()>>, pub proxy_rpc_endpoint: Arc<Endpoint<ProxyRpc, ()>>, pub rpc_host: NodeID, } @@ -46,15 +42,7 @@ impl Cli { Command::Block(bo) => self.cmd_block(bo).await, Command::Meta(mo) => self.cmd_meta(mo).await, Command::Stats(so) => self.cmd_stats(so).await, - - // TODO - Command::Repair(ro) => cli_v1::cmd_admin( - &self.admin_rpc_endpoint, - self.rpc_host, - AdminRpc::LaunchRepair(ro), - ) - .await - .ok_or_message("cli_v1"), + Command::Repair(ro) => self.cmd_repair(ro).await, _ => unreachable!(), } diff --git a/src/garage/cli_v2/node.rs b/src/garage/cli_v2/node.rs index b1915dc4..c5d0cdea 100644 --- a/src/garage/cli_v2/node.rs +++ b/src/garage/cli_v2/node.rs @@ -27,7 +27,7 @@ impl Cli { table.push(format!("{:.16}\tError: {}", node, err)); } for (node, _) in res.success.iter() { - table.push(format!("{:.16}\tOk", node)); + table.push(format!("{:.16}\tSnapshot created", node)); } format_table(table); @@ -64,4 +64,50 @@ impl Cli { Ok(()) } + + pub async fn cmd_repair(&self, cmd: RepairOpt) -> Result<(), Error> { + if !cmd.yes { + return Err(Error::Message( + "Please add --yes to start the repair operation".into(), + )); + } + + let repair_type = match cmd.what { + RepairWhat::Tables => RepairType::Tables, + RepairWhat::Blocks => RepairType::Blocks, + RepairWhat::Versions => RepairType::Versions, + RepairWhat::MultipartUploads => RepairType::MultipartUploads, + RepairWhat::BlockRefs => RepairType::BlockRefs, + RepairWhat::BlockRc => RepairType::BlockRc, + RepairWhat::Rebalance => RepairType::Rebalance, + RepairWhat::Scrub { cmd } => RepairType::Scrub(match cmd { + ScrubCmd::Start => ScrubCommand::Start, + ScrubCmd::Cancel => ScrubCommand::Cancel, + ScrubCmd::Pause => ScrubCommand::Pause, + ScrubCmd::Resume => ScrubCommand::Resume, + }), + }; + + let res = self + .api_request(LaunchRepairOperationRequest { + node: if cmd.all_nodes { + "*".to_string() + } else { + hex::encode(self.rpc_host) + }, + body: LocalLaunchRepairOperationRequest { repair_type }, + }) + .await?; + + let mut table = vec![]; + for (node, err) in res.error.iter() { + table.push(format!("{:.16}\tError: {}", node, err)); + } + for (node, _) in res.success.iter() { + table.push(format!("{:.16}\tRepair launched", node)); + } + format_table(table); + + Ok(()) + } } |