From 86a881d04cf943583dfd2c21fb80f1811356109a Mon Sep 17 00:00:00 2001 From: Simeon Romanov Date: Thu, 1 Feb 2024 19:45:59 +0300 Subject: [PATCH] cleanup + fixup --- backend/src/services/api.rs | 57 ++++++++++++++++++++++++++++--------- backend/src/services/mod.rs | 5 ++-- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/backend/src/services/api.rs b/backend/src/services/api.rs index 92cc784f..b0a162c8 100644 --- a/backend/src/services/api.rs +++ b/backend/src/services/api.rs @@ -409,30 +409,36 @@ async fn process_replica( let mut status = ReplicaStatus::Good; if let Some(disk_state) = disks.get(&replica.disk) { if !disk_state { - status = ReplicaStatus::Offline(vec![ReplicaProblem::DiskUnavailable]); + status = ReplicaStatus::Offline { + problems: vec![ReplicaProblem::DiskUnavailable], + }; } } else { - status = ReplicaStatus::Offline(vec![ReplicaProblem::DiskUnavailable]); + status = ReplicaStatus::Offline { + problems: vec![ReplicaProblem::DiskUnavailable], + }; } if let Some(node) = nodes.get(&replica.node) { if !is_node_online(client, node).await { status = match status { - ReplicaStatus::Good => { - ReplicaStatus::Offline(vec![ReplicaProblem::DiskUnavailable]) - } - ReplicaStatus::Offline(mut problems) => { + ReplicaStatus::Good => ReplicaStatus::Offline { + problems: vec![ReplicaProblem::DiskUnavailable], + }, + ReplicaStatus::Offline { mut problems } => { problems.push(ReplicaProblem::NodeUnavailable); - ReplicaStatus::Offline(problems) + ReplicaStatus::Offline { problems } } } } } else { status = match status { - ReplicaStatus::Good => ReplicaStatus::Offline(vec![ReplicaProblem::DiskUnavailable]), - ReplicaStatus::Offline(mut problems) => { + ReplicaStatus::Good => ReplicaStatus::Offline { + problems: vec![ReplicaProblem::DiskUnavailable], + }, + ReplicaStatus::Offline { mut problems } => { problems.push(ReplicaProblem::NodeUnavailable); - ReplicaStatus::Offline(problems) + ReplicaStatus::Offline { problems } } } } @@ -446,7 +452,7 @@ async fn process_replica( } async fn is_node_online(client: &HttpBobClient, node: &dto::Node) -> bool { - (client.probe_socket(&node.name).await).map_or(false, |code| code == StatusCode::OK) + (client.probe_secondary(&node.name).await).map_or(false, |code| code == StatusCode::OK) } fn proccess_disks( @@ -513,7 +519,7 @@ async fn process_vdisks_for_node( id: vdisk.id as u64, status: if res_replicas .iter() - .any(|(_, replica)| matches!(replica.status, ReplicaStatus::Offline(_))) + .any(|(_, replica)| matches!(replica.status, ReplicaStatus::Offline { .. })) { VDiskStatus::Bad } else { @@ -606,12 +612,13 @@ pub async fn raw_configuration_by_node( #[cfg_attr(feature = "swagger", utoipa::path( get, context_path = ApiV1::to_path(), - path = "/nodes/{node_name}/detailed", + path = "/nodes/{node_name}", params ( ("id", description = "Node's ID") ), responses( (status = 200, body = DetailedNode, content_type = "application/json", description = "Detailed Node information"), + (status = 401, description = "Unauthorized"), (status = 404, description = "Node Not Found") ), @@ -726,3 +733,27 @@ pub async fn get_detailed_node_info( Ok(result) } + +async fn get_client_by_node( + client: &HttpBobClient, + node_name: NodeName, +) -> AxumResult> { + let nodes = fetch_nodes(client.api_main()).await?; + + let node = nodes + .iter() + .find(|node| node.name == node_name) + .ok_or_else(|| { + tracing::error!("Couldn't find specified node"); + APIError::RequestFailed + })?; + + client + .cluster_with_addr() + .get(&node.name) + .ok_or_else(|| { + tracing::error!("Couldn't find specified node"); + APIError::RequestFailed.into() + }) + .cloned() +} diff --git a/backend/src/services/mod.rs b/backend/src/services/mod.rs index 47133a3f..e3f78afd 100644 --- a/backend/src/services/mod.rs +++ b/backend/src/services/mod.rs @@ -1,13 +1,14 @@ mod prelude { pub use super::methods::{ - fetch_configuration, fetch_metrics, fetch_nodes, fetch_vdisks, get_vdisk_by_id, + fetch_configuration, fetch_disks, fetch_metrics, fetch_node_status, fetch_nodes, + fetch_space_info, fetch_vdisks, get_vdisk_by_id, }; pub use crate::{ connector::{ api::{prelude::*, ApiNoContext}, ClientError, }, - models::api::*, + models::{api::*, bob::*}, prelude::*, }; pub use axum::{