Skip to content

Commit

Permalink
控制台接口重构,初步完成集群列表接口调整 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Apr 14, 2024
1 parent 39c3314 commit d73217d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/console/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ pub fn console_api_config_v2(config: &mut web::ServiceConfig) {
.service(
web::resource("/namespaces/remove")
.route(web::post().to(v2::namespace_api::remove_namespace)),
),
)
.service(
web::resource("/cluster/cluster_node_list")
.route(web::get().to(v2::cluster_api::query_cluster_info)),
)
);
}
24 changes: 24 additions & 0 deletions src/console/v2/cluster_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::sync::Arc;
use actix_web::{HttpResponse, Responder, web};
use crate::common::appdata::AppShareData;
use crate::common::model::ApiResult;
use crate::console::model::cluster_model::ClusterNodeInfo;

pub async fn query_cluster_info(app: web::Data<Arc<AppShareData>>) -> impl Responder {
let nodes = app.naming_node_manage.get_all_valid_nodes().await.unwrap();
let leader_node = app.raft.current_leader().await;
let mut list = vec![];
for node in nodes {
let mut node_info: ClusterNodeInfo = node.into();
if let Some(leader_node) = &leader_node {
if node_info.node_id == *leader_node {
node_info.raft_leader = true;
}
}
if app.sys_config.raft_node_id == node_info.node_id {
node_info.current_node = true;
}
list.push(node_info);
}
HttpResponse::Ok().json(ApiResult::success(Some(list)))
}
1 change: 1 addition & 0 deletions src/console/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use actix_web::HttpResponse;
pub mod login_api;
pub mod namespace_api;
pub mod user_api;
pub mod cluster_api;

pub enum ApiResponse<T>
where
Expand Down

0 comments on commit d73217d

Please sign in to comment.