Skip to content

Commit

Permalink
Exclude .opensearch index when cleanup and ignore exception in case (#…
Browse files Browse the repository at this point in the history
…1380) (#1381)

Signed-off-by: Chen Dai <[email protected]>
(cherry picked from commit 71d8604)

Co-authored-by: Chen Dai <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and dai-chen authored Mar 6, 2023
1 parent 8583fd1 commit 4749176
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 4749176

Please sign in to comment.