Skip to content

Commit

Permalink
Merge pull request #5 from SDS/SDS-2646
Browse files Browse the repository at this point in the history
convert string to long for scaleio raw
  • Loading branch information
cholco202 authored and GitHub Enterprise committed Sep 4, 2018
2 parents 3e5d40c + 1262819 commit 5e6f0cb
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 243 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chrono = "~0.4"
futures = "~0.1"
hyper = "~0.11"
influx_db_client = "~0.3"
isilon = "~4.0"
isilon = {version="~4.0", optional=true}
log = "~0.4"
native-tls = "~0.1"
nom = "~3.2"
Expand All @@ -30,3 +30,6 @@ quick-xml = "~0.12"
xml-attributes-derive = { path = "xml-attributes-derive" }
xml-rs = "~0.7"

[features]
default = []
isilon-library = ["isilon"]
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate cookie;
extern crate csv;
extern crate influx_db_client;
#[cfg(feature = "isilon-library")]
extern crate isilon;
extern crate native_tls;
extern crate postgres;
Expand All @@ -22,6 +23,7 @@ use std::string::{FromUtf8Error, ParseError};
use self::cookie::ParseError as CookieParseError;
use self::csv::Error as CsvError;
use self::influx_db_client::error::Error as InfluxError;
#[cfg(feature = "isilon-library")]
use self::isilon::apis::Error as IsilonError;
use self::native_tls::Error as NativeTlsError;
use self::quick_xml::Error as QuickXmlError;
Expand All @@ -46,6 +48,7 @@ pub enum StorageError {
HttpError(ReqwestError),
InfluxError(InfluxError),
IoError(Error),
#[cfg(feature = "isilon-library")]
IsilonError(IsilonError),
JsonError(JsonError),
NativeTlsError(NativeTlsError),
Expand Down Expand Up @@ -84,6 +87,7 @@ impl err for StorageError {
&InfluxError::Unknow(ref s) => s,
},
StorageError::IoError(ref e) => e.description(),
#[cfg(feature = "isilon-library")]
StorageError::IsilonError(ref e) => e.description(),
StorageError::JsonError(ref e) => e.description(),
StorageError::NativeTlsError(ref e) => e.description(),
Expand All @@ -109,6 +113,7 @@ impl err for StorageError {
StorageError::HttpError(ref e) => e.cause(),
StorageError::InfluxError(ref _e) => None,
StorageError::IoError(ref e) => e.cause(),
#[cfg(feature = "isilon-library")]
StorageError::IsilonError(ref e) => e.cause(),
StorageError::JsonError(ref e) => e.cause(),
StorageError::NativeTlsError(ref e) => e.cause(),
Expand Down Expand Up @@ -141,6 +146,7 @@ impl StorageError {
StorageError::HttpError(ref err) => err.description().to_string(),
StorageError::InfluxError(ref err) => err.to_string(),
StorageError::IoError(ref err) => err.description().to_string(),
#[cfg(feature = "isilon-library")]
StorageError::IsilonError(ref err) => err.description().to_string(),
StorageError::JsonError(ref err) => err.description().to_string(),
StorageError::NativeTlsError(ref err) => err.description().to_string(),
Expand Down Expand Up @@ -193,6 +199,7 @@ impl From<InfluxError> for StorageError {
}
}

#[cfg(feature = "isilon-library")]
impl From<IsilonError> for StorageError {
fn from(err: IsilonError) -> StorageError {
StorageError::IsilonError(err)
Expand Down
41 changes: 41 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate xml_attributes_derive;
extern crate serde;

use self::serde::de::Deserialize;
use self::serde::Deserializer;

pub mod brocade;
pub mod error;
pub mod hitachi;
pub mod ir;
#[cfg(feature = "isilon-library")]
pub mod isilon;
pub mod netapp;
pub mod scaleio;
Expand All @@ -31,3 +36,39 @@ pub trait IntoPoint {
pub trait ChildPoint {
fn sub_point(&self, p: &mut ir::TsPoint);
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum StringOrInt {
String(String),
Int(i64),
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum StringOrFloat {
String(String),
Float(f64),
}

fn deserialize_string_or_int<'de, D>(deserializer: D) -> ::std::result::Result<i64, D::Error>
where
D: Deserializer<'de>,
{
use self::serde::de::Error;
match StringOrInt::deserialize(deserializer)? {
StringOrInt::String(s) => s.parse().map_err(|e| D::Error::custom(e)),
StringOrInt::Int(i) => Ok(i),
}
}

fn deserialize_string_or_float<'de, D>(deserializer: D) -> ::std::result::Result<f64, D::Error>
where
D: Deserializer<'de>,
{
use self::serde::de::Error;
match StringOrFloat::deserialize(deserializer)? {
StringOrFloat::String(s) => s.parse().map_err(|e| D::Error::custom(e)),
StringOrFloat::Float(i) => Ok(i),
}
}
4 changes: 3 additions & 1 deletion src/scaleio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern crate reqwest;
extern crate serde;
extern crate serde_json;

use deserialize_string_or_int;
use error::{MetricsResult, StorageError};
use ir::{TsPoint, TsValue};
use IntoPoint;
Expand Down Expand Up @@ -1228,7 +1229,8 @@ pub struct System {
pub perf_profile: PerfProfile,
pub install_id: String,
pub days_installed: u64,
pub max_capacity_in_gb: String,
#[serde(deserialize_with = "deserialize_string_or_int")]
pub max_capacity_in_gb: i64,
pub capacity_time_left_in_days: String,
pub enterprise_features_enabled: bool,
pub is_initial_license: bool,
Expand Down
10 changes: 5 additions & 5 deletions src/vnx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,9 +1792,7 @@ pub fn login_request(
jar.add(parsed);
Ok(())
}
None => Err(StorageError::new(
"Cookie missing from server".into(),
)),
None => Err(StorageError::new("Cookie missing from server".into())),
}
}
None => Err(StorageError::new(
Expand Down Expand Up @@ -1845,7 +1843,8 @@ pub fn logout_request(
.post(&format!(
"https://{}/servlets/CelerraManagementServices",
config.endpoint
)).headers(headers)
))
.headers(headers)
.body("")
.send()?
.error_for_status()?;
Expand Down Expand Up @@ -1905,7 +1904,8 @@ where
.post(&format!(
"https://{}/servlets/CelerraManagementServices",
config.endpoint
)).body(req)
))
.body(req)
.headers(headers)
.send()?
.error_for_status()?;
Expand Down
Loading

0 comments on commit 5e6f0cb

Please sign in to comment.