1
0
Эх сурвалжийг харах

[ML] Model snapshot version too old is not server error (#80588)

If a job cannot be opened because its model snapshot is too
old then this should not be reported as a server error (status
500). It's a user error because the user did not upgrade their
old model snapshots as the deprecation info API and upgrade
assistant told them to. Instead we should report the attempt
to open the job with the old snapshot as a bad request (status
400).
David Roberts 3 жил өмнө
parent
commit
d46981a7b2

+ 5 - 4
x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AnomalyJobCRUDIT.java

@@ -16,6 +16,7 @@ import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.cluster.service.MasterService;
 import org.elasticsearch.common.settings.ClusterSettings;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.rest.RestStatus;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.xcontent.XContentType;
 import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction;
@@ -36,7 +37,6 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles;
 import org.elasticsearch.xpack.ml.MlSingleNodeTestCase;
 import org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor;
 import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
-import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor;
 import org.elasticsearch.xpack.ml.utils.persistence.ResultsPersisterService;
 import org.junit.Before;
 
@@ -50,6 +50,7 @@ import java.util.List;
 import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
 
 public class AnomalyJobCRUDIT extends MlSingleNodeTestCase {
 
@@ -80,7 +81,6 @@ public class AnomalyJobCRUDIT extends MlSingleNodeTestCase {
             clusterService,
             Settings.EMPTY
         );
-        AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client(), clusterService);
         jobResultsPersister = new JobResultsPersister(originSettingClient, resultsPersisterService);
         waitForMlTemplates();
     }
@@ -190,8 +190,8 @@ public class AnomalyJobCRUDIT extends MlSingleNodeTestCase {
         client().execute(RevertModelSnapshotAction.INSTANCE, new RevertModelSnapshotAction.Request(jobId, "snap_1")).actionGet();
 
         // should fail?
-        Exception ex = expectThrows(
-            Exception.class,
+        ElasticsearchStatusException ex = expectThrows(
+            ElasticsearchStatusException.class,
             () -> client().execute(OpenJobAction.INSTANCE, new OpenJobAction.Request(jobId)).actionGet()
         );
         assertThat(
@@ -201,6 +201,7 @@ public class AnomalyJobCRUDIT extends MlSingleNodeTestCase {
                     + "please revert to a newer model snapshot or reset the job"
             )
         );
+        assertThat(ex.status(), is(RestStatus.BAD_REQUEST));
     }
 
     private void indexModelSnapshot(ModelSnapshot snapshot) {

+ 1 - 1
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportOpenJobAction.java

@@ -196,7 +196,7 @@ public class TransportOpenJobAction extends TransportMasterNodeAction<OpenJobAct
                             return;
                         }
                         listener.onFailure(
-                            ExceptionsHelper.serverError(
+                            ExceptionsHelper.badRequestException(
                                 "[{}] job snapshot [{}] has min version before [{}], "
                                     + "please revert to a newer model snapshot or reset the job",
                                 jobParams.getJobId(),

+ 2 - 3
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java

@@ -390,9 +390,8 @@ public class OpenJobPersistentTasksExecutor extends AbstractJobPersistentTasksEx
                         return;
                     }
                     listener.onFailure(
-                        ExceptionsHelper.serverError(
-                            "[{}] job snapshot [{}] has min version before [{}], "
-                                + "please revert to a newer model snapshot or reset the job",
+                        ExceptionsHelper.badRequestException(
+                            "[{}] job snapshot [{}] has min version before [{}], please revert to a newer model snapshot or reset the job",
                             jobId,
                             jobSnapshotId,
                             MIN_SUPPORTED_SNAPSHOT_VERSION.toString()