LCOV - code coverage report
Current view: top level - control_plane/attachment_service/src - node.rs (source / functions) Coverage Total Hit
Test: 32f4a56327bc9da697706839ed4836b2a00a408f.info Lines: 91.7 % 24 22
Test Date: 2024-02-07 07:37:29 Functions: 100.0 % 4 4

            Line data    Source code
       1              : use control_plane::attachment_service::{NodeAvailability, NodeSchedulingPolicy};
       2              : use utils::id::NodeId;
       3              : 
       4              : use crate::persistence::NodePersistence;
       5              : 
       6          914 : #[derive(Clone)]
       7              : pub(crate) struct Node {
       8              :     pub(crate) id: NodeId,
       9              : 
      10              :     pub(crate) availability: NodeAvailability,
      11              :     pub(crate) scheduling: NodeSchedulingPolicy,
      12              : 
      13              :     pub(crate) listen_http_addr: String,
      14              :     pub(crate) listen_http_port: u16,
      15              : 
      16              :     pub(crate) listen_pg_addr: String,
      17              :     pub(crate) listen_pg_port: u16,
      18              : }
      19              : 
      20              : impl Node {
      21         1362 :     pub(crate) fn base_url(&self) -> String {
      22         1362 :         format!("http://{}:{}", self.listen_http_addr, self.listen_http_port)
      23         1362 :     }
      24              : 
      25              :     /// Is this node elegible to have work scheduled onto it?
      26         1410 :     pub(crate) fn may_schedule(&self) -> bool {
      27         1410 :         match self.availability {
      28         1400 :             NodeAvailability::Active => {}
      29           10 :             NodeAvailability::Offline => return false,
      30              :         }
      31              : 
      32         1400 :         match self.scheduling {
      33            0 :             NodeSchedulingPolicy::Active => true,
      34           13 :             NodeSchedulingPolicy::Draining => false,
      35         1387 :             NodeSchedulingPolicy::Filling => true,
      36            0 :             NodeSchedulingPolicy::Pause => false,
      37              :         }
      38         1410 :     }
      39              : 
      40          393 :     pub(crate) fn to_persistent(&self) -> NodePersistence {
      41          393 :         NodePersistence {
      42          393 :             node_id: self.id.0 as i64,
      43          393 :             scheduling_policy: self.scheduling.into(),
      44          393 :             listen_http_addr: self.listen_http_addr.clone(),
      45          393 :             listen_http_port: self.listen_http_port as i32,
      46          393 :             listen_pg_addr: self.listen_pg_addr.clone(),
      47          393 :             listen_pg_port: self.listen_pg_port as i32,
      48          393 :         }
      49          393 :     }
      50              : }
        

Generated by: LCOV version 2.1-beta