-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin implementation of storage connector
- Loading branch information
Showing
16 changed files
with
350 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "dash-pipe-connector-storage" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
authors = ["Ho Kim <[email protected]>"] | ||
description = "Kubernetes Is Simple, Stupid which a part of OpenARK" | ||
documentation = "https://docs.rs/kiss-api" | ||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
readme = "../../README.md" | ||
homepage = "https://github.com/ulagbulag/OpenARK" | ||
repository = "https://github.com/ulagbulag/OpenARK" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dash-pipe-provider = { path = "../../provider" } | ||
|
||
anyhow = { workspace = true } | ||
async-trait = { workspace = true } | ||
clap = { workspace = true } | ||
futures = { workspace = true } | ||
serde = { workspace = true } | ||
tokio = { workspace = true, features = ["time"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::{bail, Result}; | ||
use async_trait::async_trait; | ||
use clap::{ArgAction, Parser}; | ||
use dash_pipe_provider::{ | ||
FunctionContext, PipeArgs, PipeMessage, PipeMessages, PipePayload, StorageSet, StorageType, | ||
Stream, | ||
}; | ||
use futures::StreamExt; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
fn main() { | ||
PipeArgs::<Function>::from_env().loop_forever() | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, Parser)] | ||
pub struct FunctionArgs { | ||
#[arg(long, env = "PIPE_PERSISTENCE", action = ArgAction::SetTrue)] | ||
#[serde(default)] | ||
persistence: Option<bool>, | ||
} | ||
|
||
pub struct Function { | ||
ctx: FunctionContext, | ||
items: Stream, | ||
} | ||
|
||
#[async_trait(?Send)] | ||
impl ::dash_pipe_provider::Function for Function { | ||
type Args = FunctionArgs; | ||
type Input = (); | ||
type Output = usize; | ||
|
||
async fn try_new( | ||
args: &<Self as ::dash_pipe_provider::Function>::Args, | ||
ctx: &mut FunctionContext, | ||
storage: &Arc<StorageSet>, | ||
) -> Result<Self> { | ||
let storage_type = match args.persistence { | ||
Some(true) => StorageType::PERSISTENT, | ||
Some(false) | None => StorageType::TEMPORARY, | ||
}; | ||
|
||
Ok(Self { | ||
ctx: ctx.clone(), | ||
items: storage.get(storage_type).list().await?, | ||
}) | ||
} | ||
|
||
async fn tick( | ||
&mut self, | ||
_inputs: PipeMessages<<Self as ::dash_pipe_provider::Function>::Input>, | ||
) -> Result<PipeMessages<<Self as ::dash_pipe_provider::Function>::Output>> { | ||
match self.items.next().await { | ||
// TODO: stream이 JSON 메타데이터를 포함한 PipeMessage Object를 배출 | ||
Some(Ok((path, value))) => Ok(PipeMessages::Single(PipeMessage { | ||
payloads: vec![PipePayload::new(path.to_string(), value)], | ||
value: Default::default(), | ||
})), | ||
Some(Err(error)) => bail!("failed to load data: {error}"), | ||
None => self.ctx.terminate_ok(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.