@@ -253,6 +253,13 @@ module Database.Bloodhound.Types
253253 , FullNodeId(..)
254254 , NodeName(..)
255255 , FsSnapshotRepo(..)
256+ , SnapshotCreateSettings(..)
257+ , defaultSnapshotCreateSettings
258+ , SnapshotSelection(..)
259+ , SnapshotPattern(..)
260+ , SnapshotInfo(..)
261+ , SnapshotName(..)
262+ , SnapshotState(..)
256263
257264 , Aggregation(..)
258265 , Aggregations
@@ -3672,7 +3679,7 @@ data SnapshotRepoSelection = SnapshotRepoList (NonEmpty SnapshotRepoPattern)
36723679
36733680
36743681-- | Either specifies an exact repo name or one with globs in it,
3675−-- e.g. @RepoPattern "foo*"@ __NOTE__: Patterns are not supported on ES < 1.7
3682+-- e.g. @RepoPattern "foo*"@ __NOTE__:@ Patterns are not supported on ES < 1.7
36763683data SnapshotRepoPattern = ExactRepo SnapshotRepoName
36773684 | RepoPattern Text
36783685 deriving (Eq, Generic, Show, Typeable)
@@ -3716,7 +3723,7 @@ newtype GenericSnapshotRepoSettings = GenericSnapshotRepoSettings { gSnapshotRep
37163723instance FromJSON GenericSnapshotRepoSettings where
37173724 parseJSON = fmap (GenericSnapshotRepoSettings . fmap unStringlyTypeJSON). parseJSON
37183725
3719−-- | The result of running 'verifySnapshotRepo'. --TODO: more detail once you know what a failure looks like
3726+-- | The result of running 'verifySnapshotRepo'.
37203727newtype SnapshotVerification = SnapshotVerification { snapshotNodeVerifications :: [SnapshotNodeVerification] }
37213728 deriving (Eq, Generic, Show, Typeable)
37223729
@@ -3797,7 +3804,6 @@ instance SnapshotRepo FsSnapshotRepo where
37973804 | otherwise = Left (RepoTypeMismatch fsRepoType gSnapshotRepoType)
37983805
37993806
3800−--TODO: test what error case looks like
38013807parseRepo :: Parser a -> Either SnapshotRepoConversionError a
38023808parseRepo parser = case parseEither (const parser) () of
38033809 Left e -> Left (OtherRepoConversionError (T.pack e))
@@ -3822,3 +3828,113 @@ data SnapshotRepoConversionError = RepoTypeMismatch SnapshotRepoType
38223828
38233829
38243830instance Exception SnapshotRepoConversionError
3831+
3832+
3833+data SnapshotCreateSettings = SnapshotCreateSettings {
3834+ snapWaitForCompletion :: Bool
3835+ -- ^ Should the API call return immediately after initializing
3836+ -- the snapshot or wait until completed. Note that if this is
3837+ -- enabled it could wait a long time, so you should adjust your
3838+ -- 'ManagerSettings' accordingly to set long timeouts or
3839+ -- explicitly handle timeouts.
3840+ , snapIndices :: Maybe (NonEmpty IndexName)
3841+ -- ^ Nothing will snapshot all indices. Just [] is permissable and
3842+ -- will essentially be a no-op snapshot.
3843+ , snapIgnoreUnavailable :: Bool
3844+ -- ^ If set to True, any matched indices that don't exist will be
3845+ -- ignored. Otherwise it will be an error and fail.
3846+ , snapIncludeGlobalState :: Bool
3847+ , snapPartial :: Bool
3848+ -- ^ If some indices failed to snapshot (e.g. if not all primary
3849+ -- shards are available), should the process proceed?
3850+ }
3851+
3852+
3853+-- | Reasonable defaults for snapshot creation
3854+--
3855+-- * snapWaitForCompletion False
3856+-- * snapIndices Nothing
3857+-- * snapIgnoreUnavailable False
3858+-- * snapIncludeGlobalState True
3859+-- * snapPartial False
3860+defaultSnapshotCreateSettings :: SnapshotCreateSettings
3861+defaultSnapshotCreateSettings =
3862+ SnapshotCreateSettings False Nothing False True False
3863+
3864+
3865+data SnapshotSelection = SnapshotList (NonEmpty SnapshotPattern)
3866+ | AllSnapshots deriving (Eq, Generic, Show, Typeable)
3867+
3868+
3869+-- | Either specifies an exact snapshot name or one with globs in it,
3870+-- e.g. @SnapPattern "foo*"@ __NOTE__: Patterns are not supported on
3871+-- ES < 1.7
3872+data SnapshotPattern = ExactSnap SnapshotName
3873+ | SnapPattern Text
3874+ deriving (Eq, Generic, Show, Typeable)
3875+
3876+
3877+-- | General information about the state of a snapshot. Has some
3878+-- redundancies with 'SnapshotStatus'
3879+data SnapshotInfo = SnapshotInfo {
3880+ snapInfoShards :: ShardResult
3881+ --TODO: what does failures produce? list of what?
3882+ , snapInfoDuration :: NominalDiffTime
3883+ , snapInfoEndTime :: UTCTime
3884+ , snapInfoStartTime :: UTCTime
3885+ , snapInfoState :: SnapshotState
3886+ , snapInfoIndices :: [IndexName]
3887+ , snapInfoName :: SnapshotName
3888+ } deriving (Eq, Generic, Show, Typeable)
3889+
3890+
3891+instance FromJSON SnapshotInfo where
3892+ parseJSON = withObject "SnapshotInfo" parse
3893+ where
3894+ parse o = SnapshotInfo <$> o .: "shards"
3895+ <*> (unMS <$> o .: "duration_in_millis")
3896+ <*> (posixMS <$> o .: "end_time_in_millis")
3897+ <*> (posixMS <$> o .: "start_time_in_millis")
3898+ <*> o .: "state"
3899+ <*> o .: "indices"
3900+ <*> o .: "snapshot"
3901+
3902+-- | Milliseconds
3903+newtype MS = MS NominalDiffTime
3904+
3905+
3906+-- keeps the unexported constructor warnings at bay
3907+unMS :: MS -> NominalDiffTime
3908+unMS (MS t) = t
3909+
3910+
3911+instance FromJSON MS where
3912+ parseJSON = withScientific "MS" (return . MS . parse)
3913+ where
3914+ parse n = fromInteger ((truncate n) * 1000)
3915+
3916+
3917+data SnapshotState = SnapshotInit
3918+ | SnapshotStarted
3919+ | SnapshotSuccess
3920+ | SnapshotFailed
3921+ | SnapshotAborted
3922+ | SnapshotMissing
3923+ | SnapshotWaiting
3924+ deriving (Show, Eq, Generic, Typeable)
3925+
3926+instance FromJSON SnapshotState where
3927+ parseJSON = withText "SnapshotState" parse
3928+ where
3929+ parse "INIT" = return SnapshotInit
3930+ parse "STARTED" = return SnapshotStarted
3931+ parse "SUCCESS" = return SnapshotSuccess
3932+ parse "FAILED" = return SnapshotFailed
3933+ parse "ABORTED" = return SnapshotAborted
3934+ parse "MISSING" = return SnapshotMissing
3935+ parse "WAITING" = return SnapshotWaiting
3936+ parse t = fail ("Invalid snapshot state " <> T.unpack t)
3937+
3938+
3939+newtype SnapshotName = SnapshotName { snapshotName :: Text }
3940+ deriving (Show, Eq, Ord, Generic, Typeable, ToJSON, FromJSON)