Browse Source

[ML] Force stopping stopped DF analytics should succeed (#56421)

Force stopping a DF analytics job whose config exists and that
is stopped should succeed. This was broken by #56360.

Closes #56414
Dimitris Athanasiou 5 years ago
parent
commit
01d71d2dc0

+ 9 - 4
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStopDataFrameAnalyticsAction.java

@@ -154,11 +154,16 @@ public class TransportStopDataFrameAnalyticsAction
         ExpandedIdsMatcher expandedIdsMatcher = new ExpandedIdsMatcher(tokens, request.allowNoMatch());
         expandedIdsMatcher.filterMatchedIds(startedIds);
         if (expandedIdsMatcher.hasUnmatchedIds()) {
-            matchingIdsListener.onFailure(ExceptionsHelper.missingDataFrameAnalytics(expandedIdsMatcher.unmatchedIdsString()));
-            return;
+            // There are expressions that did not match any started task.
+            // If there are no configs for those either, we should error.
+            // We check this by trying a get with the unmatched expressions.
+            configProvider.getMultiple(expandedIdsMatcher.unmatchedIdsString(), request.allowNoMatch(), ActionListener.wrap(
+                configs -> matchingIdsListener.onResponse(MlStrings.findMatching(tokens, startedIds)),
+                matchingIdsListener::onFailure
+            ));
+        } else {
+            matchingIdsListener.onResponse(MlStrings.findMatching(tokens, startedIds));
         }
-        Set<String> matchingStartedIds = MlStrings.findMatching(tokens, startedIds);
-        matchingIdsListener.onResponse(matchingStartedIds);
     }
 
     private void normalStop(Task task, StopDataFrameAnalyticsAction.Request request,