mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-01 16:39:11 +00:00
[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:
parent
310b85083d
commit
00bc35cf9f
@ -28,6 +28,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
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.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
@ -238,17 +239,21 @@ Action<GetCategoriesAction.Request, GetCategoriesAction.Response, GetCategoriesA
|
|||||||
|
|
||||||
private final JobProvider jobProvider;
|
private final JobProvider jobProvider;
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
private final JobManager jobManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
|
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);
|
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||||
this.jobProvider = jobProvider;
|
this.jobProvider = jobProvider;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.jobManager = jobManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doExecute(Request request, ActionListener<Response> listener) {
|
protected void doExecute(Request request, ActionListener<Response> listener) {
|
||||||
|
jobManager.getJobOrThrowIfUnknown(request.jobId);
|
||||||
|
|
||||||
Integer from = request.pageParams != null ? request.pageParams.getFrom() : null;
|
Integer from = request.pageParams != null ? request.pageParams.getFrom() : null;
|
||||||
Integer size = request.pageParams != null ? request.pageParams.getSize() : null;
|
Integer size = request.pageParams != null ? request.pageParams.getSize() : null;
|
||||||
jobProvider.categoryDefinitions(request.jobId, request.categoryId, from, size,
|
jobProvider.categoryDefinitions(request.jobId, request.categoryId, from, size,
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
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.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder;
|
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
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 JobProvider jobProvider;
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
private final JobManager jobManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
|
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);
|
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||||
this.jobProvider = jobProvider;
|
this.jobProvider = jobProvider;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.jobManager = jobManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doExecute(Request request, ActionListener<Response> listener) {
|
protected void doExecute(Request request, ActionListener<Response> listener) {
|
||||||
|
jobManager.getJobOrThrowIfUnknown(request.jobId);
|
||||||
|
|
||||||
InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.includeInterim)
|
InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.includeInterim)
|
||||||
.start(request.start).end(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize())
|
.start(request.start).end(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize())
|
||||||
.anomalyScoreThreshold(request.anomalyScoreFilter).sortField(request.sort).sortDescending(request.decending).build();
|
.anomalyScoreThreshold(request.anomalyScoreFilter).sortField(request.sort).sortDescending(request.decending).build();
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
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.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshot;
|
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> {
|
public static class TransportAction extends HandledTransportAction<Request, Response> {
|
||||||
|
|
||||||
private final JobProvider jobProvider;
|
private final JobProvider jobProvider;
|
||||||
|
private final JobManager jobManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
|
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);
|
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
|
||||||
this.jobProvider = jobProvider;
|
this.jobProvider = jobProvider;
|
||||||
|
this.jobManager = jobManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -330,6 +333,8 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
|
|||||||
request.getJobId(), request.getSnapshotId(), request.pageParams.getFrom(), request.pageParams.getSize(),
|
request.getJobId(), request.getSnapshotId(), request.pageParams.getFrom(), request.pageParams.getSize(),
|
||||||
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getDescriptionString());
|
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getDescriptionString());
|
||||||
|
|
||||||
|
jobManager.getJobOrThrowIfUnknown(request.getJobId());
|
||||||
|
|
||||||
jobProvider.modelSnapshots(request.getJobId(), request.pageParams.getFrom(), request.pageParams.getSize(),
|
jobProvider.modelSnapshots(request.getJobId(), request.pageParams.getFrom(), request.pageParams.getSize(),
|
||||||
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getSnapshotId(),
|
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getSnapshotId(),
|
||||||
request.getDescriptionString(),
|
request.getDescriptionString(),
|
||||||
|
@ -155,3 +155,11 @@ setup:
|
|||||||
xpack.ml.delete_model_snapshot:
|
xpack.ml.delete_model_snapshot:
|
||||||
job_id: "foo"
|
job_id: "foo"
|
||||||
snapshot_id: "active-snapshot"
|
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"
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
setup:
|
setup:
|
||||||
- do:
|
- do:
|
||||||
indices.create:
|
xpack.ml.put_job:
|
||||||
index: .ml-anomalies-foo
|
job_id: foo
|
||||||
body:
|
body: >
|
||||||
mappings:
|
{
|
||||||
model_snapshot:
|
"analysis_config" : {
|
||||||
properties:
|
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||||
"timestamp":
|
},
|
||||||
type: date
|
"data_description" : {
|
||||||
|
"format":"xcontent",
|
||||||
|
"time_field":"time"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
@ -102,3 +106,10 @@ setup:
|
|||||||
- match: { count: 2 }
|
- match: { count: 2 }
|
||||||
- match: { model_snapshots.0.timestamp: 1464739200000 }
|
- match: { model_snapshots.0.timestamp: 1464739200000 }
|
||||||
- length: { model_snapshots: 1 }
|
- length: { model_snapshots: 1 }
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test with unknown job id":
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.ml.get_model_snapshots:
|
||||||
|
job_id: "non-existent-job"
|
||||||
|
@ -147,3 +147,10 @@ setup:
|
|||||||
body:
|
body:
|
||||||
timestamp: "2016-06-01T00:00:00Z"
|
timestamp: "2016-06-01T00:00:00Z"
|
||||||
anomaly_score: "80.0"
|
anomaly_score: "80.0"
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test with unknown job id":
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.ml.get_buckets:
|
||||||
|
job_id: "non-existent-job"
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
setup:
|
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:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: .ml-anomalies-farequote
|
index: .ml-anomalies-farequote
|
||||||
@ -94,3 +108,10 @@ setup:
|
|||||||
body:
|
body:
|
||||||
from: 0
|
from: 0
|
||||||
size: 1
|
size: 1
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test with unknown job id":
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.ml.get_categories:
|
||||||
|
job_id: "non-existent-job"
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
setup:
|
setup:
|
||||||
- do:
|
- do:
|
||||||
indices.create:
|
xpack.ml.put_job:
|
||||||
index: .ml-anomalies-farequote
|
job_id: farequote
|
||||||
body:
|
body: >
|
||||||
mappings:
|
{
|
||||||
result:
|
"analysis_config" : {
|
||||||
properties:
|
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||||
"job_id":
|
},
|
||||||
type: keyword
|
"data_description" : {
|
||||||
"timestamp":
|
"format":"xcontent",
|
||||||
type: date
|
"time_field":"time"
|
||||||
"influencer_score":
|
}
|
||||||
type: double
|
}
|
||||||
"result_type":
|
|
||||||
type: keyword
|
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: .ml-anomalies-farequote
|
index: .ml-anomalies-farequote
|
||||||
@ -71,3 +70,10 @@ setup:
|
|||||||
|
|
||||||
- match: { count: 1 }
|
- match: { count: 1 }
|
||||||
- match: { influencers.0.timestamp: 1464739200000 }
|
- match: { influencers.0.timestamp: 1464739200000 }
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test with unknown job id":
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.ml.get_influencers:
|
||||||
|
job_id: "non-existent-job"
|
||||||
|
@ -73,3 +73,10 @@ setup:
|
|||||||
- match: { records.0.timestamp: 1464739200000 }
|
- match: { records.0.timestamp: 1464739200000 }
|
||||||
- match: { records.0.job_id: farequote}
|
- match: { records.0.job_id: farequote}
|
||||||
- match: { records.0.result_type: record}
|
- match: { records.0.result_type: record}
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test with unknown job id":
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.ml.get_records:
|
||||||
|
job_id: "non-existent-job"
|
||||||
|
@ -219,3 +219,10 @@ setup:
|
|||||||
|
|
||||||
- match: { jobs.0.data_counts.latest_record_timestamp: 1464739200000 }
|
- 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"
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
setup:
|
setup:
|
||||||
- do:
|
- do:
|
||||||
indices.create:
|
xpack.ml.put_job:
|
||||||
index: .ml-anomalies-foo
|
job_id: foo
|
||||||
body:
|
body: >
|
||||||
mappings:
|
{
|
||||||
model_snapshot:
|
"analysis_config" : {
|
||||||
properties:
|
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||||
"timestamp":
|
},
|
||||||
type: date
|
"data_description" : {
|
||||||
|
"format":"xcontent",
|
||||||
|
"time_field":"time"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
@ -139,3 +143,16 @@ setup:
|
|||||||
- match: { acknowledged: true }
|
- match: { acknowledged: true }
|
||||||
- match: { model.description: "new foo" }
|
- match: { model.description: "new foo" }
|
||||||
- match: { model.retain: true }
|
- 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user