Skip to content

Commit 0d38fbf

Browse files
committed
Adapt server to use manager
1 parent b56780f commit 0d38fbf

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

rust/agama-manager/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ merge-struct = "0.1.0"
2222

2323
[dev-dependencies]
2424
tokio-test = "0.4.4"
25+
26+
[lints.rust]
27+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] }

rust/agama-manager/src/start.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ pub async fn start(
8181

8282
#[cfg(test)]
8383
mod test {
84-
use crate::supervisor::{self, l10n, message, service::Service};
85-
use agama_lib::{http::Event, install_settings::InstallSettings};
84+
use crate::{self as manager, l10n, message, service::Service};
85+
use agama_lib::{http, install_settings::InstallSettings};
8686
use agama_utils::actor::Handler;
8787
use tokio::sync::broadcast;
8888

8989
async fn start_service() -> Handler<Service> {
90-
let (events_tx, _events_rx) = broadcast::channel::<Event>(16);
91-
supervisor::start(events_tx, None).await.unwrap()
90+
let (events_sender, _events_receiver) = broadcast::channel::<http::Event>(16);
91+
manager::start(events_sender, None).await.unwrap()
9292
}
9393

9494
#[tokio::test]

rust/agama-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ agama-locale-data = { path = "../agama-locale-data" }
1212
agama-lib = { path = "../agama-lib" }
1313
agama-utils = { path = "../agama-utils" }
1414
agama-l10n = { path = "../agama-l10n" }
15+
agama-manager = { path = "../agama-manager" }
1516
zbus = { version = "5", default-features = false, features = ["tokio"] }
1617
uuid = { version = "1.10.0", features = ["v4"] }
1718
thiserror = "2.0.12"

rust/agama-server/src/server/web.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020

2121
//! This module implements Agama's HTTP API.
2222
23-
use crate::{
24-
supervisor::{self, message, ConfigScope, Scope, Service, SystemInfo},
25-
web::EventsSender,
26-
};
27-
use agama_lib::{error::ServiceError, install_settings::InstallSettings};
23+
use agama_lib::{error::ServiceError, http, install_settings::InstallSettings};
24+
use agama_manager::{self as manager, message, ConfigScope, Scope, SystemInfo};
2825
use agama_utils::actor::Handler;
2926
use anyhow;
3027
use axum::{
@@ -44,7 +41,7 @@ pub enum Error {
4441
#[error("The given configuration does not belong to the '{0}' scope.")]
4542
Scope(Scope),
4643
#[error(transparent)]
47-
Supervisor(#[from] supervisor::service::Error),
44+
Manager(#[from] manager::service::Error),
4845
}
4946

5047
impl IntoResponse for Error {
@@ -66,7 +63,7 @@ fn to_option_response<T: Serialize>(value: Option<T>) -> Response {
6663

6764
#[derive(Clone)]
6865
pub struct ServerState {
69-
supervisor: Handler<Service>,
66+
manager: Handler<manager::Service>,
7067
}
7168

7269
type ServerResult<T> = Result<T, Error>;
@@ -77,14 +74,14 @@ type ServerResult<T> = Result<T, Error>;
7774
/// * `dbus`: connection to Agama's D-Bus server. If it is not given, those features
7875
/// that require to connect to the Agama's D-Bus server won't work.
7976
pub async fn server_service(
80-
events: EventsSender,
77+
events: http::event::Sender,
8178
dbus: Option<zbus::Connection>,
8279
) -> Result<Router, ServiceError> {
83-
let supervisor = supervisor::start(events, dbus)
80+
let manager = manager::start(events, dbus)
8481
.await
8582
.map_err(|e| anyhow::Error::new(e))?;
8683

87-
let state = ServerState { supervisor };
84+
let state = ServerState { manager };
8885

8986
Ok(Router::new()
9087
.route("/status", get(get_status))
@@ -118,7 +115,7 @@ pub async fn server_service(
118115
)
119116
)]
120117
async fn get_status(State(state): State<ServerState>) -> ServerResult<Json<message::Status>> {
121-
let status = state.supervisor.call(message::GetStatus).await?;
118+
let status = state.manager.call(message::GetStatus).await?;
122119
Ok(Json(status))
123120
}
124121

@@ -133,7 +130,7 @@ async fn get_status(State(state): State<ServerState>) -> ServerResult<Json<messa
133130
)
134131
)]
135132
async fn get_system(State(state): State<ServerState>) -> ServerResult<Json<SystemInfo>> {
136-
let system = state.supervisor.call(message::GetSystem).await?;
133+
let system = state.manager.call(message::GetSystem).await?;
137134
Ok(Json(system))
138135
}
139136

@@ -150,7 +147,7 @@ async fn get_system(State(state): State<ServerState>) -> ServerResult<Json<Syste
150147
async fn get_extended_config(
151148
State(state): State<ServerState>,
152149
) -> ServerResult<Json<InstallSettings>> {
153-
let config = state.supervisor.call(message::GetExtendedConfig).await?;
150+
let config = state.manager.call(message::GetExtendedConfig).await?;
154151
Ok(Json(config))
155152
}
156153

@@ -172,7 +169,7 @@ async fn get_extended_config_scope(
172169
Path(scope): Path<Scope>,
173170
) -> ServerResult<Response> {
174171
let config = state
175-
.supervisor
172+
.manager
176173
.call(message::GetExtendedConfigScope::new(scope))
177174
.await?;
178175
Ok(to_option_response(config))
@@ -189,7 +186,7 @@ async fn get_extended_config_scope(
189186
)
190187
)]
191188
async fn get_config(State(state): State<ServerState>) -> ServerResult<Json<InstallSettings>> {
192-
let config = state.supervisor.call(message::GetConfig).await?;
189+
let config = state.manager.call(message::GetConfig).await?;
193190
Ok(Json(config))
194191
}
195192

@@ -211,7 +208,7 @@ async fn get_config_scope(
211208
Path(scope): Path<Scope>,
212209
) -> ServerResult<Response> {
213210
let config = state
214-
.supervisor
211+
.manager
215212
.call(message::GetConfigScope::new(scope))
216213
.await?;
217214
Ok(to_option_response(config))
@@ -236,10 +233,7 @@ async fn put_config(
236233
State(state): State<ServerState>,
237234
Json(config): Json<InstallSettings>,
238235
) -> ServerResult<()> {
239-
state
240-
.supervisor
241-
.call(message::SetConfig::new(config))
242-
.await?;
236+
state.manager.call(message::SetConfig::new(config)).await?;
243237
Ok(())
244238
}
245239

@@ -263,7 +257,7 @@ async fn patch_config(
263257
Json(config): Json<InstallSettings>,
264258
) -> ServerResult<()> {
265259
state
266-
.supervisor
260+
.manager
267261
.call(message::UpdateConfig::new(config))
268262
.await?;
269263
Ok(())
@@ -295,7 +289,7 @@ async fn put_config_scope(
295289
}
296290

297291
state
298-
.supervisor
292+
.manager
299293
.call(message::SetConfigScope::new(config_scope))
300294
.await?;
301295
Ok(())
@@ -327,7 +321,7 @@ async fn patch_config_scope(
327321
}
328322

329323
state
330-
.supervisor
324+
.manager
331325
.call(message::UpdateConfigScope::new(config_scope))
332326
.await?;
333327
Ok(())
@@ -344,7 +338,7 @@ async fn patch_config_scope(
344338
)
345339
)]
346340
async fn get_proposal(State(state): State<ServerState>) -> ServerResult<Response> {
347-
let proposal = state.supervisor.call(message::GetProposal).await?;
341+
let proposal = state.manager.call(message::GetProposal).await?;
348342
Ok(to_option_response(proposal))
349343
}
350344

@@ -359,7 +353,7 @@ async fn get_proposal(State(state): State<ServerState>) -> ServerResult<Response
359353
)
360354
)]
361355
async fn get_issues(State(state): State<ServerState>) -> ServerResult<Json<IssuesMap>> {
362-
let issues = state.supervisor.call(message::GetIssues).await?;
356+
let issues = state.manager.call(message::GetIssues).await?;
363357
let issues_map: IssuesMap = issues.into();
364358
Ok(Json(issues_map))
365359
}
@@ -380,9 +374,6 @@ async fn run_action(
380374
State(state): State<ServerState>,
381375
Json(action): Json<message::Action>,
382376
) -> ServerResult<()> {
383-
state
384-
.supervisor
385-
.call(message::RunAction::new(action))
386-
.await?;
377+
state.manager.call(message::RunAction::new(action)).await?;
387378
Ok(())
388379
}

rust/agama-server/src/web/docs/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ impl ApiDocBuilder for ConfigApiDocBuilder {
164164
.schema_from::<agama_lib::users::UserPassword>()
165165
.schema_from::<agama_lib::users::UserSettings>()
166166
.schema_from::<crate::software::web::SoftwareProposal>()
167-
.schema_from::<crate::supervisor::message::Action>()
168-
.schema_from::<crate::supervisor::message::Status>()
169-
.schema_from::<crate::supervisor::service::State>()
167+
.schema_from::<agama_manager::message::Action>()
168+
.schema_from::<agama_manager::message::Status>()
169+
.schema_from::<agama_manager::service::State>()
170170
.schema_from::<agama_utils::progress::Progress>()
171171
.build()
172172
}

0 commit comments

Comments
 (0)