git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #139 from bermanjosh/nodePluginVersion

Wrap VersionNumber and LoadAvgs in Maybe #138

commit7d718ef3b07eabbe57b2ac57ba272df7ba421dfc authorChris Allen <cma@bitemyapp.com> dateMon 26 Sep 2016, 15:56 (10 years ago) parentbc02cc7833020f
3 files changed+21−8
bloodhound.cabal+1−1 changelog.md+5 src/Database/Bloodhound/Types.hs+15−7
bloodhound.cabal+1−1
@@ -1,5 +1,5 @@
11name: bloodhound
2−version: 0.11.1.0
2+version: 0.12.0.0
33synopsis: ElasticSearch client library for Haskell
44description: ElasticSearch made awesome for Haskell hackers
55homepage: https://github.com/bitemyapp/bloodhound
changelog.md+5
@@ -1,3 +1,8 @@
1+0.12.0.0
2+===================
3+* #138 Make `nodeOSLoad` record a `Maybe` for Windows compatibility
4+* #138 Change the `nodePluginVersion` record to deal with plugins which report `NA` as their version.
5+
160.11.0.0
27===================
38
src/Database/Bloodhound/Types.hs+15−7
@@ -62,6 +62,7 @@ module Database.Bloodhound.Types
6262 , MonadBH(..)
6363 , Version(..)
6464 , VersionNumber(..)
65+ , MaybeNA(..)
6566 , BuildHash(..)
6667 , Status(..)
6768 , Existence(..)
@@ -4064,7 +4065,7 @@ data NodeOSStats = NodeOSStats {
40644065 , nodeOSCPUIdle :: Int
40654066 , nodeOSCPUUser :: Int
40664067 , nodeOSCPUSys :: Int
4067− , nodeOSLoad :: LoadAvgs
4068+ , nodeOSLoad :: Maybe LoadAvgs
40684069 , nodeOSUptime :: NominalDiffTime
40694070 , nodeOSTimestamp :: UTCTime
40704071 } deriving (Eq, Show, Generic, Typeable)
@@ -4189,7 +4190,7 @@ data NodePluginInfo = NodePluginInfo {
41894190 , nodePluginJVM :: Bool
41904191 -- ^ Is this plugin running on the JVM
41914192 , nodePluginDescription :: Text
4192− , nodePluginVersion :: 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 <- o .: "load_average"
4879+ load <- o .:? "load_average"
48794880 NodeOSStats <$> swap .: "free_in_bytes"
48804881 <*> swap .: "used_in_bytes"
48814882 <*> mem .: "actual_used_in_bytes"
@@ -5044,11 +5045,11 @@ parseNodeInfo nid o =
50445045instance FromJSON NodePluginInfo where
50455046 parseJSON = withObject "NodePluginInfo" parse
50465047 where
5047− parse o = NodePluginInfo <$> o .: "site"
5048− <*> o .: "jvm"
5049− <*> o .: "description"
5048+ parse o = NodePluginInfo <$> o .: "site"
5049+ <*> o .: "jvm"
5050+ <*> o .: "description"
50505051 <*> o .: "version"
5051− <*> o .: "name"
5052+ <*> o .: "name"
50525053
50535054instance FromJSON NodeHTTPInfo where
50545055 parseJSON = withObject "NodeHTTPInfo" parse
@@ -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