mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-09 06:39:25 +00:00
refactor: improve code quality with safer error handling, trait decomposition, and dead code cleanup (#1997)
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! Admin application use-case contracts.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::app::context::{AppContext, get_global_app_context};
|
||||
use crate::error::ApiError;
|
||||
@@ -58,31 +57,13 @@ pub struct QueryPoolStatusRequest {
|
||||
pub by_id: bool,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait AdminUsecase: Send + Sync {
|
||||
async fn query_server_info(&self, req: QueryServerInfoRequest) -> AdminUsecaseResult<QueryServerInfoResponse>;
|
||||
|
||||
async fn query_storage_info(&self) -> AdminUsecaseResult<StorageInfo>;
|
||||
|
||||
async fn query_data_usage_info(&self) -> AdminUsecaseResult<DataUsageInfo>;
|
||||
|
||||
async fn list_pool_statuses(&self) -> AdminUsecaseResult<Vec<PoolStatus>>;
|
||||
|
||||
async fn query_pool_status(&self, req: QueryPoolStatusRequest) -> AdminUsecaseResult<PoolStatus>;
|
||||
|
||||
fn collect_dependency_readiness(&self) -> DependencyReadiness;
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct DefaultAdminUsecase {
|
||||
context: Option<Arc<AppContext>>,
|
||||
}
|
||||
|
||||
impl DefaultAdminUsecase {
|
||||
pub fn new(context: Arc<AppContext>) -> Self {
|
||||
Self { context: Some(context) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn without_context() -> Self {
|
||||
Self { context: None }
|
||||
}
|
||||
@@ -93,10 +74,6 @@ impl DefaultAdminUsecase {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn context(&self) -> Option<Arc<AppContext>> {
|
||||
self.context.clone()
|
||||
}
|
||||
|
||||
fn endpoints(&self) -> Option<EndpointServerPools> {
|
||||
self.context.as_ref().and_then(|context| context.endpoints().handle())
|
||||
}
|
||||
@@ -292,33 +269,6 @@ impl DefaultAdminUsecase {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AdminUsecase for DefaultAdminUsecase {
|
||||
async fn query_server_info(&self, req: QueryServerInfoRequest) -> AdminUsecaseResult<QueryServerInfoResponse> {
|
||||
self.execute_query_server_info(req).await
|
||||
}
|
||||
|
||||
async fn query_storage_info(&self) -> AdminUsecaseResult<StorageInfo> {
|
||||
self.execute_query_storage_info().await
|
||||
}
|
||||
|
||||
async fn query_data_usage_info(&self) -> AdminUsecaseResult<DataUsageInfo> {
|
||||
self.execute_query_data_usage_info().await
|
||||
}
|
||||
|
||||
async fn list_pool_statuses(&self) -> AdminUsecaseResult<Vec<PoolStatus>> {
|
||||
self.execute_list_pool_statuses().await
|
||||
}
|
||||
|
||||
async fn query_pool_status(&self, req: QueryPoolStatusRequest) -> AdminUsecaseResult<PoolStatus> {
|
||||
self.execute_query_pool_status(req).await
|
||||
}
|
||||
|
||||
fn collect_dependency_readiness(&self) -> DependencyReadiness {
|
||||
self.execute_collect_dependency_readiness()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user