Skip to content

Commit

Permalink
Backport code changes (#1431)
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen authored Mar 16, 2023
1 parent d38a6ec commit bdc55d7
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.util.Timeout;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.opensearch.client.Request;
Expand All @@ -39,6 +41,8 @@
*/
public abstract class OpenSearchSQLRestTestCase extends OpenSearchRestTestCase {

private static final Logger LOG = LogManager.getLogger();

protected boolean isHttps() {
boolean isHttps = Optional.ofNullable(System.getProperty("https"))
.map("true"::equalsIgnoreCase).orElse(false);
Expand Down Expand Up @@ -78,9 +82,14 @@ protected static void wipeAllOpenSearchIndices() throws IOException {
for (Object object : jsonArray) {
JSONObject jsonObject = (JSONObject) object;
String indexName = jsonObject.getString("index");
//.opendistro_security isn't allowed to delete from cluster
if (!indexName.startsWith(".opensearch_dashboards") && !indexName.startsWith(".opendistro")) {
client().performRequest(new Request("DELETE", "/" + indexName));
try {
// System index, mostly named .opensearch-xxx or .opendistro-xxx, are not allowed to delete
if (!indexName.startsWith(".opensearch") && !indexName.startsWith(".opendistro")) {
client().performRequest(new Request("DELETE", "/" + indexName));
}
} catch (Exception e) {
// TODO: Ignore index delete error for now. Remove this if strict check on system index added above.
LOG.warn("Failed to delete index: " + indexName, e);
}
}
} catch (ParseException e) {
Expand Down

0 comments on commit bdc55d7

Please sign in to comment.