@@ -13,6 +13,7 @@ use std::fmt;
13
13
use std:: pin:: Pin ;
14
14
15
15
use async_trait:: async_trait;
16
+ use enum_as_inner:: EnumAsInner ;
16
17
use hyperactor:: Actor ;
17
18
use hyperactor:: ActorHandle ;
18
19
use hyperactor:: ActorRef ;
@@ -31,6 +32,7 @@ use hyperactor::host::LocalProcManager;
31
32
use serde:: Deserialize ;
32
33
use serde:: Serialize ;
33
34
35
+ use crate :: bootstrap;
34
36
use crate :: bootstrap:: BootstrapCommand ;
35
37
use crate :: bootstrap:: BootstrapProcManager ;
36
38
use crate :: proc_mesh:: mesh_agent:: ProcMeshAgent ;
@@ -51,6 +53,7 @@ type ProcManagerSpawnFn = Box<dyn Fn(Proc) -> ProcManagerSpawnFuture + Send + Sy
51
53
///
52
54
/// This abstraction lets the same `HostAgent` work across both
53
55
/// out-of-process and in-process execution modes.
56
+ #[ derive( EnumAsInner ) ]
54
57
pub enum HostAgentMode {
55
58
Process ( Host < BootstrapProcManager > ) ,
56
59
Local ( Host < LocalProcManager < ProcManagerSpawnFn > > ) ,
@@ -173,6 +176,8 @@ impl Handler<ShutdownHost> for HostMeshAgent {
173
176
pub struct ProcState {
174
177
pub proc_id : ProcId ,
175
178
pub mesh_agent : ActorRef < ProcMeshAgent > ,
179
+ pub bootstrap_command : Option < BootstrapCommand > ,
180
+ pub proc_status : Option < bootstrap:: ProcStatus > ,
176
181
}
177
182
178
183
#[ async_trait]
@@ -182,13 +187,24 @@ impl Handler<resource::GetState<ProcState>> for HostMeshAgent {
182
187
cx : & Context < Self > ,
183
188
get_state : resource:: GetState < ProcState > ,
184
189
) -> anyhow:: Result < ( ) > {
190
+ let manager = self
191
+ . host
192
+ . as_mut ( )
193
+ . expect ( "host" )
194
+ . as_process ( )
195
+ . map ( Host :: manager) ;
185
196
let state = match self . created . get ( & get_state. name ) {
186
197
Some ( Ok ( ( proc_id, mesh_agent) ) ) => resource:: State {
187
198
name : get_state. name . clone ( ) ,
188
199
status : resource:: Status :: Running ,
189
200
state : Some ( ProcState {
190
201
proc_id : proc_id. clone ( ) ,
191
202
mesh_agent : mesh_agent. clone ( ) ,
203
+ bootstrap_command : manager. map ( |m| m. command ( ) . clone ( ) ) ,
204
+ proc_status : match manager {
205
+ Some ( manager) => Some ( manager. status ( proc_id) . await . unwrap ( ) ) ,
206
+ None => None ,
207
+ } ,
192
208
} ) ,
193
209
} ,
194
210
Some ( Err ( e) ) => resource:: State {
@@ -288,10 +304,13 @@ impl Handler<GetHostMeshAgent> for HostMeshAgentProcMeshTrampoline {
288
304
289
305
#[ cfg( test) ]
290
306
mod tests {
307
+ use std:: assert_matches:: assert_matches;
308
+
291
309
use hyperactor:: Proc ;
292
310
use hyperactor:: channel:: ChannelTransport ;
293
311
294
312
use super :: * ;
313
+ use crate :: bootstrap:: ProcStatus ;
295
314
use crate :: resource:: CreateOrUpdateClient ;
296
315
use crate :: resource:: GetStateClient ;
297
316
@@ -326,21 +345,24 @@ mod tests {
326
345
. await
327
346
. unwrap( )
328
347
) ;
329
- assert_eq ! (
348
+ assert_matches ! (
330
349
host_agent. get_state( & client, name. clone( ) ) . await . unwrap( ) ,
331
350
resource:: State {
332
- name: name . clone ( ) ,
351
+ name: resource_name ,
333
352
status: resource:: Status :: Running ,
334
353
state: Some ( ProcState {
335
354
// The proc itself should be direct addressed, with its name directly.
336
- proc_id: ProcId :: Direct ( host_addr . clone ( ) , name . to_string ( ) ) ,
355
+ proc_id,
337
356
// The mesh agent should run in the same proc, under the name
338
357
// "agent".
339
- mesh_agent: ActorRef :: attest (
340
- ProcId :: Direct ( host_addr . clone ( ) , name . to_string ( ) ) . actor_id ( "agent" , 0 )
341
- ) ,
358
+ mesh_agent,
359
+ bootstrap_command ,
360
+ proc_status : Some ( ProcStatus :: Ready { pid : _ , started_at : _ , addr : _ , agent : proc_status_mesh_agent } ) ,
342
361
} ) ,
343
- }
362
+ } if name == resource_name
363
+ && proc_id == ProcId :: Direct ( host_addr. clone( ) , name. to_string( ) )
364
+ && mesh_agent == ActorRef :: attest( ProcId :: Direct ( host_addr. clone( ) , name. to_string( ) ) . actor_id( "agent" , 0 ) ) && bootstrap_command == Some ( BootstrapCommand :: test( ) )
365
+ && mesh_agent == proc_status_mesh_agent
344
366
) ;
345
367
}
346
368
}
0 commit comments