use std::collections::HashMap;
use serde::{self, Deserialize, Serialize};
use crate::helpers::Class;
use super::monitor;
#[derive(Debug)]
pub struct ComputerName<'a>(pub &'a str);
impl<'a> From<&'a str> for ComputerName<'a> {
fn from(v: &'a str) -> ComputerName<'a> {
ComputerName(v)
}
}
impl<'a> From<&'a String> for ComputerName<'a> {
fn from(v: &'a String) -> ComputerName<'a> {
ComputerName(v)
}
}
pub trait Computer {}
macro_rules! computer_with_common_fields_and_impl {
(
$(#[$attr:meta])*
pub struct $name:ident {
$(
$(#[$field_attr:meta])*
pub $field:ident: $field_type:ty,
)*
$(private_fields {
$(
$(#[$private_field_attr:meta])*
$private_field:ident: $private_field_type:ty
),* $(,)*
})*
}
) => {
$(#[$attr])*
pub struct $name {
/// Name of the computer
pub display_name: String,
pub description: String,
pub icon: String,
pub icon_class_name: String,
pub idle: bool,
pub jnlp_agent: bool,
pub launch_supported: bool,
pub manual_launch_allowed: bool,
pub num_executors: u32,
pub offline: bool,
pub offline_cause: Option<monitor::CommonMonitorData>,
pub offline_cause_reason: Option<String>,
pub temporarily_offline: bool,
pub monitor_data: HashMap<String, monitor::Data>,
pub executors: Vec<Executor>,
pub one_off_executors: Vec<Executor>,
pub assigned_labels: Vec<AssignedLabel>,
$(
$(#[$field_attr])*
pub $field: $field_type,
)*
$($(
$(#[$private_field_attr])*
$private_field: $private_field_type,
)*)*
}
impl Computer for $name {}
};
}
computer_with_common_fields_and_impl!( #[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CommonComputer {
#[serde(rename = "_class")]
pub class: Option<String>,
#[cfg(feature = "extra-fields-visibility")]
#[serde(flatten)]
pub extra_fields: serde_json::Value,
private_fields {
#[cfg(not(feature = "extra-fields-visibility"))]
#[serde(flatten)]
extra_fields: serde_json::Value,
}
}
);
specialize!(CommonComputer => Computer);
computer_with_common_fields_and_impl!(
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MasterComputer {}
);
register_class!("hudson.model.Hudson$MasterComputer" => MasterComputer);
computer_with_common_fields_and_impl!(
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SlaveComputer {}
);
register_class!("hudson.slave.SlaveComputer" => SlaveComputer);
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum Executor {
#[serde(rename_all = "camelCase")]
Executor {
current_executable: Option<crate::build::ShortBuild>,
likely_stuck: bool,
number: u32,
progress: ExecutorProgress,
},
MissingData {},
}
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum ExecutorProgress {
Percent(u32),
None(i32),
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AssignedLabel {
pub name: String,
}