refactor(app): route metadata/endpoints access through AppContext (#1949)

This commit is contained in:
安正超
2026-02-25 15:07:09 +08:00
committed by GitHub
parent 672c255567
commit d774d6821b
4 changed files with 94 additions and 14 deletions
+11 -3
View File
@@ -20,9 +20,10 @@ use crate::error::ApiError;
use rustfs_common::data_usage::DataUsageInfo;
use rustfs_ecstore::admin_server_info::get_server_info;
use rustfs_ecstore::data_usage::load_data_usage_from_backend;
use rustfs_ecstore::endpoints::EndpointServerPools;
use rustfs_ecstore::new_object_layer_fn;
use rustfs_ecstore::pools::{PoolStatus, get_total_usable_capacity, get_total_usable_capacity_free};
use rustfs_ecstore::store_api::StorageAPI;
use rustfs_ecstore::{GLOBAL_Endpoints, new_object_layer_fn};
use rustfs_madmin::{InfoMessage, StorageInfo};
use s3s::S3ErrorCode;
use std::sync::Arc;
@@ -96,6 +97,13 @@ impl DefaultAdminUsecase {
self.context.clone()
}
fn endpoints(&self) -> Option<EndpointServerPools> {
self.context
.as_ref()
.and_then(|context| context.endpoints().handle())
.or_else(|| rustfs_ecstore::GLOBAL_Endpoints.get().cloned())
}
fn app_error(code: S3ErrorCode, message: impl Into<String>) -> ApiError {
ApiError {
code,
@@ -221,7 +229,7 @@ impl DefaultAdminUsecase {
return Err(Self::app_error(S3ErrorCode::InternalError, "Not init"));
};
let Some(endpoints) = GLOBAL_Endpoints.get() else {
let Some(endpoints) = self.endpoints() else {
return Err(Self::app_error_default(S3ErrorCode::NotImplemented));
};
@@ -243,7 +251,7 @@ impl DefaultAdminUsecase {
let _ = context.object_store();
}
let Some(endpoints) = GLOBAL_Endpoints.get() else {
let Some(endpoints) = self.endpoints() else {
return Err(Self::app_error_default(S3ErrorCode::NotImplemented));
};