Skip to content

Commit 95f9557

Browse files
fix[backend](index-removal): fixed index state field obtention
1 parent 5afe131 commit 95f9557

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

backend/src/main/java/com/park/utmstack/service/index_policy/IndexPolicyService.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,7 @@ public boolean isIndexRemovable(String index) {
5656
JsonObject json = new Gson().fromJson(body, JsonObject.class);
5757
if (json != null && json.has(index)) {
5858
JsonObject indexInfo = json.getAsJsonObject(index);
59-
String state = null;
60-
if (indexInfo.has("index.plugins.index_state_management.current_state")) {
61-
state = indexInfo.get("index.plugins.index_state_management.current_state").getAsString();
62-
} else if (indexInfo.has("index.opendistro.index_state_management.current_state")) {
63-
state = indexInfo.get("index.opendistro.index_state_management.current_state").getAsString();
64-
} else if (indexInfo.has("opendistro.index_state_management.current_state")) {
65-
state = indexInfo.get("opendistro.index_state_management.current_state").getAsString();
66-
}
67-
59+
String state = this.getCurrentState(indexInfo)
6860
if (state != null) {
6961
return Constants.STATE_DELETE.equals(state) || Constants.STATE_SAFE_DELETE.equals(state);
7062
}
@@ -77,6 +69,28 @@ public boolean isIndexRemovable(String index) {
7769
}
7870
}
7971

72+
73+
private String getCurrentState(JsonObject indexInfo) {
74+
if (indexInfo.has("state") && indexInfo.get("state").isJsonObject()) {
75+
JsonObject stateObj = indexInfo.getAsJsonObject("state");
76+
if (stateObj.has("name")) {
77+
return stateObj.get("name").getAsString();
78+
}
79+
}
80+
81+
String[] legacyPaths = {
82+
"index.plugins.index_state_management.current_state",
83+
"index.opendistro.index_state_management.current_state",
84+
"opendistro.index_state_management.current_state"
85+
};
86+
87+
return Arrays.stream(legacyPaths)
88+
.filter(indexInfo::has)
89+
.map(path -> indexInfo.get(path).getAsString())
90+
.findFirst()
91+
.orElse(null);
92+
}
93+
8094
@EventListener(IndexPatternsReadyEvent.class)
8195
public void init() throws Exception {
8296
final String ctx = CLASSNAME + ".init";

0 commit comments

Comments
 (0)