use bamboo_config::cluster_fabric::NodeState;
use bamboo_server_tools::FabricError;
use crate::app_state::AppState;
use crate::error::AppError;
fn map_err(e: FabricError) -> AppError {
match e {
FabricError::NotFound(m) => AppError::NotFound(m),
FabricError::BadRequest(m) => AppError::BadRequest(m),
FabricError::Internal(m) => AppError::InternalError(anyhow::anyhow!(m)),
}
}
pub async fn deploy_node(
app_state: &AppState,
node_id: &str,
echo: bool,
) -> Result<NodeState, AppError> {
app_state
.fabric_deployer
.deploy(node_id, echo)
.await
.map_err(map_err)
}
pub async fn stop_node(app_state: &AppState, node_id: &str) -> Result<NodeState, AppError> {
app_state.fabric_deployer.stop(node_id).await.map_err(map_err)
}
pub async fn test_node(app_state: &AppState, node_id: &str) -> Result<String, AppError> {
app_state.fabric_deployer.test(node_id).await.map_err(map_err)
}
pub async fn read_logs(
app_state: &AppState,
node_id: &str,
lines: usize,
) -> Result<String, AppError> {
app_state
.fabric_deployer
.read_logs(node_id, lines)
.await
.map_err(map_err)
}