LCOV - differential code coverage report
Current view: top level - compute_tools/src - configurator.rs (source / functions) Coverage Total Hit UBC CBC
Current: f6946e90941b557c917ac98cd5a7e9506d180f3e.info Lines: 77.8 % 18 14 4 14
Current Date: 2023-10-19 02:04:12 Functions: 50.0 % 10 5 5 5
Baseline: c8637f37369098875162f194f92736355783b050.info
Baseline Date: 2023-10-18 20:25:20

           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         641 : #[instrument(skip_all)]
      11                 : fn configurator_main_loop(compute: &Arc<ComputeNode>) {
      12             641 :     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 UBC           0 :             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               0 :                 error!("could not configure compute node: {}", e);
      26                 :             } else {
      27                 :                 new_status = ComputeStatus::Running;
      28               0 :                 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               0 :             info!("compute node is now in Failed state, exiting");
      37                 :             break;
      38                 :         } else {
      39 CBC         632 :             info!("woken up for compute status: {:?}, sleeping", state.status);
      40                 :         }
      41                 :     }
      42                 : }
      43                 : 
      44             641 : pub fn launch_configurator(compute: &Arc<ComputeNode>) -> thread::JoinHandle<()> {
      45             641 :     let compute = Arc::clone(compute);
      46             641 : 
      47             641 :     thread::Builder::new()
      48             641 :         .name("compute-configurator".into())
      49             641 :         .spawn(move || {
      50             641 :             configurator_main_loop(&compute);
      51             641 :             info!("configurator thread is exited");
      52             641 :         })
      53             641 :         .expect("cannot launch configurator thread")
      54             641 : }
        

Generated by: LCOV version 2.1-beta