[ML] Consistently throw missing resource exception on all endpoints if the job id is not known. (elastic/x-pack-elasticsearch#1024)

Original commit: elastic/x-pack-elasticsearch@6676a03599
This commit is contained in:
David Kyle 2017-04-10 15:23:08 +01:00 committed by GitHub
parent 310b85083d
commit 00bc35cf9f
11 changed files with 132 additions and 33 deletions

View File

@ -28,6 +28,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.job.JobManager;
import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
@ -238,17 +239,21 @@ Action<GetCategoriesAction.Request, GetCategoriesAction.Response, GetCategoriesA
private final JobProvider jobProvider;
private final Client client;
private final JobManager jobManager;
@Inject
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider, Client client) {
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider, Client client, JobManager jobManager) {
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
this.jobProvider = jobProvider;
this.client = client;
this.jobManager = jobManager;
}
@Override
protected void doExecute(Request request, ActionListener<Response> listener) {
jobManager.getJobOrThrowIfUnknown(request.jobId);
Integer from = request.pageParams != null ? request.pageParams.getFrom() : null;
Integer size = request.pageParams != null ? request.pageParams.getSize() : null;
jobProvider.categoryDefinitions(request.jobId, request.categoryId, from, size,

View File

@ -31,6 +31,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.action.util.PageParams;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
import org.elasticsearch.xpack.ml.job.JobManager;
import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder;
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
@ -302,17 +303,21 @@ extends Action<GetInfluencersAction.Request, GetInfluencersAction.Response, GetI
private final JobProvider jobProvider;
private final Client client;
private final JobManager jobManager;
@Inject
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider, Client client) {
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider, Client client, JobManager jobManager) {
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
this.jobProvider = jobProvider;
this.client = client;
this.jobManager = jobManager;
}
@Override
protected void doExecute(Request request, ActionListener<Response> listener) {
jobManager.getJobOrThrowIfUnknown(request.jobId);
InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.includeInterim)
.start(request.start).end(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize())
.anomalyScoreThreshold(request.anomalyScoreFilter).sortField(request.sort).sortDescending(request.decending).build();

View File

@ -31,6 +31,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.action.util.PageParams;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
import org.elasticsearch.xpack.ml.job.JobManager;
import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshot;
@ -315,12 +316,14 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
public static class TransportAction extends HandledTransportAction<Request, Response> {
private final JobProvider jobProvider;
private final JobManager jobManager;
@Inject
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider) {
IndexNameExpressionResolver indexNameExpressionResolver, JobProvider jobProvider, JobManager jobManager) {
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
this.jobProvider = jobProvider;
this.jobManager = jobManager;
}
@Override
@ -330,6 +333,8 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
request.getJobId(), request.getSnapshotId(), request.pageParams.getFrom(), request.pageParams.getSize(),
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getDescriptionString());
jobManager.getJobOrThrowIfUnknown(request.getJobId());
jobProvider.modelSnapshots(request.getJobId(), request.pageParams.getFrom(), request.pageParams.getSize(),
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getSnapshotId(),
request.getDescriptionString(),

View File

@ -155,3 +155,11 @@ setup:
xpack.ml.delete_model_snapshot:
job_id: "foo"
snapshot_id: "active-snapshot"
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.delete_model_snapshot:
job_id: "non-existent-job"
snapshot_id: "foo"

View File

@ -1,13 +1,17 @@
setup:
- do:
indices.create:
index: .ml-anomalies-foo
body:
mappings:
model_snapshot:
properties:
"timestamp":
type: date
xpack.ml.put_job:
job_id: foo
body: >
{
"analysis_config" : {
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
},
"data_description" : {
"format":"xcontent",
"time_field":"time"
}
}
- do:
index:
@ -102,3 +106,10 @@ setup:
- match: { count: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
- length: { model_snapshots: 1 }
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.get_model_snapshots:
job_id: "non-existent-job"

View File

@ -147,3 +147,10 @@ setup:
body:
timestamp: "2016-06-01T00:00:00Z"
anomaly_score: "80.0"
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.get_buckets:
job_id: "non-existent-job"

View File

@ -1,4 +1,18 @@
setup:
- do:
xpack.ml.put_job:
job_id: farequote
body: >
{
"analysis_config" : {
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
},
"data_description" : {
"format":"xcontent",
"time_field":"time"
}
}
- do:
index:
index: .ml-anomalies-farequote
@ -94,3 +108,10 @@ setup:
body:
from: 0
size: 1
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.get_categories:
job_id: "non-existent-job"

View File

@ -1,19 +1,18 @@
setup:
- do:
indices.create:
index: .ml-anomalies-farequote
body:
mappings:
result:
properties:
"job_id":
type: keyword
"timestamp":
type: date
"influencer_score":
type: double
"result_type":
type: keyword
xpack.ml.put_job:
job_id: farequote
body: >
{
"analysis_config" : {
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
},
"data_description" : {
"format":"xcontent",
"time_field":"time"
}
}
- do:
index:
index: .ml-anomalies-farequote
@ -71,3 +70,10 @@ setup:
- match: { count: 1 }
- match: { influencers.0.timestamp: 1464739200000 }
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.get_influencers:
job_id: "non-existent-job"

View File

@ -73,3 +73,10 @@ setup:
- match: { records.0.timestamp: 1464739200000 }
- match: { records.0.job_id: farequote}
- match: { records.0.result_type: record}
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.get_records:
job_id: "non-existent-job"

View File

@ -219,3 +219,10 @@ setup:
- match: { jobs.0.data_counts.latest_record_timestamp: 1464739200000 }
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.revert_model_snapshot:
job_id: "non-existent-job"
snapshot_id: "second"

View File

@ -1,13 +1,17 @@
setup:
- do:
indices.create:
index: .ml-anomalies-foo
body:
mappings:
model_snapshot:
properties:
"timestamp":
type: date
xpack.ml.put_job:
job_id: foo
body: >
{
"analysis_config" : {
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
},
"data_description" : {
"format":"xcontent",
"time_field":"time"
}
}
- do:
index:
@ -139,3 +143,16 @@ setup:
- match: { acknowledged: true }
- match: { model.description: "new foo" }
- match: { model.retain: true }
---
"Test with unknown job id":
- do:
catch: missing
xpack.ml.update_model_snapshot:
job_id: "non-existent-job"
snapshot_id: "foo"
body: >
{
"description": "new foo",
"retain": true
}