Skip to content

Commit

Permalink
Merge pull request #127 from k82cn/sdk_rs_fix
Browse files Browse the repository at this point in the history
Enhance rust sdk.
  • Loading branch information
k82cn authored Feb 9, 2025
2 parents e32421e + 10b3436 commit b0c0247
Show file tree
Hide file tree
Showing 29 changed files with 276 additions and 437 deletions.
43 changes: 12 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ members = [
"session_manager",
"executor_manager",
"rpc",
"sdk/rust/service",
"sdk/rust/client",
"sdk/rust",
]

[workspace.dependencies]
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ci-image:
sudo docker build -t xflops/flame-console -f docker/Dockerfile.console .

update_protos:
cp rpc/protos/frontend.proto sdk/rust/client/protos
cp rpc/protos/types.proto sdk/rust/client/protos
cp rpc/protos/shim.proto sdk/rust/service/protos
cp rpc/protos/types.proto sdk/rust/service/protos
cp rpc/protos/frontend.proto sdk/rust/protos
cp rpc/protos/types.proto sdk/rust/protos
cp rpc/protos/shim.proto sdk/rust/protos
3 changes: 1 addition & 2 deletions flmctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
flame-client = { path = "../sdk/rust/client" }
common = { path = "../common" }
flame-rs = { path = "../sdk/rust" }

tokio = { workspace = true }
tonic = { workspace = true }
Expand Down
8 changes: 3 additions & 5 deletions flmctl/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ limitations under the License.

use std::error::Error;

use common::ctx::FlameContext;

use self::flame::SessionAttributes;
use flame_client as flame;
use flame_rs as flame;
use flame_rs::{apis::FlameContext, client::SessionAttributes};

