Adding the mocks

This commit is contained in:
Michael Chung committed 2023-12-21 01:58:43 -05:00
1 parent 86c80fdf19
commit 6b2d4ffdce
7 files changed
+168 -27

No files matched your search

@@ -30,6 +30,8 @@ my-workspace-hack = { version = "0.1", path = "../../../my-workspace-hack" }
anyhow = "1.0.75"
log = "0.4.14"
env_logger = "0.10.1"
async-trait = "0.1.58"
# The "never-encode-slash" feature seems to have been removed:
# https://github.com/durch/rust-s3/pull/254
rust-s3 = { version = "0.33.0" }
@@ -1,3 +1,4 @@
pub mod bucket_client;
pub mod bucket_path_unifier;
pub mod remote_file_manager;
pub mod remote_file_manager;
pub mod remote_file_manager_mock;
@@ -2,6 +2,27 @@ use errors::AnyhowResult;
use crate::bucket_client::BucketClient;
use tokio::time::Duration;
use log::info;
use crate::remote_file_manager_mock::bucket_orchestration_mock;
use async_trait::async_trait;
#[async_trait]
pub trait BucketOrchestrationDownload {
async fn download_file_to_disk(
&self,
object_path: String,
filesystem_path: String,
is_public:bool
) -> AnyhowResult<()>;
}
#[async_trait]
pub trait BucketOrchestrationUpload {
async fn upload_file_with_content_type_process(&self,object_name: &str,
bytes: &[u8],
content_type: &str,
is_public:bool) -> AnyhowResult<()>;
}
pub struct BucketOrchestration {
access_key: String,
@@ -11,6 +32,35 @@ pub struct BucketOrchestration {
private_bucket_name: String,
}
impl BucketOrchestrationDownload for BucketOrchestration {
#[async_trait]
async fn download_file_to_disk(
&self,
object_path: String,
filesystem_path: String,
is_public:bool
) -> AnyhowResult<()> {
let bucket_client = self.get_bucket_with_visbility(is_public).await?;
bucket_client.download_file_to_disk(object_path, filesystem_path).await
}
}
impl BucketOrchestrationUpload for BucketOrchestration {
#[async_trait]
async fn upload_file_with_content_type_process(&self,object_name: &str,
bytes: &[u8],
content_type: &str,
is_public:bool) -> AnyhowResult<()> {
let bucket_client = self.get_bucket_with_visbility(is_public).await?;
bucket_client.upload_file_with_content_type_process(
object_name,
bytes,
content_type
).await
}
}
impl BucketOrchestration {
pub fn new_bucket_client_from_existing_env()-> AnyhowResult<Self> {
@@ -48,32 +98,9 @@ impl BucketOrchestration {
}
}
pub async fn download_file_to_disk(
&self,
object_path: String,
filesystem_path: String,
is_public:bool
) -> AnyhowResult<()> {
let bucket_client = self.get_bucket_with_visbility(is_public).await?;
bucket_client.download_file_to_disk(object_path, filesystem_path).await
}
pub async fn upload_file_with_content_type_process(&self,object_name: &str,
bytes: &[u8],
content_type: &str,
is_public:bool) -> AnyhowResult<()> {
let bucket_client = self.get_bucket_with_visbility(is_public).await?;
bucket_client.upload_file_with_content_type_process(
object_name,
bytes,
content_type
).await
}
async fn get_bucket_with_visbility(&self, public:bool) -> AnyhowResult<BucketClient> {
let bucket_timeout = easyenv::get_env_duration_seconds_or_default(
"BUCKET_TIMEOUT_SECONDS", Duration::from_secs(60 * 10));
let bucket_client:BucketClient;
@@ -30,8 +30,17 @@ impl RemoteCloudBucketDetails {
pub fn file_descriptor_from_bucket_details(&self) -> Box<dyn FileDescriptor> {
match self.prefix.as_str() {
"loRA" => Box::new(weights_descriptor::WeightsLoRADescriptor {}),
"SD15" => Box::new(weights_descriptor::WeightsSD15Descriptor {}),
"SDXL" => Box::new(weights_descriptor::WeightsSDXLDescriptor {}),
"sd15" => Box::new(weights_descriptor::WeightsSD15Descriptor {}),
"sdxl" => Box::new(weights_descriptor::WeightsSDXLDescriptor {}),
"valle_prompt" => Box::new(weights_descriptor::WeightsVallePromptDescriptor {}),
"rvc" => {
match self.suffix.as_str() {
"safetensors" => Box::new(weights_descriptor::WeightsRVCDescriptor {}),
"index" => Box::new(weights_descriptor::WeightsRVCIndexDescriptor {}),
_ => panic!("Unknown suffix: {}",self.suffix)
}
},
"svc" => Box::new(weights_descriptor::WeightsSVCDescriptor {}),
_ => panic!("Unknown prefix: {}", self.prefix)
}
}
@@ -73,4 +73,100 @@ impl FileDescriptor for WeightsSDXLDescriptor {
fn is_public(&self) -> bool {
true
}
}
pub struct WeightsSVCDescriptor {}
impl FileDescriptor for crate::remote_file_manager::weights_descriptor::WeightsSVCDescriptor {
fn remote_directory_path(&self) -> &str {
return REMOTE_FILE_DIRECTORY;
}
// this will be the type of file peroid is handled by the file formatter
// e.g safetensors bin jpg
fn get_suffix(&self)->String {
return "safetensors".to_string();
}
// This will be the prefix of the media type or the weights type.
// name of the weights or the name of the media type
// vall-e_prompt, SD15, sd15, sdxl when implmenting add to the end
fn get_prefix(&self)->String {
return "svc".to_string();
}
// This will be ensure that the right bucket is picked
fn is_public(&self) -> bool {
true
}
}
pub struct WeightsRVCDescriptor {}
impl FileDescriptor for crate::remote_file_manager::weights_descriptor::WeightsRVCDescriptor {
fn remote_directory_path(&self) -> &str {
return REMOTE_FILE_DIRECTORY;
}
// this will be the type of file peroid is handled by the file formatter
// e.g safetensors bin jpg
fn get_suffix(&self)->String {
return "pth".to_string();
}
// This will be the prefix of the media type or the weights type.
// name of the weights or the name of the media type
// vall-e_prompt, SD15, sd15, sdxl when implmenting add to the end
fn get_prefix(&self)->String {
return "rvc".to_string();
}
// This will be ensure that the right bucket is picked
fn is_public(&self) -> bool {
true
}
}
pub struct WeightsRVCIndexDescriptor {}
impl FileDescriptor for crate::remote_file_manager::weights_descriptor::WeightsRVCDescriptor {
fn remote_directory_path(&self) -> &str {
return REMOTE_FILE_DIRECTORY;
}
// this will be the type of file peroid is handled by the file formatter
// e.g safetensors bin jpg
fn get_suffix(&self)->String {
return "index".to_string();
}
// This will be the prefix of the media type or the weights type.
// name of the weights or the name of the media type
// vall-e_prompt, SD15, sd15, sdxl when implmenting add to the end
fn get_prefix(&self)->String {
return "rvc".to_string();
}
// This will be ensure that the right bucket is picked
fn is_public(&self) -> bool {
true
}
}
pub struct WeightsVallePromptDescriptor {}
impl FileDescriptor for crate::remote_file_manager::weights_descriptor::WeightsVallePromptDescriptor {
fn remote_directory_path(&self) -> &str {
return REMOTE_FILE_DIRECTORY;
}
// this will be the type of file peroid is handled by the file formatter
// e.g safetensors bin jpg
fn get_suffix(&self)->String {
return "safetensors".to_string();
}
// This will be the prefix of the media type or the weights type.
// name of the weights or the name of the media type
// vall-e_prompt, SD15, sd15, sdxl when implmenting add to the end
fn get_prefix(&self)->String {
return "valle_prompt".to_string();
}
// This will be ensure that the right bucket is picked
fn is_public(&self) -> bool {
true
}
}
@@ -0,0 +1,5 @@
struct BucketOrchestrationMock {
}
@@ -0,0 +1 @@
pub mod bucket_orchestration_mock;