Skip to content
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

feat(blob-store): Add wasi-blob-store capability #361

Merged
merged 25 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 24 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
291 changes: 283 additions & 8 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repository = { workspace = true }

[[bin]]
name = "slight"
test = false

[lib]
name = "slight_lib"
path = "src/lib.rs"

[dependencies]
slight-blob-store = { workspace = true, features = ["aws_s3"], optional = true }
slight-core = { workspace = true }
slight-runtime = { workspace = true }
slight-keyvalue = { workspace = true, features = ["filesystem", "awsdynamodb", "redis", "azblob"], optional = true}
Expand Down Expand Up @@ -44,7 +44,8 @@ tempfile = { workspace = true }
rand = { worspace = true }

[features]
default = ["keyvalue", "distributed-locking", "messaging", "runtime-configs", "sql", "http-server", "http-client"]
default = ["blob-store", "keyvalue", "distributed-locking", "messaging", "runtime-configs", "sql", "http-server", "http-client"]
blob-store = ["dep:slight-blob-store"]
keyvalue = ["dep:slight-keyvalue"]
distributed-locking = ["dep:slight-distributed-locking"]
messaging = ["dep:slight-messaging"]
Expand All @@ -61,6 +62,7 @@ license = "MIT"
repository = "https://github.com/deislabs/spiderlightning"

[workspace.dependencies]
slight-blob-store = { path = "./crates/blob-store" }
slight-core = { path = "./crates/core" }
slight-runtime = { path = "./crates/runtime" }
slight-keyvalue = { path = "./crates/keyvalue" }
Expand Down
32 changes: 32 additions & 0 deletions crates/blob-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "slight-blob-store"
version = "0.1.0"
edition = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wit-bindgen-wasmtime = { workspace = true }
wit-error-rs = { workspace = true }
slight-common = { workspace = true }
slight-runtime-configs = { workspace = true }
anyhow = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true }
async-trait = { workspace = true }
# blobstore.s3 deps
aws-config = { version = "0.54", optional = true }
aws-sdk-s3 = { version = "0.24" , optional = true }
futures = { version = "0.3", optional = true }
# kv.azblob deps
azure_storage_blobs = { version = "0.11", optional = true }
azure_storage = { version = "0.11", optional = true }
bytes = { version = "1", optional = true }

[features]
default = ["aws_s3", "azblob"]
aws_s3 = ["aws-config", "aws-sdk-s3", "futures"]
azblob = ["azure_storage_blobs", "azure_storage", "bytes", "futures"]
66 changes: 66 additions & 0 deletions crates/blob-store/src/container.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use anyhow::Result;

use std::sync::Arc;

use async_trait::async_trait;
use slight_common::BasicState;

use crate::{
blob_store::{ContainerMetadata, ObjectMetadata, ObjectNameParam, ObjectNameResult},
implementors::{aws_s3::S3Container, azblob::AzBlobContainer},
read_stream::{ReadStreamImplementor, ReadStreamInner},
write_stream::{WriteStreamImplementor, WriteStreamInner},
BlobStoreImplementors,
};

pub(crate) type DynW = dyn WriteStreamImplementor + Send + Sync;
pub(crate) type DynR = dyn ReadStreamImplementor + Send + Sync;
pub(crate) type DynContainer = dyn ContainerImplementor + Send + Sync;

#[async_trait]
pub trait ContainerImplementor {
async fn name(&self) -> Result<String>;
async fn info(&self) -> Result<ContainerMetadata>;
async fn list_objects(&self) -> Result<Vec<ObjectNameResult>>;
async fn delete_object(&self, name: ObjectNameParam<'_>) -> Result<()>;
async fn delete_objects(&self, names: Vec<ObjectNameParam<'_>>) -> Result<()>;
async fn has_object(&self, name: ObjectNameParam<'_>) -> Result<bool>;
async fn object_info(&self, name: ObjectNameParam<'_>) -> Result<ObjectMetadata>;
async fn read_object(&self, name: ObjectNameParam<'_>) -> Result<ReadStreamInner>;
async fn write_object(&self, name: ObjectNameParam<'_>) -> Result<WriteStreamInner>;
}

impl std::fmt::Debug for DynContainer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ContainerImplementor")
.finish_non_exhaustive()
}
}

#[derive(Clone, Debug)]
pub struct ContainerInner {
pub implementor: Arc<DynContainer>,
}

impl ContainerInner {
pub(crate) async fn new(
blobstore_implementor: BlobStoreImplementors,
slight_state: &BasicState,
name: &str,
) -> Result<Self> {
let container = Self {
implementor: match blobstore_implementor {
#[cfg(feature = "aws_s3")]
BlobStoreImplementors::S3 => Arc::new(S3Container::new(slight_state, name).await?),
#[cfg(feature = "azblob")]
BlobStoreImplementors::AzBlob => {
Arc::new(AzBlobContainer::new(slight_state, name).await?)
}
BlobStoreImplementors::None => {
panic!("No implementor specified")
}
},
};
Ok(container)
}
}
Loading