Skip to content

Commit ebd4beb

Browse files
Merge pull request #391 from joshrotenberg/feat/shard-and-local-commands
feat(enterprise): implement local node commands and expose shard commands
2 parents 425f87f + 8288499 commit ebd4beb

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

crates/redisctl/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ pub enum EnterpriseCommands {
11331133
#[command(subcommand)]
11341134
Workflow(EnterpriseWorkflowCommands),
11351135

1136+
/// Local node operations
1137+
#[command(subcommand)]
1138+
Local(crate::commands::enterprise::local::LocalCommands),
1139+
11361140
/// Shard management operations
11371141
#[command(subcommand)]
11381142
Shard(crate::commands::enterprise::shard::ShardCommands),
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use crate::cli::OutputFormat;
2+
use crate::connection::ConnectionManager;
3+
use crate::error::{RedisCtlError, Result as CliResult};
4+
use clap::Subcommand;
5+
6+
#[derive(Debug, Clone, Subcommand)]
7+
pub enum LocalCommands {
8+
/// Get local node master healthcheck
9+
#[command(name = "healthcheck")]
10+
MasterHealthcheck,
11+
12+
/// List local services
13+
Services,
14+
15+
/// Update local services configuration
16+
#[command(name = "services-update")]
17+
ServicesUpdate {
18+
/// Service configuration as JSON string or @file.json
19+
#[arg(long)]
20+
data: String,
21+
},
22+
}
23+
24+
impl LocalCommands {
25+
#[allow(dead_code)]
26+
pub async fn execute(
27+
&self,
28+
conn_mgr: &ConnectionManager,
29+
profile_name: Option<&str>,
30+
output_format: OutputFormat,
31+
query: Option<&str>,
32+
) -> CliResult<()> {
33+
let client = conn_mgr.create_enterprise_client(profile_name).await?;
34+
35+
match self {
36+
LocalCommands::MasterHealthcheck => {
37+
let response: serde_json::Value = client
38+
.get("/v1/local/node/master_healthcheck")
39+
.await
40+
.map_err(RedisCtlError::from)?;
41+
42+
let output_data = if let Some(q) = query {
43+
super::utils::apply_jmespath(&response, q)?
44+
} else {
45+
response
46+
};
47+
super::utils::print_formatted_output(output_data, output_format)?;
48+
}
49+
50+
LocalCommands::Services => {
51+
let response: serde_json::Value = client
52+
.get("/v1/local/services")
53+
.await
54+
.map_err(RedisCtlError::from)?;
55+
56+
let output_data = if let Some(q) = query {
57+
super::utils::apply_jmespath(&response, q)?
58+
} else {
59+
response
60+
};
61+
super::utils::print_formatted_output(output_data, output_format)?;
62+
}
63+
64+
LocalCommands::ServicesUpdate { data } => {
65+
let json_data = super::utils::read_json_data(data)?;
66+
67+
let response: serde_json::Value = client
68+
.post("/v1/local/services", &json_data)
69+
.await
70+
.map_err(RedisCtlError::from)?;
71+
72+
let output_data = if let Some(q) = query {
73+
super::utils::apply_jmespath(&response, q)?
74+
} else {
75+
response
76+
};
77+
super::utils::print_formatted_output(output_data, output_format)?;
78+
}
79+
}
80+
81+
Ok(())
82+
}
83+
}
84+
85+
#[allow(dead_code)]
86+
pub async fn handle_local_command(
87+
conn_mgr: &ConnectionManager,
88+
profile_name: Option<&str>,
89+
local_cmd: LocalCommands,
90+
output_format: OutputFormat,
91+
query: Option<&str>,
92+
) -> CliResult<()> {
93+
local_cmd
94+
.execute(conn_mgr, profile_name, output_format, query)
95+
.await
96+
}

crates/redisctl/src/commands/enterprise/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod jsonschema;
2020
pub mod ldap;
2121
pub mod license;
2222
pub mod license_workflow;
23+
pub mod local;
2324
pub mod logs;
2425
pub mod logs_impl;
2526
pub mod migration;

crates/redisctl/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ async fn execute_enterprise_command(
436436
Workflow(workflow_cmd) => {
437437
handle_enterprise_workflow_command(conn_mgr, profile, workflow_cmd, output).await
438438
}
439+
Local(local_cmd) => {
440+
commands::enterprise::local::handle_local_command(
441+
conn_mgr,
442+
profile,
443+
local_cmd.clone(),
444+
output,
445+
query,
446+
)
447+
.await
448+
}
439449
Shard(shard_cmd) => {
440450
commands::enterprise::shard::handle_shard_command(
441451
conn_mgr,

0 commit comments

Comments
 (0)