-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Do not restore autoscaling policy from snapshots #66023
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
Merged
ywangd
merged 9 commits into
elastic:master
from
ywangd:do-not-restore-autoscaling-policy
Dec 11, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2b5ac26
Initial working version
ywangd 00b1c40
spotless
ywangd eeeca94
more spotless
ywangd 475dbc1
address feedback
ywangd 7a6dbd8
Merge remote-tracking branch 'origin/master' into do-not-restore-auto…
ywangd 1aedcfb
address feedback
ywangd ef1c636
Merge remote-tracking branch 'origin/master' into do-not-restore-auto…
ywangd 85e61ae
Address feedback
ywangd b7b4c23
revert more irrelevant changes from earlier commits
ywangd 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 hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
.../internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingSnapshotsIT.java
This file contains hidden or 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,106 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.autoscaling; | ||
|
|
||
| import org.elasticsearch.ResourceNotFoundException; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction; | ||
| import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction; | ||
| import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; | ||
| import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicy; | ||
| import org.junit.Before; | ||
|
|
||
| import java.nio.file.Path; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicy; | ||
| import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicyOfName; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class AutoscalingSnapshotsIT extends AutoscalingIntegTestCase { | ||
|
|
||
| public static final String REPO = "repo"; | ||
| public static final String SNAPSHOT = "snap"; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| Path location = randomRepoPath(); | ||
| logger.info("--> creating repository [{}] [{}]", REPO, "fs"); | ||
| assertAcked(clusterAdmin().preparePutRepository(REPO).setType("fs").setSettings(Settings.builder().put("location", location))); | ||
| } | ||
|
|
||
| public void testAutoscalingPolicyWillNotBeRestored() { | ||
| final Client client = client(); | ||
|
|
||
| AutoscalingPolicy policy = randomAutoscalingPolicy(); | ||
| putPolicy(policy); | ||
|
|
||
| CreateSnapshotResponse createSnapshotResponse = client.admin() | ||
| .cluster() | ||
| .prepareCreateSnapshot(REPO, SNAPSHOT) | ||
| .setWaitForCompletion(true) | ||
| .setIncludeGlobalState(true) | ||
| .get(); | ||
| assertEquals(RestStatus.OK, createSnapshotResponse.status()); | ||
|
|
||
| final boolean deletePolicy = randomBoolean(); | ||
| if (deletePolicy) { | ||
| final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(policy.name()); | ||
| assertAcked(client.execute(DeleteAutoscalingPolicyAction.INSTANCE, deleteRequest).actionGet()); | ||
| } else { | ||
| // Update the policy | ||
| policy = randomAutoscalingPolicyOfName(policy.name()); | ||
| putPolicy(policy); | ||
| } | ||
| final AutoscalingPolicy anotherPolicy = randomAutoscalingPolicy(); | ||
| putPolicy(anotherPolicy); | ||
|
|
||
| RestoreSnapshotResponse restoreSnapshotResponse = client.admin() | ||
| .cluster() | ||
| .prepareRestoreSnapshot(REPO, SNAPSHOT) | ||
| .setWaitForCompletion(true) | ||
| .setRestoreGlobalState(true) | ||
| .get(); | ||
| assertEquals(RestStatus.OK, restoreSnapshotResponse.status()); | ||
|
|
||
| if (deletePolicy) { | ||
| assertPolicyNotFound(policy); | ||
| } else { | ||
| assertPolicy(policy); | ||
| } | ||
| assertPolicy(anotherPolicy); | ||
| } | ||
|
|
||
| private void putPolicy(AutoscalingPolicy policy) { | ||
| final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request( | ||
| policy.name(), | ||
| policy.roles(), | ||
| policy.deciders() | ||
| ); | ||
| assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, request).actionGet()); | ||
| } | ||
|
|
||
| private void assertPolicy(AutoscalingPolicy policy) { | ||
| final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(policy.name()); | ||
| final AutoscalingPolicy actualPolicy = client().execute(GetAutoscalingPolicyAction.INSTANCE, getRequest).actionGet().policy(); | ||
| assertThat(actualPolicy, equalTo(policy)); | ||
| } | ||
|
|
||
| private void assertPolicyNotFound(AutoscalingPolicy policy) { | ||
| final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(policy.name()); | ||
| final ResourceNotFoundException e = expectThrows( | ||
| ResourceNotFoundException.class, | ||
| () -> client().execute(GetAutoscalingPolicyAction.INSTANCE, getRequest).actionGet().policy() | ||
| ); | ||
| assertThat(e.getMessage(), containsString("autoscaling policy with name [" + policy.name() + "] does not exist")); | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
I think we should extend the test to also have the case where a policy does exist when restoring to check that it survives the restore. To protect us from "restore-global-state" clearing everything during restore. Could be just randomly doing that or the delete case.
Uh oh!
There was an error while loading. Please reload this page.
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.
Good point. I have expanded the test to:
Then assert things stay the same after restore.