pub async fn run(ctx: &FlameContext, app: &str, slots: &i32) -> Result<(), Box<dyn Error>> {
let conn = flame::connect(&ctx.endpoint).await?;
let conn = flame::client::connect(&ctx.endpoint).await?;
let attr = SessionAttributes {
application: app.to_owned(),
slots: *slots,
Expand Down
8 changes: 4 additions & 4 deletions flmctl/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ limitations under the License.
use std::cmp::Ordering;
use std::error::Error;

use common::ctx::FlameContext;
use flame_client::SessionState;
use flame_client::{self as flame, Connection, FlameError};
use flame_rs as flame;
use flame_rs::apis::{FlameContext, FlameError, SessionState};
use flame_rs::client::Connection;

pub async fn run(
ctx: &FlameContext,
application: bool,
session: bool,
) -> Result<(), Box<dyn Error>> {
let conn = flame::connect(&ctx.endpoint).await?;
let conn = flame::client::connect(&ctx.endpoint).await?;
match (application, session) {
(true, false) => list_application(conn).await,
(false, true) => list_session(conn).await,
Expand Down
2 changes: 1 addition & 1 deletion flmctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
use std::error::Error;

use clap::{Parser, Subcommand};
use common::ctx::FlameContext;
use flame_rs::apis::FlameContext;

mod create;
mod helper;
Expand Down
3 changes: 1 addition & 2 deletions flmctl/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ limitations under the License.

use std::error::Error;

use flame_rs::apis::FlameContext;
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
use url::Url;

use common::ctx::FlameContext;

pub async fn run(_: &FlameContext, url: &str, sql: &str) -> Result<(), Box<dyn Error>> {
let uri = Url::parse(url)?;

Expand Down
12 changes: 8 additions & 4 deletions flmctl/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ limitations under the License.

use std::{fs, path::Path};

use serde_derive::{Deserialize, Serialize};
use flame_rs as flame;
use flame_rs::apis::Shim;
use flame_rs::{
apis::{FlameContext, FlameError},
client::ApplicationAttributes,
};

use common::ctx::FlameContext;
use flame_client::{self as flame, ApplicationAttributes, FlameError, Shim};
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct MetadataYaml {
Expand Down Expand Up @@ -53,7 +57,7 @@ pub async fn run(ctx: &FlameContext, path: &String) -> Result<(), FlameError> {

let app_attr = ApplicationAttributes::try_from(&app)?;

let conn = flame::connect(&ctx.endpoint).await?;
let conn = flame::client::connect(&ctx.endpoint).await?;

conn.register_application(app.metadata.name, app_attr)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion flmctl/src/unregister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ limitations under the License.

use std::error::Error;

use common::ctx::FlameContext;
use flame_rs::apis::FlameContext;

pub async fn run(_: &FlameContext, _: &String) -> Result<(), Box<dyn Error>> {
todo!()
Expand Down
2 changes: 1 addition & 1 deletion flmctl/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ limitations under the License.

use std::error::Error;

use common::ctx::FlameContext;
use flame_rs::apis::FlameContext;

pub async fn run(_: &FlameContext, _: &String) -> Result<(), Box<dyn Error>> {
todo!()
Expand Down
4 changes: 1 addition & 3 deletions flmexec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
flame-client = { path = "../sdk/rust/client" }
rpc = { path = "../rpc" }
common = { path = "../common" }
flame-rs = { path = "../sdk/rust" }

tokio = { workspace = true }
tonic = { workspace = true }
Expand Down
14 changes: 7 additions & 7 deletions flmexec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use chrono::Local;
use clap::Parser;
use indicatif::HumanCount;

use self::flame::FlameError;
use common::ctx::FlameContext;
use flame_client as flame;
use flame_rs as flame;
use flame_rs::apis::{FlameContext, FlameError};
use flame_rs::client::{SessionAttributes, Task, TaskInformer};

#[derive(Parser)]
#[command(name = "flmexec")]
Expand Down Expand Up @@ -54,10 +54,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
let slots = cli.slots.unwrap_or(DEFAULT_SLOTS);
let task_num = cli.task_num.unwrap_or(DEFAULT_TASK_NUM);

let conn = flame::connect(&ctx.endpoint).await?;
let conn = flame::client::connect(&ctx.endpoint).await?;

let ssn_creation_start_time = Local::now();
let ssn_attr = flame::SessionAttributes {
let ssn_attr = SessionAttributes {
application: DEFAULT_APP.to_string(),
slots,
common_data: None,
Expand Down Expand Up @@ -97,8 +97,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

struct ExecInfo {}

impl flame::TaskInformer for ExecInfo {
fn on_update(&mut self, task: flame::Task) {
impl TaskInformer for ExecInfo {
fn on_update(&mut self, task: Task) {
if task.is_completed() {
println!(
"Task {:<10}: {:?}",
Expand Down
5 changes: 1 addition & 4 deletions flmping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
flame-client = { path = "../sdk/rust/client" }
flame-service = { path = "../sdk/rust/service" }

common = { path = "../common" }
flame-rs = { path = "../sdk/rust" }

tokio = { workspace = true }
tonic = { workspace = true }
Expand Down
15 changes: 8 additions & 7 deletions flmping/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ use std::sync::{Arc, Mutex};

use chrono::Local;
use clap::Parser;
use flame_rs::apis::FlameError;
use flame_rs::client::{SessionAttributes, Task, TaskInformer};
use futures::future::try_join_all;
use indicatif::HumanCount;

use self::flame::FlameError;
use common::ctx::FlameContext;
use flame_client::{self as flame, new_ptr};
use flame::apis::FlameContext;
use flame_rs::{self as flame, new_ptr};

#[derive(Parser)]
#[command(name = "flmping")]
Expand Down Expand Up @@ -51,10 +52,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
let slots = cli.slots.unwrap_or(DEFAULT_SLOTS);
let task_num = cli.task_num.unwrap_or(DEFAULT_TASK_NUM);

let conn = flame::connect(&ctx.endpoint).await?;
let conn = flame::client::connect(&ctx.endpoint).await?;

let ssn_creation_start_time = Local::now();
let ssn_attr = flame::SessionAttributes {
let ssn_attr = SessionAttributes {
application: DEFAULT_APP.to_string(),
slots,
common_data: None,
Expand Down Expand Up @@ -102,8 +103,8 @@ impl OutputInfor {
}
}

impl flame::TaskInformer for OutputInfor {
fn on_update(&mut self, task: flame::Task) {
impl TaskInformer for OutputInfor {
fn on_update(&mut self, task: Task) {
if task.is_completed() {
let output = task.output.unwrap_or_default();
println!(
Expand Down
10 changes: 7 additions & 3 deletions flmping/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ limitations under the License.
*/
use gethostname::gethostname;

use flame_service::{self as flame, FlameError, SessionContext, TaskContext, TaskOutput};
use flame_rs::{
self as flame,
apis::{FlameError, TaskOutput},
service::{SessionContext, TaskContext},
};

#[derive(Clone)]
pub struct FlmpingService {}

#[tonic::async_trait]
impl flame::FlameService for FlmpingService {
impl flame::service::FlameService for FlmpingService {
async fn on_session_enter(&self, _: SessionContext) -> Result<(), FlameError> {
Ok(())
}
Expand All @@ -41,7 +45,7 @@ impl flame::FlameService for FlmpingService {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

flame_service::run(FlmpingService {}).await?;
flame::service::run(FlmpingService {}).await?;

log::debug!("FlmpingService was stopped.");

Expand Down
Loading

0 comments on commit b0c0247

Please sign in to comment.