1+ //! HTTP server for the admin web interface.
2+
13use crate :: state:: { State , UnitSelector } ;
24use anyhow:: Result ;
35use axum:: {
@@ -17,11 +19,16 @@ use tower_http::{
1719 services:: ServeDir , trace:: TraceLayer , validate_request:: ValidateRequestHeaderLayer ,
1820} ;
1921
22+ /// `GET /admin/action/{unit_selector}/{action}`
23+ ///
24+ /// Sets the next [`Action`] for all [`Unit`]s accepted by the [`UnitSelector`].
25+ ///
26+ /// [`Unit`]: pixie_shared::config::Unit
2027async fn action (
21- Path ( ( unit_filter , action) ) : Path < ( String , Action ) > ,
28+ Path ( ( unit_selector , action) ) : Path < ( String , Action ) > ,
2229 extract:: State ( state) : extract:: State < Arc < State > > ,
2330) -> impl IntoResponse {
24- let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_filter ) else {
31+ let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_selector ) else {
2532 return (
2633 StatusCode :: BAD_REQUEST ,
2734 "Invalid unit selector\n " . to_owned ( ) ,
@@ -36,11 +43,16 @@ async fn action(
3643 }
3744}
3845
46+ /// `GET /admin/curr_action/{unit_selector}/{action}`
47+ ///
48+ /// Sets the current [`Action`] for all [`Unit`]s accepted by the [`UnitSelector`].
49+ ///
50+ /// [`Unit`]: pixie_shared::config::Unit
3951async fn curr_action (
40- Path ( ( unit_filter , action) ) : Path < ( String , Action ) > ,
52+ Path ( ( unit_selector , action) ) : Path < ( String , Action ) > ,
4153 extract:: State ( state) : extract:: State < Arc < State > > ,
4254) -> impl IntoResponse {
43- let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_filter ) else {
55+ let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_selector ) else {
4456 return (
4557 StatusCode :: BAD_REQUEST ,
4658 "Invalid unit selector\n " . to_owned ( ) ,
@@ -55,8 +67,14 @@ async fn curr_action(
5567 }
5668}
5769
70+ /// `GET /admin/image/{unit_selector}/{image}`
71+ ///
72+ /// Sets the [`Image`] for all [`Unit`]s accepted by the [`UnitSelector`].
73+ ///
74+ /// [`Unit`]: pixie_shared::config::Unit
75+ /// [`Image`]: pixie_shared::Image
5876async fn image (
59- Path ( ( unit_filter , image) ) : Path < ( String , String ) > ,
77+ Path ( ( unit_selector , image) ) : Path < ( String , String ) > ,
6078 extract:: State ( state) : extract:: State < Arc < State > > ,
6179) -> impl IntoResponse {
6280 if !state. config . images . contains ( & image) {
@@ -66,7 +84,7 @@ async fn image(
6684 ) ;
6785 }
6886
69- let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_filter ) else {
87+ let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_selector ) else {
7088 return (
7189 StatusCode :: BAD_REQUEST ,
7290 "Invalid unit selector\n " . to_owned ( ) ,
@@ -80,11 +98,16 @@ async fn image(
8098 }
8199}
82100
101+ /// `GET /admin/forget/{unit_selector}`
102+ ///
103+ /// Forgets all [`Unit`]s selected by the [`UnitSelector`].
104+ ///
105+ /// [`Unit`]: pixie_shared::config::Unit
83106async fn forget (
84- Path ( unit_filter ) : Path < String > ,
107+ Path ( unit_selector ) : Path < String > ,
85108 extract:: State ( state) : extract:: State < Arc < State > > ,
86109) -> impl IntoResponse {
87- let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_filter ) else {
110+ let Some ( unit_selector) = UnitSelector :: parse ( & state, unit_selector ) else {
88111 return (
89112 StatusCode :: BAD_REQUEST ,
90113 "Invalid unit selector\n " . to_owned ( ) ,
@@ -119,13 +142,19 @@ async fn delete_image(
119142 }
120143}
121144
145+ /// `GET /admin/gc`
146+ ///
147+ /// Removes all chunks not used by any image.
122148async fn gc ( extract:: State ( state) : extract:: State < Arc < State > > ) -> impl IntoResponse {
123149 match state. gc_chunks ( ) {
124150 Ok ( ( ) ) => ( StatusCode :: NO_CONTENT , String :: new ( ) ) ,
125151 Err ( e) => ( StatusCode :: INTERNAL_SERVER_ERROR , format ! ( "{e}\n " ) ) ,
126152 }
127153}
128154
155+ /// `GET /admin/status`
156+ ///
157+ /// Stream of json-formatted events on changes to the database.
129158async fn status ( extract:: State ( state) : extract:: State < Arc < State > > ) -> impl IntoResponse {
130159 let initial_messages = [ StatusUpdate :: Config ( state. config . clone ( ) ) ] ;
131160
@@ -161,10 +190,13 @@ pub async fn main(state: Arc<State>) -> Result<()> {
161190 let mut router = Router :: new ( )
162191 . route ( "/admin/status" , get ( status) )
163192 . route ( "/admin/gc" , get ( gc) )
164- . route ( "/admin/action/:unit/:action" , get ( action) )
165- . route ( "/admin/curr_action/:unit/:action" , get ( curr_action) )
166- . route ( "/admin/image/:unit/:image" , get ( image) )
167- . route ( "/admin/forget/:unit" , get ( forget) )
193+ . route ( "/admin/action/:unit_selector/:action" , get ( action) )
194+ . route (
195+ "/admin/curr_action/:unit_selector/:action" ,
196+ get ( curr_action) ,
197+ )
198+ . route ( "/admin/image/:unit_selector/:image" , get ( image) )
199+ . route ( "/admin/forget/:unit_selector" , get ( forget) )
168200 . route ( "/admin/rollback/:image" , get ( rollback) )
169201 . route ( "/admin/delete/:image" , get ( delete_image) )
170202 . nest_service (
0 commit comments