|
9 | 9 | import static org.opensearch.sql.legacy.TestUtils.isIndexExist; |
10 | 10 | import static org.opensearch.sql.legacy.TestUtils.loadDataByRestClient; |
11 | 11 | import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT; |
| 12 | +import static org.opensearch.sql.sql.LegacyAPICompatibilityIT.LEGACY_QUERY_API_ENDPOINT; |
| 13 | +import static org.opensearch.sql.sql.LegacyAPICompatibilityIT.LEGACY_SQL_SETTINGS_API_ENDPOINT; |
12 | 14 | import static org.opensearch.sql.util.MatcherUtils.rows; |
13 | 15 | import static org.opensearch.sql.util.MatcherUtils.schema; |
14 | 16 | import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; |
@@ -91,10 +93,33 @@ public void testBackwardsCompatibility() throws Exception { |
91 | 93 | List<Map<String, Object>> plugins = (List<Map<String, Object>>) response.get("plugins"); |
92 | 94 | Set<Object> pluginNames = |
93 | 95 | plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet()); |
| 96 | + String version = (String) response.get("version"); |
| 97 | + |
| 98 | + boolean isBackwardsIncompatibleVersion = version.startsWith("2."); |
| 99 | + |
94 | 100 | switch (CLUSTER_TYPE) { |
| 101 | + case OLD: |
| 102 | + Assert.assertTrue(pluginNames.contains("opensearch-sql")); |
| 103 | + if (isBackwardsIncompatibleVersion) { |
| 104 | + updateLegacySQLSettings(); |
| 105 | + } |
| 106 | + loadIndex(Index.ACCOUNT); |
| 107 | + verifySQLQueries( |
| 108 | + isBackwardsIncompatibleVersion ? LEGACY_QUERY_API_ENDPOINT : QUERY_API_ENDPOINT); |
| 109 | + break; |
| 110 | + case MIXED: |
| 111 | + Assert.assertTrue(pluginNames.contains("opensearch-sql")); |
| 112 | + if (isBackwardsIncompatibleVersion) { |
| 113 | + verifySQLSettings(); |
| 114 | + } else { |
| 115 | + // For upgraded nodes, we don't need to verify legacy settings |
| 116 | + } |
| 117 | + verifySQLQueries( |
| 118 | + isBackwardsIncompatibleVersion ? LEGACY_QUERY_API_ENDPOINT : QUERY_API_ENDPOINT); |
| 119 | + break; |
95 | 120 | case UPGRADED: |
96 | 121 | Assert.assertTrue(pluginNames.contains("opensearch-sql")); |
97 | | - verifySQLSettings(); |
| 122 | + // For fully upgraded clusters, we don't need to verify legacy settings |
98 | 123 | verifySQLQueries(QUERY_API_ENDPOINT); |
99 | 124 | break; |
100 | 125 | } |
@@ -122,6 +147,24 @@ private String getUri() { |
122 | 147 | } |
123 | 148 | } |
124 | 149 |
|
| 150 | + private void updateLegacySQLSettings() throws IOException { |
| 151 | + Request request = new Request("PUT", LEGACY_SQL_SETTINGS_API_ENDPOINT); |
| 152 | + request.setJsonEntity( |
| 153 | + String.format( |
| 154 | + Locale.ROOT, |
| 155 | + "{\n" + " \"persistent\" : {\n \"%s\" : \"%s\"\n }\n}", |
| 156 | + "opendistro.sql.cursor.keep_alive", |
| 157 | + "7m")); |
| 158 | + |
| 159 | + RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder(); |
| 160 | + restOptionsBuilder.addHeader("Content-Type", "application/json"); |
| 161 | + request.setOptions(restOptionsBuilder); |
| 162 | + |
| 163 | + Response response = client().performRequest(request); |
| 164 | + JSONObject jsonObject = new JSONObject(getResponseBody(response)); |
| 165 | + Assert.assertTrue((boolean) jsonObject.get("acknowledged")); |
| 166 | + } |
| 167 | + |
125 | 168 | private void verifySQLSettings() throws IOException { |
126 | 169 | Request request = new Request("GET", "_cluster/settings?flat_settings"); |
127 | 170 |
|
|
0 commit comments