mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Retrieve paused state of follower index from ES instead of depending upon the client to provide it. (#35342) (#35409)
This commit is contained in:
parent
5415c8303a
commit
798e92655f
1 changed files with 25 additions and 9 deletions
|
@ -89,13 +89,13 @@ export const registerFollowerIndexRoutes = (server) => {
|
|||
|
||||
const followerIndexInfo = followerIndices && followerIndices[0];
|
||||
|
||||
if(!followerIndexInfo) {
|
||||
if (!followerIndexInfo) {
|
||||
const error = Boom.notFound(`The follower index "${id}" does not exist.`);
|
||||
throw(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
// If this follower is paused, skip call to ES stats api since it will return 404
|
||||
if(followerIndexInfo.status === 'paused') {
|
||||
if (followerIndexInfo.status === 'paused') {
|
||||
return deserializeFollowerIndex({
|
||||
...followerIndexInfo
|
||||
});
|
||||
|
@ -154,19 +154,35 @@ export const registerFollowerIndexRoutes = (server) => {
|
|||
},
|
||||
handler: async (request) => {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const { id: _id } = request.params;
|
||||
const { isPaused = false } = request.payload;
|
||||
const body = removeEmptyFields(serializeAdvancedSettings(request.payload));
|
||||
const { id } = request.params;
|
||||
|
||||
async function isFollowerIndexPaused() {
|
||||
const {
|
||||
follower_indices: followerIndices
|
||||
} = await callWithRequest('ccr.info', { id });
|
||||
|
||||
const followerIndexInfo = followerIndices && followerIndices[0];
|
||||
|
||||
if (!followerIndexInfo) {
|
||||
const error = Boom.notFound(`The follower index "${id}" does not exist.`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return followerIndexInfo.status === 'paused';
|
||||
}
|
||||
|
||||
// We need to first pause the follower and then resume it passing the advanced settings
|
||||
try {
|
||||
// Retrieve paused state instead of pulling it from the payload to ensure it's not stale.
|
||||
const isPaused = await isFollowerIndexPaused();
|
||||
// Pause follower if not already paused
|
||||
if(!isPaused) {
|
||||
await callWithRequest('ccr.pauseFollowerIndex', { id: _id });
|
||||
if (!isPaused) {
|
||||
await callWithRequest('ccr.pauseFollowerIndex', { id });
|
||||
}
|
||||
|
||||
// Resume follower
|
||||
return await callWithRequest('ccr.resumeFollowerIndex', { id: _id, body });
|
||||
const body = removeEmptyFields(serializeAdvancedSettings(request.payload));
|
||||
return await callWithRequest('ccr.resumeFollowerIndex', { id, body });
|
||||
} catch(err) {
|
||||
if (isEsError(err)) {
|
||||
throw wrapEsError(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue