Admin API refactoring: convert existing commands to API requests (step 3) #945

Merged
lx merged 12 commits from refactor-admin into next-v2 2025-02-05 19:54:42 +00:00
11 changed files with 4 additions and 68 deletions
Showing only changes of commit 7c8fc04b96 - Show all commits

View file

@ -3,7 +3,6 @@ use std::convert::TryFrom;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use paste::paste; use paste::paste;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,7 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use garage_util::data::*; use garage_util::data::*;
use garage_util::error::Error as GarageError; use garage_util::error::Error as GarageError;
use garage_util::time::now_msec; use garage_util::time::now_msec;
@ -18,7 +16,6 @@ use crate::api::*;
use crate::error::*; use crate::error::*;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for LocalListBlockErrorsRequest { impl RequestHandler for LocalListBlockErrorsRequest {
type Response = LocalListBlockErrorsResponse; type Response = LocalListBlockErrorsResponse;
@ -43,7 +40,6 @@ impl RequestHandler for LocalListBlockErrorsRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalGetBlockInfoRequest { impl RequestHandler for LocalGetBlockInfoRequest {
type Response = LocalGetBlockInfoResponse; type Response = LocalGetBlockInfoResponse;
@ -109,7 +105,6 @@ impl RequestHandler for LocalGetBlockInfoRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalRetryBlockResyncRequest { impl RequestHandler for LocalRetryBlockResyncRequest {
type Response = LocalRetryBlockResyncResponse; type Response = LocalRetryBlockResyncResponse;
@ -143,7 +138,6 @@ impl RequestHandler for LocalRetryBlockResyncRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalPurgeBlocksRequest { impl RequestHandler for LocalPurgeBlocksRequest {
type Response = LocalPurgeBlocksResponse; type Response = LocalPurgeBlocksResponse;

View file

@ -2,8 +2,6 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use async_trait::async_trait;
use garage_util::crdt::*; use garage_util::crdt::*;
use garage_util::data::*; use garage_util::data::*;
use garage_util::time::*; use garage_util::time::*;
@ -23,7 +21,6 @@ use crate::api::*;
use crate::error::*; use crate::error::*;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for ListBucketsRequest { impl RequestHandler for ListBucketsRequest {
type Response = ListBucketsResponse; type Response = ListBucketsResponse;
@ -74,7 +71,6 @@ impl RequestHandler for ListBucketsRequest {
} }
} }
#[async_trait]
impl RequestHandler for GetBucketInfoRequest { impl RequestHandler for GetBucketInfoRequest {
type Response = GetBucketInfoResponse; type Response = GetBucketInfoResponse;
@ -230,7 +226,6 @@ async fn bucket_info_results(
Ok(res) Ok(res)
} }
#[async_trait]
impl RequestHandler for CreateBucketRequest { impl RequestHandler for CreateBucketRequest {
type Response = CreateBucketResponse; type Response = CreateBucketResponse;
@ -305,7 +300,6 @@ impl RequestHandler for CreateBucketRequest {
} }
} }
#[async_trait]
impl RequestHandler for DeleteBucketRequest { impl RequestHandler for DeleteBucketRequest {
type Response = DeleteBucketResponse; type Response = DeleteBucketResponse;
@ -358,7 +352,6 @@ impl RequestHandler for DeleteBucketRequest {
} }
} }
#[async_trait]
impl RequestHandler for UpdateBucketRequest { impl RequestHandler for UpdateBucketRequest {
type Response = UpdateBucketResponse; type Response = UpdateBucketResponse;
@ -409,7 +402,6 @@ impl RequestHandler for UpdateBucketRequest {
} }
} }
#[async_trait]
impl RequestHandler for CleanupIncompleteUploadsRequest { impl RequestHandler for CleanupIncompleteUploadsRequest {
type Response = CleanupIncompleteUploadsResponse; type Response = CleanupIncompleteUploadsResponse;
@ -435,7 +427,6 @@ impl RequestHandler for CleanupIncompleteUploadsRequest {
// ---- BUCKET/KEY PERMISSIONS ---- // ---- BUCKET/KEY PERMISSIONS ----
#[async_trait]
impl RequestHandler for AllowBucketKeyRequest { impl RequestHandler for AllowBucketKeyRequest {
type Response = AllowBucketKeyResponse; type Response = AllowBucketKeyResponse;
@ -449,7 +440,6 @@ impl RequestHandler for AllowBucketKeyRequest {
} }
} }
#[async_trait]
impl RequestHandler for DenyBucketKeyRequest { impl RequestHandler for DenyBucketKeyRequest {
type Response = DenyBucketKeyResponse; type Response = DenyBucketKeyResponse;
@ -502,7 +492,6 @@ pub async fn handle_bucket_change_key_perm(
// ---- BUCKET ALIASES ---- // ---- BUCKET ALIASES ----
#[async_trait]
impl RequestHandler for AddBucketAliasRequest { impl RequestHandler for AddBucketAliasRequest {
type Response = AddBucketAliasResponse; type Response = AddBucketAliasResponse;
@ -537,7 +526,6 @@ impl RequestHandler for AddBucketAliasRequest {
} }
} }
#[async_trait]
impl RequestHandler for RemoveBucketAliasRequest { impl RequestHandler for RemoveBucketAliasRequest {
type Response = RemoveBucketAliasResponse; type Response = RemoveBucketAliasResponse;

View file

@ -1,8 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use garage_util::crdt::*; use garage_util::crdt::*;
use garage_util::data::*; use garage_util::data::*;
@ -14,7 +12,6 @@ use crate::api::*;
use crate::error::*; use crate::error::*;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for GetClusterStatusRequest { impl RequestHandler for GetClusterStatusRequest {
type Response = GetClusterStatusResponse; type Response = GetClusterStatusResponse;
@ -120,7 +117,6 @@ impl RequestHandler for GetClusterStatusRequest {
} }
} }
#[async_trait]
impl RequestHandler for GetClusterHealthRequest { impl RequestHandler for GetClusterHealthRequest {
type Response = GetClusterHealthResponse; type Response = GetClusterHealthResponse;
@ -150,7 +146,6 @@ impl RequestHandler for GetClusterHealthRequest {
} }
} }
#[async_trait]
impl RequestHandler for ConnectClusterNodesRequest { impl RequestHandler for ConnectClusterNodesRequest {
type Response = ConnectClusterNodesResponse; type Response = ConnectClusterNodesResponse;
@ -177,7 +172,6 @@ impl RequestHandler for ConnectClusterNodesRequest {
} }
} }
#[async_trait]
impl RequestHandler for GetClusterLayoutRequest { impl RequestHandler for GetClusterLayoutRequest {
type Response = GetClusterLayoutResponse; type Response = GetClusterLayoutResponse;
@ -241,7 +235,6 @@ fn format_cluster_layout(layout: &layout::LayoutHistory) -> GetClusterLayoutResp
// ---- update functions ---- // ---- update functions ----
#[async_trait]
impl RequestHandler for UpdateClusterLayoutRequest { impl RequestHandler for UpdateClusterLayoutRequest {
type Response = UpdateClusterLayoutResponse; type Response = UpdateClusterLayoutResponse;
@ -291,7 +284,6 @@ impl RequestHandler for UpdateClusterLayoutRequest {
} }
} }
#[async_trait]
impl RequestHandler for ApplyClusterLayoutRequest { impl RequestHandler for ApplyClusterLayoutRequest {
type Response = ApplyClusterLayoutResponse; type Response = ApplyClusterLayoutResponse;
@ -316,7 +308,6 @@ impl RequestHandler for ApplyClusterLayoutRequest {
} }
} }
#[async_trait]
impl RequestHandler for RevertClusterLayoutRequest { impl RequestHandler for RevertClusterLayoutRequest {
type Response = RevertClusterLayoutResponse; type Response = RevertClusterLayoutResponse;

View file

@ -1,8 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use garage_table::*; use garage_table::*;
use garage_model::garage::Garage; use garage_model::garage::Garage;
@ -12,7 +10,6 @@ use crate::api::*;
use crate::error::*; use crate::error::*;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for ListKeysRequest { impl RequestHandler for ListKeysRequest {
type Response = ListKeysResponse; type Response = ListKeysResponse;
@ -38,7 +35,6 @@ impl RequestHandler for ListKeysRequest {
} }
} }
#[async_trait]
impl RequestHandler for GetKeyInfoRequest { impl RequestHandler for GetKeyInfoRequest {
type Response = GetKeyInfoResponse; type Response = GetKeyInfoResponse;
@ -66,7 +62,6 @@ impl RequestHandler for GetKeyInfoRequest {
} }
} }
#[async_trait]
impl RequestHandler for CreateKeyRequest { impl RequestHandler for CreateKeyRequest {
type Response = CreateKeyResponse; type Response = CreateKeyResponse;
@ -84,7 +79,6 @@ impl RequestHandler for CreateKeyRequest {
} }
} }
#[async_trait]
impl RequestHandler for ImportKeyRequest { impl RequestHandler for ImportKeyRequest {
type Response = ImportKeyResponse; type Response = ImportKeyResponse;
@ -112,7 +106,6 @@ impl RequestHandler for ImportKeyRequest {
} }
} }
#[async_trait]
impl RequestHandler for UpdateKeyRequest { impl RequestHandler for UpdateKeyRequest {
type Response = UpdateKeyResponse; type Response = UpdateKeyResponse;
@ -147,7 +140,6 @@ impl RequestHandler for UpdateKeyRequest {
} }
} }
#[async_trait]
impl RequestHandler for DeleteKeyRequest { impl RequestHandler for DeleteKeyRequest {
type Response = DeleteKeyResponse; type Response = DeleteKeyResponse;

View file

@ -22,8 +22,6 @@ mod worker;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use garage_model::garage::Garage; use garage_model::garage::Garage;
pub use api_server::AdminApiServer as Admin; pub use api_server::AdminApiServer as Admin;
@ -34,13 +32,12 @@ pub enum Authorization {
AdminToken, AdminToken,
} }
#[async_trait]
pub trait RequestHandler { pub trait RequestHandler {
type Response; type Response;
async fn handle( fn handle(
self, self,
garage: &Arc<Garage>, garage: &Arc<Garage>,
admin: &Admin, admin: &Admin,
) -> Result<Self::Response, error::Error>; ) -> impl std::future::Future<Output = Result<Self::Response, error::Error>> + Send;
} }

View file

@ -70,7 +70,6 @@ macro_rules! admin_endpoints {
} }
)* )*
#[async_trait]
impl RequestHandler for AdminApiRequest { impl RequestHandler for AdminApiRequest {
type Response = AdminApiResponse; type Response = AdminApiResponse;
@ -133,7 +132,6 @@ macro_rules! local_admin_endpoints {
} }
} }
#[async_trait]
impl RequestHandler for [< $endpoint Request >] { impl RequestHandler for [< $endpoint Request >] {
type Response = [< $endpoint Response >]; type Response = [< $endpoint Response >];
@ -202,7 +200,6 @@ macro_rules! local_admin_endpoints {
} }
} }
#[async_trait]
impl RequestHandler for LocalAdminApiRequest { impl RequestHandler for LocalAdminApiRequest {
type Response = LocalAdminApiResponse; type Response = LocalAdminApiResponse;

View file

@ -2,8 +2,6 @@ use std::collections::HashMap;
use std::fmt::Write; use std::fmt::Write;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use format_table::format_table_to_string; use format_table::format_table_to_string;
use garage_util::data::*; use garage_util::data::*;
@ -20,7 +18,6 @@ use crate::api::*;
use crate::error::Error; use crate::error::Error;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for LocalCreateMetadataSnapshotRequest { impl RequestHandler for LocalCreateMetadataSnapshotRequest {
type Response = LocalCreateMetadataSnapshotResponse; type Response = LocalCreateMetadataSnapshotResponse;
@ -34,7 +31,6 @@ impl RequestHandler for LocalCreateMetadataSnapshotRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalGetNodeStatisticsRequest { impl RequestHandler for LocalGetNodeStatisticsRequest {
type Response = LocalGetNodeStatisticsResponse; type Response = LocalGetNodeStatisticsResponse;
@ -99,7 +95,6 @@ impl RequestHandler for LocalGetNodeStatisticsRequest {
} }
} }
#[async_trait]
impl RequestHandler for GetClusterStatisticsRequest { impl RequestHandler for GetClusterStatisticsRequest {
type Response = GetClusterStatisticsResponse; type Response = GetClusterStatisticsResponse;

View file

@ -27,7 +27,6 @@ use crate::{Admin, RequestHandler};
const RC_REPAIR_ITER_COUNT: usize = 64; const RC_REPAIR_ITER_COUNT: usize = 64;
#[async_trait]
impl RequestHandler for LocalLaunchRepairOperationRequest { impl RequestHandler for LocalLaunchRepairOperationRequest {
type Response = LocalLaunchRepairOperationResponse; type Response = LocalLaunchRepairOperationResponse;
@ -96,17 +95,16 @@ impl RequestHandler for LocalLaunchRepairOperationRequest {
// ---- // ----
#[async_trait]
trait TableRepair: Send + Sync + 'static { trait TableRepair: Send + Sync + 'static {
type T: TableSchema; type T: TableSchema;
fn table(garage: &Garage) -> &Table<Self::T, TableShardedReplication>; fn table(garage: &Garage) -> &Table<Self::T, TableShardedReplication>;
async fn process( fn process(
&mut self, &mut self,
garage: &Garage, garage: &Garage,
entry: <<Self as TableRepair>::T as TableSchema>::E, entry: <<Self as TableRepair>::T as TableSchema>::E,
) -> Result<bool, GarageError>; ) -> impl std::future::Future<Output = Result<bool, GarageError>> + Send;
} }
struct TableRepairWorker<T: TableRepair> { struct TableRepairWorker<T: TableRepair> {
@ -180,7 +178,6 @@ impl<R: TableRepair> Worker for TableRepairWorker<R> {
struct RepairVersions; struct RepairVersions;
#[async_trait]
impl TableRepair for RepairVersions { impl TableRepair for RepairVersions {
type T = VersionTable; type T = VersionTable;
@ -227,7 +224,6 @@ impl TableRepair for RepairVersions {
struct RepairBlockRefs; struct RepairBlockRefs;
#[async_trait]
impl TableRepair for RepairBlockRefs { impl TableRepair for RepairBlockRefs {
type T = BlockRefTable; type T = BlockRefTable;
@ -267,7 +263,6 @@ impl TableRepair for RepairBlockRefs {
struct RepairMpu; struct RepairMpu;
#[async_trait]
impl TableRepair for RepairMpu { impl TableRepair for RepairMpu {
type T = MultipartUploadTable; type T = MultipartUploadTable;

View file

@ -1,7 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use http::header::{ use http::header::{
ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW,
}; };
@ -20,7 +18,6 @@ use crate::api_server::ResBody;
use crate::error::*; use crate::error::*;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for OptionsRequest { impl RequestHandler for OptionsRequest {
type Response = Response<ResBody>; type Response = Response<ResBody>;
@ -39,7 +36,6 @@ impl RequestHandler for OptionsRequest {
} }
} }
#[async_trait]
impl RequestHandler for MetricsRequest { impl RequestHandler for MetricsRequest {
type Response = Response<ResBody>; type Response = Response<ResBody>;
@ -76,7 +72,6 @@ impl RequestHandler for MetricsRequest {
} }
} }
#[async_trait]
impl RequestHandler for HealthRequest { impl RequestHandler for HealthRequest {
type Response = Response<ResBody>; type Response = Response<ResBody>;
@ -110,7 +105,6 @@ impl RequestHandler for HealthRequest {
} }
} }
#[async_trait]
impl RequestHandler for CheckDomainRequest { impl RequestHandler for CheckDomainRequest {
type Response = Response<ResBody>; type Response = Response<ResBody>;

View file

@ -1,8 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait;
use garage_util::background::*; use garage_util::background::*;
use garage_util::time::now_msec; use garage_util::time::now_msec;
@ -12,7 +10,6 @@ use crate::api::*;
use crate::error::Error; use crate::error::Error;
use crate::{Admin, RequestHandler}; use crate::{Admin, RequestHandler};
#[async_trait]
impl RequestHandler for LocalListWorkersRequest { impl RequestHandler for LocalListWorkersRequest {
type Response = LocalListWorkersResponse; type Response = LocalListWorkersResponse;
@ -35,7 +32,6 @@ impl RequestHandler for LocalListWorkersRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalGetWorkerInfoRequest { impl RequestHandler for LocalGetWorkerInfoRequest {
type Response = LocalGetWorkerInfoResponse; type Response = LocalGetWorkerInfoResponse;
@ -56,7 +52,6 @@ impl RequestHandler for LocalGetWorkerInfoRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalGetWorkerVariableRequest { impl RequestHandler for LocalGetWorkerVariableRequest {
type Response = LocalGetWorkerVariableResponse; type Response = LocalGetWorkerVariableResponse;
@ -78,7 +73,6 @@ impl RequestHandler for LocalGetWorkerVariableRequest {
} }
} }
#[async_trait]
impl RequestHandler for LocalSetWorkerVariableRequest { impl RequestHandler for LocalSetWorkerVariableRequest {
type Response = LocalSetWorkerVariableResponse; type Response = LocalSetWorkerVariableResponse;