mirror of
https://github.com/typeable/bloodhound.git
synced 2024-09-19 04:37:29 +03:00
Allow VersionNumber parser to fail
Wrap the VersionNumber in a newtype MaybeNA which checks for the String "NA" specifically, allowing for the VersionNumber parser to fail when needed. Also returns the load_average parser to a simpler (more correct) version.
This commit is contained in:
parent
7ffb3d2fde
commit
2c79525f6f
@ -62,6 +62,7 @@ module Database.Bloodhound.Types
|
||||
, MonadBH(..)
|
||||
, Version(..)
|
||||
, VersionNumber(..)
|
||||
, MaybeNA(..)
|
||||
, BuildHash(..)
|
||||
, Status(..)
|
||||
, Existence(..)
|
||||
@ -4189,7 +4190,7 @@ data NodePluginInfo = NodePluginInfo {
|
||||
, nodePluginJVM :: Bool
|
||||
-- ^ Is this plugin running on the JVM
|
||||
, nodePluginDescription :: Text
|
||||
, nodePluginVersion :: Maybe VersionNumber
|
||||
, nodePluginVersion :: MaybeNA VersionNumber
|
||||
, nodePluginName :: PluginName
|
||||
} deriving (Eq, Show, Generic, Typeable)
|
||||
|
||||
@ -4875,7 +4876,7 @@ instance FromJSON NodeOSStats where
|
||||
swap <- o .: "swap"
|
||||
mem <- o .: "mem"
|
||||
cpu <- o .: "cpu"
|
||||
load <- (Just <$> o .: "load_average" <|> pure Nothing)
|
||||
load <- o .:? "load_average"
|
||||
NodeOSStats <$> swap .: "free_in_bytes"
|
||||
<*> swap .: "used_in_bytes"
|
||||
<*> mem .: "actual_used_in_bytes"
|
||||
@ -5047,7 +5048,7 @@ instance FromJSON NodePluginInfo where
|
||||
parse o = NodePluginInfo <$> o .: "site"
|
||||
<*> o .: "jvm"
|
||||
<*> o .: "description"
|
||||
<*> (Just <$> (o .: "version") <|> pure Nothing)
|
||||
<*> o .: "version"
|
||||
<*> o .: "name"
|
||||
|
||||
instance FromJSON NodeHTTPInfo where
|
||||
@ -5212,3 +5213,10 @@ instance FromJSON NodeNetworkInterface where
|
||||
parse o = NodeNetworkInterface <$> o .: "mac_address"
|
||||
<*> o .: "name"
|
||||
<*> o .: "address"
|
||||
|
||||
newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
|
||||
deriving (Show, Eq)
|
||||
|
||||
instance FromJSON a => FromJSON (MaybeNA a) where
|
||||
parseJSON (String "NA") = pure $ MaybeNA Nothing
|
||||
parseJSON o = MaybeNA . Just <$> parseJSON o
|
||||
|
Loading…
Reference in New Issue
Block a user