agent: Convert image service to be async

With the runtime-rs changes the agent services need to be asynchronous,
so attempt to update the image_service to match this

Co-authored-by: Georgina Kinge <georgina.kinge@ibm.com>
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman 2022-08-17 17:01:29 +01:00
parent acb7a16522
commit 73566bb4b9
4 changed files with 36 additions and 16 deletions

View File

@ -257,7 +257,7 @@ impl ImageService {
}
#[async_trait]
impl protocols::image_ttrpc::Image for ImageService {
impl protocols::image_ttrpc_async::Image for ImageService {
async fn pull_image(
&self,
_ctx: &ttrpc::r#async::TtrpcContext,

View File

@ -34,7 +34,10 @@ use protocols::health::{
HealthCheckResponse, HealthCheckResponse_ServingStatus, VersionCheckResponse,
};
use protocols::types::Interface;
use protocols::{agent_ttrpc_async as agent_ttrpc, health_ttrpc_async as health_ttrpc};
use protocols::{
agent_ttrpc_async as agent_ttrpc, health_ttrpc_async as health_ttrpc,
image_ttrpc_async as image_ttrpc,
};
use rustjail::cgroups::notifier;
use rustjail::container::{BaseContainer, Container, LinuxContainer};
use rustjail::process::Process;
@ -1744,27 +1747,26 @@ async fn read_stream(reader: Arc<Mutex<ReadHalf<PipeStream>>>, l: usize) -> Resu
pub fn start(s: Arc<Mutex<Sandbox>>, server_address: &str) -> Result<TtrpcServer> {
let agent_service = Box::new(AgentService { sandbox: s.clone() })
as Box<dyn protocols::agent_ttrpc::AgentService + Send + Sync>;
as Box<dyn agent_ttrpc::AgentService + Send + Sync>;
let agent_worker = Arc::new(agent_service);
let health_service = Box::new(HealthService {}) as Box<dyn health_ttrpc::Health + Send + Sync>;
let health_worker = Arc::new(health_service);
let image_service = Box::new(image_rpc::ImageService::new(s))
as Box<dyn protocols::image_ttrpc::Image + Send + Sync>;
let image_service =
Box::new(image_rpc::ImageService::new(s)) as Box<dyn image_ttrpc::Image + Send + Sync>;
let agent_service = protocols::agent_ttrpc::create_agent_service(agent_worker);
let aservice = agent_ttrpc::create_agent_service(agent_worker);
let health_service = protocols::health_ttrpc::create_health(health_worker);
let hservice = health_ttrpc::create_health(health_worker);
let image_service = protocols::image_ttrpc::create_image(Arc::new(image_service));
let iservice = image_ttrpc::create_image(Arc::new(image_service));
let server = TtrpcServer::new()
.bind(server_address)?
.register_service(agent_service)
.register_service(health_service)
.register_service(image_service);
.register_service(aservice)
.register_service(hservice)
.register_service(iservice);
info!(sl!(), "ttRPC server started"; "address" => server_address);

View File

@ -150,7 +150,6 @@ fn real_main() -> Result<(), std::io::Error> {
"protos/oci.proto",
"protos/types.proto",
"protos/csi.proto",
"protos/image.proto",
],
false,
)?;
@ -158,13 +157,30 @@ fn real_main() -> Result<(), std::io::Error> {
// generate async
#[cfg(feature = "async")]
{
codegen("src", &["protos/agent.proto", "protos/health.proto"], true)?;
codegen(
"src",
&[
"protos/agent.proto",
"protos/health.proto",
"protos/image.proto",
],
true,
)?;
fs::rename("src/agent_ttrpc.rs", "src/agent_ttrpc_async.rs")?;
fs::rename("src/health_ttrpc.rs", "src/health_ttrpc_async.rs")?;
fs::rename("src/image_ttrpc.rs", "src/image_ttrpc_async.rs")?;
}
codegen("src", &["protos/agent.proto", "protos/health.proto"], false)?;
codegen(
"src",
&[
"protos/agent.proto",
"protos/health.proto",
"protos/image.proto",
],
false,
)?;
// There is a message named 'Box' in oci.proto
// so there is a struct named 'Box', we should replace Box<Self> to ::std::boxed::Box<Self>

View File

@ -13,10 +13,12 @@ pub mod csi;
pub mod empty;
pub mod health;
pub mod health_ttrpc;
#[cfg(feature = "async")]
pub mod health_ttrpc_async;
pub mod image;
pub mod image_ttrpc;
#[cfg(feature = "async")]
pub mod health_ttrpc_async;
pub mod image_ttrpc_async;
pub mod oci;
pub mod trans;
pub mod types;