Line data Source code
1 : use crate::http::JsonResponse;
2 : use axum::extract::Json;
3 : use compute_api::responses::PromoteConfig;
4 : use http::StatusCode;
5 :
6 0 : pub(in crate::http) async fn promote(
7 0 : compute: axum::extract::State<std::sync::Arc<crate::compute::ComputeNode>>,
8 0 : Json(cfg): Json<PromoteConfig>,
9 0 : ) -> axum::response::Response {
10 : // Return early at the cost of extra parsing spec
11 0 : let pspec = match crate::compute::ParsedSpec::try_from(cfg.spec) {
12 0 : Ok(p) => p,
13 0 : Err(e) => return JsonResponse::error(StatusCode::BAD_REQUEST, e),
14 : };
15 :
16 0 : let cfg = PromoteConfig {
17 0 : spec: pspec.spec,
18 0 : wal_flush_lsn: cfg.wal_flush_lsn,
19 0 : };
20 0 : let state = compute.promote(cfg).await;
21 0 : if let compute_api::responses::PromoteState::Failed { error: _ } = state {
22 0 : return JsonResponse::create_response(StatusCode::INTERNAL_SERVER_ERROR, state);
23 0 : }
24 0 : JsonResponse::success(StatusCode::OK, state)
25 0 : }
|