@@ -8,14 +8,13 @@ extern crate serde_derive;
8
8
use anyhow:: { bail, Context , Error , Result } ;
9
9
use async_trait:: async_trait;
10
10
use cachepot:: config:: {
11
- coordinator as coordinator_config, scheduler as scheduler_config, WorkerUrl ,
12
- INSECURE_DIST_CLIENT_TOKEN ,
11
+ scheduler as scheduler_config, worker, WorkerUrl , INSECURE_DIST_CLIENT_TOKEN ,
13
12
} ;
14
13
use cachepot:: dist:: {
15
14
self , AllocJobResult , AssignJobResult , BuilderIncoming , CompileCommand , CoordinatorIncoming ,
16
- CoordinatorOutgoing , HeartbeatServerResult , InputsReader , JobAlloc , JobAuthorizer , JobComplete ,
15
+ CoordinatorOutgoing , HeartbeatWorkerResult , InputsReader , JobAlloc , JobAuthorizer , JobComplete ,
17
16
JobId , JobState , RunJobResult , SchedulerIncoming , SchedulerOutgoing , SchedulerStatusResult ,
18
- ServerNonce , SubmitToolchainResult , TcCache , Toolchain , ToolchainReader , UpdateJobStateResult ,
17
+ SubmitToolchainResult , TcCache , Toolchain , ToolchainReader , UpdateJobStateResult , WorkerNonce ,
19
18
} ;
20
19
use cachepot:: util:: daemonize;
21
20
use jsonwebtoken as jwt;
@@ -41,7 +40,7 @@ pub const INSECURE_DIST_WORKER_TOKEN: &str = "dangerously_insecure_server";
41
40
enum Command {
42
41
Auth ( AuthSubcommand ) ,
43
42
Scheduler ( SchedulerSubcommand ) ,
44
- Server ( ServerSubcommand ) ,
43
+ Worker ( WorkerSubcommand ) ,
45
44
}
46
45
47
46
#[ derive( StructOpt ) ]
@@ -58,7 +57,7 @@ struct SchedulerSubcommand {
58
57
59
58
#[ derive( StructOpt ) ]
60
59
#[ structopt( rename_all = "kebab-case" ) ]
61
- struct ServerSubcommand {
60
+ struct WorkerSubcommand {
62
61
/// Use the server config file at PATH
63
62
#[ structopt( long, value_name = "PATH" ) ]
64
63
config : PathBuf ,
@@ -303,15 +302,15 @@ async fn run(command: Command) -> Result<i32> {
303
302
void:: unreachable ( http_scheduler. start ( ) . await ?) ;
304
303
}
305
304
306
- Command :: Server ( ServerSubcommand { config, syslog } ) => {
307
- let coordinator_config :: Config {
305
+ Command :: Worker ( WorkerSubcommand { config, syslog } ) => {
306
+ let worker :: Config {
308
307
builder,
309
308
cache_dir,
310
309
public_addr,
311
310
scheduler_url,
312
311
scheduler_auth,
313
312
toolchain_cache_size,
314
- } = if let Some ( config) = coordinator_config :: from_path ( & config) ? {
313
+ } = if let Some ( config) = worker :: from_path ( & config) ? {
315
314
config
316
315
} else {
317
316
bail ! ( "Could not load config!" ) ;
@@ -322,10 +321,10 @@ async fn run(command: Command) -> Result<i32> {
322
321
}
323
322
324
323
let builder: Box < dyn dist:: BuilderIncoming > = match builder {
325
- coordinator_config :: BuilderType :: Docker => {
324
+ worker :: BuilderType :: Docker => {
326
325
Box :: new ( build:: DockerBuilder :: new ( ) . context ( "Docker builder failed to start" ) ?)
327
326
}
328
- coordinator_config :: BuilderType :: Overlay {
327
+ worker :: BuilderType :: Overlay {
329
328
bwrap_path,
330
329
build_dir,
331
330
} => Box :: new (
@@ -336,14 +335,12 @@ async fn run(command: Command) -> Result<i32> {
336
335
337
336
let server_id = public_addr. clone ( ) ;
338
337
let scheduler_auth = match scheduler_auth {
339
- coordinator_config :: SchedulerAuth :: Insecure => {
338
+ worker :: SchedulerAuth :: Insecure => {
340
339
warn ! ( "Server starting with DANGEROUSLY_INSECURE scheduler authentication" ) ;
341
340
create_server_token ( server_id, INSECURE_DIST_WORKER_TOKEN )
342
341
}
343
- coordinator_config:: SchedulerAuth :: Token { token } => {
344
- create_server_token ( server_id, & token)
345
- }
346
- coordinator_config:: SchedulerAuth :: JwtToken { token } => {
342
+ worker:: SchedulerAuth :: Token { token } => create_server_token ( server_id, & token) ,
343
+ worker:: SchedulerAuth :: JwtToken { token } => {
347
344
let token_server_id: WorkerUrl =
348
345
dangerous_insecure_extract_jwt_server_token ( & token)
349
346
. context ( "Could not decode scheduler auth jwt" ) ?;
@@ -358,9 +355,9 @@ async fn run(command: Command) -> Result<i32> {
358
355
}
359
356
} ;
360
357
361
- let server = Server :: new ( builder, & cache_dir, toolchain_cache_size)
358
+ let server = Worker :: new ( builder, & cache_dir, toolchain_cache_size)
362
359
. context ( "Failed to create cachepot server instance" ) ?;
363
- let http_server = dist:: http:: Server :: new (
360
+ let http_server = dist:: http:: Worker :: new (
364
361
public_addr. 0 . to_url ( ) . clone ( ) ,
365
362
scheduler_url. to_url ( ) . clone ( ) ,
366
363
scheduler_auth,
@@ -400,18 +397,18 @@ pub struct Scheduler {
400
397
// Currently running jobs, can never be Complete
401
398
jobs : Mutex < BTreeMap < JobId , JobDetail > > ,
402
399
403
- servers : Mutex < HashMap < WorkerUrl , ServerDetails > > ,
400
+ servers : Mutex < HashMap < WorkerUrl , WorkerDetails > > ,
404
401
}
405
402
406
- struct ServerDetails {
403
+ struct WorkerDetails {
407
404
jobs_assigned : HashSet < JobId > ,
408
405
// Jobs assigned that haven't seen a state change. Can only be pending
409
406
// or ready.
410
407
jobs_unclaimed : HashMap < JobId , Instant > ,
411
408
last_seen : Instant ,
412
409
last_error : Option < Instant > ,
413
410
num_cpus : usize ,
414
- server_nonce : ServerNonce ,
411
+ server_nonce : WorkerNonce ,
415
412
job_authorizer : Box < dyn JobAuthorizer > ,
416
413
}
417
414
@@ -426,7 +423,7 @@ impl Scheduler {
426
423
427
424
fn prune_workers (
428
425
& self ,
429
- servers : & mut MutexGuard < HashMap < WorkerUrl , ServerDetails > > ,
426
+ servers : & mut MutexGuard < HashMap < WorkerUrl , WorkerDetails > > ,
430
427
jobs : & mut MutexGuard < BTreeMap < JobId , JobDetail > > ,
431
428
) {
432
429
let now = Instant :: now ( ) ;
@@ -492,7 +489,7 @@ impl SchedulerIncoming for Scheduler {
492
489
match best_err {
493
490
Some ( (
494
491
_,
495
- & mut ServerDetails {
492
+ & mut WorkerDetails {
496
493
last_error : Some ( best_last_err) ,
497
494
..
498
495
} ,
@@ -611,13 +608,13 @@ impl SchedulerIncoming for Scheduler {
611
608
} )
612
609
}
613
610
614
- fn handle_heartbeat_server (
611
+ fn handle_heartbeat_worker (
615
612
& self ,
616
613
server_id : WorkerUrl ,
617
- server_nonce : ServerNonce ,
614
+ server_nonce : WorkerNonce ,
618
615
num_cpus : usize ,
619
616
job_authorizer : Box < dyn JobAuthorizer > ,
620
- ) -> Result < HeartbeatServerResult > {
617
+ ) -> Result < HeartbeatWorkerResult > {
621
618
if num_cpus == 0 {
622
619
bail ! ( "Invalid number of CPUs (0) specified in heartbeat" )
623
620
}
@@ -680,7 +677,7 @@ impl SchedulerIncoming for Scheduler {
680
677
}
681
678
}
682
679
683
- return Ok ( HeartbeatServerResult { is_new : false } ) ;
680
+ return Ok ( HeartbeatWorkerResult { is_new : false } ) ;
684
681
}
685
682
Some ( ref mut details) if details. server_nonce != server_nonce => {
686
683
for job_id in details. jobs_assigned . iter ( ) {
@@ -697,7 +694,7 @@ impl SchedulerIncoming for Scheduler {
697
694
info ! ( "Registered new server {:?}" , server_id) ;
698
695
servers. insert (
699
696
server_id,
700
- ServerDetails {
697
+ WorkerDetails {
701
698
last_seen : Instant :: now ( ) ,
702
699
last_error : None ,
703
700
jobs_assigned : HashSet :: new ( ) ,
@@ -707,7 +704,7 @@ impl SchedulerIncoming for Scheduler {
707
704
job_authorizer,
708
705
} ,
709
706
) ;
710
- Ok ( HeartbeatServerResult { is_new : true } )
707
+ Ok ( HeartbeatWorkerResult { is_new : true } )
711
708
}
712
709
713
710
fn handle_update_job_state (
@@ -778,21 +775,21 @@ impl SchedulerIncoming for Scheduler {
778
775
}
779
776
}
780
777
781
- pub struct Server {
778
+ pub struct Worker {
782
779
builder : Box < dyn BuilderIncoming > ,
783
780
cache : Mutex < TcCache > ,
784
781
job_toolchains : tokio:: sync:: Mutex < HashMap < JobId , Toolchain > > ,
785
782
}
786
783
787
- impl Server {
784
+ impl Worker {
788
785
pub fn new (
789
786
builder : Box < dyn BuilderIncoming > ,
790
787
cache_dir : & Path ,
791
788
toolchain_cache_size : u64 ,
792
- ) -> Result < Server > {
789
+ ) -> Result < Worker > {
793
790
let cache = TcCache :: new ( & cache_dir. join ( "tc" ) , toolchain_cache_size)
794
791
. context ( "Failed to create toolchain cache" ) ?;
795
- Ok ( Server {
792
+ Ok ( Worker {
796
793
builder,
797
794
cache : Mutex :: new ( cache) ,
798
795
job_toolchains : tokio:: sync:: Mutex :: new ( HashMap :: new ( ) ) ,
@@ -801,7 +798,7 @@ impl Server {
801
798
}
802
799
803
800
#[ async_trait]
804
- impl CoordinatorIncoming for Server {
801
+ impl CoordinatorIncoming for Worker {
805
802
async fn handle_assign_job ( & self , job_id : JobId , tc : Toolchain ) -> Result < AssignJobResult > {
806
803
let need_toolchain = !self . cache . lock ( ) . unwrap ( ) . contains_toolchain ( & tc) ;
807
804
assert ! ( self
0 commit comments