This commit is contained in:
parent
53a8d8e720
commit
b185ec2f85
8 changed files with 214 additions and 175 deletions
|
@ -279,7 +279,8 @@ impl DataLayout {
|
|||
u16::from_be_bytes([
|
||||
hash.as_slice()[HASH_DRIVE_BYTES.0],
|
||||
hash.as_slice()[HASH_DRIVE_BYTES.1],
|
||||
]) as usize % DRIVE_NPART
|
||||
]) as usize
|
||||
% DRIVE_NPART
|
||||
}
|
||||
|
||||
fn block_dir_from(&self, hash: &Hash, dir: &PathBuf) -> PathBuf {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use crate::admin::AdminRpc;
|
||||
use crate::cli::{cmd_apply_layout, cmd_assign_role, fetch_layout, fetch_status, ApplyLayoutOpt, AssignRoleOpt, BucketOperation, BucketOpt, KeyImportOpt, KeyInfoOpt, KeyOperation, PermBucketOpt};
|
||||
use crate::cli::{
|
||||
cmd_apply_layout, cmd_assign_role, fetch_layout, fetch_status, ApplyLayoutOpt, AssignRoleOpt,
|
||||
BucketOperation, BucketOpt, KeyImportOpt, KeyInfoOpt, KeyOperation, PermBucketOpt,
|
||||
};
|
||||
use bytesize::ByteSize;
|
||||
use garage_model::helper::error::Error as HelperError;
|
||||
use garage_net::endpoint::Endpoint;
|
||||
|
@ -17,11 +20,14 @@ pub async fn key_exists(
|
|||
key_pattern: String,
|
||||
) -> Result<bool, Error> {
|
||||
match rpc_cli
|
||||
.call(&rpc_host, AdminRpc::KeyOperation(
|
||||
KeyOperation::Info(KeyInfoOpt{
|
||||
.call(
|
||||
&rpc_host,
|
||||
AdminRpc::KeyOperation(KeyOperation::Info(KeyInfoOpt {
|
||||
key_pattern,
|
||||
show_secret: false,
|
||||
})), PRIO_NORMAL)
|
||||
})),
|
||||
PRIO_NORMAL,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(_) => Ok(true),
|
||||
|
@ -36,9 +42,11 @@ pub async fn bucket_exists(
|
|||
name: String,
|
||||
) -> Result<bool, Error> {
|
||||
match rpc_cli
|
||||
.call(&rpc_host, AdminRpc::BucketOperation(
|
||||
BucketOperation::Info(BucketOpt{name})
|
||||
), PRIO_NORMAL)
|
||||
.call(
|
||||
&rpc_host,
|
||||
AdminRpc::BucketOperation(BucketOperation::Info(BucketOpt { name })),
|
||||
PRIO_NORMAL,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(_) => Ok(true),
|
||||
|
@ -53,18 +61,21 @@ pub async fn key_create(
|
|||
params: &AutoKey,
|
||||
) -> Result<(), Error> {
|
||||
match rpc_cli
|
||||
.call(&rpc_host, AdminRpc::KeyOperation(
|
||||
KeyOperation::Import(KeyImportOpt{
|
||||
.call(
|
||||
&rpc_host,
|
||||
AdminRpc::KeyOperation(KeyOperation::Import(KeyImportOpt {
|
||||
name: params.name.clone(),
|
||||
secret_key: params.secret.clone(),
|
||||
key_id: params.id.clone(),
|
||||
yes: true,
|
||||
})
|
||||
), PRIO_NORMAL).await?
|
||||
})),
|
||||
PRIO_NORMAL,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(HelperError::BadRequest(msg)) => Err(Error::Message(msg)),
|
||||
resp => Err(Error::unexpected_rpc_message(resp))
|
||||
resp => Err(Error::unexpected_rpc_message(resp)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,14 +85,18 @@ pub async fn bucket_create(
|
|||
params: &AutoBucket,
|
||||
) -> Result<(), Error> {
|
||||
match rpc_cli
|
||||
.call(&rpc_host, AdminRpc::BucketOperation(
|
||||
BucketOperation::Create(BucketOpt{name: params.name.clone()})
|
||||
), PRIO_NORMAL)
|
||||
.call(
|
||||
&rpc_host,
|
||||
AdminRpc::BucketOperation(BucketOperation::Create(BucketOpt {
|
||||
name: params.name.clone(),
|
||||
})),
|
||||
PRIO_NORMAL,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(HelperError::BadRequest(msg)) => Err(Error::Message(msg)),
|
||||
resp => Err(Error::unexpected_rpc_message(resp))
|
||||
resp => Err(Error::unexpected_rpc_message(resp)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,20 +107,22 @@ pub async fn grant_permission(
|
|||
perm: &AutoPermission,
|
||||
) -> Result<(), Error> {
|
||||
match rpc_cli
|
||||
.call(&rpc_host, AdminRpc::BucketOperation(
|
||||
BucketOperation::Allow(PermBucketOpt{
|
||||
.call(
|
||||
&rpc_host,
|
||||
AdminRpc::BucketOperation(BucketOperation::Allow(PermBucketOpt {
|
||||
key_pattern: perm.key.clone(),
|
||||
read: perm.read,
|
||||
write: perm.write,
|
||||
owner: perm.owner,
|
||||
bucket: bucket_name,
|
||||
})
|
||||
), PRIO_NORMAL)
|
||||
})),
|
||||
PRIO_NORMAL,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(HelperError::BadRequest(msg)) => Err(Error::Message(msg)),
|
||||
resp => Err(Error::unexpected_rpc_message(resp))
|
||||
resp => Err(Error::unexpected_rpc_message(resp)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,26 +170,31 @@ pub async fn assign_node_layout(
|
|||
auto_nodes: &Vec<AutoNode>,
|
||||
) -> Result<(), Error> {
|
||||
if unassigned_nodes.len() != auto_nodes.len() {
|
||||
return Err(Error::Message("Cannot apply auto layout: configured nodes do not match actual nodes".to_string()));
|
||||
return Err(Error::Message(
|
||||
"Cannot apply auto layout: configured nodes do not match actual nodes".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
for (i, node_id) in unassigned_nodes.iter().enumerate() {
|
||||
if let Some(auto) = auto_nodes.get(i) {
|
||||
let capacity = auto.capacity.parse::<ByteSize>()?;
|
||||
cmd_assign_role(rpc_cli, rpc_host, AssignRoleOpt{
|
||||
cmd_assign_role(
|
||||
rpc_cli,
|
||||
rpc_host,
|
||||
AssignRoleOpt {
|
||||
node_ids: vec![format!("{id:?}", id = node_id)],
|
||||
zone: Some(auto.zone.clone()),
|
||||
capacity: Some(capacity),
|
||||
gateway: false,
|
||||
tags: vec![],
|
||||
replace: vec![],
|
||||
}).await?;
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
cmd_apply_layout(rpc_cli, rpc_host, ApplyLayoutOpt{
|
||||
version: Some(1),
|
||||
}).await?;
|
||||
cmd_apply_layout(rpc_cli, rpc_host, ApplyLayoutOpt { version: Some(1) }).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -47,7 +47,13 @@ pub async fn cli_command_dispatch(
|
|||
cmd_admin(admin_rpc_endpoint, rpc_host, AdminRpc::MetaOperation(mo)).await
|
||||
}
|
||||
Command::Auto => {
|
||||
cmd_auto(admin_rpc_endpoint, system_rpc_endpoint, rpc_host, config.auto.as_ref()).await
|
||||
cmd_auto(
|
||||
admin_rpc_endpoint,
|
||||
system_rpc_endpoint,
|
||||
rpc_host,
|
||||
config.auto.as_ref(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -277,7 +283,6 @@ pub async fn cmd_auto(
|
|||
) -> Result<(), HelperError> {
|
||||
match config {
|
||||
Some(auto) => {
|
||||
|
||||
// Assign cluster layout if all nodes are unassigned.
|
||||
// This is to ensure a newly created cluster is readily available.
|
||||
// Further changes to the cluster layout must be done manually.
|
||||
|
@ -307,7 +312,9 @@ pub async fn cmd_auto(
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(HelperError::BadRequest("Auto configuration is missing".to_string()))
|
||||
return Err(HelperError::BadRequest(
|
||||
"Auto configuration is missing".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
pub(crate) mod auto;
|
||||
pub(crate) mod cmd;
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod layout;
|
||||
pub(crate) mod structs;
|
||||
pub(crate) mod util;
|
||||
pub(crate) mod auto;
|
||||
|
||||
pub(crate) mod convert_db;
|
||||
|
||||
pub(crate) use auto::*;
|
||||
pub(crate) use cmd::*;
|
||||
pub(crate) use init::*;
|
||||
pub(crate) use layout::*;
|
||||
pub(crate) use structs::*;
|
||||
pub(crate) use util::*;
|
||||
pub(crate) use auto::*;
|
|
@ -284,7 +284,15 @@ async fn cli_command(opt: Opt) -> Result<(), Error> {
|
|||
let system_rpc_endpoint = netapp.endpoint::<SystemRpc, ()>(SYSTEM_RPC_PATH.into());
|
||||
let admin_rpc_endpoint = netapp.endpoint::<AdminRpc, ()>(ADMIN_RPC_PATH.into());
|
||||
|
||||
match cli_command_dispatch(opt.cmd, &system_rpc_endpoint, &admin_rpc_endpoint, id, config.as_ref().unwrap()).await {
|
||||
match cli_command_dispatch(
|
||||
opt.cmd,
|
||||
&system_rpc_endpoint,
|
||||
&admin_rpc_endpoint,
|
||||
id,
|
||||
config.as_ref().unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Err(HelperError::Internal(i)) => Err(Error::Message(format!("Internal error: {}", i))),
|
||||
Err(HelperError::BadRequest(b)) => Err(Error::Message(b)),
|
||||
Err(e) => Err(Error::Message(format!("{}", e))),
|
||||
|
|
|
@ -279,7 +279,8 @@ impl<'a> LockedHelper<'a> {
|
|||
.local_aliases
|
||||
.get(alias_name)
|
||||
.cloned()
|
||||
.flatten() != Some(bucket_id)
|
||||
.flatten()
|
||||
!= Some(bucket_id)
|
||||
{
|
||||
return Err(GarageError::Message(format!(
|
||||
"Bucket {:?} does not have alias {} in namespace of key {}",
|
||||
|
|
Loading…
Reference in a new issue