-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Implement GET API for System Feature Upgrades #78642
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
williamrandolph
merged 15 commits into
elastic:master
from
williamrandolph:get-upgrade-status-api
Oct 7, 2021
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ae26206
Implement and test get feature upgrade status API
williamrandolph a5c302e
Merge branch 'master' into get-upgrade-status-api
williamrandolph f5d1414
Use Version object instead of string versions
williamrandolph d609f7e
Refactor for streams
williamrandolph a90f875
Merge branch 'master' into get-upgrade-status-api
williamrandolph 4db3266
Add integration test for feature upgrade endpoint
williamrandolph 6bfe376
Use tasks instead of watcher to avoid license stuff in testing
williamrandolph 8fe49bf
Add sort order on response and fix docs test
williamrandolph 555abaa
Use different index to avoid conflict with other system test
williamrandolph 4b9e57c
Use constant enum for statuses
williamrandolph 0a91f1d
PR feedback
williamrandolph 9ad60ce
Merge branch 'master' into get-upgrade-status-api
williamrandolph e73f65f
Add unit tests for transport class methods
williamrandolph a8f4d09
Add IN_PROGRESS upgrade status
williamrandolph 74e7482
Merge branch 'master' into get-upgrade-status-api
williamrandolph 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
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
103 changes: 103 additions & 0 deletions
103
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/FeatureUpgradeIT.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,103 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.upgrades; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.test.XContentTestUtils; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class FeatureUpgradeIT extends AbstractRollingTestCase { | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public void testGetFeatureUpgradeStatus() throws Exception { | ||
|
|
||
| final String systemIndexWarning = "this request accesses system indices: [.tasks], but in a future major version, direct " + | ||
| "access to system indices will be prevented by default"; | ||
| if (CLUSTER_TYPE == ClusterType.OLD) { | ||
| // setup - put something in the tasks index | ||
| // create index | ||
| Request createTestIndex = new Request("PUT", "/feature_test_index_old"); | ||
| createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}"); | ||
| client().performRequest(createTestIndex); | ||
|
|
||
| Request bulk = new Request("POST", "/_bulk"); | ||
| bulk.addParameter("refresh", "true"); | ||
| bulk.setJsonEntity("{\"index\": {\"_index\": \"feature_test_index_old\"}}\n" + | ||
| "{\"f1\": \"v1\", \"f2\": \"v2\"}\n"); | ||
| client().performRequest(bulk); | ||
|
|
||
| // start a async reindex job | ||
| Request reindex = new Request("POST", "/_reindex"); | ||
| reindex.setJsonEntity( | ||
| "{\n" + | ||
| " \"source\":{\n" + | ||
| " \"index\":\"feature_test_index_old\"\n" + | ||
| " },\n" + | ||
| " \"dest\":{\n" + | ||
| " \"index\":\"feature_test_index_reindex\"\n" + | ||
| " }\n" + | ||
| "}"); | ||
| reindex.addParameter("wait_for_completion", "false"); | ||
| Map<String, Object> response = entityAsMap(client().performRequest(reindex)); | ||
| String taskId = (String) response.get("task"); | ||
|
|
||
| // wait for task | ||
| Request getTask = new Request("GET", "/_tasks/" + taskId); | ||
| getTask.addParameter("wait_for_completion", "true"); | ||
| client().performRequest(getTask); | ||
|
|
||
| // make sure .tasks index exists | ||
| Request getTasksIndex = new Request("GET", "/.tasks"); | ||
| getTasksIndex.setOptions(expectVersionSpecificWarnings(v -> { | ||
| v.current(systemIndexWarning); | ||
| v.compatible(systemIndexWarning); | ||
| })); | ||
| getTasksIndex.addParameter("allow_no_indices", "false"); | ||
|
|
||
| assertBusy(() -> { | ||
| try { | ||
| assertThat(client().performRequest(getTasksIndex).getStatusLine().getStatusCode(), is(200)); | ||
| } catch (ResponseException e) { | ||
| throw new AssertionError(".tasks index does not exist yet"); | ||
| } | ||
| }); | ||
|
|
||
| } else if (CLUSTER_TYPE == ClusterType.UPGRADED) { | ||
| // check results | ||
| assertBusy(() -> { | ||
| Request clusterStateRequest = new Request("GET", "/_migration/system_features"); | ||
| XContentTestUtils.JsonMapView view = new XContentTestUtils.JsonMapView( | ||
| entityAsMap(client().performRequest(clusterStateRequest))); | ||
|
|
||
| List<Map<String, Object>> features = view.get("features"); | ||
| Map<String, Object> feature = features.stream() | ||
| .filter(e -> "tasks".equals(e.get("feature_name"))) | ||
| .findFirst() | ||
| .orElse(Collections.emptyMap()); | ||
|
|
||
| assertThat(feature.size(), equalTo(4)); | ||
| assertThat(feature.get("minimum_index_version"), equalTo(UPGRADE_FROM_VERSION.toString())); | ||
| if (UPGRADE_FROM_VERSION.before(Version.CURRENT.minimumIndexCompatibilityVersion())) { | ||
| assertThat(feature.get("upgrade_status"), equalTo("UPGRADE_NEEDED")); | ||
| } else { | ||
| assertThat(feature.get("upgrade_status"), equalTo("NO_UPGRADE_NEEDED")); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| } | ||
70 changes: 70 additions & 0 deletions
70
...m-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.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,70 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.system.indices; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.test.XContentTestUtils; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.junit.After; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class FeatureUpgradeApiIT extends ESRestTestCase { | ||
|
|
||
| static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("rest_user", new SecureString("rest-user-password".toCharArray())); | ||
|
|
||
| @After | ||
| public void resetFeatures() throws Exception { | ||
| client().performRequest(new Request("POST", "/_features/_reset")); | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings restClientSettings() { | ||
| return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build(); | ||
| } | ||
|
|
||
| public void testCreatingSystemIndex() throws Exception { | ||
| Response response = client().performRequest(new Request("PUT", "/_net_new_sys_index/_create")); | ||
| assertThat(response.getStatusLine().getStatusCode(), is(200)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public void testGetFeatureUpgradedStatuses() throws Exception { | ||
| client().performRequest(new Request("PUT", "/_net_new_sys_index/_create")); | ||
| Response response = client().performRequest(new Request("GET", "/_migration/system_features")); | ||
| assertThat(response.getStatusLine().getStatusCode(), is(200)); | ||
| XContentTestUtils.JsonMapView view = XContentTestUtils.createJsonMapView(response.getEntity().getContent()); | ||
| String upgradeStatus = view.get("upgrade_status"); | ||
| assertThat(upgradeStatus, equalTo("NO_UPGRADE_NEEDED")); | ||
| List<Map<String, Object>> features = view.get("features"); | ||
| Map<String, Object> testFeature = features.stream() | ||
| .filter(feature -> "system indices qa".equals(feature.get("feature_name"))) | ||
| .findFirst() | ||
| .orElse(Collections.emptyMap()); | ||
|
|
||
| assertThat(testFeature.size(), equalTo(4)); | ||
| assertThat(testFeature.get("minimum_index_version"), equalTo(Version.CURRENT.toString())); | ||
| assertThat(testFeature.get("upgrade_status"), equalTo("NO_UPGRADE_NEEDED")); | ||
| assertThat(testFeature.get("indices"), instanceOf(List.class)); | ||
|
|
||
| assertThat((List<Object>) testFeature.get("indices"), hasSize(1)); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.