{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Network.Livy.Client.Batch.GetBatchLogs
(
GetBatchLogs (..)
, getBatchLogs
, gblFrom
, gblSize
, GetBatchLogsResponse (..)
, gblrId
, gblrFrom
, gblrSize
, gblrLog
) where
import Control.Lens
import Data.Aeson.TH
import qualified Data.ByteString.Char8 as C
import Data.Maybe (isJust)
import Data.Text (Text)
import Data.Typeable
import Network.Livy.Client.Internal.JSON
import Network.Livy.Client.Types.Batch
import Network.Livy.Internal.Text
import Network.Livy.Request
import Network.Livy.Types
data GetBatchLogs = GetBatchLogs
{ _gblBatchId :: BatchId
, _gblFrom :: Maybe Int
, _gblSize :: Maybe Int
} deriving (Eq, Show, Typeable)
makeLenses ''GetBatchLogs
instance ToPath GetBatchLogs where
toPath r = toPath ["batches", toText $ r ^. gblBatchId, "log"]
instance ToQuery GetBatchLogs where
toQueryString r = filter (isJust . snd)
[ ("from", C.pack . show <$> r ^. gblFrom)
, ("size", C.pack . show <$> r ^. gblSize)
]
instance LivyRequest GetBatchLogs where
request = getQuery
getBatchLogs :: BatchId -> GetBatchLogs
getBatchLogs bid = GetBatchLogs bid Nothing Nothing
data GetBatchLogsResponse = GetBatchLogsResponse
{ _gblrId :: !BatchId
, _gblrFrom :: !Int
, _gblrSize :: !(Maybe Int)
, _gblrLog :: ![Text]
} deriving (Eq, Show, Typeable)
makeLenses ''GetBatchLogsResponse
deriveFromJSON (recordPrefixOptions 5) ''GetBatchLogsResponse
type instance LivyResponse GetBatchLogs = GetBatchLogsResponse