-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e97b32
commit 8f9d6e1
Showing
10 changed files
with
336 additions
and
54 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,49 +1,52 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::configure() | ||
.build_client(true) | ||
.build_server(true) | ||
.compile_protos( | ||
&[ | ||
"protos/V1/agent_common.proto", | ||
"protos/V1/agent_service.proto", | ||
"protos/V1/applications_common.proto", | ||
"protos/V1/applications_fields.proto", | ||
"protos/V1/applications_filters.proto", | ||
"protos/V1/applications_service.proto", | ||
"protos/V1/auth_common.proto", | ||
"protos/V1/auth_service.proto", | ||
"protos/V1/events_common.proto", | ||
"protos/V1/events_service.proto", | ||
"protos/V1/filters_common.proto", | ||
"protos/V1/objects.proto", | ||
"protos/V1/partitions_common.proto", | ||
"protos/V1/partitions_fields.proto", | ||
"protos/V1/partitions_filters.proto", | ||
"protos/V1/partitions_service.proto", | ||
"protos/V1/result_status.proto", | ||
"protos/V1/results_common.proto", | ||
"protos/V1/results_fields.proto", | ||
"protos/V1/results_filters.proto", | ||
"protos/V1/results_service.proto", | ||
"protos/V1/session_status.proto", | ||
"protos/V1/sessions_common.proto", | ||
"protos/V1/sessions_fields.proto", | ||
"protos/V1/sessions_filters.proto", | ||
"protos/V1/sessions_service.proto", | ||
"protos/V1/sort_direction.proto", | ||
"protos/V1/submitter_common.proto", | ||
"protos/V1/submitter_service.proto", | ||
"protos/V1/task_status.proto", | ||
"protos/V1/tasks_common.proto", | ||
"protos/V1/tasks_fields.proto", | ||
"protos/V1/tasks_filters.proto", | ||
"protos/V1/tasks_service.proto", | ||
"protos/V1/versions_common.proto", | ||
"protos/V1/versions_service.proto", | ||
"protos/V1/worker_common.proto", | ||
"protos/V1/worker_service.proto", | ||
], | ||
&["protos/V1"], | ||
)?; | ||
let builder = tonic_build::configure(); | ||
|
||
#[cfg(feature = "client")] | ||
let builder = builder.build_client(true); | ||
#[cfg(feature = "server")] | ||
let builder = builder.build_server(true); | ||
builder.compile_protos( | ||
&[ | ||
"protos/V1/agent_common.proto", | ||
"protos/V1/agent_service.proto", | ||
"protos/V1/applications_common.proto", | ||
"protos/V1/applications_fields.proto", | ||
"protos/V1/applications_filters.proto", | ||
"protos/V1/applications_service.proto", | ||
"protos/V1/auth_common.proto", | ||
"protos/V1/auth_service.proto", | ||
"protos/V1/events_common.proto", | ||
"protos/V1/events_service.proto", | ||
"protos/V1/filters_common.proto", | ||
"protos/V1/objects.proto", | ||
"protos/V1/partitions_common.proto", | ||
"protos/V1/partitions_fields.proto", | ||
"protos/V1/partitions_filters.proto", | ||
"protos/V1/partitions_service.proto", | ||
"protos/V1/result_status.proto", | ||
"protos/V1/results_common.proto", | ||
"protos/V1/results_fields.proto", | ||
"protos/V1/results_filters.proto", | ||
"protos/V1/results_service.proto", | ||
"protos/V1/session_status.proto", | ||
"protos/V1/sessions_common.proto", | ||
"protos/V1/sessions_fields.proto", | ||
"protos/V1/sessions_filters.proto", | ||
"protos/V1/sessions_service.proto", | ||
"protos/V1/sort_direction.proto", | ||
"protos/V1/submitter_common.proto", | ||
"protos/V1/submitter_service.proto", | ||
"protos/V1/task_status.proto", | ||
"protos/V1/tasks_common.proto", | ||
"protos/V1/tasks_fields.proto", | ||
"protos/V1/tasks_filters.proto", | ||
"protos/V1/tasks_service.proto", | ||
"protos/V1/versions_common.proto", | ||
"protos/V1/versions_service.proto", | ||
"protos/V1/worker_common.proto", | ||
"protos/V1/worker_service.proto", | ||
], | ||
&["protos/V1"], | ||
)?; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use tracing_subscriber::{prelude::*, EnvFilter}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), eyre::Report> { | ||
tracing_subscriber::registry() | ||
.with(tracing_subscriber::fmt::layer()) | ||
.with(EnvFilter::from_default_env()) | ||
.init(); | ||
let client = armonik::Client::new().await?; | ||
|
||
let session = tokio::time::timeout( | ||
tokio::time::Duration::from_secs(1), | ||
client.sessions().create([""], Default::default()), | ||
) | ||
.await??; | ||
|
||
println!("Created session {session} using partition"); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use std::sync::Arc; | ||
|
||
use tokio_util::sync::CancellationToken; | ||
use tracing_subscriber::{prelude::*, EnvFilter}; | ||
|
||
use armonik::server::SessionsServiceExt; | ||
use armonik::sessions; | ||
|
||
pub struct Server; | ||
|
||
impl armonik::server::SessionsService for Server { | ||
/// Get a sessions list using pagination, filters and sorting. | ||
async fn list( | ||
self: Arc<Self>, | ||
_request: sessions::list::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::list::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Get a session by its id. | ||
async fn get( | ||
self: Arc<Self>, | ||
_request: sessions::get::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::get::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Cancel a session by its id. | ||
async fn cancel( | ||
self: Arc<Self>, | ||
_request: sessions::cancel::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::cancel::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Create a session | ||
async fn create( | ||
self: Arc<Self>, | ||
_request: sessions::create::Request, | ||
cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::create::Response, tonic::Status> { | ||
tracing::info!("create called"); | ||
if let Some(()) = cancellation_token | ||
.run_until_cancelled(tokio::time::sleep(tokio::time::Duration::from_secs(2))) | ||
.await | ||
{ | ||
tracing::info!("create returned"); | ||
Ok(sessions::create::Response { | ||
session_id: String::from("abc"), | ||
}) | ||
} else { | ||
tracing::info!("client cancelled RPC"); | ||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; | ||
tracing::info!("future still running"); | ||
Err(tonic::Status::aborted("client cancelled RPC")) | ||
} | ||
} | ||
|
||
/// Pause a session by its id. | ||
async fn pause( | ||
self: Arc<Self>, | ||
_request: sessions::pause::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::pause::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Resume a paused session by its id. | ||
async fn resume( | ||
self: Arc<Self>, | ||
_request: sessions::resume::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::resume::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Close a session by its id. | ||
async fn close( | ||
self: Arc<Self>, | ||
_request: sessions::close::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::close::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Purge a session by its id. Removes Results data. | ||
async fn purge( | ||
self: Arc<Self>, | ||
_request: sessions::purge::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::purge::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Delete a session by its id. Removes metadata from Results, Sessions and Tasks associated to the session. | ||
async fn delete( | ||
self: Arc<Self>, | ||
_request: sessions::delete::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::delete::Response, tonic::Status> { | ||
todo!() | ||
} | ||
|
||
/// Stops clients and/or workers from submitting new tasks in the given session. | ||
async fn stop_submission( | ||
self: Arc<Self>, | ||
_request: sessions::stop_submission::Request, | ||
_cancellation_token: CancellationToken, | ||
) -> std::result::Result<sessions::stop_submission::Response, tonic::Status> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn main() -> Result<(), eyre::Report> { | ||
tracing_subscriber::registry() | ||
.with(tracing_subscriber::fmt::layer()) | ||
.with(EnvFilter::from_default_env()) | ||
.init(); | ||
tonic::transport::Server::builder() | ||
.add_service(Server.sessions_server()) | ||
.serve("127.0.0.1:3456".parse()?) | ||
.await?; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
mod sessions; | ||
|
||
pub use sessions::{SessionsService, SessionsServiceExt}; | ||
|
||
macro_rules! define_trait_methods { | ||
(trait $name:ident {$($(#[$attr:meta])* fn $service:ident::$method:ident ;)* $(--- $($body:tt)*)?}) => { | ||
pub trait $name { | ||
$( | ||
$(#[$attr])* | ||
fn $method( | ||
self: Arc<Self>, | ||
request: $service::$method::Request, | ||
cancellation_token: tokio_util::sync::CancellationToken, | ||
) -> impl std::future::Future<Output = std::result::Result<$service::$method::Response, tonic::Status>> + Send; | ||
)* | ||
$($($body)*)? | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! impl_trait_methods { | ||
(impl ($name:ty) for Arc<$type:ident> {$(fn $method:ident($request:ty) -> $response:ty {$inner:ident})* $(--- $($body:tt)*)?}) => { | ||
#[async_trait::async_trait] | ||
impl<T: $type + Send + Sync + 'static> $name for Arc<T> { | ||
$( | ||
async fn $method( | ||
&self, | ||
request: tonic::Request<$request>, | ||
) -> std::result::Result<tonic::Response<$response>, tonic::Status> { | ||
let server = self.clone(); | ||
let ct = tokio_util::sync::CancellationToken::new(); | ||
let _cancel_guard = ct.clone().drop_guard(); | ||
let fut = tokio::spawn(async move { server.$inner(request.into_inner().into(), ct).await}); | ||
match fut.await { | ||
Ok(Ok(res)) => Ok(tonic::Response::new(res.into())), | ||
Ok(Err(err)) => Err(err), | ||
Err(err) => Err(tonic::Status::internal(err.to_string())), | ||
} | ||
} | ||
)* | ||
$($($body)*)? | ||
} | ||
}; | ||
} | ||
|
||
use define_trait_methods; | ||
use impl_trait_methods; |
Oops, something went wrong.