Skip to content

Commit 72da717

Browse files
committed
Make client send SnapshotDownloadMessage
1 parent 72387cb commit 72da717

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

mithril-client/src/aggregator_client/http_client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ impl AggregatorHTTPClient {
159159
/// Issue a POST HTTP request.
160160
#[async_recursion]
161161
async fn post(&self, url: &str, json: &str) -> Result<Response, AggregatorHTTPClientError> {
162-
let request_builder = Client::new().post(url.to_owned()).json(json);
162+
debug!("POST url='{url}' json='{json}'.");
163+
let request_builder = Client::new().post(url.to_owned()).body(json.to_owned());
163164
let current_api_version = self
164165
.compute_current_api_version()
165166
.await
@@ -177,7 +178,7 @@ impl AggregatorHTTPClient {
177178
})?;
178179

179180
match response.status() {
180-
StatusCode::OK => Ok(response),
181+
StatusCode::OK | StatusCode::CREATED => Ok(response),
181182
StatusCode::PRECONDITION_FAILED => {
182183
if self.discard_current_api_version().await.is_some()
183184
&& !self.api_versions.read().await.is_empty()

mithril-client/src/aggregator_client/snapshot_client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ use thiserror::Error;
66

77
use mithril_common::{
88
entities::Snapshot,
9-
messages::{SnapshotListItemMessage, SnapshotListMessage, SnapshotMessage},
9+
messages::{SnapshotListItemMessage, SnapshotListMessage, SnapshotMessage, ToMessageAdapter},
1010
StdResult,
1111
};
1212

13-
use crate::aggregator_client::AggregatorClient;
1413
use crate::utils::DownloadProgressReporter;
14+
use crate::{
15+
aggregator_client::AggregatorClient, message_adapters::ToSnapshotDownloadMessageAdapter,
16+
};
1517

1618
/// Error for the Snapshot client
1719
#[derive(Error, Debug)]
@@ -77,7 +79,9 @@ impl SnapshotClient {
7779
{
7880
Ok(()) => {
7981
// the snapshot download does not fail if the statistic call fails.
80-
let _ = self.add_statistics(snapshot).await;
82+
if let Err(e) = self.add_statistics(snapshot).await {
83+
warn!("Could not POST snapshot download statistics: {e:?}");
84+
}
8185

8286
Ok(())
8387
}
@@ -101,7 +105,8 @@ impl SnapshotClient {
101105
/// Increments Aggregator's download statistics
102106
pub async fn add_statistics(&self, snapshot: &Snapshot) -> StdResult<()> {
103107
let url = "statistics/snapshot";
104-
let json = serde_json::to_string(snapshot)?;
108+
let snapshot_download_message = ToSnapshotDownloadMessageAdapter::adapt(snapshot);
109+
let json = serde_json::to_string(&snapshot_download_message)?;
105110
let _response = self.http_client.post_content(url, &json).await?;
106111

107112
Ok(())

0 commit comments

Comments
 (0)