/*
* Nomad
*
* Nomad OpenApi specification
*
* The version of the OpenAPI document: 0.11.0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use crate::apis::ResponseContent;
use super::{Error, configuration};
/// struct for typed errors of method `fail_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FailDeploymentError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `get_allocations_for_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAllocationsForDeploymentError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `get_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeploymentError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `get_deployments`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeploymentsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `pause_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PauseDeploymentError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `promote_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PromoteDeploymentError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `set_allocation_health_in_deployment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetAllocationHealthInDeploymentError {
UnknownValue(serde_json::Value),
}
pub async fn fail_deployment(configuration: &configuration::Configuration, deployment_id: &str) -> Result<crate::models::DeploymentUpdateResponse, Error<FailDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/fail/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FailDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_allocations_for_deployment(configuration: &configuration::Configuration, deployment_id: &str) -> Result<Vec<crate::models::AllocationListStub>, Error<GetAllocationsForDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/allocations/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetAllocationsForDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_deployment(configuration: &configuration::Configuration, deployment_id: &str) -> Result<crate::models::Deployment, Error<GetDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_deployments(configuration: &configuration::Configuration, prefix: Option<&str>) -> Result<Vec<crate::models::Deployment>, Error<GetDeploymentsError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployments", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = prefix {
local_var_req_builder = local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetDeploymentsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn pause_deployment(configuration: &configuration::Configuration, deployment_id: &str, deployment_pause_request: Option<crate::models::DeploymentPauseRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<PauseDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/pause/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&deployment_pause_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<PauseDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn promote_deployment(configuration: &configuration::Configuration, deployment_id: &str, deployment_promote_request: Option<crate::models::DeploymentPromoteRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<PromoteDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/promote/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&deployment_promote_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<PromoteDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
/// In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = \"manual\". Those allocations must have their health marked manually using this endpoint. Marking an allocation as healthy will allow the rolling upgrade to proceed. Marking it as failed will cause the deployment to fail. This endpoint only triggers a rollback if the most recent stable version of the job has a different specification than the job being reverted
pub async fn set_allocation_health_in_deployment(configuration: &configuration::Configuration, deployment_id: &str, deployment_alloc_health_request: Option<crate::models::DeploymentAllocHealthRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<SetAllocationHealthInDeploymentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/deployment/allocation-health/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&deployment_alloc_health_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SetAllocationHealthInDeploymentError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}