git.iko.soy/typeable/bloodhound
on master help sign in
Wrap up feature
commit42040f8318af28b7b68722394426ccd29c5253a7 authorMichael Xavier <michael@michaelxavier.net> dateThu 21 Jul 2016, 10:35 (10 years ago) parenta451b84
2 files changed+43−14
src/Database/Bloodhound/Client.hs+4−2 src/Database/Bloodhound/Types.hs+39−12
src/Database/Bloodhound/Client.hs+4−2
@@ -343,6 +343,7 @@ deleteSnapshotRepo (SnapshotRepoName n) = delete =<< url
343343 url = joinPath ["_snapshot", n]
344344
345345
346+-- | Create and start a snapshot
346347createSnapshot
347348 :: (MonadBH m)
348349 => SnapshotRepoName
@@ -370,14 +371,14 @@ renderIndices (i :| is) = T.intercalate "," (renderIndex <$> (i:is))
370371 renderIndex (IndexName n) = n
371372
372373
374+-- | Get info about known snapshots given a pattern and repo name.
373375getSnapshots
374376 :: ( MonadBH m
375377 , MonadThrow m
376378 )
377379 => SnapshotRepoName
378380 -> SnapshotSelection
379− -> m (Either EsError
380− [SnapshotInfo])
381+ -> m (Either EsError [SnapshotInfo])
381382getSnapshots (SnapshotRepoName repoName) sel =
382383 fmap (fmap unSIs) . parseEsResponse =<< get =<< url
383384 where
@@ -398,6 +399,7 @@ instance FromJSON SIs where
398399 parse o = SIs <$> o .: "snapshots"
399400
400401
402+-- | Delete a snapshot. Cancels if it is running.
401403deleteSnapshot :: MonadBH m => SnapshotRepoName -> SnapshotName -> m Reply
402404deleteSnapshot (SnapshotRepoName repoName) (SnapshotName snapName) =
403405 delete =<< url
src/Database/Bloodhound/Types.hs+39−12
@@ -258,6 +258,8 @@ module Database.Bloodhound.Types
258258 , SnapshotSelection(..)
259259 , SnapshotPattern(..)
260260 , SnapshotInfo(..)
261+ , SnapshotShardFailure(..)
262+ , ShardId(..)
261263 , SnapshotName(..)
262264 , SnapshotState(..)
263265 , SnapshotRestoreSettings(..)
@@ -3687,7 +3689,7 @@ data SnapshotRepoSelection = SnapshotRepoList (NonEmpty SnapshotRepoPattern)
36873689
36883690
36893691-- | Either specifies an exact repo name or one with globs in it,
3690−-- e.g. @RepoPattern "foo*"@ __NOTE__:@ Patterns are not supported on ES < 1.7
3692+-- e.g. @RepoPattern "foo*"@ __NOTE__: Patterns are not supported on ES < 1.7
36913693data SnapshotRepoPattern = ExactRepo SnapshotRepoName
36923694 | RepoPattern Text
36933695 deriving (Eq, Generic, Show, Typeable)
@@ -3746,6 +3748,7 @@ instance FromJSON SnapshotVerification where
37463748 SnapshotNodeVerification (FullNodeId rawFullId) <$> o .: "name"
37473749
37483750
3751+-- | A node that has verified a snapshot
37493752data SnapshotNodeVerification = SnapshotNodeVerification {
37503753 snvFullId :: FullNodeId
37513754 , snvNodeName :: NodeName
@@ -3758,6 +3761,8 @@ newtype FullNodeId = FullNodeId { fullNodeId :: Text }
37583761 deriving (Eq, Ord, Generic, Show, Typeable, FromJSON)
37593762
37603763
3764+-- | A human-readable node name that is supplied by the user in the
3765+-- node config or automatically generated by ElasticSearch.
37613766newtype NodeName = NodeName { nodeName :: Text }
37623767 deriving (Eq, Ord, Generic, Show, Typeable, FromJSON)
37633768
@@ -3778,14 +3783,19 @@ defaultSnapshotRepoUpdateSettings :: SnapshotRepoUpdateSettings
37783783defaultSnapshotRepoUpdateSettings = SnapshotRepoUpdateSettings True
37793784
37803785
3781−-- | A filesystem-based snapshot repo that ships with elasticsearch.
3786+-- | A filesystem-based snapshot repo that ships with
3787+-- ElasticSearch. This is an instance of 'SnapshotRepo' so it can be
3788+-- used with 'updateSnapshotRepo'
37823789data FsSnapshotRepo = FsSnapshotRepo {
37833790 fsrName :: SnapshotRepoName
37843791 , fsrLocation :: FilePath
37853792 , fsrCompressMetadata :: Bool
37863793 , fsrChunkSize :: Maybe Bytes
3794+ -- ^ Size by which to split large files during snapshotting.
37873795 , fsrMaxRestoreBytesPerSec :: Maybe Bytes
3796+ -- ^ Throttle node restore rate. If not supplied, defaults to 40mb/sec
37883797 , fsrMaxSnapshotBytesPerSec :: Maybe Bytes
3798+ -- ^ Throttle node snapshot rate. If not supplied, defaults to 40mb/sec
37893799 } deriving (Eq, Generic, Show, Typeable)
37903800
37913801
@@ -3827,10 +3837,8 @@ class SnapshotRepo r where
38273837 fromGSnapshotRepo :: GenericSnapshotRepo -> Either SnapshotRepoConversionError r
38283838
38293839
3830−data SnapshotRepoConversionError = RepoTypeMismatch SnapshotRepoType
3831− -- ^ Expected type
3832− SnapshotRepoType
3833− -- ^ Actual type
3840+data SnapshotRepoConversionError = RepoTypeMismatch SnapshotRepoType SnapshotRepoType
3841+ -- ^ Expected type and actual type
38343842 | OtherRepoConversionError Text
38353843 deriving (Show, Eq, Generic, Typeable)
38363844
@@ -3891,7 +3899,7 @@ data SnapshotPattern = ExactSnap SnapshotName
38913899-- redundancies with 'SnapshotStatus'
38923900data SnapshotInfo = SnapshotInfo {
38933901 snapInfoShards :: ShardResult
3894− --TODO: what does failures produce? list of what?
3902+ , snapInfoFailures :: [SnapshotShardFailure]
38953903 , snapInfoDuration :: NominalDiffTime
38963904 , snapInfoEndTime :: UTCTime
38973905 , snapInfoStartTime :: UTCTime
@@ -3905,6 +3913,7 @@ instance FromJSON SnapshotInfo where
39053913 parseJSON = withObject "SnapshotInfo" parse
39063914 where
39073915 parse o = SnapshotInfo <$> o .: "shards"
3916+ <*> o .: "failures"
39083917 <*> (unMS <$> o .: "duration_in_millis")
39093918 <*> (posixMS <$> o .: "end_time_in_millis")
39103919 <*> (posixMS <$> o .: "start_time_in_millis")
@@ -3912,6 +3921,26 @@ instance FromJSON SnapshotInfo where
39123921 <*> o .: "indices"
39133922 <*> o .: "snapshot"
39143923
3924+data SnapshotShardFailure = SnapshotShardFailure {
3925+ snapShardFailureIndex :: IndexName
3926+ , snapShardFailureNodeId :: Maybe NodeName -- I'm not 100% sure this isn't actually 'FullNodeId'
3927+ , snapShardFailureReason :: Text
3928+ , snapShardFailureShardId :: ShardId
3929+ } deriving (Eq, Show, Generic, Typeable)
3930+
3931+
3932+instance FromJSON SnapshotShardFailure where
3933+ parseJSON = withObject "SnapshotShardFailure" parse
3934+ where
3935+ parse o = SnapshotShardFailure <$> o .: "index"
3936+ <*> o .:? "node_id"
3937+ <*> o .: "reason"
3938+ <*> o .: "shard_id"
3939+
3940+
3941+newtype ShardId = ShardId { shardId :: Int }
3942+ deriving (Eq, Show, Generic, Typeable, FromJSON)
3943+
39153944-- | Milliseconds
39163945newtype MS = MS NominalDiffTime
39173946
@@ -3999,8 +4028,7 @@ newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
39994028-- | A single token in a index renaming scheme for a restore. These
40004029-- are concatenated into a string before being sent to
40014030-- ElasticSearch. Check out these Java
4002−-- <https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html
4003−-- docs> to find out more if you're into that sort of thing.
4031+-- <https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html docs> to find out more if you're into that sort of thing.
40044032data RestoreRenameToken = RRTLit Text
40054033 -- ^ Just a literal string of characters
40064034 | RRSubWholeMatch
@@ -4011,7 +4039,7 @@ data RestoreRenameToken = RRTLit Text
40114039
40124040
40134041-- | A group number for regex matching. Only values from 1-9 are
4014−-- supported. Construct with mkRRGroupRefNum
4042+-- supported. Construct with 'mkRRGroupRefNum'
40154043newtype RRGroupRefNum = RRGroupRefNum { rrGroupRefNum :: Int }
40164044 deriving (Show, Eq, Generic, Typeable, Ord)
40174045
@@ -4020,8 +4048,7 @@ instance Bounded RRGroupRefNum where
40204048 maxBound = RRGroupRefNum 9
40214049
40224050
4023−
4024−-- | Only allows valid group number references (0-9).
4051+-- | Only allows valid group number references (1-9).
40254052mkRRGroupRefNum :: Int -> Maybe RRGroupRefNum
40264053mkRRGroupRefNum i
40274054 | i >= (rrGroupRefNum minBound) && i <= (rrGroupRefNum maxBound) =