mirror of
https://github.com/typeable/bloodhound.git
synced 2024-12-04 08:47:36 +03:00
Test restore API
This commit is contained in:
parent
051a15ec05
commit
a451b84b8d
@ -418,7 +418,7 @@ restoreSnapshot
|
||||
-> m Reply
|
||||
restoreSnapshot (SnapshotRepoName repoName)
|
||||
(SnapshotName snapName)
|
||||
SnapshotRestoreSettings {..} = bindM2 put url (return (Just body))
|
||||
SnapshotRestoreSettings {..} = bindM2 post url (return (Just body))
|
||||
where
|
||||
url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
|
||||
params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
|
||||
@ -429,6 +429,8 @@ restoreSnapshot (SnapshotRepoName repoName)
|
||||
, ("rename_pattern" .=) <$> snapRestoreRenamePattern
|
||||
, ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
|
||||
, Just ("include_aliases" .= snapRestoreIncludeAliases)
|
||||
, ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
|
||||
, ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
|
||||
]
|
||||
renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
|
||||
renderToken (RRTLit t) = t
|
||||
|
@ -267,6 +267,7 @@ module Database.Bloodhound.Types
|
||||
, RRGroupRefNum
|
||||
, rrGroupRefNum
|
||||
, mkRRGroupRefNum
|
||||
, RestoreIndexSettings(..)
|
||||
|
||||
, Aggregation(..)
|
||||
, Aggregations
|
||||
@ -3979,8 +3980,16 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
|
||||
, snapRestoreIncludeAliases :: Bool
|
||||
-- ^ Should the restore also restore the aliases captured in the
|
||||
-- snapshot.
|
||||
, snapRestoreIndexSettingsOverrides :: Maybe RestoreIndexSettings
|
||||
-- ^ Settings to apply during the restore process.
|
||||
, snapRestoreIgnoreIndexSettings :: Maybe (NonEmpty Text)
|
||||
-- ^ This type could be more rich but it isn't clear which
|
||||
-- settings are allowed to be ignored during restore, so we're
|
||||
-- going with including this feature in a basic form rather than
|
||||
-- omitting it. One example here would be
|
||||
-- "index.refresh_interval". Any setting specified here will
|
||||
-- revert back to the server default during the restore process.
|
||||
} deriving (Eq, Generic, Show, Typeable)
|
||||
--TODO: temporary settings changes
|
||||
|
||||
-- | Regex-stype pattern, e.g. "index_(.+)" to match index names
|
||||
newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
|
||||
@ -4030,6 +4039,8 @@ mkRRGroupRefNum i
|
||||
-- * snapRestoreRenameReplacement Nothing
|
||||
-- * snapRestorePartial False
|
||||
-- * snapRestoreIncludeAliases True
|
||||
-- * snapRestoreIndexSettingsOverrides Nothing
|
||||
-- * snapRestoreIgnoreIndexSettings Nothing
|
||||
defaultSnapshotRestoreSettings :: SnapshotRestoreSettings
|
||||
defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
|
||||
snapRestoreWaitForCompletion = False
|
||||
@ -4040,4 +4051,20 @@ defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
|
||||
, snapRestoreRenameReplacement = Nothing
|
||||
, snapRestorePartial = False
|
||||
, snapRestoreIncludeAliases = True
|
||||
, snapRestoreIndexSettingsOverrides = Nothing
|
||||
, snapRestoreIgnoreIndexSettings = Nothing
|
||||
}
|
||||
|
||||
|
||||
-- | Index settings that can be overridden. The docs only mention you
|
||||
-- can update number of replicas, but there may be more. You
|
||||
-- definitely cannot override shard count.
|
||||
data RestoreIndexSettings = RestoreIndexSettings {
|
||||
restoreOverrideReplicas :: Maybe ReplicaCount
|
||||
} deriving (Show, Eq, Generic, Typeable)
|
||||
|
||||
|
||||
instance ToJSON RestoreIndexSettings where
|
||||
toJSON RestoreIndexSettings {..} = object prs
|
||||
where
|
||||
prs = catMaybes [("index.number_of_replicas" .=) <$> restoreOverrideReplicas]
|
||||
|
@ -1488,7 +1488,39 @@ main = hspec $ do
|
||||
Left e -> expectationFailure (show e)
|
||||
|
||||
describe "snapshot restore" $ do
|
||||
it "can restore a snapshot that we create" pending
|
||||
it "can restore a snapshot that we create" $ withTestEnv $ do
|
||||
let r1n = SnapshotRepoName "bloodhound-repo1"
|
||||
withSnapshotRepo r1n $ \_ -> do
|
||||
let s1n = SnapshotName "example-snapshot"
|
||||
withSnapshot r1n s1n $ do
|
||||
let settings = defaultSnapshotRestoreSettings { snapRestoreWaitForCompletion = True }
|
||||
-- have to close an index to restore it
|
||||
resp1 <- closeIndex testIndex
|
||||
liftIO (validateStatus resp1 200)
|
||||
resp2 <- restoreSnapshot r1n s1n settings
|
||||
liftIO (validateStatus resp2 200)
|
||||
|
||||
it "can restore and rename" $ withTestEnv $ do
|
||||
let r1n = SnapshotRepoName "bloodhound-repo1"
|
||||
withSnapshotRepo r1n $ \_ -> do
|
||||
let s1n = SnapshotName "example-snapshot"
|
||||
withSnapshot r1n s1n $ do
|
||||
let pat = RestoreRenamePattern "bloodhound-tests-twitter-(\\d+)"
|
||||
let replace = RRTLit "restored-" :| [RRSubWholeMatch]
|
||||
let expectedIndex = IndexName "restored-bloodhound-tests-twitter-1"
|
||||
let overrides = RestoreIndexSettings { restoreOverrideReplicas = Just (ReplicaCount 0) }
|
||||
let settings = defaultSnapshotRestoreSettings { snapRestoreWaitForCompletion = True
|
||||
, snapRestoreRenamePattern = Just pat
|
||||
, snapRestoreRenameReplacement = Just replace
|
||||
, snapRestoreIndexSettingsOverrides = Just overrides
|
||||
}
|
||||
-- have to close an index to restore it
|
||||
let go = do
|
||||
resp <- restoreSnapshot r1n s1n settings
|
||||
liftIO (validateStatus resp 200)
|
||||
exists <- indexExists expectedIndex
|
||||
liftIO (exists `shouldBe` True)
|
||||
go `finally` deleteIndex expectedIndex
|
||||
|
||||
describe "Enum DocVersion" $ do
|
||||
it "follows the laws of Enum, Bounded" $ do
|
||||
|
Loading…
Reference in New Issue
Block a user