Adds the step of stopping all data frame analytics before deleting them to the cleanup of the corresponding HLRC tests. Closes #56097 Backport of #56101
This commit is contained in:
parent
5d1bc6c89c
commit
76fa5a2397
|
@ -29,6 +29,7 @@ import org.elasticsearch.client.ml.GetDatafeedRequest;
|
||||||
import org.elasticsearch.client.ml.GetDatafeedResponse;
|
import org.elasticsearch.client.ml.GetDatafeedResponse;
|
||||||
import org.elasticsearch.client.ml.GetJobRequest;
|
import org.elasticsearch.client.ml.GetJobRequest;
|
||||||
import org.elasticsearch.client.ml.GetJobResponse;
|
import org.elasticsearch.client.ml.GetJobResponse;
|
||||||
|
import org.elasticsearch.client.ml.StopDataFrameAnalyticsRequest;
|
||||||
import org.elasticsearch.client.ml.StopDatafeedRequest;
|
import org.elasticsearch.client.ml.StopDatafeedRequest;
|
||||||
import org.elasticsearch.client.ml.datafeed.DatafeedConfig;
|
import org.elasticsearch.client.ml.datafeed.DatafeedConfig;
|
||||||
import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig;
|
import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig;
|
||||||
|
@ -106,10 +107,28 @@ public class MlTestStateCleaner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAllDataFrameAnalytics() throws IOException {
|
private void deleteAllDataFrameAnalytics() throws IOException {
|
||||||
|
stopAllDataFrameAnalytics();
|
||||||
|
|
||||||
GetDataFrameAnalyticsResponse getDataFrameAnalyticsResponse =
|
GetDataFrameAnalyticsResponse getDataFrameAnalyticsResponse =
|
||||||
mlClient.getDataFrameAnalytics(GetDataFrameAnalyticsRequest.getAllDataFrameAnalyticsRequest(), RequestOptions.DEFAULT);
|
mlClient.getDataFrameAnalytics(GetDataFrameAnalyticsRequest.getAllDataFrameAnalyticsRequest(), RequestOptions.DEFAULT);
|
||||||
for (DataFrameAnalyticsConfig config : getDataFrameAnalyticsResponse.getAnalytics()) {
|
for (DataFrameAnalyticsConfig config : getDataFrameAnalyticsResponse.getAnalytics()) {
|
||||||
mlClient.deleteDataFrameAnalytics(new DeleteDataFrameAnalyticsRequest(config.getId()), RequestOptions.DEFAULT);
|
mlClient.deleteDataFrameAnalytics(new DeleteDataFrameAnalyticsRequest(config.getId()), RequestOptions.DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void stopAllDataFrameAnalytics() {
|
||||||
|
StopDataFrameAnalyticsRequest stopAllRequest = new StopDataFrameAnalyticsRequest("*");
|
||||||
|
try {
|
||||||
|
mlClient.stopDataFrameAnalytics(stopAllRequest, RequestOptions.DEFAULT);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.warn("failed to stop all data frame analytics. Will proceed to force-stopping", e1);
|
||||||
|
stopAllRequest.setForce(true);
|
||||||
|
try {
|
||||||
|
mlClient.stopDataFrameAnalytics(stopAllRequest, RequestOptions.DEFAULT);
|
||||||
|
} catch (Exception e2) {
|
||||||
|
logger.warn("force-stopping all data frame analytics failed", e2);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Had to resort to force-stopping data frame analytics, something went wrong?", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ public class MlRestTestStateCleaner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAllDataFrameAnalytics() throws IOException {
|
private void deleteAllDataFrameAnalytics() throws IOException {
|
||||||
|
stopAllDataFrameAnalytics();
|
||||||
|
|
||||||
final Request analyticsRequest = new Request("GET", "/_ml/data_frame/analytics?size=10000");
|
final Request analyticsRequest = new Request("GET", "/_ml/data_frame/analytics?size=10000");
|
||||||
analyticsRequest.addParameter("filter_path", "data_frame_analytics");
|
analyticsRequest.addParameter("filter_path", "data_frame_analytics");
|
||||||
final Response analyticsResponse = adminClient.performRequest(analyticsRequest);
|
final Response analyticsResponse = adminClient.performRequest(analyticsRequest);
|
||||||
|
@ -108,4 +110,18 @@ public class MlRestTestStateCleaner {
|
||||||
adminClient.performRequest(new Request("DELETE", "/_ml/data_frame/analytics/" + id));
|
adminClient.performRequest(new Request("DELETE", "/_ml/data_frame/analytics/" + id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void stopAllDataFrameAnalytics() {
|
||||||
|
try {
|
||||||
|
adminClient.performRequest(new Request("POST", "_ml/data_frame/analytics/*/_stop"));
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.warn("failed to stop all data frame analytics. Will proceed to force-stopping", e1);
|
||||||
|
try {
|
||||||
|
adminClient.performRequest(new Request("POST", "_ml/data_frame/analytics/*/_stop?force=true"));
|
||||||
|
} catch (Exception e2) {
|
||||||
|
logger.warn("Force-stopping all data frame analytics failed", e2);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Had to resort to force-stopping data frame analytics, something went wrong?", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue