git.iko.soy/typeable/bloodhound
on master help sign in
Test restore API
a451b84Michael Xavier
src/Database/Bloodhound/Client.hs+3−1
@@ -418,7 +418,7 @@ restoreSnapshot
418 -> m Reply
418 -> m Reply
419restoreSnapshot (SnapshotRepoName repoName)
419restoreSnapshot (SnapshotRepoName repoName)
420 (SnapshotName snapName)
420 (SnapshotName snapName)
421− SnapshotRestoreSettings {..} = bindM2 put url (return (Just body))
421+ SnapshotRestoreSettings {..} = bindM2 post url (return (Just body))
422 where
422 where
423 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
423 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
424 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
424 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
@@ -429,6 +429,8 @@ restoreSnapshot (SnapshotRepoName repoName)
429 , ("rename_pattern" .=) <$> snapRestoreRenamePattern
429 , ("rename_pattern" .=) <$> snapRestoreRenamePattern
430 , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
430 , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
431 , Just ("include_aliases" .= snapRestoreIncludeAliases)
431 , Just ("include_aliases" .= snapRestoreIncludeAliases)
432+ , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
433+ , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
432 ]
434 ]
433 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
435 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
434 renderToken (RRTLit t) = t
436 renderToken (RRTLit t) = t
src/Database/Bloodhound/Types.hs+28−1
@@ -267,6 +267,7 @@ module Database.Bloodhound.Types
267 , RRGroupRefNum
267 , RRGroupRefNum
268 , rrGroupRefNum
268 , rrGroupRefNum
269 , mkRRGroupRefNum
269 , mkRRGroupRefNum
270+ , RestoreIndexSettings(..)
270
271
271 , Aggregation(..)
272 , Aggregation(..)
272 , Aggregations
273 , Aggregations
@@ -3979,8 +3980,16 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
3979 , snapRestoreIncludeAliases :: Bool
3980 , snapRestoreIncludeAliases :: Bool
3980 -- ^ Should the restore also restore the aliases captured in the
3981 -- ^ Should the restore also restore the aliases captured in the
3981 -- snapshot.
3982 -- 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.
3982 } deriving (Eq, Generic, Show, Typeable)
3992 } deriving (Eq, Generic, Show, Typeable)
3983−--TODO: temporary settings changes
3984
3993
3985-- | Regex-stype pattern, e.g. "index_(.+)" to match index names
3994-- | Regex-stype pattern, e.g. "index_(.+)" to match index names
3986newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
3995newtype RestoreRenamePattern = RestoreRenamePattern { rrPattern :: Text }
@@ -4030,6 +4039,8 @@ mkRRGroupRefNum i
4030-- * snapRestoreRenameReplacement Nothing
4039-- * snapRestoreRenameReplacement Nothing
4031-- * snapRestorePartial False
4040-- * snapRestorePartial False
4032-- * snapRestoreIncludeAliases True
4041-- * snapRestoreIncludeAliases True
4042+-- * snapRestoreIndexSettingsOverrides Nothing
4043+-- * snapRestoreIgnoreIndexSettings Nothing
4033defaultSnapshotRestoreSettings :: SnapshotRestoreSettings
4044defaultSnapshotRestoreSettings :: SnapshotRestoreSettings
4034defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
4045defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
4035 snapRestoreWaitForCompletion = False
4046 snapRestoreWaitForCompletion = False
@@ -4040,4 +4051,20 @@ defaultSnapshotRestoreSettings = SnapshotRestoreSettings {
4040 , snapRestoreRenameReplacement = Nothing
4051 , snapRestoreRenameReplacement = Nothing
4041 , snapRestorePartial = False
4052 , snapRestorePartial = False
4042 , snapRestoreIncludeAliases = True
4053 , snapRestoreIncludeAliases = True
4054+ , snapRestoreIndexSettingsOverrides = Nothing
4055+ , snapRestoreIgnoreIndexSettings = Nothing
4043 }
4056 }
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
1488 Left e -> expectationFailure (show e)
1488 Left e -> expectationFailure (show e)
1489
1489
1490 describe "snapshot restore" $ do
1490 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
1492
1524
1493 describe "Enum DocVersion" $ do
1525 describe "Enum DocVersion" $ do
1494 it "follows the laws of Enum, Bounded" $ do
1526 it "follows the laws of Enum, Bounded" $ do