3232import org .elasticsearch .cluster .service .ClusterService ;
3333import org .elasticsearch .common .breaker .CircuitBreaker ;
3434import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
35- import org .elasticsearch .common .logging .DeprecationLogger ;
3635import org .elasticsearch .common .settings .ClusterSettings ;
3736import org .elasticsearch .common .settings .IndexScopedSettings ;
3837import org .elasticsearch .common .settings .Setting ;
162161import org .elasticsearch .xpack .core .ml .action .PutTrainedModelDefinitionPartAction ;
163162import org .elasticsearch .xpack .core .ml .action .PutTrainedModelVocabularyAction ;
164163import org .elasticsearch .xpack .core .ml .action .ResetJobAction ;
164+ import org .elasticsearch .xpack .core .ml .action .ResetMlComponentsAction ;
165165import org .elasticsearch .xpack .core .ml .action .RevertModelSnapshotAction ;
166166import org .elasticsearch .xpack .core .ml .action .SetResetModeAction ;
167167import org .elasticsearch .xpack .core .ml .action .SetUpgradeModeAction ;
272272import org .elasticsearch .xpack .ml .action .TransportPutTrainedModelDefinitionPartAction ;
273273import org .elasticsearch .xpack .ml .action .TransportPutTrainedModelVocabularyAction ;
274274import org .elasticsearch .xpack .ml .action .TransportResetJobAction ;
275+ import org .elasticsearch .xpack .ml .action .TransportResetMlComponentsAction ;
275276import org .elasticsearch .xpack .ml .action .TransportRevertModelSnapshotAction ;
276277import org .elasticsearch .xpack .ml .action .TransportSetResetModeAction ;
277278import org .elasticsearch .xpack .ml .action .TransportSetUpgradeModeAction ;
@@ -785,7 +786,6 @@ public void loadExtensions(ExtensionLoader loader) {
785786 public static final int MAX_LOW_PRIORITY_MODELS_PER_NODE = 100 ;
786787
787788 private static final Logger logger = LogManager .getLogger (MachineLearning .class );
788- private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (MachineLearning .class );
789789
790790 private final Settings settings ;
791791 private final boolean enabled ;
@@ -805,7 +805,7 @@ public void loadExtensions(ExtensionLoader loader) {
805805 private final SetOnce <LearningToRankService > learningToRankService = new SetOnce <>();
806806 private final SetOnce <MlAutoscalingDeciderService > mlAutoscalingDeciderService = new SetOnce <>();
807807 private final SetOnce <DeploymentManager > deploymentManager = new SetOnce <>();
808- private final SetOnce <TrainedModelAssignmentClusterService > trainedModelAllocationClusterServiceSetOnce = new SetOnce <>();
808+ private final SetOnce <TrainedModelAssignmentClusterService > trainedModelAllocationClusterService = new SetOnce <>();
809809
810810 private final SetOnce <MachineLearningExtension > machineLearningExtension = new SetOnce <>();
811811
@@ -1315,7 +1315,7 @@ public Collection<?> createComponents(PluginServices services) {
13151315 clusterService ,
13161316 threadPool
13171317 );
1318- trainedModelAllocationClusterServiceSetOnce .set (
1318+ trainedModelAllocationClusterService .set (
13191319 new TrainedModelAssignmentClusterService (
13201320 settings ,
13211321 clusterService ,
@@ -1391,7 +1391,8 @@ public Collection<?> createComponents(PluginServices services) {
13911391 trainedModelCacheMetadataService ,
13921392 trainedModelProvider ,
13931393 trainedModelAssignmentService ,
1394- trainedModelAllocationClusterServiceSetOnce .get (),
1394+ trainedModelAllocationClusterService .get (),
1395+ trainedModelStatsService ,
13951396 deploymentManager .get (),
13961397 nodeAvailabilityZoneMapper ,
13971398 new MachineLearningExtensionHolder (machineLearningExtension .get ()),
@@ -1564,6 +1565,7 @@ public List<ActionHandler> getActions() {
15641565 actionHandlers .add (new ActionHandler (MlMemoryAction .INSTANCE , TransportMlMemoryAction .class ));
15651566 actionHandlers .add (new ActionHandler (SetUpgradeModeAction .INSTANCE , TransportSetUpgradeModeAction .class ));
15661567 actionHandlers .add (new ActionHandler (SetResetModeAction .INSTANCE , TransportSetResetModeAction .class ));
1568+ actionHandlers .add (new ActionHandler (ResetMlComponentsAction .INSTANCE , TransportResetMlComponentsAction .class ));
15671569 // Included in this section as it's used by MlMemoryAction
15681570 actionHandlers .add (new ActionHandler (TrainedModelCacheInfoAction .INSTANCE , TransportTrainedModelCacheInfoAction .class ));
15691571 actionHandlers .add (new ActionHandler (GetMlAutoscalingStats .INSTANCE , TransportGetMlAutoscalingStats .class ));
@@ -2149,8 +2151,6 @@ public void cleanUpFeature(
21492151 final Map <String , Boolean > results = new ConcurrentHashMap <>();
21502152
21512153 ActionListener <ResetFeatureStateResponse .ResetFeatureStateStatus > unsetResetModeListener = ActionListener .wrap (success -> {
2152- // reset the auditors as aliases used may be removed
2153- resetAuditors ();
21542154
21552155 client .execute (SetResetModeAction .INSTANCE , SetResetModeActionRequest .disabled (true ), ActionListener .wrap (resetSuccess -> {
21562156 finalListener .onResponse (success );
@@ -2176,8 +2176,24 @@ public void cleanUpFeature(
21762176 );
21772177 });
21782178
2179+ ActionListener <ResetFeatureStateResponse .ResetFeatureStateStatus > resetAuditors = ActionListener .wrap (success -> {
2180+ // reset components, such as the auditors the trained model stats queue
2181+ client .execute (
2182+ ResetMlComponentsAction .INSTANCE ,
2183+ ResetMlComponentsAction .Request .RESET_AUDITOR_REQUEST ,
2184+ ActionListener .wrap (ignored -> unsetResetModeListener .onResponse (success ), unsetResetModeListener ::onFailure )
2185+ );
2186+ }, failure -> {
2187+ logger .error ("failed to reset machine learning" , failure );
2188+ client .execute (
2189+ ResetMlComponentsAction .INSTANCE ,
2190+ ResetMlComponentsAction .Request .RESET_AUDITOR_REQUEST ,
2191+ ActionListener .wrap (ignored -> unsetResetModeListener .onFailure (failure ), unsetResetModeListener ::onFailure )
2192+ );
2193+ });
2194+
21792195 // Stop all model deployments
2180- ActionListener <AcknowledgedResponse > pipelineValidation = unsetResetModeListener .<ListTasksResponse >delegateFailureAndWrap (
2196+ ActionListener <AcknowledgedResponse > pipelineValidation = resetAuditors .<ListTasksResponse >delegateFailureAndWrap (
21812197 (delegate , listTasksResponse ) -> {
21822198 listTasksResponse .rethrowFailures ("Waiting for indexing requests for .ml-* indices" );
21832199 if (results .values ().stream ().allMatch (b -> b )) {
@@ -2306,11 +2322,11 @@ public void cleanUpFeature(
23062322 );
23072323 client .execute (CancelJobModelSnapshotUpgradeAction .INSTANCE , cancelSnapshotUpgradesReq , delegate );
23082324 }).delegateFailureAndWrap ((delegate , acknowledgedResponse ) -> {
2309- if (trainedModelAllocationClusterServiceSetOnce .get () == null || machineLearningExtension .get ().isNlpEnabled () == false ) {
2325+ if (trainedModelAllocationClusterService .get () == null || machineLearningExtension .get ().isNlpEnabled () == false ) {
23102326 delegate .onResponse (AcknowledgedResponse .TRUE );
23112327 return ;
23122328 }
2313- trainedModelAllocationClusterServiceSetOnce .get ().removeAllModelAssignments (delegate );
2329+ trainedModelAllocationClusterService .get ().removeAllModelAssignments (delegate );
23142330 });
23152331
23162332 // validate no pipelines are using machine learning models
@@ -2332,18 +2348,6 @@ public void cleanUpFeature(
23322348 client .execute (SetResetModeAction .INSTANCE , SetResetModeActionRequest .enabled (), afterResetModeSet );
23332349 }
23342350
2335- private void resetAuditors () {
2336- if (anomalyDetectionAuditor .get () != null ) {
2337- anomalyDetectionAuditor .get ().reset ();
2338- }
2339- if (dataFrameAnalyticsAuditor .get () != null ) {
2340- dataFrameAnalyticsAuditor .get ().reset ();
2341- }
2342- if (inferenceAuditor .get () != null ) {
2343- inferenceAuditor .get ().reset ();
2344- }
2345- }
2346-
23472351 @ Override
23482352 public BreakerSettings getCircuitBreaker (Settings settingsToUse ) {
23492353 return BreakerSettings .updateFromSettings (
0 commit comments