Skip to content

Commit 0084fae

Browse files
committed
refactor: Remobe file from file uploaders modules
1 parent 424f6d3 commit 0084fae

File tree

10 files changed

+59
-63
lines changed

10 files changed

+59
-63
lines changed

mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ mod tests {
173173
use mithril_common::{entities::CompressionAlgorithm, test_utils::fake_data};
174174

175175
use crate::{
176-
file_uploaders::MockFileUploader, test_tools::TestLogger, DumbFileUploader, DumbSnapshotter,
176+
file_uploaders::MockFileUploader, test_tools::TestLogger, DumbUploader, DumbSnapshotter,
177177
};
178178

179179
use super::*;
@@ -188,7 +188,7 @@ mod tests {
188188
.unwrap();
189189

190190
let dumb_snapshotter = Arc::new(DumbSnapshotter::new());
191-
let dumb_snapshot_uploader = Arc::new(DumbFileUploader::new());
191+
let dumb_snapshot_uploader = Arc::new(DumbUploader::new());
192192

193193
let cardano_immutable_files_full_artifact_builder =
194194
CardanoImmutableFilesFullArtifactBuilder::new(
@@ -235,7 +235,7 @@ mod tests {
235235
fake_data::network(),
236236
&Version::parse("1.0.0").unwrap(),
237237
Arc::new(DumbSnapshotter::new()),
238-
Arc::new(DumbFileUploader::new()),
238+
Arc::new(DumbUploader::new()),
239239
CompressionAlgorithm::default(),
240240
TestLogger::stdout(),
241241
);
@@ -262,7 +262,7 @@ mod tests {
262262
network,
263263
&Version::parse("1.0.0").unwrap(),
264264
Arc::new(DumbSnapshotter::new()),
265-
Arc::new(DumbFileUploader::new()),
265+
Arc::new(DumbUploader::new()),
266266
CompressionAlgorithm::Gzip,
267267
TestLogger::stdout(),
268268
);
@@ -291,7 +291,7 @@ mod tests {
291291
fake_data::network(),
292292
&Version::parse("1.0.0").unwrap(),
293293
Arc::new(DumbSnapshotter::new()),
294-
Arc::new(DumbFileUploader::new()),
294+
Arc::new(DumbUploader::new()),
295295
algorithm,
296296
TestLogger::stdout(),
297297
);

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::{
6464
},
6565
entities::AggregatorEpochSettings,
6666
event_store::{EventMessage, EventStore, TransmitterService},
67-
file_uploaders::GcpFileUploader,
67+
file_uploaders::GcpUploader,
6868
http_server::routes::router::{self, RouterConfig, RouterState},
6969
services::{
7070
AggregatorSignableSeedBuilder, AggregatorUpkeepService, BufferedCertifierService,
@@ -77,9 +77,9 @@ use crate::{
7777
store::CertificatePendingStorer,
7878
tools::{CExplorerSignerRetriever, GenesisToolsDependency, SignersImporter},
7979
AggregatorConfig, AggregatorRunner, AggregatorRuntime, CompressedArchiveSnapshotter,
80-
Configuration, DependencyContainer, DumbFileUploader, DumbSnapshotter, EpochSettingsStorer,
81-
FileUploader, LocalFileUploader, MetricsService, MithrilSignerRegisterer, MultiSigner,
82-
MultiSignerImpl, RemoteSnapshotUploader, SingleSignatureAuthenticator, SnapshotUploaderType,
80+
Configuration, DependencyContainer, DumbSnapshotter, DumbUploader, EpochSettingsStorer,
81+
FileUploader, LocalUploader, MetricsService, MithrilSignerRegisterer, MultiSigner,
82+
MultiSignerImpl, RemoteUploader, SingleSignatureAuthenticator, SnapshotUploaderType,
8383
Snapshotter, SnapshotterCompressionAlgorithm, VerificationKeyStorer,
8484
};
8585

@@ -462,23 +462,23 @@ impl DependenciesBuilder {
462462
)
463463
})?;
464464

465-
Ok(Arc::new(RemoteSnapshotUploader::new(
466-
Box::new(GcpFileUploader::new(
465+
Ok(Arc::new(RemoteUploader::new(
466+
Box::new(GcpUploader::new(
467467
bucket,
468468
self.configuration.snapshot_use_cdn_domain,
469469
logger.clone(),
470470
)),
471471
logger,
472472
)))
473473
}
474-
SnapshotUploaderType::Local => Ok(Arc::new(LocalFileUploader::new(
474+
SnapshotUploaderType::Local => Ok(Arc::new(LocalUploader::new(
475475
self.configuration.get_server_url(),
476476
&self.configuration.snapshot_directory,
477477
logger,
478478
))),
479479
}
480480
} else {
481-
Ok(Arc::new(DumbFileUploader::new()))
481+
Ok(Arc::new(DumbUploader::new()))
482482
}
483483
}
484484

mithril-aggregator/src/file_uploaders/dumb_file_uploader.rs renamed to mithril-aggregator/src/file_uploaders/dumb_uploader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use super::{FileLocation, FileUploader};
99
///
1010
/// It actually does NOT upload any file but remembers the last file it
1111
/// was asked to upload. This is intended to by used by integration tests.
12-
pub struct DumbFileUploader {
12+
pub struct DumbUploader {
1313
last_uploaded: RwLock<Option<String>>,
1414
}
1515

16-
impl DumbFileUploader {
16+
impl DumbUploader {
1717
/// Create a new instance.
1818
pub fn new() -> Self {
1919
Self {
@@ -32,14 +32,14 @@ impl DumbFileUploader {
3232
}
3333
}
3434

35-
impl Default for DumbFileUploader {
35+
impl Default for DumbUploader {
3636
fn default() -> Self {
3737
Self::new()
3838
}
3939
}
4040

4141
#[async_trait]
42-
impl FileUploader for DumbFileUploader {
42+
impl FileUploader for DumbUploader {
4343
/// Upload a file
4444
async fn upload(&self, filepath: &Path) -> StdResult<FileLocation> {
4545
let mut value = self
@@ -60,7 +60,7 @@ mod tests {
6060

6161
#[tokio::test]
6262
async fn test_dumb_uploader() {
63-
let uploader = DumbFileUploader::new();
63+
let uploader = DumbUploader::new();
6464
assert!(uploader
6565
.get_last_upload()
6666
.expect("uploader should not fail")

mithril-aggregator/src/file_uploaders/gcp_file_uploader.rs renamed to mithril-aggregator/src/file_uploaders/gcp_uploader.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use mithril_common::StdResult;
1414
use crate::file_uploaders::FileLocation;
1515
use crate::FileUploader;
1616

17-
/// GcpFileUploader represents a Google Cloud Platform file uploader interactor
18-
pub struct GcpFileUploader {
17+
/// GcpUploader represents a Google Cloud Platform file uploader interactor
18+
pub struct GcpUploader {
1919
bucket: String,
2020
use_cdn_domain: bool,
2121
logger: Logger,
2222
}
2323

24-
impl GcpFileUploader {
25-
/// GcpFileUploader factory
24+
impl GcpUploader {
25+
/// GcpUploader factory
2626
pub fn new(bucket: String, use_cdn_domain: bool, logger: Logger) -> Self {
2727
Self {
2828
bucket,
@@ -44,7 +44,7 @@ impl GcpFileUploader {
4444
}
4545

4646
#[async_trait]
47-
impl FileUploader for GcpFileUploader {
47+
impl FileUploader for GcpUploader {
4848
async fn upload(&self, filepath: &Path) -> StdResult<FileLocation> {
4949
if env::var("GOOGLE_APPLICATION_CREDENTIALS_JSON").is_err() {
5050
return Err(anyhow!(
@@ -107,7 +107,7 @@ mod tests {
107107
async fn get_location_not_using_cdn_domain_return_google_api_uri() {
108108
let use_cdn_domain = false;
109109

110-
let file_uploader = GcpFileUploader::new(
110+
let file_uploader = GcpUploader::new(
111111
"cardano-testnet".to_string(),
112112
use_cdn_domain,
113113
TestLogger::stdout(),
@@ -125,7 +125,7 @@ mod tests {
125125
async fn get_location_using_cdn_domain_return_cdn_in_uri() {
126126
let use_cdn_domain = true;
127127

128-
let file_uploader = GcpFileUploader::new(
128+
let file_uploader = GcpUploader::new(
129129
"cdn.mithril.network".to_string(),
130130
use_cdn_domain,
131131
TestLogger::stdout(),

mithril-aggregator/src/file_uploaders/local_file_uploader.rs renamed to mithril-aggregator/src/file_uploaders/local_uploader.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::file_uploaders::{FileLocation, FileUploader};
1010
use crate::http_server;
1111
use crate::tools;
1212

13-
/// LocalFileUploader is a file uploader working using local files
14-
pub struct LocalFileUploader {
13+
/// LocalUploader is a file uploader working using local files
14+
pub struct LocalUploader {
1515
/// File server listening IP
1616
file_server_url: String,
1717

@@ -21,11 +21,11 @@ pub struct LocalFileUploader {
2121
logger: Logger,
2222
}
2323

24-
impl LocalFileUploader {
25-
/// LocalFileUploader factory
24+
impl LocalUploader {
25+
/// LocalUploader factory
2626
pub(crate) fn new(file_server_url: String, target_location: &Path, logger: Logger) -> Self {
2727
let logger = logger.new_with_component_name::<Self>();
28-
debug!(logger, "New LocalFileUploader created"; "file_server_url" => &file_server_url);
28+
debug!(logger, "New LocalUploader created"; "file_server_url" => &file_server_url);
2929
Self {
3030
file_server_url,
3131
target_location: target_location.to_path_buf(),
@@ -35,7 +35,7 @@ impl LocalFileUploader {
3535
}
3636

3737
#[async_trait]
38-
impl FileUploader for LocalFileUploader {
38+
impl FileUploader for LocalUploader {
3939
async fn upload(&self, filepath: &Path) -> StdResult<FileLocation> {
4040
let archive_name = filepath.file_name().unwrap().to_str().unwrap();
4141
let target_path = &self.target_location.join(archive_name);
@@ -69,7 +69,7 @@ mod tests {
6969
use crate::http_server;
7070
use crate::test_tools::TestLogger;
7171

72-
use super::LocalFileUploader;
72+
use super::LocalUploader;
7373

7474
fn create_fake_archive(dir: &Path, digest: &str) -> PathBuf {
7575
let file_path = dir.join(format!("test.{digest}.tar.gz"));
@@ -96,7 +96,7 @@ mod tests {
9696
http_server::SERVER_BASE_PATH,
9797
&digest
9898
);
99-
let uploader = LocalFileUploader::new(url, target_dir.path(), TestLogger::stdout());
99+
let uploader = LocalUploader::new(url, target_dir.path(), TestLogger::stdout());
100100

101101
let location = uploader
102102
.upload(&archive)
@@ -112,7 +112,7 @@ mod tests {
112112
let target_dir = tempdir().unwrap();
113113
let digest = "41e27b9ed5a32531b95b2b7ff3c0757591a06a337efaf19a524a998e348028e7";
114114
let archive = create_fake_archive(source_dir.path(), digest);
115-
let uploader = LocalFileUploader::new(
115+
let uploader = LocalUploader::new(
116116
"http://test.com:8080/".to_string(),
117117
target_dir.path(),
118118
TestLogger::stdout(),
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
mod dumb_file_uploader;
2-
mod file_uploader;
3-
mod gcp_file_uploader;
4-
mod local_file_uploader;
5-
mod remote_file_uploader;
1+
mod dumb_uploader;
2+
mod gcp_uploader;
3+
mod interface;
4+
mod local_uploader;
5+
mod remote_uploader;
66

7-
pub use dumb_file_uploader::*;
8-
pub use file_uploader::FileLocation;
9-
pub use file_uploader::FileUploader;
10-
pub use gcp_file_uploader::GcpFileUploader;
11-
pub use local_file_uploader::LocalFileUploader;
12-
pub use remote_file_uploader::RemoteSnapshotUploader;
7+
pub use dumb_uploader::*;
8+
pub use gcp_uploader::GcpUploader;
9+
pub use interface::FileLocation;
10+
pub use interface::FileUploader;
11+
pub use local_uploader::LocalUploader;
12+
pub use remote_uploader::RemoteUploader;
1313

1414
#[cfg(test)]
15-
pub use file_uploader::MockFileUploader;
15+
pub use interface::MockFileUploader;

mithril-aggregator/src/file_uploaders/remote_file_uploader.rs renamed to mithril-aggregator/src/file_uploaders/remote_uploader.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ use mithril_common::StdResult;
77

88
use crate::file_uploaders::{FileLocation, FileUploader};
99

10-
/// RemoteSnapshotUploader is a snapshot uploader working using Google Cloud Platform services
11-
pub struct RemoteSnapshotUploader {
10+
/// RemoteUploader is a snapshot uploader working using Google Cloud Platform services
11+
pub struct RemoteUploader {
1212
file_uploader: Box<dyn FileUploader>,
1313
logger: Logger,
1414
}
1515

16-
impl RemoteSnapshotUploader {
17-
/// RemoteSnapshotUploader factory
16+
impl RemoteUploader {
17+
/// RemoteUploader factory
1818
pub fn new(file_uploader: Box<dyn FileUploader>, logger: Logger) -> Self {
1919
let logger = logger.new_with_component_name::<Self>();
20-
debug!(logger, "New RemoteSnapshotUploader created");
20+
debug!(logger, "New RemoteUploader created");
2121
Self {
2222
file_uploader,
2323
logger,
@@ -26,7 +26,7 @@ impl RemoteSnapshotUploader {
2626
}
2727

2828
#[async_trait]
29-
impl FileUploader for RemoteSnapshotUploader {
29+
impl FileUploader for RemoteUploader {
3030
async fn upload(&self, snapshot_filepath: &Path) -> StdResult<FileLocation> {
3131
let location = self.file_uploader.upload(snapshot_filepath).await?;
3232
debug!(self.logger, "Snapshot upload to remote storage completed"; "location" => &location);
@@ -44,7 +44,7 @@ mod tests {
4444
use crate::file_uploaders::{FileUploader, MockFileUploader};
4545
use crate::test_tools::TestLogger;
4646

47-
use super::RemoteSnapshotUploader;
47+
use super::RemoteUploader;
4848

4949
#[tokio::test]
5050
async fn upload_call_uploader_and_return_location() {
@@ -54,8 +54,7 @@ mod tests {
5454
.with(eq(Path::new("test/snapshot.xxx.tar.gz")))
5555
.times(1)
5656
.returning(|_| Ok("https://cdn.mithril.network/snapshot.xxx.tar.gz".to_string()));
57-
let snapshot_uploader =
58-
RemoteSnapshotUploader::new(Box::new(file_uploader), TestLogger::stdout());
57+
let snapshot_uploader = RemoteUploader::new(Box::new(file_uploader), TestLogger::stdout());
5958
let filepath = Path::new("test/snapshot.xxx.tar.gz");
6059
let expected_location = "https://cdn.mithril.network/snapshot.xxx.tar.gz".to_string();
6160

@@ -73,8 +72,7 @@ mod tests {
7372
file_uploader
7473
.expect_upload()
7574
.returning(|_| Err(anyhow!("unexpected error")));
76-
let snapshot_uploader =
77-
RemoteSnapshotUploader::new(Box::new(file_uploader), TestLogger::stdout());
75+
let snapshot_uploader = RemoteUploader::new(Box::new(file_uploader), TestLogger::stdout());
7876
let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz");
7977

8078
let result = snapshot_uploader

mithril-aggregator/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ pub use crate::configuration::{
3838
pub use crate::multi_signer::{MultiSigner, MultiSignerImpl};
3939
pub use commands::{CommandType, MainOpts};
4040
pub use dependency_injection::DependencyContainer;
41-
pub use file_uploaders::{
42-
DumbFileUploader, FileUploader, LocalFileUploader, RemoteSnapshotUploader,
43-
};
41+
pub use file_uploaders::{DumbUploader, FileUploader, LocalUploader, RemoteUploader};
4442
pub use message_adapters::{FromRegisterSignerAdapter, ToCertificatePendingMessageAdapter};
4543
pub use metrics::*;
4644
pub use runtime::{

mithril-aggregator/tests/test_extensions/runtime_tester.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use mithril_aggregator::{
77
database::{record::SignedEntityRecord, repository::OpenMessageRepository},
88
dependency_injection::DependenciesBuilder,
99
event_store::EventMessage,
10-
AggregatorRuntime, Configuration, DependencyContainer, DumbFileUploader, DumbSnapshotter,
10+
AggregatorRuntime, Configuration, DependencyContainer, DumbSnapshotter, DumbUploader,
1111
SignerRegistrationError,
1212
};
1313
use mithril_common::{
@@ -100,7 +100,7 @@ macro_rules! assert_metrics_eq {
100100

101101
pub struct RuntimeTester {
102102
pub network: String,
103-
pub snapshot_uploader: Arc<DumbFileUploader>,
103+
pub snapshot_uploader: Arc<DumbUploader>,
104104
pub chain_observer: Arc<FakeObserver>,
105105
pub immutable_file_observer: Arc<DumbImmutableFileObserver>,
106106
pub digester: Arc<DumbImmutableDigester>,
@@ -130,7 +130,7 @@ impl RuntimeTester {
130130
let logger = build_logger();
131131
let global_logger = slog_scope::set_global_logger(logger.clone());
132132
let network = configuration.network.clone();
133-
let snapshot_uploader = Arc::new(DumbFileUploader::new());
133+
let snapshot_uploader = Arc::new(DumbUploader::new());
134134
let immutable_file_observer = Arc::new(DumbImmutableFileObserver::new());
135135
immutable_file_observer
136136
.shall_return(Some(start_time_point.immutable_file_number))

0 commit comments

Comments
 (0)