LCOV - differential code coverage report
Current view: top level - compute_tools/src - configurator.rs (source / functions) Coverage Total Hit UBC CBC
Current: cd44433dd675caa99df17a61b18949c8387e2242.info Lines: 94.4 % 18 17 1 17
Current Date: 2024-01-09 02:06:09 Functions: 90.0 % 10 9 1 9
Baseline: 66c52a629a0f4a503e193045e0df4c77139e344b.info
Baseline Date: 2024-01-08 15:34:46

           TLA  Line data    Source code
       1                 : use std::sync::Arc;
       2                 : use std::thread;
       3                 : 
       4                 : use tracing::{error, info, instrument};
       5                 : 
       6                 : use compute_api::responses::ComputeStatus;
       7                 : 
       8                 : use crate::compute::ComputeNode;
       9                 : 
      10 CBC         544 : #[instrument(skip_all)]
      11                 : fn configurator_main_loop(compute: &Arc<ComputeNode>) {
      12             544 :     info!("waiting for reconfiguration requests");
      13                 :     loop {
      14                 :         let state = compute.state.lock().unwrap();
      15                 :         let mut state = compute.state_changed.wait(state).unwrap();
      16                 : 
      17                 :         if state.status == ComputeStatus::ConfigurationPending {
      18             217 :             info!("got configuration request");
      19                 :             state.status = ComputeStatus::Configuration;
      20                 :             compute.state_changed.notify_all();
      21                 :             drop(state);
      22                 : 
      23                 :             let mut new_status = ComputeStatus::Failed;
      24                 :             if let Err(e) = compute.reconfigure() {
      25 UBC           0 :                 error!("could not configure compute node: {}", e);
      26                 :             } else {
      27                 :                 new_status = ComputeStatus::Running;
      28 CBC         217 :                 info!("compute node configured");
      29                 :             }
      30                 : 
      31                 :             // XXX: used to test that API is blocking
      32                 :             // std::thread::sleep(std::time::Duration::from_millis(10000));
      33                 : 
      34                 :             compute.set_status(new_status);
      35                 :         } else if state.status == ComputeStatus::Failed {
      36               7 :             info!("compute node is now in Failed state, exiting");
      37                 :             break;
      38                 :         } else {
      39             537 :             info!("woken up for compute status: {:?}, sleeping", state.status);
      40                 :         }
      41                 :     }
      42                 : }
      43                 : 
      44             544 : pub fn launch_configurator(compute: &Arc<ComputeNode>) -> thread::JoinHandle<()> {
      45             544 :     let compute = Arc::clone(compute);
      46             544 : 
      47             544 :     thread::Builder::new()
      48             544 :         .name("compute-configurator".into())
      49             544 :         .spawn(move || {
      50             544 :             configurator_main_loop(&compute);
      51             544 :             info!("configurator thread is exited");
      52             544 :         })
      53             544 :         .expect("cannot launch configurator thread")
      54             544 : }
        

Generated by: LCOV version 2.1-beta