|
9 | 9 | import com.google.common.io.Resources;
|
10 | 10 | import com.google.common.primitives.Floats;
|
11 | 11 | import org.apache.commons.lang.StringUtils;
|
| 12 | +import org.apache.http.util.EntityUtils; |
12 | 13 | import org.opensearch.common.bytes.BytesReference;
|
13 | 14 | import org.opensearch.common.xcontent.XContentHelper;
|
| 15 | +import org.opensearch.core.xcontent.DeprecationHandler; |
| 16 | +import org.opensearch.core.xcontent.NamedXContentRegistry; |
| 17 | +import org.opensearch.core.xcontent.XContentParser; |
14 | 18 | import org.opensearch.index.query.MatchAllQueryBuilder;
|
15 | 19 | import org.opensearch.knn.index.query.KNNQueryBuilder;
|
16 | 20 | import org.opensearch.knn.index.KNNSettings;
|
|
20 | 24 | import org.opensearch.knn.indices.ModelState;
|
21 | 25 | import org.opensearch.knn.plugin.KNNPlugin;
|
22 | 26 | import org.opensearch.knn.plugin.script.KNNScoringScriptEngine;
|
23 |
| -import org.apache.http.util.EntityUtils; |
24 | 27 | import org.junit.AfterClass;
|
25 | 28 | import org.junit.Before;
|
26 | 29 | import org.opensearch.client.Request;
|
|
59 | 62 | import java.util.Locale;
|
60 | 63 | import java.util.Map;
|
61 | 64 | import java.util.PriorityQueue;
|
| 65 | +import java.util.Set; |
62 | 66 | import java.util.concurrent.TimeUnit;
|
63 | 67 | import java.util.stream.Collectors;
|
64 | 68 |
|
@@ -111,6 +115,7 @@ public class KNNRestTestCase extends ODFERestTestCase {
|
111 | 115 | private static final String DOCUMENT_FIELD_FOUND = "found";
|
112 | 116 | protected static final int DELAY_MILLI_SEC = 1000;
|
113 | 117 | protected static final int NUM_OF_ATTEMPTS = 30;
|
| 118 | + private static final String SYSTEM_INDEX_PREFIX = ".opendistro"; |
114 | 119 |
|
115 | 120 | @AfterClass
|
116 | 121 | public static void dumpCoverage() throws IOException, MalformedObjectNameException {
|
@@ -1266,4 +1271,39 @@ public interface IProxy {
|
1266 | 1271 |
|
1267 | 1272 | void reset();
|
1268 | 1273 | }
|
| 1274 | + |
| 1275 | + protected void refreshAllNonSystemIndices() throws Exception { |
| 1276 | + Response response = adminClient().performRequest(new Request("GET", "/_cat/indices?format=json&expand_wildcards=all")); |
| 1277 | + XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue()); |
| 1278 | + try ( |
| 1279 | + XContentParser parser = xContentType.xContent() |
| 1280 | + .createParser( |
| 1281 | + NamedXContentRegistry.EMPTY, |
| 1282 | + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, |
| 1283 | + response.getEntity().getContent() |
| 1284 | + ) |
| 1285 | + ) { |
| 1286 | + XContentParser.Token token = parser.nextToken(); |
| 1287 | + List<Map<String, Object>> parserList; |
| 1288 | + if (token == XContentParser.Token.START_ARRAY) { |
| 1289 | + parserList = parser.listOrderedMap().stream().map(obj -> (Map<String, Object>) obj).collect(Collectors.toList()); |
| 1290 | + } else { |
| 1291 | + parserList = Collections.singletonList(parser.mapOrdered()); |
| 1292 | + } |
| 1293 | + Set<String> indices = parserList.stream() |
| 1294 | + .map(index -> (String) index.get("index")) |
| 1295 | + .filter(index -> !index.startsWith(SYSTEM_INDEX_PREFIX)) |
| 1296 | + .collect(Collectors.toSet()); |
| 1297 | + for (String index : indices) { |
| 1298 | + refreshIndex(index); |
| 1299 | + } |
| 1300 | + } |
| 1301 | + } |
| 1302 | + |
| 1303 | + protected void refreshIndex(final String index) throws IOException { |
| 1304 | + Request request = new Request("POST", "/" + index + "/_refresh"); |
| 1305 | + |
| 1306 | + Response response = client().performRequest(request); |
| 1307 | + assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); |
| 1308 | + } |
1269 | 1309 | }
|
0 commit comments