Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Exclude OpenSearch system index when IT cleanup #1381

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.http.message.BasicHeader;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
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 @@ -35,6 +37,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 @@ -73,9 +77,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);
}
}
}
Expand Down