feat/web: Patchset 3 (#455)
https://apifox.com/apidoc/shared-ceda7a60-e817-4ea8-827b-de4e874dc45e implement all backend API
This commit is contained in:
@@ -55,7 +55,6 @@ pub fn join_joinset_background<T: Debug + Send + Sync + 'static>(
|
||||
}
|
||||
|
||||
future::poll_fn(|cx| {
|
||||
tracing::debug!("try join joinset tasks");
|
||||
let Some(js) = js.upgrade() else {
|
||||
return std::task::Poll::Ready(());
|
||||
};
|
||||
|
||||
@@ -17,6 +17,12 @@ impl From<Uuid> for uuid::Uuid {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Uuid {
|
||||
fn from(value: String) -> Self {
|
||||
uuid::Uuid::parse_str(&value).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Uuid {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", uuid::Uuid::from(self.clone()))
|
||||
|
||||
@@ -36,6 +36,12 @@ message HeartbeatRequest {
|
||||
common.UUID machine_id = 1;
|
||||
common.UUID inst_id = 2;
|
||||
string user_token = 3;
|
||||
|
||||
string easytier_version = 4;
|
||||
string report_time = 5;
|
||||
string hostname = 6;
|
||||
|
||||
repeated common.UUID running_network_instances = 7;
|
||||
}
|
||||
|
||||
message HeartbeatResponse {
|
||||
@@ -53,10 +59,12 @@ message ValidateConfigResponse {
|
||||
}
|
||||
|
||||
message RunNetworkInstanceRequest {
|
||||
string config = 1;
|
||||
common.UUID inst_id = 1;
|
||||
string config = 2;
|
||||
}
|
||||
|
||||
message RunNetworkInstanceResponse {
|
||||
common.UUID inst_id = 1;
|
||||
}
|
||||
|
||||
message RetainNetworkInstanceRequest {
|
||||
|
||||
@@ -547,7 +547,7 @@ impl ZCPacket {
|
||||
ZCPacketType::NIC => unreachable!(),
|
||||
};
|
||||
|
||||
tracing::debug!(?self.packet_type, ?target_packet_type, ?new_offset, "convert zc packet type");
|
||||
tracing::trace!(?self.packet_type, ?target_packet_type, ?new_offset, "convert zc packet type");
|
||||
|
||||
if new_offset == INVALID_OFFSET {
|
||||
// copy peer manager header and payload to new buffer
|
||||
|
||||
@@ -101,8 +101,14 @@ impl WebClientService for Controller {
|
||||
req: RunNetworkInstanceRequest,
|
||||
) -> Result<RunNetworkInstanceResponse, rpc_types::error::Error> {
|
||||
let cfg = TomlConfigLoader::new_from_str(&req.config)?;
|
||||
let id = cfg.get_id();
|
||||
if let Some(inst_id) = req.inst_id {
|
||||
cfg.set_id(inst_id.into());
|
||||
}
|
||||
self.run_network_instance(cfg)?;
|
||||
Ok(RunNetworkInstanceResponse {})
|
||||
Ok(RunNetworkInstanceResponse {
|
||||
inst_id: Some(id.into()),
|
||||
})
|
||||
}
|
||||
|
||||
async fn retain_network_instance(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use tokio::{
|
||||
sync::{broadcast, Mutex},
|
||||
@@ -7,7 +7,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
common::get_machine_id,
|
||||
common::{constants::EASYTIER_VERSION, get_machine_id},
|
||||
proto::{
|
||||
rpc_impl::bidirect::BidirectRpcManager,
|
||||
rpc_types::controller::BaseController,
|
||||
@@ -47,7 +47,8 @@ impl Session {
|
||||
.register(WebClientServiceServer::new(controller.clone()), "");
|
||||
|
||||
let mut tasks: JoinSet<()> = JoinSet::new();
|
||||
let heartbeat_ctx = Self::heartbeat_routine(&rpc_mgr, controller.token(), &mut tasks);
|
||||
let heartbeat_ctx =
|
||||
Self::heartbeat_routine(&rpc_mgr, Arc::downgrade(&controller), &mut tasks);
|
||||
|
||||
Session {
|
||||
rpc_mgr,
|
||||
@@ -59,7 +60,7 @@ impl Session {
|
||||
|
||||
fn heartbeat_routine(
|
||||
rpc_mgr: &BidirectRpcManager,
|
||||
token: String,
|
||||
controller: Weak<Controller>,
|
||||
tasks: &mut JoinSet<()>,
|
||||
) -> HeartbeatCtx {
|
||||
let (tx, _rx1) = broadcast::channel(2);
|
||||
@@ -71,7 +72,8 @@ impl Session {
|
||||
|
||||
let mid = get_machine_id();
|
||||
let inst_id = uuid::Uuid::new_v4();
|
||||
let token = token;
|
||||
let token = controller.upgrade().unwrap().token();
|
||||
let hostname = gethostname::gethostname().to_string_lossy().to_string();
|
||||
|
||||
let ctx_clone = ctx.clone();
|
||||
let mut tick = interval(std::time::Duration::from_secs(1));
|
||||
@@ -79,13 +81,29 @@ impl Session {
|
||||
.rpc_client()
|
||||
.scoped_client::<WebServerServiceClientFactory<BaseController>>(1, 1, "".to_string());
|
||||
tasks.spawn(async move {
|
||||
let req = HeartbeatRequest {
|
||||
machine_id: Some(mid.into()),
|
||||
inst_id: Some(inst_id.into()),
|
||||
user_token: token.to_string(),
|
||||
};
|
||||
loop {
|
||||
tick.tick().await;
|
||||
|
||||
let Some(controller) = controller.upgrade() else {
|
||||
break;
|
||||
};
|
||||
|
||||
let req = HeartbeatRequest {
|
||||
machine_id: Some(mid.into()),
|
||||
inst_id: Some(inst_id.into()),
|
||||
user_token: token.to_string(),
|
||||
|
||||
easytier_version: EASYTIER_VERSION.to_string(),
|
||||
hostname: hostname.clone(),
|
||||
report_time: chrono::Local::now().to_string(),
|
||||
|
||||
running_network_instances: controller
|
||||
.list_network_instance_ids()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
match client
|
||||
.heartbeat(BaseController::default(), req.clone())
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user