Use IndexSelection for snapshot/restore

In the future, IndexSelection can fully support multi-index syntax, so
we should have any API that supports that syntax using IndexSelection so
it gets upgrades for free.
This commit is contained in:
Michael Xavier 2016-07-25 09:30:51 -07:00
parent ec2bfeb793
commit ac5d6f6827
3 changed files with 19 additions and 20 deletions

View File

@ -358,15 +358,16 @@ createSnapshot (SnapshotRepoName repoName)
url = addQuery params <$> joinPath ["_snapshot", repoName, snapName]
params = [("wait_for_completion", Just (boolQP snapWaitForCompletion))]
body = encode $ object prs
prs = catMaybes [ ("indices" .=) . renderIndices <$> snapIndices
prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapIndices
, Just ("ignore_unavailable" .= snapIgnoreUnavailable)
, Just ("ignore_global_state" .= snapIncludeGlobalState)
, Just ("partial" .= snapPartial)
]
renderIndices :: NonEmpty IndexName -> Text
renderIndices (i :| is) = T.intercalate "," (renderIndex <$> (i:is))
indexSelectionName :: IndexSelection -> Text
indexSelectionName AllIndexes = "_all"
indexSelectionName (IndexList (i :| is)) = T.intercalate "," (renderIndex <$> (i:is))
where
renderIndex (IndexName n) = n
@ -425,15 +426,17 @@ restoreSnapshot (SnapshotRepoName repoName)
url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
body = encode (object prs)
prs = catMaybes [ ("indices" .=) . renderIndices <$> snapRestoreIndices
, Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
, Just ("include_global_state" .= snapRestoreIncludeGlobalState)
, ("rename_pattern" .=) <$> snapRestoreRenamePattern
, ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
, Just ("include_aliases" .= snapRestoreIncludeAliases)
, ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
, ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
]
prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapRestoreIndices
, Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
, Just ("include_global_state" .= snapRestoreIncludeGlobalState)
, ("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
renderToken RRSubWholeMatch = "$0"
@ -522,11 +525,6 @@ optimizeIndex ixs IndexOptimizationSettings {..} =
body = Nothing
-------------------------------------------------------------------------------
indexSelectionName :: IndexSelection -> Text
indexSelectionName (IndexList names) = renderIndices names
indexSelectionName AllIndexes = "_all"
deepMerge :: [Object] -> Object
deepMerge = LS.foldl' go mempty
where go acc = LS.foldl' go' acc . HM.toList

View File

@ -861,6 +861,7 @@ newtype IndexName = IndexName Text deriving (Eq, Generic, Read, Show, ToJSON, Fr
{-| 'IndexSelection' is used for APIs which take a single index, a list of
indexes, or the special @_all@ index.
-}
--TODO: this does not fully support <https://www.elastic.co/guide/en/elasticsearch/reference/1.7/multi-index.html multi-index syntax>. It wouldn't be too hard to implement but you'd have to add the optional parameters (ignore_unavailable, allow_no_indices, expand_wildcards) to any APIs using it. Also would be a breaking API.
data IndexSelection = IndexList (NonEmpty IndexName)
| AllIndexes deriving (Eq, Generic, Show, Typeable)
@ -3853,7 +3854,7 @@ data SnapshotCreateSettings = SnapshotCreateSettings {
-- enabled it could wait a long time, so you should adjust your
-- 'ManagerSettings' accordingly to set long timeouts or
-- explicitly handle timeouts.
, snapIndices :: Maybe (NonEmpty IndexName)
, snapIndices :: Maybe IndexSelection
-- ^ Nothing will snapshot all indices. Just [] is permissable and
-- will essentially be a no-op snapshot.
, snapIgnoreUnavailable :: Bool
@ -3989,7 +3990,7 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
-- enabled, it could wait a long time, so you should adjust your
-- 'ManagerSettings' accordingly to set long timeouts or
-- explicitly handle timeouts.
, snapRestoreIndices :: Maybe (NonEmpty IndexName)
, snapRestoreIndices :: Maybe IndexSelection
-- ^ Nothing will restore all indices in the snapshot. Just [] is
-- permissable and will essentially be a no-op restore.
, snapRestoreIgnoreUnavailable :: Bool

View File

@ -358,7 +358,7 @@ withSnapshot srn sn = bracket_ alloc free
liftIO (validateStatus resp 200)
-- We'll make this synchronous for testing purposes
createSettings = defaultSnapshotCreateSettings { snapWaitForCompletion = True
, snapIndices = Just (testIndex :| [])
, snapIndices = Just (IndexList (testIndex :| []))
-- We don't actually need to back up any data
}
free = do