forked from Deuxfleurs/garage
Added a CLI command to update the parameters for the layout computation (for now, only the zone redundancy)
This commit is contained in:
parent
ceac3713d6
commit
a951b6c452
2 changed files with 46 additions and 3 deletions
|
@ -14,8 +14,8 @@ pub async fn cli_layout_command_dispatch(
|
||||||
rpc_host: NodeID,
|
rpc_host: NodeID,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
match cmd {
|
match cmd {
|
||||||
LayoutOperation::Assign(configure_opt) => {
|
LayoutOperation::Assign(assign_opt) => {
|
||||||
cmd_assign_role(system_rpc_endpoint, rpc_host, configure_opt).await
|
cmd_assign_role(system_rpc_endpoint, rpc_host, assign_opt).await
|
||||||
}
|
}
|
||||||
LayoutOperation::Remove(remove_opt) => {
|
LayoutOperation::Remove(remove_opt) => {
|
||||||
cmd_remove_role(system_rpc_endpoint, rpc_host, remove_opt).await
|
cmd_remove_role(system_rpc_endpoint, rpc_host, remove_opt).await
|
||||||
|
@ -27,6 +27,9 @@ pub async fn cli_layout_command_dispatch(
|
||||||
LayoutOperation::Revert(revert_opt) => {
|
LayoutOperation::Revert(revert_opt) => {
|
||||||
cmd_revert_layout(system_rpc_endpoint, rpc_host, revert_opt).await
|
cmd_revert_layout(system_rpc_endpoint, rpc_host, revert_opt).await
|
||||||
}
|
}
|
||||||
|
LayoutOperation::Config(config_opt) => {
|
||||||
|
cmd_config_layout(system_rpc_endpoint, rpc_host, config_opt).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +248,34 @@ pub async fn cmd_revert_layout(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn cmd_config_layout(
|
||||||
|
rpc_cli: &Endpoint<SystemRpc, ()>,
|
||||||
|
rpc_host: NodeID,
|
||||||
|
config_opt: ConfigLayoutOpt,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let mut layout = fetch_layout(rpc_cli, rpc_host).await?;
|
||||||
|
|
||||||
|
match config_opt.redundancy {
|
||||||
|
None => (),
|
||||||
|
Some(r) => {
|
||||||
|
if r > layout.replication_factor {
|
||||||
|
println!("The zone redundancy must be smaller or equal to the \
|
||||||
|
replication factor ({}).", layout.replication_factor);
|
||||||
|
}
|
||||||
|
else if r < 1 {
|
||||||
|
println!("The zone redundancy must be at least 1.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
layout.parameters.update(LayoutParameters{ zone_redundancy: r });
|
||||||
|
println!("The new zone redundancy has been staged.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_layout(rpc_cli, rpc_host, layout).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// --- utility ---
|
// --- utility ---
|
||||||
|
|
||||||
pub async fn fetch_layout(
|
pub async fn fetch_layout(
|
||||||
|
|
|
@ -87,6 +87,10 @@ pub enum LayoutOperation {
|
||||||
#[structopt(name = "remove", version = garage_version())]
|
#[structopt(name = "remove", version = garage_version())]
|
||||||
Remove(RemoveRoleOpt),
|
Remove(RemoveRoleOpt),
|
||||||
|
|
||||||
|
/// Configure parameters value for the layout computation
|
||||||
|
#[structopt(name = "config", version = garage_version())]
|
||||||
|
Config(ConfigLayoutOpt),
|
||||||
|
|
||||||
/// Show roles currently assigned to nodes and changes staged for commit
|
/// Show roles currently assigned to nodes and changes staged for commit
|
||||||
#[structopt(name = "show", version = garage_version())]
|
#[structopt(name = "show", version = garage_version())]
|
||||||
Show,
|
Show,
|
||||||
|
@ -100,6 +104,7 @@ pub enum LayoutOperation {
|
||||||
Revert(RevertLayoutOpt),
|
Revert(RevertLayoutOpt),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub struct AssignRoleOpt {
|
pub struct AssignRoleOpt {
|
||||||
/// Node(s) to which to assign role (prefix of hexadecimal node id)
|
/// Node(s) to which to assign role (prefix of hexadecimal node id)
|
||||||
|
@ -110,7 +115,7 @@ pub struct AssignRoleOpt {
|
||||||
#[structopt(short = "z", long = "zone")]
|
#[structopt(short = "z", long = "zone")]
|
||||||
pub(crate) zone: Option<String>,
|
pub(crate) zone: Option<String>,
|
||||||
|
|
||||||
/// Capacity (in relative terms, use 1 to represent your smallest server)
|
/// Capacity (in relative terms)
|
||||||
#[structopt(short = "c", long = "capacity")]
|
#[structopt(short = "c", long = "capacity")]
|
||||||
pub(crate) capacity: Option<u32>,
|
pub(crate) capacity: Option<u32>,
|
||||||
|
|
||||||
|
@ -133,6 +138,13 @@ pub struct RemoveRoleOpt {
|
||||||
pub(crate) node_id: String,
|
pub(crate) node_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
pub struct ConfigLayoutOpt {
|
||||||
|
/// Zone redundancy parameter
|
||||||
|
#[structopt(short = "r", long = "redundancy")]
|
||||||
|
pub(crate) redundancy: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub struct ApplyLayoutOpt {
|
pub struct ApplyLayoutOpt {
|
||||||
/// Version number of new configuration: this command will fail if
|
/// Version number of new configuration: this command will fail if
|
||||||
|
|
Loading…
Reference in a new issue