use std::error::Error;
use std::fmt;
use std::io;
#[allow(warnings)]
use futures::future;
use futures::Future;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoFuture};
use rusoto_core::credential::{CredentialsError, ProvideAwsCredentials};
use rusoto_core::request::HttpDispatchError;
use rusoto_core::signature::SignedRequest;
use serde_json;
use serde_json::from_slice;
use serde_json::Value as SerdeJsonValue;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ApplicationSource {
#[serde(rename = "CloudFormationStackARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_formation_stack_arn: Option<String>,
#[serde(rename = "TagFilters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tag_filters: Option<Vec<TagFilter>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateScalingPlanRequest {
#[serde(rename = "ApplicationSource")]
pub application_source: ApplicationSource,
#[serde(rename = "ScalingInstructions")]
pub scaling_instructions: Vec<ScalingInstruction>,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateScalingPlanResponse {
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CustomizedLoadMetricSpecification {
#[serde(rename = "Dimensions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<Vec<MetricDimension>>,
#[serde(rename = "MetricName")]
pub metric_name: String,
#[serde(rename = "Namespace")]
pub namespace: String,
#[serde(rename = "Statistic")]
pub statistic: String,
#[serde(rename = "Unit")]
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CustomizedScalingMetricSpecification {
#[serde(rename = "Dimensions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<Vec<MetricDimension>>,
#[serde(rename = "MetricName")]
pub metric_name: String,
#[serde(rename = "Namespace")]
pub namespace: String,
#[serde(rename = "Statistic")]
pub statistic: String,
#[serde(rename = "Unit")]
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Datapoint {
#[serde(rename = "Timestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<f64>,
#[serde(rename = "Value")]
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<f64>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteScalingPlanRequest {
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteScalingPlanResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeScalingPlanResourcesRequest {
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeScalingPlanResourcesResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ScalingPlanResources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_plan_resources: Option<Vec<ScalingPlanResource>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeScalingPlansRequest {
#[serde(rename = "ApplicationSources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub application_sources: Option<Vec<ApplicationSource>>,
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ScalingPlanNames")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_plan_names: Option<Vec<String>>,
#[serde(rename = "ScalingPlanVersion")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_plan_version: Option<i64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeScalingPlansResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ScalingPlans")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_plans: Option<Vec<ScalingPlan>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetScalingPlanResourceForecastDataRequest {
#[serde(rename = "EndTime")]
pub end_time: f64,
#[serde(rename = "ForecastDataType")]
pub forecast_data_type: String,
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "ScalableDimension")]
pub scalable_dimension: String,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
#[serde(rename = "ServiceNamespace")]
pub service_namespace: String,
#[serde(rename = "StartTime")]
pub start_time: f64,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetScalingPlanResourceForecastDataResponse {
#[serde(rename = "Datapoints")]
pub datapoints: Vec<Datapoint>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MetricDimension {
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "Value")]
pub value: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PredefinedLoadMetricSpecification {
#[serde(rename = "PredefinedLoadMetricType")]
pub predefined_load_metric_type: String,
#[serde(rename = "ResourceLabel")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_label: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PredefinedScalingMetricSpecification {
#[serde(rename = "PredefinedScalingMetricType")]
pub predefined_scaling_metric_type: String,
#[serde(rename = "ResourceLabel")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_label: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ScalingInstruction {
#[serde(rename = "CustomizedLoadMetricSpecification")]
#[serde(skip_serializing_if = "Option::is_none")]
pub customized_load_metric_specification: Option<CustomizedLoadMetricSpecification>,
#[serde(rename = "DisableDynamicScaling")]
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_dynamic_scaling: Option<bool>,
#[serde(rename = "MaxCapacity")]
pub max_capacity: i64,
#[serde(rename = "MinCapacity")]
pub min_capacity: i64,
#[serde(rename = "PredefinedLoadMetricSpecification")]
#[serde(skip_serializing_if = "Option::is_none")]
pub predefined_load_metric_specification: Option<PredefinedLoadMetricSpecification>,
#[serde(rename = "PredictiveScalingMaxCapacityBehavior")]
#[serde(skip_serializing_if = "Option::is_none")]
pub predictive_scaling_max_capacity_behavior: Option<String>,
#[serde(rename = "PredictiveScalingMaxCapacityBuffer")]
#[serde(skip_serializing_if = "Option::is_none")]
pub predictive_scaling_max_capacity_buffer: Option<i64>,
#[serde(rename = "PredictiveScalingMode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub predictive_scaling_mode: Option<String>,
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "ScalableDimension")]
pub scalable_dimension: String,
#[serde(rename = "ScalingPolicyUpdateBehavior")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_policy_update_behavior: Option<String>,
#[serde(rename = "ScheduledActionBufferTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scheduled_action_buffer_time: Option<i64>,
#[serde(rename = "ServiceNamespace")]
pub service_namespace: String,
#[serde(rename = "TargetTrackingConfigurations")]
pub target_tracking_configurations: Vec<TargetTrackingConfiguration>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ScalingPlan {
#[serde(rename = "ApplicationSource")]
pub application_source: ApplicationSource,
#[serde(rename = "CreationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time: Option<f64>,
#[serde(rename = "ScalingInstructions")]
pub scaling_instructions: Vec<ScalingInstruction>,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
#[serde(rename = "StatusCode")]
pub status_code: String,
#[serde(rename = "StatusMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status_message: Option<String>,
#[serde(rename = "StatusStartTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status_start_time: Option<f64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ScalingPlanResource {
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "ScalableDimension")]
pub scalable_dimension: String,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
#[serde(rename = "ScalingPolicies")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_policies: Option<Vec<ScalingPolicy>>,
#[serde(rename = "ScalingStatusCode")]
pub scaling_status_code: String,
#[serde(rename = "ScalingStatusMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_status_message: Option<String>,
#[serde(rename = "ServiceNamespace")]
pub service_namespace: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ScalingPolicy {
#[serde(rename = "PolicyName")]
pub policy_name: String,
#[serde(rename = "PolicyType")]
pub policy_type: String,
#[serde(rename = "TargetTrackingConfiguration")]
#[serde(skip_serializing_if = "Option::is_none")]
pub target_tracking_configuration: Option<TargetTrackingConfiguration>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TagFilter {
#[serde(rename = "Key")]
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
#[serde(rename = "Values")]
#[serde(skip_serializing_if = "Option::is_none")]
pub values: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TargetTrackingConfiguration {
#[serde(rename = "CustomizedScalingMetricSpecification")]
#[serde(skip_serializing_if = "Option::is_none")]
pub customized_scaling_metric_specification: Option<CustomizedScalingMetricSpecification>,
#[serde(rename = "DisableScaleIn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_scale_in: Option<bool>,
#[serde(rename = "EstimatedInstanceWarmup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub estimated_instance_warmup: Option<i64>,
#[serde(rename = "PredefinedScalingMetricSpecification")]
#[serde(skip_serializing_if = "Option::is_none")]
pub predefined_scaling_metric_specification: Option<PredefinedScalingMetricSpecification>,
#[serde(rename = "ScaleInCooldown")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scale_in_cooldown: Option<i64>,
#[serde(rename = "ScaleOutCooldown")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scale_out_cooldown: Option<i64>,
#[serde(rename = "TargetValue")]
pub target_value: f64,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UpdateScalingPlanRequest {
#[serde(rename = "ApplicationSource")]
#[serde(skip_serializing_if = "Option::is_none")]
pub application_source: Option<ApplicationSource>,
#[serde(rename = "ScalingInstructions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scaling_instructions: Option<Vec<ScalingInstruction>>,
#[serde(rename = "ScalingPlanName")]
pub scaling_plan_name: String,
#[serde(rename = "ScalingPlanVersion")]
pub scaling_plan_version: i64,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateScalingPlanResponse {}
#[derive(Debug, PartialEq)]
pub enum CreateScalingPlanError {
ConcurrentUpdate(String),
InternalService(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateScalingPlanError {
pub fn from_response(res: BufferedHttpResponse) -> CreateScalingPlanError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"ConcurrentUpdateException" => {
return CreateScalingPlanError::ConcurrentUpdate(String::from(error_message));
}
"InternalServiceException" => {
return CreateScalingPlanError::InternalService(String::from(error_message));
}
"LimitExceededException" => {
return CreateScalingPlanError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return CreateScalingPlanError::Validation(error_message.to_string());
}
_ => {}
}
}
return CreateScalingPlanError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateScalingPlanError {
fn from(err: serde_json::error::Error) -> CreateScalingPlanError {
CreateScalingPlanError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateScalingPlanError {
fn from(err: CredentialsError) -> CreateScalingPlanError {
CreateScalingPlanError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateScalingPlanError {
fn from(err: HttpDispatchError) -> CreateScalingPlanError {
CreateScalingPlanError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateScalingPlanError {
fn from(err: io::Error) -> CreateScalingPlanError {
CreateScalingPlanError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateScalingPlanError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateScalingPlanError {
fn description(&self) -> &str {
match *self {
CreateScalingPlanError::ConcurrentUpdate(ref cause) => cause,
CreateScalingPlanError::InternalService(ref cause) => cause,
CreateScalingPlanError::LimitExceeded(ref cause) => cause,
CreateScalingPlanError::Validation(ref cause) => cause,
CreateScalingPlanError::Credentials(ref err) => err.description(),
CreateScalingPlanError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
CreateScalingPlanError::ParseError(ref cause) => cause,
CreateScalingPlanError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteScalingPlanError {
ConcurrentUpdate(String),
InternalService(String),
ObjectNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteScalingPlanError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteScalingPlanError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"ConcurrentUpdateException" => {
return DeleteScalingPlanError::ConcurrentUpdate(String::from(error_message));
}
"InternalServiceException" => {
return DeleteScalingPlanError::InternalService(String::from(error_message));
}
"ObjectNotFoundException" => {
return DeleteScalingPlanError::ObjectNotFound(String::from(error_message));
}
"ValidationException" => {
return DeleteScalingPlanError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteScalingPlanError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteScalingPlanError {
fn from(err: serde_json::error::Error) -> DeleteScalingPlanError {
DeleteScalingPlanError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteScalingPlanError {
fn from(err: CredentialsError) -> DeleteScalingPlanError {
DeleteScalingPlanError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteScalingPlanError {
fn from(err: HttpDispatchError) -> DeleteScalingPlanError {
DeleteScalingPlanError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteScalingPlanError {
fn from(err: io::Error) -> DeleteScalingPlanError {
DeleteScalingPlanError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteScalingPlanError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteScalingPlanError {
fn description(&self) -> &str {
match *self {
DeleteScalingPlanError::ConcurrentUpdate(ref cause) => cause,
DeleteScalingPlanError::InternalService(ref cause) => cause,
DeleteScalingPlanError::ObjectNotFound(ref cause) => cause,
DeleteScalingPlanError::Validation(ref cause) => cause,
DeleteScalingPlanError::Credentials(ref err) => err.description(),
DeleteScalingPlanError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DeleteScalingPlanError::ParseError(ref cause) => cause,
DeleteScalingPlanError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeScalingPlanResourcesError {
ConcurrentUpdate(String),
InternalService(String),
InvalidNextToken(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeScalingPlanResourcesError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeScalingPlanResourcesError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"ConcurrentUpdateException" => {
return DescribeScalingPlanResourcesError::ConcurrentUpdate(String::from(
error_message,
));
}
"InternalServiceException" => {
return DescribeScalingPlanResourcesError::InternalService(String::from(
error_message,
));
}
"InvalidNextTokenException" => {
return DescribeScalingPlanResourcesError::InvalidNextToken(String::from(
error_message,
));
}
"ValidationException" => {
return DescribeScalingPlanResourcesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeScalingPlanResourcesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeScalingPlanResourcesError {
fn from(err: serde_json::error::Error) -> DescribeScalingPlanResourcesError {
DescribeScalingPlanResourcesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeScalingPlanResourcesError {
fn from(err: CredentialsError) -> DescribeScalingPlanResourcesError {
DescribeScalingPlanResourcesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeScalingPlanResourcesError {
fn from(err: HttpDispatchError) -> DescribeScalingPlanResourcesError {
DescribeScalingPlanResourcesError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeScalingPlanResourcesError {
fn from(err: io::Error) -> DescribeScalingPlanResourcesError {
DescribeScalingPlanResourcesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeScalingPlanResourcesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeScalingPlanResourcesError {
fn description(&self) -> &str {
match *self {
DescribeScalingPlanResourcesError::ConcurrentUpdate(ref cause) => cause,
DescribeScalingPlanResourcesError::InternalService(ref cause) => cause,
DescribeScalingPlanResourcesError::InvalidNextToken(ref cause) => cause,
DescribeScalingPlanResourcesError::Validation(ref cause) => cause,
DescribeScalingPlanResourcesError::Credentials(ref err) => err.description(),
DescribeScalingPlanResourcesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeScalingPlanResourcesError::ParseError(ref cause) => cause,
DescribeScalingPlanResourcesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeScalingPlansError {
ConcurrentUpdate(String),
InternalService(String),
InvalidNextToken(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeScalingPlansError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeScalingPlansError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"ConcurrentUpdateException" => {
return DescribeScalingPlansError::ConcurrentUpdate(String::from(error_message));
}
"InternalServiceException" => {
return DescribeScalingPlansError::InternalService(String::from(error_message));
}
"InvalidNextTokenException" => {
return DescribeScalingPlansError::InvalidNextToken(String::from(error_message));
}
"ValidationException" => {
return DescribeScalingPlansError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeScalingPlansError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeScalingPlansError {
fn from(err: serde_json::error::Error) -> DescribeScalingPlansError {
DescribeScalingPlansError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeScalingPlansError {
fn from(err: CredentialsError) -> DescribeScalingPlansError {
DescribeScalingPlansError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeScalingPlansError {
fn from(err: HttpDispatchError) -> DescribeScalingPlansError {
DescribeScalingPlansError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeScalingPlansError {
fn from(err: io::Error) -> DescribeScalingPlansError {
DescribeScalingPlansError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeScalingPlansError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeScalingPlansError {
fn description(&self) -> &str {
match *self {
DescribeScalingPlansError::ConcurrentUpdate(ref cause) => cause,
DescribeScalingPlansError::InternalService(ref cause) => cause,
DescribeScalingPlansError::InvalidNextToken(ref cause) => cause,
DescribeScalingPlansError::Validation(ref cause) => cause,
DescribeScalingPlansError::Credentials(ref err) => err.description(),
DescribeScalingPlansError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeScalingPlansError::ParseError(ref cause) => cause,
DescribeScalingPlansError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetScalingPlanResourceForecastDataError {
InternalService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetScalingPlanResourceForecastDataError {
pub fn from_response(res: BufferedHttpResponse) -> GetScalingPlanResourceForecastDataError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"InternalServiceException" => {
return GetScalingPlanResourceForecastDataError::InternalService(String::from(
error_message,
));
}
"ValidationException" => {
return GetScalingPlanResourceForecastDataError::Validation(
error_message.to_string(),
);
}
_ => {}
}
}
return GetScalingPlanResourceForecastDataError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetScalingPlanResourceForecastDataError {
fn from(err: serde_json::error::Error) -> GetScalingPlanResourceForecastDataError {
GetScalingPlanResourceForecastDataError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetScalingPlanResourceForecastDataError {
fn from(err: CredentialsError) -> GetScalingPlanResourceForecastDataError {
GetScalingPlanResourceForecastDataError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetScalingPlanResourceForecastDataError {
fn from(err: HttpDispatchError) -> GetScalingPlanResourceForecastDataError {
GetScalingPlanResourceForecastDataError::HttpDispatch(err)
}
}
impl From<io::Error> for GetScalingPlanResourceForecastDataError {
fn from(err: io::Error) -> GetScalingPlanResourceForecastDataError {
GetScalingPlanResourceForecastDataError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetScalingPlanResourceForecastDataError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetScalingPlanResourceForecastDataError {
fn description(&self) -> &str {
match *self {
GetScalingPlanResourceForecastDataError::InternalService(ref cause) => cause,
GetScalingPlanResourceForecastDataError::Validation(ref cause) => cause,
GetScalingPlanResourceForecastDataError::Credentials(ref err) => err.description(),
GetScalingPlanResourceForecastDataError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
GetScalingPlanResourceForecastDataError::ParseError(ref cause) => cause,
GetScalingPlanResourceForecastDataError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UpdateScalingPlanError {
ConcurrentUpdate(String),
InternalService(String),
ObjectNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UpdateScalingPlanError {
pub fn from_response(res: BufferedHttpResponse) -> UpdateScalingPlanError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"ConcurrentUpdateException" => {
return UpdateScalingPlanError::ConcurrentUpdate(String::from(error_message));
}
"InternalServiceException" => {
return UpdateScalingPlanError::InternalService(String::from(error_message));
}
"ObjectNotFoundException" => {
return UpdateScalingPlanError::ObjectNotFound(String::from(error_message));
}
"ValidationException" => {
return UpdateScalingPlanError::Validation(error_message.to_string());
}
_ => {}
}
}
return UpdateScalingPlanError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UpdateScalingPlanError {
fn from(err: serde_json::error::Error) -> UpdateScalingPlanError {
UpdateScalingPlanError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UpdateScalingPlanError {
fn from(err: CredentialsError) -> UpdateScalingPlanError {
UpdateScalingPlanError::Credentials(err)
}
}
impl From<HttpDispatchError> for UpdateScalingPlanError {
fn from(err: HttpDispatchError) -> UpdateScalingPlanError {
UpdateScalingPlanError::HttpDispatch(err)
}
}
impl From<io::Error> for UpdateScalingPlanError {
fn from(err: io::Error) -> UpdateScalingPlanError {
UpdateScalingPlanError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UpdateScalingPlanError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UpdateScalingPlanError {
fn description(&self) -> &str {
match *self {
UpdateScalingPlanError::ConcurrentUpdate(ref cause) => cause,
UpdateScalingPlanError::InternalService(ref cause) => cause,
UpdateScalingPlanError::ObjectNotFound(ref cause) => cause,
UpdateScalingPlanError::Validation(ref cause) => cause,
UpdateScalingPlanError::Credentials(ref err) => err.description(),
UpdateScalingPlanError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
UpdateScalingPlanError::ParseError(ref cause) => cause,
UpdateScalingPlanError::Unknown(_) => "unknown error",
}
}
}
pub trait AutoscalingPlans {
fn create_scaling_plan(
&self,
input: CreateScalingPlanRequest,
) -> RusotoFuture<CreateScalingPlanResponse, CreateScalingPlanError>;
fn delete_scaling_plan(
&self,
input: DeleteScalingPlanRequest,
) -> RusotoFuture<DeleteScalingPlanResponse, DeleteScalingPlanError>;
fn describe_scaling_plan_resources(
&self,
input: DescribeScalingPlanResourcesRequest,
) -> RusotoFuture<DescribeScalingPlanResourcesResponse, DescribeScalingPlanResourcesError>;
fn describe_scaling_plans(
&self,
input: DescribeScalingPlansRequest,
) -> RusotoFuture<DescribeScalingPlansResponse, DescribeScalingPlansError>;
fn get_scaling_plan_resource_forecast_data(
&self,
input: GetScalingPlanResourceForecastDataRequest,
) -> RusotoFuture<
GetScalingPlanResourceForecastDataResponse,
GetScalingPlanResourceForecastDataError,
>;
fn update_scaling_plan(
&self,
input: UpdateScalingPlanRequest,
) -> RusotoFuture<UpdateScalingPlanResponse, UpdateScalingPlanError>;
}
#[derive(Clone)]
pub struct AutoscalingPlansClient {
client: Client,
region: region::Region,
}
impl AutoscalingPlansClient {
pub fn new(region: region::Region) -> AutoscalingPlansClient {
AutoscalingPlansClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> AutoscalingPlansClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
AutoscalingPlansClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl AutoscalingPlans for AutoscalingPlansClient {
fn create_scaling_plan(
&self,
input: CreateScalingPlanRequest,
) -> RusotoFuture<CreateScalingPlanResponse, CreateScalingPlanError> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.CreateScalingPlan",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<CreateScalingPlanResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateScalingPlanError::from_response(response))),
)
}
})
}
fn delete_scaling_plan(
&self,
input: DeleteScalingPlanRequest,
) -> RusotoFuture<DeleteScalingPlanResponse, DeleteScalingPlanError> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.DeleteScalingPlan",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DeleteScalingPlanResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteScalingPlanError::from_response(response))),
)
}
})
}
fn describe_scaling_plan_resources(
&self,
input: DescribeScalingPlanResourcesRequest,
) -> RusotoFuture<DescribeScalingPlanResourcesResponse, DescribeScalingPlanResourcesError> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.DescribeScalingPlanResources",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DescribeScalingPlanResourcesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DescribeScalingPlanResourcesError::from_response(response))
}))
}
})
}
fn describe_scaling_plans(
&self,
input: DescribeScalingPlansRequest,
) -> RusotoFuture<DescribeScalingPlansResponse, DescribeScalingPlansError> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.DescribeScalingPlans",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DescribeScalingPlansResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(DescribeScalingPlansError::from_response(response))
}),
)
}
})
}
fn get_scaling_plan_resource_forecast_data(
&self,
input: GetScalingPlanResourceForecastDataRequest,
) -> RusotoFuture<
GetScalingPlanResourceForecastDataResponse,
GetScalingPlanResourceForecastDataError,
> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.GetScalingPlanResourceForecastData",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<GetScalingPlanResourceForecastDataResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(GetScalingPlanResourceForecastDataError::from_response(
response,
))
}))
}
})
}
fn update_scaling_plan(
&self,
input: UpdateScalingPlanRequest,
) -> RusotoFuture<UpdateScalingPlanResponse, UpdateScalingPlanError> {
let mut request = SignedRequest::new("POST", "autoscaling-plans", &self.region, "/");
request.set_endpoint_prefix("autoscaling".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AnyScaleScalingPlannerFrontendService.UpdateScalingPlan",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<UpdateScalingPlanResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UpdateScalingPlanError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}