Skip to content

Feat: GcpUploader implements synchronization for Cardano database artifacts #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.6.13"
version = "0.6.14"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use mithril_common::{
};

use crate::{
file_uploaders::LocalUploader, snapshotter::OngoingSnapshot, FileUploader, Snapshotter,
file_uploaders::{GcpUploader, LocalUploader},
snapshotter::OngoingSnapshot,
DumbUploader, FileUploader, Snapshotter,
};

/// The [AncillaryFileUploader] trait allows identifying uploaders that return locations for ancillary archive files.
Expand All @@ -26,13 +28,28 @@ pub trait AncillaryFileUploader: Send + Sync {
async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation>;
}

#[async_trait]
impl AncillaryFileUploader for DumbUploader {
async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation> {
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(AncillaryLocation::CloudStorage { uri })
}
}

#[async_trait]
impl AncillaryFileUploader for LocalUploader {
async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation> {
let uri = FileUploader::upload(self, filepath)
.await
.with_context(|| "Error while uploading with 'LocalUploader'")?
.into();
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(AncillaryLocation::CloudStorage { uri })
}
}

#[async_trait]
impl AncillaryFileUploader for GcpUploader {
async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation> {
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(AncillaryLocation::CloudStorage { uri })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use mithril_common::{
use reqwest::Url;
use slog::{error, Logger};

use crate::ImmutableFileDigestMapper;
use crate::{
file_uploaders::{GcpUploader, LocalUploader},
DumbUploader, FileUploader, ImmutableFileDigestMapper,
};

/// The [DigestFileUploader] trait allows identifying uploaders that return locations for digest files.
#[cfg_attr(test, mockall::automock)]
Expand All @@ -23,6 +26,33 @@ pub trait DigestFileUploader: Send + Sync {
async fn upload(&self, filepath: &Path) -> StdResult<DigestLocation>;
}

#[async_trait]
impl DigestFileUploader for DumbUploader {
async fn upload(&self, filepath: &Path) -> StdResult<DigestLocation> {
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(DigestLocation::CloudStorage { uri })
}
}

#[async_trait]
impl DigestFileUploader for LocalUploader {
async fn upload(&self, filepath: &Path) -> StdResult<DigestLocation> {
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(DigestLocation::CloudStorage { uri })
}
}

#[async_trait]
impl DigestFileUploader for GcpUploader {
async fn upload(&self, filepath: &Path) -> StdResult<DigestLocation> {
let uri = FileUploader::upload(self, filepath).await?.into();

Ok(DigestLocation::CloudStorage { uri })
}
}

pub struct DigestArtifactBuilder {
/// Aggregator URL prefix
aggregator_url_prefix: Url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use mithril_common::{
StdResult,
};

use crate::{file_uploaders::LocalUploader, FileUploader, Snapshotter};
use crate::{
file_uploaders::{GcpUploader, LocalUploader},
DumbUploader, FileUploader, Snapshotter,
};

fn immmutable_file_number_extractor(file_uri: &str) -> StdResult<Option<String>> {
let regex = Regex::new(r".*(\d{5})")?;
Expand All @@ -39,6 +42,27 @@ pub trait ImmutableFilesUploader: Send + Sync {
async fn batch_upload(&self, filepaths: &[PathBuf]) -> StdResult<ImmutablesLocation>;
}

#[async_trait]
impl ImmutableFilesUploader for DumbUploader {
async fn batch_upload(&self, filepaths: &[PathBuf]) -> StdResult<ImmutablesLocation> {
let last_file_path = filepaths.last().ok_or_else(|| {
anyhow!("No file to upload with 'DumbUploader' as the filepaths list is empty")
})?;

let template_uri = MultiFilesUri::extract_template_from_uris(
vec![self.upload(last_file_path).await?.into()],
immmutable_file_number_extractor,
)?
.ok_or_else(|| {
anyhow!("No matching template found in the uploaded files with 'DumbUploader'")
})?;

Ok(ImmutablesLocation::CloudStorage {
uri: MultiFilesUri::Template(template_uri),
})
}
}

#[async_trait]
impl ImmutableFilesUploader for LocalUploader {
async fn batch_upload(&self, filepaths: &[PathBuf]) -> StdResult<ImmutablesLocation> {
Expand All @@ -49,7 +73,29 @@ impl ImmutableFilesUploader for LocalUploader {

let template_uri =
MultiFilesUri::extract_template_from_uris(file_uris, immmutable_file_number_extractor)?
.ok_or_else(|| anyhow!("No matching template found in the uploaded files"))?;
.ok_or_else(|| {
anyhow!("No matching template found in the uploaded files with 'LocalUploader'")
})?;

Ok(ImmutablesLocation::CloudStorage {
uri: MultiFilesUri::Template(template_uri),
})
}
}

#[async_trait]
impl ImmutableFilesUploader for GcpUploader {
async fn batch_upload(&self, filepaths: &[PathBuf]) -> StdResult<ImmutablesLocation> {
let mut file_uris = Vec::new();
for filepath in filepaths {
file_uris.push(self.upload(filepath).await?.into());
}

let template_uri =
MultiFilesUri::extract_template_from_uris(file_uris, immmutable_file_number_extractor)?
.ok_or_else(|| {
anyhow!("No matching template found in the uploaded files with 'GcpUploader'")
})?;

Ok(ImmutablesLocation::CloudStorage {
uri: MultiFilesUri::Template(template_uri),
Expand Down
Loading
Loading