git.iko.soy/typeable/bloodhound
on master help sign in
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.

commit2c79525f6f4b89548296b993134e53216c0dcc80 authorJosh Berman <berman.josh@gmail.com> dateThu 22 Sep 2016, 22:17 (10 years ago) parent7ffb3d2
1 file changed+11−3
src/Database/Bloodhound/Types.hs+11−3
src/Database/Bloodhound/Types.hs+11−3
@@ -62,6 +62,7 @@ module Database.Bloodhound.Types
6262 , MonadBH(..)
6363 , Version(..)
6464 , VersionNumber(..)
65+ , MaybeNA(..)
6566 , BuildHash(..)
6667 , Status(..)
6768 , Existence(..)
@@ -4189,7 +4190,7 @@ data NodePluginInfo = NodePluginInfo {
41894190 , nodePluginJVM :: Bool
41904191 -- ^ Is this plugin running on the JVM
41914192 , nodePluginDescription :: Text
4192− , nodePluginVersion :: Maybe VersionNumber
4193+ , nodePluginVersion :: MaybeNA VersionNumber
41934194 , nodePluginName :: PluginName
41944195 } deriving (Eq, Show, Generic, Typeable)
41954196
@@ -4875,7 +4876,7 @@ instance FromJSON NodeOSStats where
48754876 swap <- o .: "swap"
48764877 mem <- o .: "mem"
48774878 cpu <- o .: "cpu"
4878− load <- (Just <$> o .: "load_average" <|> pure Nothing)
4879+ load <- o .:? "load_average"
48794880 NodeOSStats <$> swap .: "free_in_bytes"
48804881 <*> swap .: "used_in_bytes"
48814882 <*> mem .: "actual_used_in_bytes"
@@ -5047,7 +5048,7 @@ instance FromJSON NodePluginInfo where
50475048 parse o = NodePluginInfo <$> o .: "site"
50485049 <*> o .: "jvm"
50495050 <*> o .: "description"
5050− <*> (Just <$> (o .: "version") <|> pure Nothing)
5051+ <*> o .: "version"
50515052 <*> o .: "name"
50525053
50535054instance FromJSON NodeHTTPInfo where
@@ -5212,3 +5213,10 @@ instance FromJSON NodeNetworkInterface where
52125213 parse o = NodeNetworkInterface <$> o .: "mac_address"
52135214 <*> o .: "name"
52145215 <*> o .: "address"
5216+
5217+newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
5218+ deriving (Show, Eq)
5219+
5220+instance FromJSON a => FromJSON (MaybeNA a) where
5221+ parseJSON (String "NA") = pure $ MaybeNA Nothing
5222+ parseJSON o = MaybeNA . Just <$> parseJSON o