packages feed

hs-rqlite 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+23/−17 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Rqlite: NotLeader :: RQliteError

Files

hs-rqlite.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                hs-rqlite-version:             0.1.0.0+version:             0.1.1.0 synopsis:            A Haskell client for RQlite description:         See README at <https://github.com/kderme/hs-rqlite/blob/master/README.md> bug-reports:         https://github.com/kderme/hs-rqlite/issues
src/Rqlite.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DeriveAnyClass      #-} {-# LANGUAGE DeriveGeneric       #-}-{-# LANGUAGE LambdaCase          #-} {-# LANGUAGE OverloadedStrings   #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -73,7 +72,7 @@                     ["Failed to decode ", show j, " as PostResult"]  post :: String -> String -> IO (Either (Response String) String)-post request body = do+post request body =     reifyRed $ simpleHTTP $ postRequestWithBody         request         "application/json"@@ -101,8 +100,7 @@                     if redirect                     then case find isLocation (rspHeaders resp) of                         Nothing            -> throwIO $ FailedRedirection resp-                        Just (Header _ q') -> do-                            putStrLn $ "Rqlite Warning: Redirected to " ++ q'+                        Just (Header _ q') ->                             go (n + 1) q' (resp : acc)                     else throwIO $ HttpRedirect resp     go 0 (mkPostRequest host) []@@ -171,13 +169,12 @@                     case eitherDecodeStrict $ Char8.pack respBody of                     Left e -> throwIO $ UnexpectedResponse $ concat                         ["Got ", e, " while trying to decode ", respBody, " as GetResult"]-                    Right (RQResults res)     -> return $ head $ res+                    Right (RQResults res)     -> return $ head res                     Right (RQLeaderError err) -> throwIO $ LeadershipLost err-                Left resp -> do+                Left resp ->                     case find isLocation (rspHeaders resp) of                         Nothing            -> throwIO $ FailedRedirection resp-                        Just (Header _ q') -> do-                            putStrLn $ "Rqlite Warning: Redirected to " ++ q'+                        Just (Header _ q') ->                             go (n + 1) q' (resp : acc)  isLocation :: Header -> Bool@@ -213,7 +210,8 @@     case rspCode resp of         (2,0,0) -> return $ Right $ rspBody resp         (3,_,_) -> return $ Left resp-        _       -> throwIO $ HttpError $ resp+        (5,0,3) | Text.isPrefixOf "not leader"  (Text.pack $ rspBody resp) -> throwIO NotLeader+        _       -> throwIO $ HttpError resp  reifyHTTPErrors :: IO (Response String) -> IO String reifyHTTPErrors action = do@@ -241,5 +239,6 @@     | MaxNumberOfRedirections [Response String]     | FailedRedirection (Response String)     | LeadershipLost Text+    | NotLeader     | UnexpectedResponse String     deriving (Show, Typeable, Exception)
src/Rqlite/Status.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveAnyClass      #-} {-# LANGUAGE DeriveGeneric       #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE OverloadedStrings   #-}@@ -14,6 +13,7 @@ import           Control.Exception import           Data.Aeson hiding (Result) import qualified Data.ByteString.Char8 as C8+import qualified Data.HashMap.Strict as M import           GHC.Generics import           Network.HTTP hiding (host) @@ -29,18 +29,19 @@             , host             , "/status?pretty"             ]-    case eitherDecodeStrict $ C8.pack $ resp of+    case eitherDecodeStrict $ C8.pack resp of             Left e -> throwIO $ UnexpectedResponse $ concat                 ["Got ", e, " while trying to decode ", resp, " as PostResult"]             Right st -> return st -data RQState = Leader | Follower | UnknownState+data RQState = Leader | Follower | Candidate | UnknownState     deriving (Show, Eq, Generic)  readState :: String -> RQState-readState "Leader"   = Leader-readState "Follower" = Follower-readState _          = UnknownState+readState "Leader"    = Leader+readState "Follower"  = Follower+readState "Candidate" = error "Candidate is real"+readState _           = UnknownState  -- | A subset of the status that a node reports. data RQStatus = RQStatus {@@ -58,7 +59,13 @@         pth <- store .: "dir"         ldr <- store .: "leader"         let mLeader = if ldr == "" then Nothing else Just ldr-        prs :: [String] <- store .: "peers"+        prs :: [String] <- case M.lookup "peers" store of+            Just Null -> throw $ UnexpectedResponse $ concat+                [ "peers were empty while querying status! This probably indicates that the node path "+                , pth+                , " does not exist or the peers file was deleted"+                ]+            _    -> store .: "peers"         sqliteInfo <- store .: "sqlite3"         raft <- store .: "raft"         stStr <- raft .: "state"