From 53375609322397194d7ea3251f22144661da31a1 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Mon, 1 Feb 2021 13:13:47 -0500 Subject: [PATCH] [wip] Integrate updated Dropshot API --- src/oxide_controller/mod.rs | 28 +++++++--------------------- src/sled_agent/mod.rs | 16 ++++++---------- tests/common/mod.rs | 11 +++-------- tests/test_basic.rs | 6 +----- 4 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/oxide_controller/mod.rs b/src/oxide_controller/mod.rs index 3b0f710814..d2a5b0467d 100644 --- a/src/oxide_controller/mod.rs +++ b/src/oxide_controller/mod.rs @@ -21,7 +21,6 @@ use http_entrypoints_internal::controller_internal_api; use slog::Logger; use std::sync::Arc; -use tokio::task::JoinHandle; use uuid::Uuid; /** @@ -49,11 +48,6 @@ pub struct OxideControllerServer { pub http_server_external: dropshot::HttpServer, /** dropshot server for internal API */ pub http_server_internal: dropshot::HttpServer, - - /** task handle for the external API server */ - join_handle_external: JoinHandle>, - /** task handle for the internal API server */ - join_handle_internal: JoinHandle>, } impl OxideControllerServer { @@ -71,7 +65,7 @@ impl OxideControllerServer { let apictx = ControllerServerContext::new(rack_id, ctxlog); let c1 = Arc::clone(&apictx); - let mut http_server_external = dropshot::HttpServer::new( + let http_server_starter_external = dropshot::HttpServerStarter::new( &config.dropshot_external, controller_external_api(), c1, @@ -80,7 +74,7 @@ impl OxideControllerServer { .map_err(|error| format!("initializing external server: {}", error))?; let c2 = Arc::clone(&apictx); - let mut http_server_internal = dropshot::HttpServer::new( + let http_server_starter_internal = dropshot::HttpServerStarter::new( &config.dropshot_internal, controller_internal_api(), c2, @@ -88,15 +82,13 @@ impl OxideControllerServer { ) .map_err(|error| format!("initializing internal server: {}", error))?; - let join_handle_external = http_server_external.run(); - let join_handle_internal = http_server_internal.run(); + let http_server_external = http_server_starter_external.start(); + let http_server_internal = http_server_starter_internal.start(); Ok(OxideControllerServer { apictx, http_server_external, http_server_internal, - join_handle_external, - join_handle_internal, }) } @@ -107,15 +99,9 @@ impl OxideControllerServer { * immediately after calling `start()`, the program will block indefinitely * or until something else initiates a graceful shutdown. */ - pub async fn wait_for_finish(mut self) -> Result<(), String> { - let result_external = self - .http_server_external - .wait_for_shutdown(self.join_handle_external) - .await; - let result_internal = self - .http_server_internal - .wait_for_shutdown(self.join_handle_internal) - .await; + pub async fn wait_for_finish(self) -> Result<(), String> { + let result_external = self.http_server_external.await; + let result_internal = self.http_server_internal.await; match (result_external, result_internal) { (Ok(()), Ok(())) => Ok(()), diff --git a/src/sled_agent/mod.rs b/src/sled_agent/mod.rs index 0181d3578d..be840f73f9 100644 --- a/src/sled_agent/mod.rs +++ b/src/sled_agent/mod.rs @@ -19,7 +19,6 @@ use sled_agent::SledAgent; use slog::Logger; use std::sync::Arc; use std::time::Duration; -use tokio::task::JoinHandle; /** * Delay time in milliseconds between attempts to notify OXC about a sled agent @@ -36,8 +35,6 @@ pub struct SledAgentServer { pub sled_agent: Arc, /** dropshot server for the API */ pub http_server: dropshot::HttpServer, - /** task handle for the dropshot server */ - join_handle: JoinHandle>, } impl SledAgentServer { @@ -69,15 +66,14 @@ impl SledAgentServer { let sa = Arc::clone(&sled_agent); let dropshot_log = log.new(o!("component" => "dropshot")); - let mut http_server = dropshot::HttpServer::new( + let http_server = dropshot::HttpServerStarter::new( &config.dropshot, http_entrypoints::sa_api(), sa, &dropshot_log, ) - .map_err(|error| format!("initializing server: {}", error))?; - - let join_handle = http_server.run(); + .map_err(|error| format!("initializing server: {}", error))? + .start(); /* * Notify the control plane that we're up, and continue trying this @@ -113,7 +109,7 @@ impl SledAgentServer { info!(log, "contacted server controller"); - Ok(SledAgentServer { sled_agent, http_server, join_handle }) + Ok(SledAgentServer { sled_agent, http_server }) } /** @@ -123,8 +119,8 @@ impl SledAgentServer { * immediately after calling `start()`, the program will block indefinitely * or until something else initiates a graceful shutdown. */ - pub async fn wait_for_finish(mut self) -> Result<(), String> { - self.http_server.wait_for_shutdown(self.join_handle).await + pub async fn wait_for_finish(self) -> Result<(), String> { + self.http_server.await } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4c67569d28..f5459fcb15 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -31,14 +31,9 @@ pub struct ControlPlaneTestContext { impl ControlPlaneTestContext { pub async fn teardown(self) { - self.server.http_server_external.close(); - self.server.http_server_internal.close(); - /* - * TODO-correctness - * can we (/ how do we?) wait for these things to shut down? We want to - * use wait_for_finish() here on the http servers. - */ - self.sled_agent.http_server.close(); + self.server.http_server_external.close().await.unwrap(); + self.server.http_server_internal.close().await.unwrap(); + self.sled_agent.http_server.close().await.unwrap(); self.logctx.cleanup_successful(); } } diff --git a/tests/test_basic.rs b/tests/test_basic.rs index 2a40b4bd22..06c0ee2d5c 100644 --- a/tests/test_basic.rs +++ b/tests/test_basic.rs @@ -615,11 +615,7 @@ async fn test_sleds_list() { /* Tear down the agents. */ for sa in sas { - /* - * TODO-correctness see note in testctx.teardown() about shutting down - * sled agents. - */ - sa.http_server.close(); + sa.http_server.close().await.unwrap(); } testctx.teardown().await;