git.iko.soy/typeable/bloodhound
on master help sign in
Test restore API
commita451b84b8d9c59949a47157c45c1fda6f3551f1e authorMichael Xavier <michael@michaelxavier.net> dateThu 21 Jul 2016, 09:26 (10 years ago) parent051a15e
3 files changed+64−3
src/Database/Bloodhound/Client.hs+3−1 src/Database/Bloodhound/Types.hs+28−1 tests/tests.hs+33−1
src/Database/Bloodhound/Client.hs+3−1
@@ -418,7 +418,7 @@ restoreSnapshot
418418 -> m Reply
419419restoreSnapshot (SnapshotRepoName repoName)
420420 (SnapshotName snapName)
421− SnapshotRestoreSettings {..} = bindM2 put url (return (Just body))
421+ SnapshotRestoreSettings {..} = bindM2 post url (return (Just body))
422422 where
423423 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
424424 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
@@ -429,6 +429,8 @@ restoreSnapshot (SnapshotRepoName repoName)
429429 , ("rename_pattern" .=) <$> snapRestoreRenamePattern
430430 , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
431431 , Just ("include_aliases" .= snapRestoreIncludeAliases)
432+ , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
433+ , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
432434 ]
433435 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
434436 renderToken (RRTLit t) = t
src/Database/Bloodhound/Types.hs+28−1
@@ -267,6 +267,7 @@ module Database.Bloodhound.Types
267267 , RRGroupRefNum
268268 , rrGroupRefNum
269269 , mkRRGroupRefNum
270+ , RestoreIndexSettings(..)
270271
271272 , Aggregation(..)
272273 , Aggregations
@@ -3979,8 +3980,16 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
39793980 , snapRestoreIncludeAliases :: Bool
39803981 -- ^ Should the restore also restore the aliases captured in the
39813982 -- snapshot.
3983+ , snapRestoreIndexSettingsOverrides :: Maybe RestoreIndexSettings
3984+ -- ^ Settings to apply during the restore process.
3985+ , snapRestoreIgnoreIndexSettings :: Maybe (NonEmpty Text)
3986+ -- ^ This type could be more rich but it isn't clear which
3987+ -- settings are allowed to be ignored during restore, so we're
3988+ -- going with including this feature in a basic form rather than
3989+ -- omitting it. One example here would be
3990+ -- "index.refresh_interval". Any setting specified here will
3991+ -- revert back to the server default during the restore process.
39823992 } deriving (Eq, Generic, Show, Typeable)
3983−--TODO: temporary settings changes
39843993
39853994-- | Regex-stype pattern, e.g. "index_(.+)" to match index names
39863995newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
@@ -4030,6 +4039,8 @@ mkRRGroupRefNum i
40304039-- * snapRestoreRenameReplacement Nothing
40314040-- * snapRestorePartial False
40324041-- * snapRestoreIncludeAliases True
4042+-- * snapRestoreIndexSettingsOverrides Nothing
4043+-- * snapRestoreIgnoreIndexSettings Nothing
40334044defaultSnapshotRestoreSettings :: SnapshotRestoreSettings
40344045defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
40354046 snapRestoreWaitForCompletion = False
@@ -4040,4 +4051,20 @@ defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
40404051 , snapRestoreRenameReplacement = Nothing
40414052 , snapRestorePartial = False
40424053 , snapRestoreIncludeAliases = True
4054+ , snapRestoreIndexSettingsOverrides = Nothing
4055+ , snapRestoreIgnoreIndexSettings = Nothing
40434056 }
4057+
4058+
4059+-- | Index settings that can be overridden. The docs only mention you
4060+-- can update number of replicas, but there may be more. You
4061+-- definitely cannot override shard count.
4062+data RestoreIndexSettings = RestoreIndexSettings {
4063+ restoreOverrideReplicas :: Maybe ReplicaCount
4064+ } deriving (Show, Eq, Generic, Typeable)
4065+
4066+
4067+instance ToJSON RestoreIndexSettings where
4068+ toJSON RestoreIndexSettings {..} = object prs
4069+ where
4070+ prs = catMaybes [("index.number_of_replicas" .=) <$> restoreOverrideReplicas]
tests/tests.hs+33−1
@@ -1488,7 +1488,39 @@ main = hspec $ do
14881488 Left e -> expectationFailure (show e)
14891489
14901490 describe "snapshot restore" $ do
1491− it "can restore a snapshot that we create" pending
1491+ it "can restore a snapshot that we create" $ withTestEnv $ do
1492+ let r1n = SnapshotRepoName "bloodhound-repo1"
1493+ withSnapshotRepo r1n $ \_ -> do
1494+ let s1n = SnapshotName "example-snapshot"
1495+ withSnapshot r1n s1n $ do
1496+ let settings = defaultSnapshotRestoreSettings { snapRestoreWaitForCompletion = True }
1497+ -- have to close an index to restore it
1498+ resp1 <- closeIndex testIndex
1499+ liftIO (validateStatus resp1 200)
1500+ resp2 <- restoreSnapshot r1n s1n settings
1501+ liftIO (validateStatus resp2 200)
1502+
1503+ it "can restore and rename" $ withTestEnv $ do
1504+ let r1n = SnapshotRepoName "bloodhound-repo1"
1505+ withSnapshotRepo r1n $ \_ -> do
1506+ let s1n = SnapshotName "example-snapshot"
1507+ withSnapshot r1n s1n $ do
1508+ let pat = RestoreRenamePattern "bloodhound-tests-twitter-(\\d+)"
1509+ let replace = RRTLit "restored-" :| [RRSubWholeMatch]
1510+ let expectedIndex = IndexName "restored-bloodhound-tests-twitter-1"
1511+ let overrides = RestoreIndexSettings { restoreOverrideReplicas = Just (ReplicaCount 0) }
1512+ let settings = defaultSnapshotRestoreSettings { snapRestoreWaitForCompletion = True
1513+ , snapRestoreRenamePattern = Just pat
1514+ , snapRestoreRenameReplacement = Just replace
1515+ , snapRestoreIndexSettingsOverrides = Just overrides
1516+ }
1517+ -- have to close an index to restore it
1518+ let go = do
1519+ resp <- restoreSnapshot r1n s1n settings
1520+ liftIO (validateStatus resp 200)
1521+ exists <- indexExists expectedIndex
1522+ liftIO (exists `shouldBe` True)
1523+ go `finally` deleteIndex expectedIndex
14921524
14931525 describe "Enum DocVersion" $ do
14941526 it "follows the laws of Enum, Bounded" $ do