-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Snapshot Restore] Fix initial policy form state #83928
Merged
alisonelizabeth
merged 5 commits into
elastic:master
from
alisonelizabeth:bugfix/save_policy
Dec 2, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33e628b
fix policy intial state when editing a SLM policy
alisonelizabeth e9b2e30
Merge branch 'master' of github.com:elastic/kibana into bugfix/save_p…
alisonelizabeth 0c4792e
add api integration tests
alisonelizabeth 5c8476b
Merge branch 'master' of github.com:elastic/kibana into bugfix/save_p…
alisonelizabeth e8bcd96
address review feedback
alisonelizabeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
x-pack/test/api_integration/apis/management/snapshot_restore/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('Snapshot and Restore', () => { | ||
loadTestFile(require.resolve('./snapshot_restore')); | ||
}); | ||
} |
89 changes: 89 additions & 0 deletions
89
x-pack/test/api_integration/apis/management/snapshot_restore/lib/elasticsearch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
interface SlmPolicy { | ||
name: string; | ||
snapshotName: string; | ||
schedule: string; | ||
repository: string; | ||
isManagedPolicy: boolean; | ||
config?: { | ||
indices?: string | string[]; | ||
ignoreUnavailable?: boolean; | ||
includeGlobalState?: boolean; | ||
partial?: boolean; | ||
metadata?: Record<string, string>; | ||
}; | ||
retention?: { | ||
expireAfterValue?: number | ''; | ||
expireAfterUnit?: string; | ||
maxCount?: number | ''; | ||
minCount?: number | ''; | ||
}; | ||
} | ||
|
||
/** | ||
* Helpers to create and delete SLM policies on the Elasticsearch instance | ||
* during our tests. | ||
* @param {ElasticsearchClient} es The Elasticsearch client instance | ||
*/ | ||
export const registerEsHelpers = (getService: FtrProviderContext['getService']) => { | ||
let policiesCreated: string[] = []; | ||
|
||
const es = getService('legacyEs'); | ||
|
||
const createRepository = (repoName: string) => { | ||
return es.snapshot.createRepository({ | ||
repository: repoName, | ||
body: { | ||
type: 'fs', | ||
settings: { | ||
location: '/tmp/', | ||
}, | ||
}, | ||
verify: false, | ||
}); | ||
}; | ||
|
||
const createPolicy = (policy: SlmPolicy, cachePolicy?: boolean) => { | ||
if (cachePolicy) { | ||
policiesCreated.push(policy.name); | ||
} | ||
|
||
return es.sr.updatePolicy({ | ||
name: policy.name, | ||
body: policy, | ||
}); | ||
}; | ||
|
||
const getPolicy = (policyName: string) => { | ||
return es.sr.policy({ | ||
name: policyName, | ||
human: true, | ||
}); | ||
}; | ||
|
||
const deletePolicy = (policyName: string) => es.sr.deletePolicy({ name: policyName }); | ||
|
||
const cleanupPolicies = () => | ||
Promise.all(policiesCreated.map(deletePolicy)) | ||
.then(() => { | ||
policiesCreated = []; | ||
}) | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`[Cleanup error] Error deleting ES resources: ${err.message}`); | ||
}); | ||
|
||
return { | ||
createRepository, | ||
createPolicy, | ||
deletePolicy, | ||
cleanupPolicies, | ||
getPolicy, | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/test/api_integration/apis/management/snapshot_restore/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { registerEsHelpers } from './elasticsearch'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for this comment!