use crate::client::apis;
use crate::client::commands::pagination::base::{
Paginatable, PaginatedIterator, PaginatedResponse, PaginationParams,
};
use crate::models::ComputeNodeModel;
#[derive(Debug, Clone, Default)]
pub struct ComputeNodeListParams {
pub workflow_id: i64,
pub offset: i64,
pub limit: Option<i64>,
pub sort_by: Option<String>,
pub reverse_sort: Option<bool>,
pub hostname: Option<String>,
pub is_active: Option<bool>,
pub scheduled_compute_node_id: Option<i64>,
}
impl ComputeNodeListParams {
pub fn new() -> Self {
Self::default()
}
pub fn with_offset(mut self, offset: i64) -> Self {
self.offset = offset;
self
}
pub fn with_limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
pub fn with_sort_by(mut self, sort_by: String) -> Self {
self.sort_by = Some(sort_by);
self
}
pub fn with_reverse_sort(mut self, reverse: bool) -> Self {
self.reverse_sort = Some(reverse);
self
}
pub fn with_hostname(mut self, hostname: String) -> Self {
self.hostname = Some(hostname);
self
}
pub fn with_is_active(mut self, is_active: bool) -> Self {
self.is_active = Some(is_active);
self
}
pub fn with_scheduled_compute_node_id(mut self, id: i64) -> Self {
self.scheduled_compute_node_id = Some(id);
self
}
}
impl PaginationParams for ComputeNodeListParams {
fn offset(&self) -> i64 {
self.offset
}
fn set_offset(&mut self, offset: i64) {
self.offset = offset;
}
fn limit(&self) -> Option<i64> {
self.limit
}
fn sort_by(&self) -> Option<&str> {
self.sort_by.as_deref()
}
fn reverse_sort(&self) -> Option<bool> {
self.reverse_sort
}
}
impl Paginatable for ComputeNodeModel {
type ListError = apis::default_api::ListComputeNodesError;
type Params = ComputeNodeListParams;
fn fetch_page(
config: &apis::configuration::Configuration,
params: &Self::Params,
limit: i64,
) -> Result<PaginatedResponse<Self>, apis::Error<Self::ListError>> {
let response = apis::default_api::list_compute_nodes(
config,
params.workflow_id,
Some(params.offset),
Some(limit),
params.sort_by.as_deref(),
params.reverse_sort,
params.hostname.as_deref(),
params.is_active,
params.scheduled_compute_node_id,
)?;
Ok(PaginatedResponse {
items: response.items,
has_more: response.has_more,
})
}
}
pub type ComputeNodesIterator = PaginatedIterator<ComputeNodeModel>;
pub fn iter_compute_nodes(
config: &apis::configuration::Configuration,
workflow_id: i64,
params: ComputeNodeListParams,
) -> ComputeNodesIterator {
let mut params = params;
params.workflow_id = workflow_id;
PaginatedIterator::new(config.clone(), params, None)
}
pub fn paginate_compute_nodes(
config: &apis::configuration::Configuration,
workflow_id: i64,
params: ComputeNodeListParams,
) -> Result<Vec<ComputeNodeModel>, apis::Error<apis::default_api::ListComputeNodesError>> {
iter_compute_nodes(config, workflow_id, params).collect()
}