-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GET API for System Feature Upgrades (#78642)
* Implement and test get feature upgrade status API * Add integration test for feature upgrade endpoint * Use constant enum for statuses * Add unit tests for transport class methods
- Loading branch information
1 parent
3e3d974
commit ccfec46
Showing
9 changed files
with
485 additions
and
64 deletions.
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
103 changes: 103 additions & 0 deletions
103
qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java
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,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 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.