Skip to content

Commit 04a2fa2

Browse files
committed
Add reset feature
1 parent 0a71ff4 commit 04a2fa2

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

x-pack/plugin/ml/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
opens org.elasticsearch.xpack.ml to org.elasticsearch.painless.spi; // whitelist resource access
3333
opens org.elasticsearch.xpack.ml.utils; // for exact.properties access
3434

35+
provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.ml.MachineLearningFeatures;
3536
provides org.elasticsearch.painless.spi.PainlessExtension with org.elasticsearch.xpack.ml.MachineLearningPainlessExtension;
3637
provides org.elasticsearch.xpack.autoscaling.AutoscalingExtension with org.elasticsearch.xpack.ml.autoscaling.MlAutoscalingExtension;
3738

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.ml;
9+
10+
import org.elasticsearch.features.FeatureSpecification;
11+
import org.elasticsearch.features.NodeFeature;
12+
13+
import java.util.Set;
14+
15+
public class MachineLearningFeatures implements FeatureSpecification {
16+
17+
public static final NodeFeature COMPONENTS_RESET_ACTION = new NodeFeature("ml.components.reset");
18+
19+
public Set<NodeFeature> getFeatures() {
20+
return Set.of(COMPONENTS_RESET_ACTION);
21+
}
22+
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportResetMlComponentsAction.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
package org.elasticsearch.xpack.ml.action;
99

10+
import org.elasticsearch.action.ActionListener;
1011
import org.elasticsearch.action.FailedNodeException;
1112
import org.elasticsearch.action.support.ActionFilters;
1213
import org.elasticsearch.action.support.nodes.TransportNodesAction;
1314
import org.elasticsearch.cluster.node.DiscoveryNode;
1415
import org.elasticsearch.cluster.service.ClusterService;
1516
import org.elasticsearch.common.io.stream.StreamInput;
17+
import org.elasticsearch.features.FeatureService;
1618
import org.elasticsearch.injection.guice.Inject;
1719
import org.elasticsearch.tasks.Task;
1820
import org.elasticsearch.threadpool.ThreadPool;
1921
import org.elasticsearch.transport.TransportService;
2022
import org.elasticsearch.xpack.core.ml.action.ResetMlComponentsAction;
23+
import org.elasticsearch.xpack.ml.MachineLearningFeatures;
2124
import org.elasticsearch.xpack.ml.inference.TrainedModelStatsService;
2225
import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor;
2326
import org.elasticsearch.xpack.ml.notifications.DataFrameAnalyticsAuditor;
@@ -37,6 +40,7 @@ public class TransportResetMlComponentsAction extends TransportNodesAction<
3740
private final DataFrameAnalyticsAuditor dfaAuditor;
3841
private final InferenceAuditor inferenceAuditor;
3942
private final TrainedModelStatsService trainedModelStatsService;
43+
private final FeatureService featureService;
4044

4145
@Inject
4246
public TransportResetMlComponentsAction(
@@ -47,7 +51,8 @@ public TransportResetMlComponentsAction(
4751
AnomalyDetectionAuditor anomalyDetectionAuditor,
4852
DataFrameAnalyticsAuditor dfaAuditor,
4953
InferenceAuditor inferenceAuditor,
50-
TrainedModelStatsService trainedModelStatsService
54+
TrainedModelStatsService trainedModelStatsService,
55+
FeatureService featureService
5156
) {
5257
super(
5358
ResetMlComponentsAction.NAME,
@@ -61,6 +66,20 @@ public TransportResetMlComponentsAction(
6166
this.dfaAuditor = dfaAuditor;
6267
this.inferenceAuditor = inferenceAuditor;
6368
this.trainedModelStatsService = trainedModelStatsService;
69+
this.featureService = featureService;
70+
}
71+
72+
@Override
73+
protected void doExecute(
74+
Task task,
75+
ResetMlComponentsAction.Request request,
76+
ActionListener<ResetMlComponentsAction.Response> listener
77+
) {
78+
if (featureService.clusterHasFeature(clusterService.state(), MachineLearningFeatures.COMPONENTS_RESET_ACTION) == false) {
79+
listener.onResponse(new ResetMlComponentsAction.Response(clusterService.getClusterName(), List.of(), List.of()));
80+
} else {
81+
super.doExecute(task, request, listener);
82+
}
6483
}
6584

6685
@Override

0 commit comments

Comments
 (0)