diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 011e20d84fbfd..9850dfaeef5af 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -34,11 +34,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.rest.action.document.RestBulkAction; -import org.elasticsearch.rest.action.document.RestGetAction; -import org.elasticsearch.rest.action.document.RestIndexAction; -import org.elasticsearch.rest.action.document.RestUpdateAction; -import org.elasticsearch.rest.action.search.RestExplainAction; import org.elasticsearch.test.NotEqualMessageBuilder; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.yaml.ObjectPath; @@ -62,7 +57,6 @@ import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING; import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -78,21 +72,14 @@ * with {@code tests.is_old_cluster} set to {@code false}. */ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { - private final boolean supportsLenientBooleans = getOldClusterVersion().before(Version.V_6_0_0_alpha1); private String index; - private String type; @Before public void setIndex() throws IOException { index = getTestName().toLowerCase(Locale.ROOT); } - @Before - public void setType() { - type = getOldClusterVersion().before(Version.V_6_7_0) ? "doc" : "_doc"; - } - public void testSearch() throws Exception { int count; if (isRunningAgainstOldCluster()) { @@ -106,9 +93,6 @@ public void testSearch() throws Exception { } { mappingsAndSettings.startObject("mappings"); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.startObject(type); - } mappingsAndSettings.startObject("properties"); { mappingsAndSettings.startObject("string"); @@ -127,16 +111,12 @@ public void testSearch() throws Exception { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.endObject(); - } mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); count = randomIntBetween(2000, 3000); @@ -151,7 +131,7 @@ public void testSearch() throws Exception { .field("int", randomInt(100)) .field("float", randomFloat()) // be sure to create a "proper" boolean (True, False) for the first document so that automapping is correct - .field("bool", i > 0 && supportsLenientBooleans ? randomLenientBoolean() : randomBoolean()) + .field("bool", i > 0 && randomBoolean()) .field("field.with.dots", randomAlphaOfLength(10)) .field("binary", Base64.getEncoder().encodeToString(randomByteArray)) .endObject() @@ -165,7 +145,7 @@ public void testSearch() throws Exception { assertBasicSearchWorks(count); assertAllSearchWorks(count); assertBasicAggregationWorks(); - assertRealtimeGetWorks(type); + assertRealtimeGetWorks(); assertStoredBinaryFields(count); } @@ -181,9 +161,6 @@ public void testNewReplicasWork() throws Exception { } { mappingsAndSettings.startObject("mappings"); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.startObject(type); - } mappingsAndSettings.startObject("properties"); { mappingsAndSettings.startObject("field"); @@ -191,16 +168,12 @@ public void testNewReplicasWork() throws Exception { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.endObject(); - } mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); int numDocs = randomIntBetween(2000, 3000); @@ -289,9 +262,6 @@ public void testShrink() throws IOException { { mappingsAndSettings.startObject("mappings"); { - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.startObject(type); - } mappingsAndSettings.startObject("properties"); { mappingsAndSettings.startObject("field"); @@ -301,25 +271,18 @@ public void testShrink() throws IOException { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.endObject(); - } } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster() == false) { - // the default number of shards is now one so we have to set the number of shards to be more than one explicitly - mappingsAndSettings.startObject("settings"); - { - mappingsAndSettings.field("index.number_of_shards", 5); - } - mappingsAndSettings.endObject(); + mappingsAndSettings.startObject("settings"); + { + mappingsAndSettings.field("index.number_of_shards", 5); } + mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); numDocs = randomIntBetween(512, 1024); @@ -370,9 +333,6 @@ public void testShrinkAfterUpgrade() throws IOException { { mappingsAndSettings.startObject("mappings"); { - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.startObject(type); - } mappingsAndSettings.startObject("properties"); { mappingsAndSettings.startObject("field"); @@ -382,23 +342,17 @@ public void testShrinkAfterUpgrade() throws IOException { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster()) { - mappingsAndSettings.endObject(); - } } mappingsAndSettings.endObject(); - if (isRunningAgainstAncientCluster() == false) { - // the default number of shards is now one so we have to set the number of shards to be more than one explicitly - mappingsAndSettings.startObject("settings"); - mappingsAndSettings.field("index.number_of_shards", 5); - mappingsAndSettings.endObject(); - } + // the default number of shards is now one so we have to set the number of shards to be more than one explicitly + mappingsAndSettings.startObject("settings"); + mappingsAndSettings.field("index.number_of_shards", 5); + mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); numDocs = randomIntBetween(512, 1024); @@ -474,15 +428,13 @@ public void testRollover() throws IOException { bulk.append("{\"index\":{}}\n"); bulk.append("{\"test\":\"test\"}\n"); } - Request bulkRequest = new Request("POST", "/" + index + "_write/" + type + "/_bulk"); + Request bulkRequest = new Request("POST", "/" + index + "_write/_bulk"); bulkRequest.setJsonEntity(bulk.toString()); bulkRequest.addParameter("refresh", ""); - bulkRequest.setOptions(expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE)); assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false")); if (isRunningAgainstOldCluster()) { Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover"); - rolloverRequest.setOptions(allowTypesRemovalWarnings()); rolloverRequest.setJsonEntity("{" + " \"conditions\": {" + " \"max_docs\": 5" @@ -552,12 +504,10 @@ void assertAllSearchWorks(int count) throws IOException { // the 'string' field has a boost of 4 in the mappings so it should get a payload boost String stringValue = (String) XContentMapValues.extractValue("_source.string", bestHit); assertNotNull(stringValue); - String type = (String) bestHit.get("_type"); String id = (String) bestHit.get("_id"); - Request explainRequest = new Request("GET", "/" + index + "/" + type + "/" + id + "/_explain"); + Request explainRequest = new Request("GET", "/" + index + "/_explain/" + id); explainRequest.setJsonEntity("{ \"query\": { \"match_all\" : {} }}"); - explainRequest.setOptions(expectWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE)); String explanation = toStr(client().performRequest(explainRequest)); assertFalse("Could not find payload boost in explanation\n" + explanation, explanation.contains("payloadBoost")); @@ -597,7 +547,7 @@ void assertBasicAggregationWorks() throws IOException { assertTotalHits(termsCount, boolTerms); } - void assertRealtimeGetWorks(final String typeName) throws IOException { + void assertRealtimeGetWorks() throws IOException { Request disableAutoRefresh = new Request("PUT", "/" + index + "/_settings"); disableAutoRefresh.setJsonEntity("{ \"index\": { \"refresh_interval\" : -1 }}"); client().performRequest(disableAutoRefresh); @@ -608,14 +558,12 @@ void assertRealtimeGetWorks(final String typeName) throws IOException { Map hit = (Map) ((List)(XContentMapValues.extractValue("hits.hits", searchResponse))).get(0); String docId = (String) hit.get("_id"); - Request updateRequest = new Request("POST", "/" + index + "/" + typeName + "/" + docId + "/_update"); - updateRequest.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)); + Request updateRequest = new Request("POST", "/" + index + "/_update/" + docId); updateRequest.setJsonEntity("{ \"doc\" : { \"foo\": \"bar\"}}"); client().performRequest(updateRequest); - Request getRequest = new Request("GET", "/" + index + "/" + typeName + "/" + docId); + Request getRequest = new Request("GET", "/" + index + "/_doc/" + docId); if (getOldClusterVersion().before(Version.V_6_7_0)) { - getRequest.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE)); } Map getRsp = entityAsMap(client().performRequest(getRequest)); Map source = (Map) getRsp.get("_source"); @@ -659,18 +607,14 @@ void assertTotalHits(int expectedTotalHits, Map response) { } int extractTotalHits(Map response) { - if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_7_0_0)) { - return (Integer) XContentMapValues.extractValue("hits.total", response); - } else { - return (Integer) XContentMapValues.extractValue("hits.total.value", response); - } + return (Integer) XContentMapValues.extractValue("hits.total.value", response); } /** * Tests that a single document survives. Super basic smoke test. */ public void testSingleDoc() throws IOException { - String docLocation = "/" + index + "/" + type + "/1"; + String docLocation = "/" + index + "/_doc/1"; String doc = "{\"test\": \"test\"}"; if (isRunningAgainstOldCluster()) { @@ -681,9 +625,6 @@ public void testSingleDoc() throws IOException { Request request = new Request("GET", docLocation); - if (getOldClusterVersion().before(Version.V_6_7_0)) { - request.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE)); - } assertThat(toStr(client().performRequest(request)), containsString(doc)); } @@ -754,10 +695,10 @@ public void testRecovery() throws Exception { i -> jsonBuilder().startObject().field("field", "value").endObject() ); } - saveInfoDocument("should_have_translog", Boolean.toString(shouldHaveTranslog)); + saveInfoDocument(index + "_should_have_translog", Boolean.toString(shouldHaveTranslog)); } else { count = countOfIndexedRandomDocuments(); - shouldHaveTranslog = Booleans.parseBoolean(loadInfoDocument("should_have_translog")); + shouldHaveTranslog = Booleans.parseBoolean(loadInfoDocument(index + "_should_have_translog")); } // Count the documents in the index to make sure we have as many as we put there @@ -867,9 +808,6 @@ public void testSnapshotRestore() throws IOException { } templateBuilder.endObject(); templateBuilder.startObject("mappings"); { - if (isRunningAgainstAncientCluster()) { - templateBuilder.startObject(type); - } { templateBuilder.startObject("_source"); { @@ -877,9 +815,6 @@ public void testSnapshotRestore() throws IOException { } templateBuilder.endObject(); } - if (isRunningAgainstAncientCluster()) { - templateBuilder.endObject(); - } } templateBuilder.endObject(); templateBuilder.startObject("aliases"); { @@ -899,13 +834,6 @@ public void testSnapshotRestore() throws IOException { Request createTemplateRequest = new Request("PUT", "/_template/test_template"); createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder)); - // In 7.0, type names are no longer expected by default in put index template requests. - // We therefore use the deprecated typed APIs when running against the current version, but testing with a pre-7 version - if (isRunningAgainstOldCluster() == false && getOldClusterVersion().major < 7) { - createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true"); - } - createTemplateRequest.setOptions(allowTypesRemovalWarnings()); - client().performRequest(createTemplateRequest); if (isRunningAgainstOldCluster()) { @@ -995,10 +923,7 @@ public void testSoftDeletes() throws Exception { int numDocs = between(10, 100); for (int i = 0; i < numDocs; i++) { String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v1").endObject()); - Request request = new Request("POST", "/" + index + "/" + type + "/" + i); - if (isRunningAgainstAncientCluster() == false) { - request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); - } + Request request = new Request("POST", "/" + index + "/_doc/" + i); request.setJsonEntity(doc); client().performRequest(request); refresh(); @@ -1009,19 +934,19 @@ public void testSoftDeletes() throws Exception { for (int i = 0; i < numDocs; i++) { if (randomBoolean()) { String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v2").endObject()); - Request request = new Request("POST", "/" + index + "/" + type + "/" + i); + Request request = new Request("POST", "/" + index + "/_doc/" + i); request.setJsonEntity(doc); client().performRequest(request); } else if (randomBoolean()) { - client().performRequest(new Request("DELETE", "/" + index + "/" + type + "/" + i)); + client().performRequest(new Request("DELETE", "/" + index + "/_doc/" + i)); liveDocs--; } } refresh(); assertTotalHits(liveDocs, entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")))); - saveInfoDocument("doc_count", Integer.toString(liveDocs)); + saveInfoDocument(index + "_doc_count", Integer.toString(liveDocs)); } else { - int liveDocs = Integer.parseInt(loadInfoDocument("doc_count")); + int liveDocs = Integer.parseInt(loadInfoDocument(index + "_doc_count")); assertTotalHits(liveDocs, entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")))); } } @@ -1044,8 +969,7 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver * If this test is executed on the upgraded mode before testRemoteClusterSettingsUpgraded, * we will hit a warning exception because we put some deprecated settings in that test. */ - if (isRunningAgainstOldCluster() == false - && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().before(Version.V_6_5_0)) { + if (isRunningAgainstOldCluster() == false) { for (String warning : e.getResponse().getWarnings()) { assertThat(warning, containsString( "setting was deprecated in Elasticsearch and will be removed in a future release! " @@ -1083,10 +1007,9 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n"); bulk.append("{\"test\":\"test\"}\n"); } - Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/" + type + "/_bulk"); + Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/_bulk"); writeToRestoredRequest.addParameter("refresh", "true"); writeToRestoredRequest.setJsonEntity(bulk.toString()); - writeToRestoredRequest.setOptions(expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE)); assertThat(EntityUtils.toString(client().performRequest(writeToRestoredRequest).getEntity()), containsString("\"errors\":false")); // And count to make sure the add worked @@ -1110,13 +1033,6 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b // Check that the template was restored successfully Request getTemplateRequest = new Request("GET", "/_template/test_template"); - // In 7.0, type names are no longer returned by default in get index template requests. - // We therefore use the deprecated typed APIs when running against the current version. - if (isRunningAgainstAncientCluster() == false) { - getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true"); - } - getTemplateRequest.setOptions(allowTypesRemovalWarnings()); - Map getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest)); Map expectedTemplate = new HashMap<>(); if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_0_0_beta1)) { @@ -1125,13 +1041,7 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b expectedTemplate.put("index_patterns", singletonList("evil_*")); } expectedTemplate.put("settings", singletonMap("index", singletonMap("number_of_shards", "1"))); - // We don't have the type in the response starting with 7.0, but we won't have it on old cluster after upgrade - // either so look at the response to figure out the correct assertions - if (isTypeInTemplateResponse(getTemplateResponse)) { - expectedTemplate.put("mappings", singletonMap(type, singletonMap("_source", singletonMap("enabled", true)))); - } else { - expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true))); - } + expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true))); expectedTemplate.put("order", 0); Map aliases = new HashMap<>(); @@ -1147,13 +1057,6 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b } } - @SuppressWarnings("unchecked") - private boolean isTypeInTemplateResponse(Map getTemplateResponse) { - return ( (Map) ( - (Map) getTemplateResponse.getOrDefault("test_template", emptyMap()) - ).get("mappings")).get("_source") == null; - } - // TODO tests for upgrades after shrink. We've had trouble with shrink in the past. private void indexRandomDocuments( @@ -1165,10 +1068,7 @@ private void indexRandomDocuments( logger.info("Indexing {} random documents", count); for (int i = 0; i < count; i++) { logger.debug("Indexing document [{}]", i); - Request createDocument = new Request("POST", "/" + index + "/" + type + "/" + i); - if (isRunningAgainstAncientCluster() == false) { - createDocument.setOptions(expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE)); - } + Request createDocument = new Request("POST", "/" + index + "/_doc/" + i); createDocument.setJsonEntity(Strings.toString(docSupplier.apply(i))); client().performRequest(createDocument); if (rarely()) { @@ -1180,44 +1080,34 @@ private void indexRandomDocuments( } } if (saveInfo) { - saveInfoDocument("count", Integer.toString(count)); + saveInfoDocument(index + "_count", Integer.toString(count)); } } private int countOfIndexedRandomDocuments() throws IOException { - return Integer.parseInt(loadInfoDocument("count")); + return Integer.parseInt(loadInfoDocument(index + "_count")); } - private void saveInfoDocument(String type, String value) throws IOException { + private void saveInfoDocument(String id, String value) throws IOException { XContentBuilder infoDoc = JsonXContent.contentBuilder().startObject(); infoDoc.field("value", value); infoDoc.endObject(); // Only create the first version so we know how many documents are created when the index is first created - Request request = new Request("PUT", "/info/" + this.type + "/" + index + "_" + type); + Request request = new Request("PUT", "/info/_doc/" + id); request.addParameter("op_type", "create"); request.setJsonEntity(Strings.toString(infoDoc)); - if (isRunningAgainstAncientCluster() == false) { - request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); - } client().performRequest(request); } - private String loadInfoDocument(String type) throws IOException { - Request request = new Request("GET", "/info/" + this.type + "/" + index + "_" + type); + private String loadInfoDocument(String id) throws IOException { + Request request = new Request("GET", "/info/_doc/" + id); request.addParameter("filter_path", "_source"); - if (isRunningAgainstAncientCluster()) { - request.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE)); - } String doc = toStr(client().performRequest(request)); Matcher m = Pattern.compile("\"value\":\"(.+)\"").matcher(doc); assertTrue(doc, m.find()); return m.group(1); } - private Object randomLenientBoolean() { - return randomFrom(new Object[] {"off", "no", "0", 0, "false", false, "on", "yes", "1", 1, "true", true}); - } - private void refresh() throws IOException { logger.debug("Refreshing [{}]", index); client().performRequest(new Request("POST", "/" + index + "/_refresh"));