@@ -260,6 +260,13 @@ module Database.Bloodhound.Types
260260 , SnapshotInfo(..)
261261 , SnapshotName(..)
262262 , SnapshotState(..)
263+ , SnapshotRestoreSettings(..)
264+ , defaultSnapshotRestoreSettings
265+ , RestoreRenamePattern(..)
266+ , RestoreRenameToken(..)
267+ , RRGroupRefNum
268+ , rrGroupRefNum
269+ , mkRRGroupRefNum
263270
264271 , Aggregation(..)
265272 , Aggregations
@@ -3831,23 +3838,23 @@ instance Exception SnapshotRepoConversionError
38313838
38323839
38333840data SnapshotCreateSettings = SnapshotCreateSettings {
3834− snapWaitForCompletion :: Bool
3841+ snapWaitForCompletion :: Bool
38353842 -- ^ Should the API call return immediately after initializing
3836− -- the snapshot or wait until completed. Note that if this is
3843+ -- the snapshot or wait until completed? Note that if this is
38373844 -- enabled it could wait a long time, so you should adjust your
38383845 -- 'ManagerSettings' accordingly to set long timeouts or
38393846 -- explicitly handle timeouts.
3840− , snapIndices :: Maybe (NonEmpty IndexName)
3847+ , snapIndices :: Maybe (NonEmpty IndexName)
38413848 -- ^ Nothing will snapshot all indices. Just [] is permissable and
38423849 -- will essentially be a no-op snapshot.
3843− , snapIgnoreUnavailable :: Bool
3850+ , snapIgnoreUnavailable :: Bool
38443851 -- ^ If set to True, any matched indices that don't exist will be
38453852 -- ignored. Otherwise it will be an error and fail.
38463853 , snapIncludeGlobalState :: Bool
3847− , snapPartial :: Bool
3854+ , snapPartial :: Bool
38483855 -- ^ If some indices failed to snapshot (e.g. if not all primary
38493856 -- shards are available), should the process proceed?
3850− }
3857+ } deriving (Eq, Generic, Show, Typeable)
38513858
38523859
38533860-- | Reasonable defaults for snapshot creation
@@ -3858,8 +3865,13 @@ data SnapshotCreateSettings = SnapshotCreateSettings {
38583865-- * snapIncludeGlobalState True
38593866-- * snapPartial False
38603867defaultSnapshotCreateSettings :: SnapshotCreateSettings
3861−defaultSnapshotCreateSettings =
3862− SnapshotCreateSettings False Nothing False True False
3868+defaultSnapshotCreateSettings = SnapshotCreateSettings {
3869+ snapWaitForCompletion = False
3870+ , snapIndices = Nothing
3871+ , snapIgnoreUnavailable = False
3872+ , snapIncludeGlobalState = True
3873+ , snapPartial = False
3874+ }
38633875
38643876
38653877data SnapshotSelection = SnapshotList (NonEmpty SnapshotPattern)
@@ -3938,3 +3950,94 @@ instance FromJSON SnapshotState where
39383950
39393951newtype SnapshotName = SnapshotName { snapshotName :: Text }
39403952 deriving (Show, Eq, Ord, Generic, Typeable, ToJSON, FromJSON)
3953+
3954+
3955+data SnapshotRestoreSettings = SnapshotRestoreSettings {
3956+ snapRestoreWaitForCompletion :: Bool
3957+ -- ^ Should the API call return immediately after initializing
3958+ -- the restore or wait until completed? Note that if this is
3959+ -- enabled, it could wait a long time, so you should adjust your
3960+ -- 'ManagerSettings' accordingly to set long timeouts or
3961+ -- explicitly handle timeouts.
3962+ , snapRestoreIndices :: Maybe (NonEmpty IndexName)
3963+ -- ^ Nothing will restore all indices in the snapshot. Just [] is
3964+ -- permissable and will essentially be a no-op restore.
3965+ , snapRestoreIgnoreUnavailable :: Bool
3966+ -- ^ If set to True, any indices that do not exist will be ignored
3967+ -- during snapshot rather than failing the restore.
3968+ , snapRestoreIncludeGlobalState :: Bool
3969+ -- ^ If set to false, will ignore any global state in the snapshot
3970+ -- and will not restore it.
3971+ , snapRestoreRenamePattern :: Maybe RestoreRenamePattern
3972+ -- ^ A regex pattern for matching indices. Used with
3973+ -- 'snapRestoreRenameReplacement', the restore can reference the
3974+ -- matched index and create a new index name upon restore.
3975+ , snapRestoreRenameReplacement :: Maybe (NonEmpty RestoreRenameToken)
3976+ -- ^ Expression of how index renames should be constructed.
3977+ , snapRestorePartial :: Bool
3978+ -- ^ If some indices fail to restore, should the process proceed?
3979+ , snapRestoreIncludeAliases :: Bool
3980+ -- ^ Should the restore also restore the aliases captured in the
3981+ -- snapshot.
3982+ } deriving (Eq, Generic, Show, Typeable)
3983+--TODO: temporary settings changes
3984+
3985+-- | Regex-stype pattern, e.g. "index_(.+)" to match index names
3986+newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
3987+ deriving (Show, Eq, Generic, Typeable, Ord, ToJSON)
3988+
3989+
3990+-- | A single token in a index renaming scheme for a restore. These
3991+-- are concatenated into a string before being sent to
3992+-- ElasticSearch. Check out these Java
3993+-- <https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html
3994+-- docs> to find out more if you're into that sort of thing.
3995+data RestoreRenameToken = RRTLit Text
3996+ -- ^ Just a literal string of characters
3997+ | RRSubWholeMatch
3998+ -- ^ Equivalent to $0. The entire matched pattern, not any subgroup
3999+ | RRSubGroup RRGroupRefNum
4000+ -- ^ A specific reference to a group number
4001+ deriving (Show, Eq, Generic, Typeable)
4002+
4003+
4004+-- | A group number for regex matching. Only values from 1-9 are
4005+-- supported. Construct with mkRRGroupRefNum
4006+newtype RRGroupRefNum = RRGroupRefNum { rrGroupRefNum :: Int }
4007+ deriving (Show, Eq, Generic, Typeable, Ord)
4008+
4009+instance Bounded RRGroupRefNum where
4010+ minBound = RRGroupRefNum 1
4011+ maxBound = RRGroupRefNum 9
4012+
4013+
4014+
4015+-- | Only allows valid group number references (0-9).
4016+mkRRGroupRefNum :: Int -> Maybe RRGroupRefNum
4017+mkRRGroupRefNum i
4018+ | i >= (rrGroupRefNum minBound) && i <= (rrGroupRefNum maxBound) =
4019+ Just $ RRGroupRefNum i
4020+ | otherwise = Nothing
4021+
4022+
4023+-- | Reasonable defaults for snapshot restores
4024+--
4025+-- * snapRestoreWaitForCompletion False
4026+-- * snapRestoreIndices Nothing
4027+-- * snapRestoreIgnoreUnavailable False
4028+-- * snapRestoreIncludeGlobalState True
4029+-- * snapRestoreRenamePattern Nothing
4030+-- * snapRestoreRenameReplacement Nothing
4031+-- * snapRestorePartial False
4032+-- * snapRestoreIncludeAliases True
4033+defaultSnapshotRestoreSettings :: SnapshotRestoreSettings
4034+defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
4035+ snapRestoreWaitForCompletion = False
4036+ , snapRestoreIndices = Nothing
4037+ , snapRestoreIgnoreUnavailable = False
4038+ , snapRestoreIncludeGlobalState = True
4039+ , snapRestoreRenamePattern = Nothing
4040+ , snapRestoreRenameReplacement = Nothing
4041+ , snapRestorePartial = False
4042+ , snapRestoreIncludeAliases = True
4043+ }