Skip to content

Commit

Permalink
cleanup + fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Feb 2, 2024
1 parent 50b4586 commit 86a881d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
57 changes: 44 additions & 13 deletions backend/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
),
Expand Down Expand Up @@ -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<Arc<HttpClient>> {
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()
}
5 changes: 3 additions & 2 deletions backend/src/services/mod.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down

0 comments on commit 86a881d

Please sign in to comment.