use super::ResponseContent;
use super::{ContentType, Error, configuration};
use crate::models;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSlurmStatsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSlurmStatsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
pub fn create_slurm_stats(
configuration: &configuration::Configuration,
slurm_stats_model: models::SlurmStatsModel,
) -> Result<models::SlurmStatsModel, Error<CreateSlurmStatsError>> {
let p_body_slurm_stats_model = slurm_stats_model;
let uri_str = format!("{}/slurm_stats", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_slurm_stats_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::SlurmStatsModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::SlurmStatsModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<CreateSlurmStatsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn list_slurm_stats(
configuration: &configuration::Configuration,
workflow_id: i64,
job_id: Option<i64>,
run_id: Option<i64>,
attempt_id: Option<i64>,
offset: Option<i64>,
limit: Option<i64>,
) -> Result<models::ListSlurmStatsResponse, Error<ListSlurmStatsError>> {
let p_query_workflow_id = workflow_id;
let p_query_job_id = job_id;
let p_query_run_id = run_id;
let p_query_attempt_id = attempt_id;
let p_query_offset = offset;
let p_query_limit = limit;
let uri_str = format!("{}/slurm_stats", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("workflow_id", &p_query_workflow_id.to_string())]);
if let Some(ref param_value) = p_query_job_id {
req_builder = req_builder.query(&[("job_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_run_id {
req_builder = req_builder.query(&[("run_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_attempt_id {
req_builder = req_builder.query(&[("attempt_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ListSlurmStatsResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::ListSlurmStatsResponse`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<ListSlurmStatsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}