LCOV - code coverage report
Current view: top level - pageserver/client/src - mgmt_api.rs (source / functions) Coverage Total Hit
Test: 40847ed574e0fcb4c245504ae69f84bc64a0e184.info Lines: 0.0 % 473 0
Test Date: 2024-06-26 19:30:22 Functions: 0.0 % 119 0

            Line data    Source code
       1              : use std::collections::HashMap;
       2              : 
       3              : use bytes::Bytes;
       4              : use pageserver_api::{models::*, shard::TenantShardId};
       5              : use reqwest::{IntoUrl, Method, StatusCode};
       6              : use utils::{
       7              :     http::error::HttpErrorBody,
       8              :     id::{TenantId, TimelineId},
       9              :     lsn::Lsn,
      10              : };
      11              : 
      12              : pub mod util;
      13              : 
      14              : #[derive(Debug, Clone)]
      15              : pub struct Client {
      16              :     mgmt_api_endpoint: String,
      17              :     authorization_header: Option<String>,
      18              :     client: reqwest::Client,
      19              : }
      20              : 
      21            0 : #[derive(thiserror::Error, Debug)]
      22              : pub enum Error {
      23              :     #[error("receive body: {0}")]
      24              :     ReceiveBody(reqwest::Error),
      25              : 
      26              :     #[error("receive error body: {0}")]
      27              :     ReceiveErrorBody(String),
      28              : 
      29              :     #[error("pageserver API: {1}")]
      30              :     ApiError(StatusCode, String),
      31              : 
      32              :     #[error("Cancelled")]
      33              :     Cancelled,
      34              : }
      35              : 
      36              : pub type Result<T> = std::result::Result<T, Error>;
      37              : 
      38              : pub trait ResponseErrorMessageExt: Sized {
      39              :     fn error_from_body(self) -> impl std::future::Future<Output = Result<Self>> + Send;
      40              : }
      41              : 
      42              : impl ResponseErrorMessageExt for reqwest::Response {
      43            0 :     async fn error_from_body(self) -> Result<Self> {
      44            0 :         let status = self.status();
      45            0 :         if !(status.is_client_error() || status.is_server_error()) {
      46            0 :             return Ok(self);
      47            0 :         }
      48            0 : 
      49            0 :         let url = self.url().to_owned();
      50            0 :         Err(match self.json::<HttpErrorBody>().await {
      51            0 :             Ok(HttpErrorBody { msg }) => Error::ApiError(status, msg),
      52              :             Err(_) => {
      53            0 :                 Error::ReceiveErrorBody(format!("Http error ({}) at {}.", status.as_u16(), url))
      54              :             }
      55              :         })
      56            0 :     }
      57              : }
      58              : 
      59              : pub enum ForceAwaitLogicalSize {
      60              :     Yes,
      61              :     No,
      62              : }
      63              : 
      64              : impl Client {
      65            0 :     pub fn new(mgmt_api_endpoint: String, jwt: Option<&str>) -> Self {
      66            0 :         Self::from_client(reqwest::Client::new(), mgmt_api_endpoint, jwt)
      67            0 :     }
      68              : 
      69            0 :     pub fn from_client(
      70            0 :         client: reqwest::Client,
      71            0 :         mgmt_api_endpoint: String,
      72            0 :         jwt: Option<&str>,
      73            0 :     ) -> Self {
      74            0 :         Self {
      75            0 :             mgmt_api_endpoint,
      76            0 :             authorization_header: jwt.map(|jwt| format!("Bearer {jwt}")),
      77            0 :             client,
      78            0 :         }
      79            0 :     }
      80              : 
      81            0 :     pub async fn list_tenants(&self) -> Result<Vec<pageserver_api::models::TenantInfo>> {
      82            0 :         let uri = format!("{}/v1/tenant", self.mgmt_api_endpoint);
      83            0 :         let resp = self.get(&uri).await?;
      84            0 :         resp.json().await.map_err(Error::ReceiveBody)
      85            0 :     }
      86              : 
      87              :     /// Get an arbitrary path and returning a streaming Response.  This function is suitable
      88              :     /// for pass-through/proxy use cases where we don't care what the response content looks
      89              :     /// like.
      90              :     ///
      91              :     /// Use/add one of the properly typed methods below if you know aren't proxying, and
      92              :     /// know what kind of response you expect.
      93            0 :     pub async fn get_raw(&self, path: String) -> Result<reqwest::Response> {
      94            0 :         debug_assert!(path.starts_with('/'));
      95            0 :         let uri = format!("{}{}", self.mgmt_api_endpoint, path);
      96            0 : 
      97            0 :         let req = self.client.request(Method::GET, uri);
      98            0 :         let req = if let Some(value) = &self.authorization_header {
      99            0 :             req.header(reqwest::header::AUTHORIZATION, value)
     100              :         } else {
     101            0 :             req
     102              :         };
     103            0 :         req.send().await.map_err(Error::ReceiveBody)
     104            0 :     }
     105              : 
     106            0 :     pub async fn tenant_details(
     107            0 :         &self,
     108            0 :         tenant_shard_id: TenantShardId,
     109            0 :     ) -> Result<pageserver_api::models::TenantDetails> {
     110            0 :         let uri = format!("{}/v1/tenant/{tenant_shard_id}", self.mgmt_api_endpoint);
     111            0 :         self.get(uri)
     112            0 :             .await?
     113            0 :             .json()
     114            0 :             .await
     115            0 :             .map_err(Error::ReceiveBody)
     116            0 :     }
     117              : 
     118            0 :     pub async fn list_timelines(
     119            0 :         &self,
     120            0 :         tenant_shard_id: TenantShardId,
     121            0 :     ) -> Result<Vec<pageserver_api::models::TimelineInfo>> {
     122            0 :         let uri = format!(
     123            0 :             "{}/v1/tenant/{tenant_shard_id}/timeline",
     124            0 :             self.mgmt_api_endpoint
     125            0 :         );
     126            0 :         self.get(&uri)
     127            0 :             .await?
     128            0 :             .json()
     129            0 :             .await
     130            0 :             .map_err(Error::ReceiveBody)
     131            0 :     }
     132              : 
     133            0 :     pub async fn timeline_info(
     134            0 :         &self,
     135            0 :         tenant_shard_id: TenantShardId,
     136            0 :         timeline_id: TimelineId,
     137            0 :         force_await_logical_size: ForceAwaitLogicalSize,
     138            0 :     ) -> Result<pageserver_api::models::TimelineInfo> {
     139            0 :         let uri = format!(
     140            0 :             "{}/v1/tenant/{tenant_shard_id}/timeline/{timeline_id}",
     141            0 :             self.mgmt_api_endpoint
     142            0 :         );
     143              : 
     144            0 :         let uri = match force_await_logical_size {
     145            0 :             ForceAwaitLogicalSize::Yes => format!("{}?force-await-logical-size={}", uri, true),
     146            0 :             ForceAwaitLogicalSize::No => uri,
     147              :         };
     148              : 
     149            0 :         self.get(&uri)
     150            0 :             .await?
     151            0 :             .json()
     152            0 :             .await
     153            0 :             .map_err(Error::ReceiveBody)
     154            0 :     }
     155              : 
     156            0 :     pub async fn keyspace(
     157            0 :         &self,
     158            0 :         tenant_shard_id: TenantShardId,
     159            0 :         timeline_id: TimelineId,
     160            0 :     ) -> Result<pageserver_api::models::partitioning::Partitioning> {
     161            0 :         let uri = format!(
     162            0 :             "{}/v1/tenant/{tenant_shard_id}/timeline/{timeline_id}/keyspace",
     163            0 :             self.mgmt_api_endpoint
     164            0 :         );
     165            0 :         self.get(&uri)
     166            0 :             .await?
     167            0 :             .json()
     168            0 :             .await
     169            0 :             .map_err(Error::ReceiveBody)
     170            0 :     }
     171              : 
     172            0 :     async fn get<U: IntoUrl>(&self, uri: U) -> Result<reqwest::Response> {
     173            0 :         self.request(Method::GET, uri, ()).await
     174            0 :     }
     175              : 
     176            0 :     async fn request_noerror<B: serde::Serialize, U: reqwest::IntoUrl>(
     177            0 :         &self,
     178            0 :         method: Method,
     179            0 :         uri: U,
     180            0 :         body: B,
     181            0 :     ) -> Result<reqwest::Response> {
     182            0 :         let req = self.client.request(method, uri);
     183            0 :         let req = if let Some(value) = &self.authorization_header {
     184            0 :             req.header(reqwest::header::AUTHORIZATION, value)
     185              :         } else {
     186            0 :             req
     187              :         };
     188            0 :         req.json(&body).send().await.map_err(Error::ReceiveBody)
     189            0 :     }
     190              : 
     191            0 :     async fn request<B: serde::Serialize, U: reqwest::IntoUrl>(
     192            0 :         &self,
     193            0 :         method: Method,
     194            0 :         uri: U,
     195            0 :         body: B,
     196            0 :     ) -> Result<reqwest::Response> {
     197            0 :         let res = self.request_noerror(method, uri, body).await?;
     198            0 :         let response = res.error_from_body().await?;
     199            0 :         Ok(response)
     200            0 :     }
     201              : 
     202            0 :     pub async fn status(&self) -> Result<()> {
     203            0 :         let uri = format!("{}/v1/status", self.mgmt_api_endpoint);
     204            0 :         self.get(&uri).await?;
     205            0 :         Ok(())
     206            0 :     }
     207              : 
     208              :     /// The tenant deletion API can return 202 if deletion is incomplete, or
     209              :     /// 404 if it is complete.  Callers are responsible for checking the status
     210              :     /// code and retrying.  Error codes other than 404 will return Err().
     211            0 :     pub async fn tenant_delete(&self, tenant_shard_id: TenantShardId) -> Result<StatusCode> {
     212            0 :         let uri = format!("{}/v1/tenant/{tenant_shard_id}", self.mgmt_api_endpoint);
     213            0 : 
     214            0 :         match self.request(Method::DELETE, &uri, ()).await {
     215            0 :             Err(Error::ApiError(status_code, msg)) => {
     216            0 :                 if status_code == StatusCode::NOT_FOUND {
     217            0 :                     Ok(StatusCode::NOT_FOUND)
     218              :                 } else {
     219            0 :                     Err(Error::ApiError(status_code, msg))
     220              :                 }
     221              :             }
     222            0 :             Err(e) => Err(e),
     223            0 :             Ok(response) => Ok(response.status()),
     224              :         }
     225            0 :     }
     226              : 
     227            0 :     pub async fn tenant_time_travel_remote_storage(
     228            0 :         &self,
     229            0 :         tenant_shard_id: TenantShardId,
     230            0 :         timestamp: &str,
     231            0 :         done_if_after: &str,
     232            0 :     ) -> Result<()> {
     233            0 :         let uri = format!(
     234            0 :             "{}/v1/tenant/{tenant_shard_id}/time_travel_remote_storage?travel_to={timestamp}&done_if_after={done_if_after}",
     235            0 :             self.mgmt_api_endpoint
     236            0 :         );
     237            0 :         self.request(Method::PUT, &uri, ()).await?;
     238            0 :         Ok(())
     239            0 :     }
     240              : 
     241            0 :     pub async fn tenant_scan_remote_storage(
     242            0 :         &self,
     243            0 :         tenant_id: TenantId,
     244            0 :     ) -> Result<TenantScanRemoteStorageResponse> {
     245            0 :         let uri = format!(
     246            0 :             "{}/v1/tenant/{tenant_id}/scan_remote_storage",
     247            0 :             self.mgmt_api_endpoint
     248            0 :         );
     249            0 :         let response = self.request(Method::GET, &uri, ()).await?;
     250            0 :         let body = response.json().await.map_err(Error::ReceiveBody)?;
     251            0 :         Ok(body)
     252            0 :     }
     253              : 
     254            0 :     pub async fn tenant_config(&self, req: &TenantConfigRequest) -> Result<()> {
     255            0 :         let uri = format!("{}/v1/tenant/config", self.mgmt_api_endpoint);
     256            0 :         self.request(Method::PUT, &uri, req).await?;
     257            0 :         Ok(())
     258            0 :     }
     259              : 
     260            0 :     pub async fn tenant_secondary_download(
     261            0 :         &self,
     262            0 :         tenant_id: TenantShardId,
     263            0 :         wait: Option<std::time::Duration>,
     264            0 :     ) -> Result<(StatusCode, SecondaryProgress)> {
     265            0 :         let mut path = reqwest::Url::parse(&format!(
     266            0 :             "{}/v1/tenant/{}/secondary/download",
     267            0 :             self.mgmt_api_endpoint, tenant_id
     268            0 :         ))
     269            0 :         .expect("Cannot build URL");
     270              : 
     271            0 :         if let Some(wait) = wait {
     272            0 :             path.query_pairs_mut()
     273            0 :                 .append_pair("wait_ms", &format!("{}", wait.as_millis()));
     274            0 :         }
     275              : 
     276            0 :         let response = self.request(Method::POST, path, ()).await?;
     277            0 :         let status = response.status();
     278            0 :         let progress: SecondaryProgress = response.json().await.map_err(Error::ReceiveBody)?;
     279            0 :         Ok((status, progress))
     280            0 :     }
     281              : 
     282            0 :     pub async fn tenant_secondary_status(
     283            0 :         &self,
     284            0 :         tenant_shard_id: TenantShardId,
     285            0 :     ) -> Result<SecondaryProgress> {
     286            0 :         let path = reqwest::Url::parse(&format!(
     287            0 :             "{}/v1/tenant/{}/secondary/status",
     288            0 :             self.mgmt_api_endpoint, tenant_shard_id
     289            0 :         ))
     290            0 :         .expect("Cannot build URL");
     291            0 : 
     292            0 :         self.request(Method::GET, path, ())
     293            0 :             .await?
     294            0 :             .json()
     295            0 :             .await
     296            0 :             .map_err(Error::ReceiveBody)
     297            0 :     }
     298              : 
     299            0 :     pub async fn tenant_heatmap_upload(&self, tenant_id: TenantShardId) -> Result<()> {
     300            0 :         let path = reqwest::Url::parse(&format!(
     301            0 :             "{}/v1/tenant/{}/heatmap_upload",
     302            0 :             self.mgmt_api_endpoint, tenant_id
     303            0 :         ))
     304            0 :         .expect("Cannot build URL");
     305            0 : 
     306            0 :         self.request(Method::POST, path, ()).await?;
     307            0 :         Ok(())
     308            0 :     }
     309              : 
     310            0 :     pub async fn location_config(
     311            0 :         &self,
     312            0 :         tenant_shard_id: TenantShardId,
     313            0 :         config: LocationConfig,
     314            0 :         flush_ms: Option<std::time::Duration>,
     315            0 :         lazy: bool,
     316            0 :     ) -> Result<()> {
     317            0 :         let req_body = TenantLocationConfigRequest { config };
     318            0 : 
     319            0 :         let mut path = reqwest::Url::parse(&format!(
     320            0 :             "{}/v1/tenant/{}/location_config",
     321            0 :             self.mgmt_api_endpoint, tenant_shard_id
     322            0 :         ))
     323            0 :         // Should always work: mgmt_api_endpoint is configuration, not user input.
     324            0 :         .expect("Cannot build URL");
     325            0 : 
     326            0 :         if lazy {
     327            0 :             path.query_pairs_mut().append_pair("lazy", "true");
     328            0 :         }
     329              : 
     330            0 :         if let Some(flush_ms) = flush_ms {
     331            0 :             path.query_pairs_mut()
     332            0 :                 .append_pair("flush_ms", &format!("{}", flush_ms.as_millis()));
     333            0 :         }
     334              : 
     335            0 :         self.request(Method::PUT, path, &req_body).await?;
     336            0 :         Ok(())
     337            0 :     }
     338              : 
     339            0 :     pub async fn list_location_config(&self) -> Result<LocationConfigListResponse> {
     340            0 :         let path = format!("{}/v1/location_config", self.mgmt_api_endpoint);
     341            0 :         self.request(Method::GET, &path, ())
     342            0 :             .await?
     343            0 :             .json()
     344            0 :             .await
     345            0 :             .map_err(Error::ReceiveBody)
     346            0 :     }
     347              : 
     348            0 :     pub async fn get_location_config(
     349            0 :         &self,
     350            0 :         tenant_shard_id: TenantShardId,
     351            0 :     ) -> Result<Option<LocationConfig>> {
     352            0 :         let path = format!(
     353            0 :             "{}/v1/location_config/{tenant_shard_id}",
     354            0 :             self.mgmt_api_endpoint
     355            0 :         );
     356            0 :         self.request(Method::GET, &path, ())
     357            0 :             .await?
     358            0 :             .json()
     359            0 :             .await
     360            0 :             .map_err(Error::ReceiveBody)
     361            0 :     }
     362              : 
     363            0 :     pub async fn timeline_create(
     364            0 :         &self,
     365            0 :         tenant_shard_id: TenantShardId,
     366            0 :         req: &TimelineCreateRequest,
     367            0 :     ) -> Result<TimelineInfo> {
     368            0 :         let uri = format!(
     369            0 :             "{}/v1/tenant/{}/timeline",
     370            0 :             self.mgmt_api_endpoint, tenant_shard_id
     371            0 :         );
     372            0 :         self.request(Method::POST, &uri, req)
     373            0 :             .await?
     374            0 :             .json()
     375            0 :             .await
     376            0 :             .map_err(Error::ReceiveBody)
     377            0 :     }
     378              : 
     379              :     /// The timeline deletion API can return 201 if deletion is incomplete, or
     380              :     /// 403 if it is complete.  Callers are responsible for checking the status
     381              :     /// code and retrying.  Error codes other than 403 will return Err().
     382            0 :     pub async fn timeline_delete(
     383            0 :         &self,
     384            0 :         tenant_shard_id: TenantShardId,
     385            0 :         timeline_id: TimelineId,
     386            0 :     ) -> Result<StatusCode> {
     387            0 :         let uri = format!(
     388            0 :             "{}/v1/tenant/{tenant_shard_id}/timeline/{timeline_id}",
     389            0 :             self.mgmt_api_endpoint
     390            0 :         );
     391            0 : 
     392            0 :         match self.request(Method::DELETE, &uri, ()).await {
     393            0 :             Err(Error::ApiError(status_code, msg)) => {
     394            0 :                 if status_code == StatusCode::NOT_FOUND {
     395            0 :                     Ok(StatusCode::NOT_FOUND)
     396              :                 } else {
     397            0 :                     Err(Error::ApiError(status_code, msg))
     398              :                 }
     399              :             }
     400            0 :             Err(e) => Err(e),
     401            0 :             Ok(response) => Ok(response.status()),
     402              :         }
     403            0 :     }
     404              : 
     405            0 :     pub async fn tenant_reset(&self, tenant_shard_id: TenantShardId) -> Result<()> {
     406            0 :         let uri = format!(
     407            0 :             "{}/v1/tenant/{}/reset",
     408            0 :             self.mgmt_api_endpoint, tenant_shard_id
     409            0 :         );
     410            0 :         self.request(Method::POST, &uri, ())
     411            0 :             .await?
     412            0 :             .json()
     413            0 :             .await
     414            0 :             .map_err(Error::ReceiveBody)
     415            0 :     }
     416              : 
     417            0 :     pub async fn tenant_shard_split(
     418            0 :         &self,
     419            0 :         tenant_shard_id: TenantShardId,
     420            0 :         req: TenantShardSplitRequest,
     421            0 :     ) -> Result<TenantShardSplitResponse> {
     422            0 :         let uri = format!(
     423            0 :             "{}/v1/tenant/{}/shard_split",
     424            0 :             self.mgmt_api_endpoint, tenant_shard_id
     425            0 :         );
     426            0 :         self.request(Method::PUT, &uri, req)
     427            0 :             .await?
     428            0 :             .json()
     429            0 :             .await
     430            0 :             .map_err(Error::ReceiveBody)
     431            0 :     }
     432              : 
     433            0 :     pub async fn timeline_list(
     434            0 :         &self,
     435            0 :         tenant_shard_id: &TenantShardId,
     436            0 :     ) -> Result<Vec<TimelineInfo>> {
     437            0 :         let uri = format!(
     438            0 :             "{}/v1/tenant/{}/timeline",
     439            0 :             self.mgmt_api_endpoint, tenant_shard_id
     440            0 :         );
     441            0 :         self.get(&uri)
     442            0 :             .await?
     443            0 :             .json()
     444            0 :             .await
     445            0 :             .map_err(Error::ReceiveBody)
     446            0 :     }
     447              : 
     448            0 :     pub async fn tenant_synthetic_size(
     449            0 :         &self,
     450            0 :         tenant_shard_id: TenantShardId,
     451            0 :     ) -> Result<TenantHistorySize> {
     452            0 :         let uri = format!(
     453            0 :             "{}/v1/tenant/{}/synthetic_size",
     454            0 :             self.mgmt_api_endpoint, tenant_shard_id
     455            0 :         );
     456            0 :         self.get(&uri)
     457            0 :             .await?
     458            0 :             .json()
     459            0 :             .await
     460            0 :             .map_err(Error::ReceiveBody)
     461            0 :     }
     462              : 
     463            0 :     pub async fn put_io_engine(
     464            0 :         &self,
     465            0 :         engine: &pageserver_api::models::virtual_file::IoEngineKind,
     466            0 :     ) -> Result<()> {
     467            0 :         let uri = format!("{}/v1/io_engine", self.mgmt_api_endpoint);
     468            0 :         self.request(Method::PUT, uri, engine)
     469            0 :             .await?
     470            0 :             .json()
     471            0 :             .await
     472            0 :             .map_err(Error::ReceiveBody)
     473            0 :     }
     474              : 
     475            0 :     pub async fn get_utilization(&self) -> Result<PageserverUtilization> {
     476            0 :         let uri = format!("{}/v1/utilization", self.mgmt_api_endpoint);
     477            0 :         self.get(uri)
     478            0 :             .await?
     479            0 :             .json()
     480            0 :             .await
     481            0 :             .map_err(Error::ReceiveBody)
     482            0 :     }
     483              : 
     484            0 :     pub async fn top_tenant_shards(
     485            0 :         &self,
     486            0 :         request: TopTenantShardsRequest,
     487            0 :     ) -> Result<TopTenantShardsResponse> {
     488            0 :         let uri = format!("{}/v1/top_tenants", self.mgmt_api_endpoint);
     489            0 :         self.request(Method::POST, uri, request)
     490            0 :             .await?
     491            0 :             .json()
     492            0 :             .await
     493            0 :             .map_err(Error::ReceiveBody)
     494            0 :     }
     495              : 
     496            0 :     pub async fn layer_map_info(
     497            0 :         &self,
     498            0 :         tenant_shard_id: TenantShardId,
     499            0 :         timeline_id: TimelineId,
     500            0 :     ) -> Result<LayerMapInfo> {
     501            0 :         let uri = format!(
     502            0 :             "{}/v1/tenant/{}/timeline/{}/layer",
     503            0 :             self.mgmt_api_endpoint, tenant_shard_id, timeline_id,
     504            0 :         );
     505            0 :         self.get(&uri)
     506            0 :             .await?
     507            0 :             .json()
     508            0 :             .await
     509            0 :             .map_err(Error::ReceiveBody)
     510            0 :     }
     511              : 
     512            0 :     pub async fn layer_evict(
     513            0 :         &self,
     514            0 :         tenant_shard_id: TenantShardId,
     515            0 :         timeline_id: TimelineId,
     516            0 :         layer_file_name: &str,
     517            0 :     ) -> Result<bool> {
     518            0 :         let uri = format!(
     519            0 :             "{}/v1/tenant/{}/timeline/{}/layer/{}",
     520            0 :             self.mgmt_api_endpoint, tenant_shard_id, timeline_id, layer_file_name
     521            0 :         );
     522            0 :         let resp = self.request_noerror(Method::DELETE, &uri, ()).await?;
     523            0 :         match resp.status() {
     524            0 :             StatusCode::OK => Ok(true),
     525            0 :             StatusCode::NOT_MODIFIED => Ok(false),
     526              :             // TODO: dedupe this pattern / introduce separate error variant?
     527            0 :             status => Err(match resp.json::<HttpErrorBody>().await {
     528            0 :                 Ok(HttpErrorBody { msg }) => Error::ApiError(status, msg),
     529              :                 Err(_) => {
     530            0 :                     Error::ReceiveErrorBody(format!("Http error ({}) at {}.", status.as_u16(), uri))
     531              :                 }
     532              :             }),
     533              :         }
     534            0 :     }
     535              : 
     536            0 :     pub async fn layer_ondemand_download(
     537            0 :         &self,
     538            0 :         tenant_shard_id: TenantShardId,
     539            0 :         timeline_id: TimelineId,
     540            0 :         layer_file_name: &str,
     541            0 :     ) -> Result<bool> {
     542            0 :         let uri = format!(
     543            0 :             "{}/v1/tenant/{}/timeline/{}/layer/{}",
     544            0 :             self.mgmt_api_endpoint, tenant_shard_id, timeline_id, layer_file_name
     545            0 :         );
     546            0 :         let resp = self.request_noerror(Method::GET, &uri, ()).await?;
     547            0 :         match resp.status() {
     548            0 :             StatusCode::OK => Ok(true),
     549            0 :             StatusCode::NOT_MODIFIED => Ok(false),
     550              :             // TODO: dedupe this pattern / introduce separate error variant?
     551            0 :             status => Err(match resp.json::<HttpErrorBody>().await {
     552            0 :                 Ok(HttpErrorBody { msg }) => Error::ApiError(status, msg),
     553              :                 Err(_) => {
     554            0 :                     Error::ReceiveErrorBody(format!("Http error ({}) at {}.", status.as_u16(), uri))
     555              :                 }
     556              :             }),
     557              :         }
     558            0 :     }
     559              : 
     560            0 :     pub async fn ingest_aux_files(
     561            0 :         &self,
     562            0 :         tenant_shard_id: TenantShardId,
     563            0 :         timeline_id: TimelineId,
     564            0 :         aux_files: HashMap<String, String>,
     565            0 :     ) -> Result<bool> {
     566            0 :         let uri = format!(
     567            0 :             "{}/v1/tenant/{}/timeline/{}/ingest_aux_files",
     568            0 :             self.mgmt_api_endpoint, tenant_shard_id, timeline_id
     569            0 :         );
     570            0 :         let resp = self
     571            0 :             .request_noerror(Method::POST, &uri, IngestAuxFilesRequest { aux_files })
     572            0 :             .await?;
     573            0 :         match resp.status() {
     574            0 :             StatusCode::OK => Ok(true),
     575            0 :             status => Err(match resp.json::<HttpErrorBody>().await {
     576            0 :                 Ok(HttpErrorBody { msg }) => Error::ApiError(status, msg),
     577              :                 Err(_) => {
     578            0 :                     Error::ReceiveErrorBody(format!("Http error ({}) at {}.", status.as_u16(), uri))
     579              :                 }
     580              :             }),
     581              :         }
     582            0 :     }
     583              : 
     584            0 :     pub async fn list_aux_files(
     585            0 :         &self,
     586            0 :         tenant_shard_id: TenantShardId,
     587            0 :         timeline_id: TimelineId,
     588            0 :         lsn: Lsn,
     589            0 :     ) -> Result<HashMap<String, Bytes>> {
     590            0 :         let uri = format!(
     591            0 :             "{}/v1/tenant/{}/timeline/{}/list_aux_files",
     592            0 :             self.mgmt_api_endpoint, tenant_shard_id, timeline_id
     593            0 :         );
     594            0 :         let resp = self
     595            0 :             .request_noerror(Method::POST, &uri, ListAuxFilesRequest { lsn })
     596            0 :             .await?;
     597            0 :         match resp.status() {
     598              :             StatusCode::OK => {
     599            0 :                 let resp: HashMap<String, Bytes> = resp.json().await.map_err(|e| {
     600            0 :                     Error::ApiError(StatusCode::INTERNAL_SERVER_ERROR, format!("{e}"))
     601            0 :                 })?;
     602            0 :                 Ok(resp)
     603              :             }
     604            0 :             status => Err(match resp.json::<HttpErrorBody>().await {
     605            0 :                 Ok(HttpErrorBody { msg }) => Error::ApiError(status, msg),
     606              :                 Err(_) => {
     607            0 :                     Error::ReceiveErrorBody(format!("Http error ({}) at {}.", status.as_u16(), uri))
     608              :                 }
     609              :             }),
     610              :         }
     611            0 :     }
     612              : }
        

Generated by: LCOV version 2.1-beta