Changes rest actions with data namespace into the job namespace.

Also added `_status` suffic to get job api as it would otherwise clash with open/close/flush APIs.

Original commit: elastic/x-pack-elasticsearch@6e8ef0ef7d
This commit is contained in:
Martijn van Groningen 2016-12-06 14:59:25 +01:00
parent d807eda9ed
commit e396e8aa68
21 changed files with 113 additions and 115 deletions

View File

@ -8,7 +8,6 @@ package org.elasticsearch.xpack.prelert;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.service.ClusterService;
@ -17,9 +16,7 @@ import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.env.Environment;
import org.elasticsearch.http.HttpTransportSettings;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestHandler;
@ -38,9 +35,9 @@ import org.elasticsearch.xpack.prelert.action.GetJobsAction;
import org.elasticsearch.xpack.prelert.action.GetListAction;
import org.elasticsearch.xpack.prelert.action.GetModelSnapshotsAction;
import org.elasticsearch.xpack.prelert.action.GetRecordsAction;
import org.elasticsearch.xpack.prelert.action.PostDataAction;
import org.elasticsearch.xpack.prelert.action.JobDataAction;
import org.elasticsearch.xpack.prelert.action.CloseJobAction;
import org.elasticsearch.xpack.prelert.action.PostDataFlushAction;
import org.elasticsearch.xpack.prelert.action.FlushJobAction;
import org.elasticsearch.xpack.prelert.action.PutJobAction;
import org.elasticsearch.xpack.prelert.action.PutListAction;
import org.elasticsearch.xpack.prelert.action.PutModelSnapshotDescriptionAction;
@ -74,13 +71,13 @@ import org.elasticsearch.xpack.prelert.job.scheduler.ScheduledJobService;
import org.elasticsearch.xpack.prelert.job.scheduler.http.HttpDataExtractorFactory;
import org.elasticsearch.xpack.prelert.job.status.StatusReporter;
import org.elasticsearch.xpack.prelert.job.usage.UsageReporter;
import org.elasticsearch.xpack.prelert.rest.data.RestPostDataAction;
import org.elasticsearch.xpack.prelert.rest.job.RestJobDataAction;
import org.elasticsearch.xpack.prelert.rest.job.RestCloseJobAction;
import org.elasticsearch.xpack.prelert.rest.data.RestPostDataFlushAction;
import org.elasticsearch.xpack.prelert.rest.job.RestFlushJobAction;
import org.elasticsearch.xpack.prelert.rest.results.RestGetInfluencersAction;
import org.elasticsearch.xpack.prelert.rest.job.RestDeleteJobAction;
import org.elasticsearch.xpack.prelert.rest.job.RestGetJobsAction;
import org.elasticsearch.xpack.prelert.rest.job.RestPutJobsAction;
import org.elasticsearch.xpack.prelert.rest.job.RestPutJobAction;
import org.elasticsearch.xpack.prelert.rest.job.RestOpenJobAction;
import org.elasticsearch.xpack.prelert.rest.list.RestGetListAction;
import org.elasticsearch.xpack.prelert.rest.list.RestPutListAction;
@ -195,7 +192,7 @@ public class PrelertPlugin extends Plugin implements ActionPlugin {
public List<Class<? extends RestHandler>> getRestHandlers() {
return Arrays.asList(
RestGetJobsAction.class,
RestPutJobsAction.class,
RestPutJobAction.class,
RestDeleteJobAction.class,
RestOpenJobAction.class,
RestGetListAction.class,
@ -203,9 +200,9 @@ public class PrelertPlugin extends Plugin implements ActionPlugin {
RestGetInfluencersAction.class,
RestGetRecordsAction.class,
RestGetBucketsAction.class,
RestPostDataAction.class,
RestJobDataAction.class,
RestCloseJobAction.class,
RestPostDataFlushAction.class,
RestFlushJobAction.class,
RestValidateDetectorAction.class,
RestValidateTransformAction.class,
RestValidateTransformsAction.class,
@ -233,9 +230,9 @@ public class PrelertPlugin extends Plugin implements ActionPlugin {
new ActionHandler<>(GetBucketsAction.INSTANCE, GetBucketsAction.TransportAction.class),
new ActionHandler<>(GetInfluencersAction.INSTANCE, GetInfluencersAction.TransportAction.class),
new ActionHandler<>(GetRecordsAction.INSTANCE, GetRecordsAction.TransportAction.class),
new ActionHandler<>(PostDataAction.INSTANCE, PostDataAction.TransportAction.class),
new ActionHandler<>(JobDataAction.INSTANCE, JobDataAction.TransportAction.class),
new ActionHandler<>(CloseJobAction.INSTANCE, CloseJobAction.TransportAction.class),
new ActionHandler<>(PostDataFlushAction.INSTANCE, PostDataFlushAction.TransportAction.class),
new ActionHandler<>(FlushJobAction.INSTANCE, FlushJobAction.TransportAction.class),
new ActionHandler<>(ValidateDetectorAction.INSTANCE, ValidateDetectorAction.TransportAction.class),
new ActionHandler<>(ValidateTransformAction.INSTANCE, ValidateTransformAction.TransportAction.class),
new ActionHandler<>(ValidateTransformsAction.INSTANCE, ValidateTransformsAction.TransportAction.class),

View File

@ -37,13 +37,12 @@ import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
import java.io.IOException;
import java.util.Objects;
public class PostDataFlushAction extends Action<PostDataFlushAction.Request, PostDataFlushAction.Response,
PostDataFlushAction.RequestBuilder> {
public class FlushJobAction extends Action<FlushJobAction.Request, FlushJobAction.Response, FlushJobAction.RequestBuilder> {
public static final PostDataFlushAction INSTANCE = new PostDataFlushAction();
public static final String NAME = "cluster:admin/prelert/data/post/flush";
public static final FlushJobAction INSTANCE = new FlushJobAction();
public static final String NAME = "cluster:admin/prelert/job/flush";
private PostDataFlushAction() {
private FlushJobAction() {
super(NAME);
}
@ -196,7 +195,7 @@ PostDataFlushAction.RequestBuilder> {
static class RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder> {
public RequestBuilder(ElasticsearchClient client, PostDataFlushAction action) {
public RequestBuilder(ElasticsearchClient client, FlushJobAction action) {
super(client, action, new Request());
}
}
@ -231,14 +230,14 @@ PostDataFlushAction.RequestBuilder> {
@Inject
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, AutodetectProcessManager processManager) {
super(settings, PostDataFlushAction.NAME, false, threadPool, transportService, actionFilters,
indexNameExpressionResolver, PostDataFlushAction.Request::new);
super(settings, FlushJobAction.NAME, false, threadPool, transportService, actionFilters,
indexNameExpressionResolver, FlushJobAction.Request::new);
this.processManager = processManager;
}
@Override
protected final void doExecute(PostDataFlushAction.Request request, ActionListener<PostDataFlushAction.Response> listener) {
protected final void doExecute(FlushJobAction.Request request, ActionListener<FlushJobAction.Response> listener) {
threadPool.executor(PrelertPlugin.THREAD_POOL_NAME).execute(() -> {
try {
TimeRange timeRange = TimeRange.builder().startTime(request.getStart()).endTime(request.getEnd()).build();

View File

@ -40,12 +40,12 @@ import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
import java.io.IOException;
import java.util.Objects;
public class PostDataAction extends Action<PostDataAction.Request, PostDataAction.Response, PostDataAction.RequestBuilder> {
public class JobDataAction extends Action<JobDataAction.Request, JobDataAction.Response, JobDataAction.RequestBuilder> {
public static final PostDataAction INSTANCE = new PostDataAction();
public static final String NAME = "cluster:admin/prelert/data/post";
public static final JobDataAction INSTANCE = new JobDataAction();
public static final String NAME = "cluster:admin/prelert/job/data";
private PostDataAction() {
private JobDataAction() {
super(NAME);
}
@ -61,7 +61,7 @@ public class PostDataAction extends Action<PostDataAction.Request, PostDataActio
static class RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder> {
RequestBuilder(ElasticsearchClient client, PostDataAction action) {
RequestBuilder(ElasticsearchClient client, JobDataAction action) {
super(client, action, new Request());
}
}
@ -251,7 +251,7 @@ public class PostDataAction extends Action<PostDataAction.Request, PostDataActio
@Inject
public TransportAction(Settings settings, TransportService transportService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, AutodetectProcessManager processManager) {
super(settings, PostDataAction.NAME, false, threadPool, transportService, actionFilters,
super(settings, JobDataAction.NAME, false, threadPool, transportService, actionFilters,
indexNameExpressionResolver, Request::new);
this.processManager = processManager;
}

View File

@ -28,7 +28,7 @@ public class RestCloseJobAction extends BaseRestHandler {
super(settings);
this.closeJobAction = closeJobAction;
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH
+ "data/{" + Job.ID.getPreferredName() + "}/_close", this);
+ "jobs/{" + Job.ID.getPreferredName() + "}/_close", this);
}
@Override

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.prelert.rest.data;
package org.elasticsearch.xpack.prelert.rest.job;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.bytes.BytesReference;
@ -17,26 +17,26 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.AcknowledgedRestListener;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.xpack.prelert.PrelertPlugin;
import org.elasticsearch.xpack.prelert.action.PostDataFlushAction;
import org.elasticsearch.xpack.prelert.action.FlushJobAction;
import org.elasticsearch.xpack.prelert.job.Job;
import java.io.IOException;
public class RestPostDataFlushAction extends BaseRestHandler {
public class RestFlushJobAction extends BaseRestHandler {
private final boolean DEFAULT_CALC_INTERIM = false;
private final String DEFAULT_START = "";
private final String DEFAULT_END = "";
private final String DEFAULT_ADVANCE_TIME = "";
private final PostDataFlushAction.TransportAction transportPostDataFlushAction;
private final FlushJobAction.TransportAction flushJobAction;
@Inject
public RestPostDataFlushAction(Settings settings, RestController controller,
PostDataFlushAction.TransportAction transportPostDataFlushAction) {
public RestFlushJobAction(Settings settings, RestController controller,
FlushJobAction.TransportAction flushJobAction) {
super(settings);
this.transportPostDataFlushAction = transportPostDataFlushAction;
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "data/{" + Job.ID.getPreferredName() + "}/_flush",
this.flushJobAction = flushJobAction;
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/_flush",
this);
}
@ -44,19 +44,19 @@ public class RestPostDataFlushAction extends BaseRestHandler {
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String jobId = restRequest.param(Job.ID.getPreferredName());
BytesReference bodyBytes = RestActions.getRestContent(restRequest);
final PostDataFlushAction.Request request;
final FlushJobAction.Request request;
if (RestActions.hasBodyContent(restRequest)) {
XContentParser parser = XContentFactory.xContent(bodyBytes).createParser(bodyBytes);
request = PostDataFlushAction.Request.parseRequest(jobId, parser, () -> parseFieldMatcher);
request = FlushJobAction.Request.parseRequest(jobId, parser, () -> parseFieldMatcher);
} else {
request = new PostDataFlushAction.Request(restRequest.param(Job.ID.getPreferredName()));
request.setCalcInterim(restRequest.paramAsBoolean(PostDataFlushAction.Request.CALC_INTERIM.getPreferredName(),
request = new FlushJobAction.Request(restRequest.param(Job.ID.getPreferredName()));
request.setCalcInterim(restRequest.paramAsBoolean(FlushJobAction.Request.CALC_INTERIM.getPreferredName(),
DEFAULT_CALC_INTERIM));
request.setStart(restRequest.param(PostDataFlushAction.Request.START.getPreferredName(), DEFAULT_START));
request.setEnd(restRequest.param(PostDataFlushAction.Request.END.getPreferredName(), DEFAULT_END));
request.setAdvanceTime(restRequest.param(PostDataFlushAction.Request.ADVANCE_TIME.getPreferredName(), DEFAULT_ADVANCE_TIME));
request.setStart(restRequest.param(FlushJobAction.Request.START.getPreferredName(), DEFAULT_START));
request.setEnd(restRequest.param(FlushJobAction.Request.END.getPreferredName(), DEFAULT_END));
request.setAdvanceTime(restRequest.param(FlushJobAction.Request.ADVANCE_TIME.getPreferredName(), DEFAULT_ADVANCE_TIME));
}
return channel -> transportPostDataFlushAction.execute(request, new AcknowledgedRestListener<>(channel));
return channel -> flushJobAction.execute(request, new AcknowledgedRestListener<>(channel));
}
}

View File

@ -35,16 +35,18 @@ public class RestGetJobsAction extends BaseRestHandler {
this.transportGetJobAction = transportGetJobAction;
// GETs
controller.registerHandler(RestRequest.Method.GET, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.GET, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/_stats",
this);
controller.registerHandler(RestRequest.Method.GET,
PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/{metric}", this);
controller.registerHandler(RestRequest.Method.GET, PrelertPlugin.BASE_PATH + "jobs", this);
PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/{metric}/_stats", this);
controller.registerHandler(RestRequest.Method.GET, PrelertPlugin.BASE_PATH + "jobs/_stats", this);
// POSTs
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/_stats",
this);
controller.registerHandler(RestRequest.Method.POST,
PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/{metric}", this);
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs", this);
PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/{metric}/_stats", this);
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/_stats", this);
}
@Override

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.prelert.rest.data;
package org.elasticsearch.xpack.prelert.rest.job;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
@ -13,33 +13,34 @@ import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.xpack.prelert.PrelertPlugin;
import org.elasticsearch.xpack.prelert.action.PostDataAction;
import org.elasticsearch.xpack.prelert.action.JobDataAction;
import org.elasticsearch.xpack.prelert.job.Job;
import java.io.IOException;
public class RestPostDataAction extends BaseRestHandler {
public class RestJobDataAction extends BaseRestHandler {
private static final boolean DEFAULT_IGNORE_DOWNTIME = false;
private static final String DEFAULT_RESET_START = "";
private static final String DEFAULT_RESET_END = "";
private final PostDataAction.TransportAction transportPostDataAction;
private final JobDataAction.TransportAction transportPostDataAction;
@Inject
public RestPostDataAction(Settings settings, RestController controller, PostDataAction.TransportAction transportPostDataAction) {
public RestJobDataAction(Settings settings, RestController controller, JobDataAction.TransportAction transportPostDataAction) {
super(settings);
this.transportPostDataAction = transportPostDataAction;
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "data/{" + Job.ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/data",
this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
PostDataAction.Request request = new PostDataAction.Request(restRequest.param(Job.ID.getPreferredName()));
JobDataAction.Request request = new JobDataAction.Request(restRequest.param(Job.ID.getPreferredName()));
request.setIgnoreDowntime(
restRequest.paramAsBoolean(PostDataAction.Request.IGNORE_DOWNTIME.getPreferredName(), DEFAULT_IGNORE_DOWNTIME));
request.setResetStart(restRequest.param(PostDataAction.Request.RESET_START.getPreferredName(), DEFAULT_RESET_START));
request.setResetEnd(restRequest.param(PostDataAction.Request.RESET_END.getPreferredName(), DEFAULT_RESET_END));
restRequest.paramAsBoolean(JobDataAction.Request.IGNORE_DOWNTIME.getPreferredName(), DEFAULT_IGNORE_DOWNTIME));
request.setResetStart(restRequest.param(JobDataAction.Request.RESET_START.getPreferredName(), DEFAULT_RESET_START));
request.setResetEnd(restRequest.param(JobDataAction.Request.RESET_END.getPreferredName(), DEFAULT_RESET_END));
request.setContent(restRequest.content());
return channel -> transportPostDataAction.execute(request, new RestStatusToXContentListener<>(channel));

View File

@ -27,7 +27,7 @@ public class RestOpenJobAction extends BaseRestHandler {
public RestOpenJobAction(Settings settings, RestController controller, OpenJobAction.TransportAction openJobAction) {
super(settings);
this.openJobAction = openJobAction;
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "data/{" + Job.ID.getPreferredName() + "}/_open",
controller.registerHandler(RestRequest.Method.POST, PrelertPlugin.BASE_PATH + "jobs/{" + Job.ID.getPreferredName() + "}/_open",
this);
}

View File

@ -19,12 +19,12 @@ import org.elasticsearch.xpack.prelert.action.PutJobAction;
import java.io.IOException;
public class RestPutJobsAction extends BaseRestHandler {
public class RestPutJobAction extends BaseRestHandler {
private final PutJobAction.TransportAction transportPutJobAction;
@Inject
public RestPutJobsAction(Settings settings, RestController controller, PutJobAction.TransportAction transportPutJobAction) {
public RestPutJobAction(Settings settings, RestController controller, PutJobAction.TransportAction transportPutJobAction) {
super(settings);
this.transportPutJobAction = transportPutJobAction;
controller.registerHandler(RestRequest.Method.PUT, PrelertPlugin.BASE_PATH + "jobs", this);

View File

@ -7,10 +7,10 @@ package org.elasticsearch.xpack.prelert.action;
import org.elasticsearch.xpack.prelert.support.AbstractStreamableTestCase;
public class PostDataActionRequestTests extends AbstractStreamableTestCase<PostDataAction.Request> {
public class PostDataActionRequestTests extends AbstractStreamableTestCase<JobDataAction.Request> {
@Override
protected PostDataAction.Request createTestInstance() {
PostDataAction.Request request = new PostDataAction.Request(randomAsciiOfLengthBetween(1, 20));
protected JobDataAction.Request createTestInstance() {
JobDataAction.Request request = new JobDataAction.Request(randomAsciiOfLengthBetween(1, 20));
request.setIgnoreDowntime(randomBoolean());
if (randomBoolean()) {
request.setResetStart(randomAsciiOfLengthBetween(1, 20));
@ -22,7 +22,7 @@ public class PostDataActionRequestTests extends AbstractStreamableTestCase<PostD
}
@Override
protected PostDataAction.Request createBlankInstance() {
return new PostDataAction.Request();
protected JobDataAction.Request createBlankInstance() {
return new JobDataAction.Request();
}
}

View File

@ -9,20 +9,20 @@ import org.elasticsearch.xpack.prelert.job.DataCounts;
import org.elasticsearch.xpack.prelert.support.AbstractStreamableTestCase;
import org.joda.time.DateTime;
public class PostDataActionResponseTests extends AbstractStreamableTestCase<PostDataAction.Response> {
public class PostDataActionResponseTests extends AbstractStreamableTestCase<JobDataAction.Response> {
@Override
protected PostDataAction.Response createTestInstance() {
protected JobDataAction.Response createTestInstance() {
DataCounts counts = new DataCounts(randomAsciiOfLength(10), randomIntBetween(1, 1_000_000),
randomIntBetween(1, 1_000_000), randomIntBetween(1, 1_000_000), randomIntBetween(1, 1_000_000),
randomIntBetween(1, 1_000_000), randomIntBetween(1, 1_000_000), randomIntBetween(1, 1_000_000),
new DateTime(randomDateTimeZone()).toDate(), new DateTime(randomDateTimeZone()).toDate());
return new PostDataAction.Response(counts);
return new JobDataAction.Response(counts);
}
@Override
protected PostDataAction.Response createBlankInstance() {
return new PostDataAction.Response("foo") ;
protected JobDataAction.Response createBlankInstance() {
return new JobDataAction.Response("foo") ;
}
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.prelert.action;
import org.elasticsearch.xpack.prelert.action.PostDataFlushAction.Request;
import org.elasticsearch.xpack.prelert.action.FlushJobAction.Request;
import org.elasticsearch.xpack.prelert.support.AbstractStreamableTestCase;
public class PostDataFlushRequestTests extends AbstractStreamableTestCase<Request> {

View File

@ -52,7 +52,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJob_GivenNoSuchJob() throws Exception {
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/non-existing-job"));
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/non-existing-job/_stats"));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
assertThat(e.getMessage(), containsString("Could not find requested jobs"));
@ -61,7 +61,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJob_GivenJobExists() throws Exception {
createFarequoteJob();
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/farequote");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/farequote/_stats");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
@ -71,7 +71,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJobs_GivenNegativeFrom() throws Exception {
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?from=-1"));
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?from=-1"));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
assertThat(e.getMessage(), containsString("\"reason\":\"Parameter [from] cannot be < 0\""));
@ -79,7 +79,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJobs_GivenNegativeSize() throws Exception {
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?size=-1"));
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?size=-1"));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
assertThat(e.getMessage(), containsString("\"reason\":\"Parameter [size] cannot be < 0\""));
@ -87,7 +87,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJobs_GivenFromAndSizeSumTo10001() throws Exception {
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?from=1000&size=11001"));
() -> client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?from=1000&size=11001"));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
assertThat(e.getMessage(), containsString("\"reason\":\"The sum of parameters [from] and [size] cannot be higher than 10000."));
@ -96,7 +96,7 @@ public class PrelertJobIT extends ESRestTestCase {
public void testGetJobs_GivenSingleJob() throws Exception {
createFarequoteJob();
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
@ -109,7 +109,7 @@ public class PrelertJobIT extends ESRestTestCase {
createFarequoteJob("farequote_2");
createFarequoteJob("farequote_3");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
@ -124,7 +124,7 @@ public class PrelertJobIT extends ESRestTestCase {
createFarequoteJob("farequote_2");
createFarequoteJob("farequote_3");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?from=1");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?from=1");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
@ -139,7 +139,7 @@ public class PrelertJobIT extends ESRestTestCase {
createFarequoteJob("farequote_2");
createFarequoteJob("farequote_3");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?size=1");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?size=1");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
@ -154,7 +154,7 @@ public class PrelertJobIT extends ESRestTestCase {
createFarequoteJob("farequote_2");
createFarequoteJob("farequote_3");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs?from=1&size=1");
Response response = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/_stats?from=1&size=1");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);

View File

@ -15,7 +15,6 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.prelert.PrelertPlugin;
import org.elasticsearch.xpack.prelert.action.ScheduledJobsIT;
import org.junit.After;
import java.io.BufferedReader;
@ -63,7 +62,7 @@ public class ScheduledJobIT extends ESRestTestCase {
assertBusy(() -> {
try {
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId,
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId + "/_stats",
Collections.singletonMap("metric", "data_counts"));
assertThat(responseEntityToString(getJobResponse), containsString("\"input_record_count\":2"));
} catch (Exception e) {
@ -87,7 +86,7 @@ public class ScheduledJobIT extends ESRestTestCase {
waitForSchedulerStartedState(jobId);
assertBusy(() -> {
try {
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId,
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId + "/_stats",
Collections.singletonMap("metric", "data_counts,status"));
String responseAsString = responseEntityToString(getJobResponse);
assertThat(responseAsString, containsString("\"status\":\"OPENED\""));
@ -108,7 +107,7 @@ public class ScheduledJobIT extends ESRestTestCase {
assertThat(responseEntityToString(response), equalTo("{\"acknowledged\":true}"));
waitForSchedulerStoppedState(client(), jobId);
client().performRequest("POST", "/_xpack/prelert/data/" + jobId + "/_close");
client().performRequest("POST", "/_xpack/prelert/jobs/" + jobId + "/_close");
response = client().performRequest("delete", PrelertPlugin.BASE_PATH + "jobs/" + jobId);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
assertThat(responseEntityToString(response), equalTo("{\"acknowledged\":true}"));
@ -163,7 +162,7 @@ public class ScheduledJobIT extends ESRestTestCase {
try {
assertBusy(() -> {
try {
Response getJobResponse = client.performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId,
Response getJobResponse = client.performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId + "/_stats",
Collections.singletonMap("metric", "scheduler_state"));
assertThat(responseEntityToString(getJobResponse), containsString("\"status\":\"STOPPED\""));
} catch (Exception e) {
@ -181,7 +180,7 @@ public class ScheduledJobIT extends ESRestTestCase {
try {
assertBusy(() -> {
try {
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId,
Response getJobResponse = client().performRequest("get", PrelertPlugin.BASE_PATH + "jobs/" + jobId + "/_stats",
Collections.singletonMap("metric", "scheduler_state"));
assertThat(responseEntityToString(getJobResponse), containsString("\"status\":\"STARTED\""));
} catch (Exception e) {
@ -218,7 +217,7 @@ public class ScheduledJobIT extends ESRestTestCase {
// ignore
}
try {
Response response = client.performRequest("POST", "/_xpack/prelert/data/" + jobId + "/_close");
Response response = client.performRequest("POST", "/_xpack/prelert/jobs/" + jobId + "/_close");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
} catch (Exception e) {
// ignore
@ -228,7 +227,7 @@ public class ScheduledJobIT extends ESRestTestCase {
}
public static void openJob(RestClient client, String jobId) throws IOException {
Response response = client.performRequest("post", PrelertPlugin.BASE_PATH + "data/" + jobId + "/_open");
Response response = client.performRequest("post", PrelertPlugin.BASE_PATH + "jobs/" + jobId + "/_open");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
}
}

View File

@ -2,8 +2,8 @@
"xpack.prelert.close_job": {
"methods": [ "POST" ],
"url": {
"path": "/_xpack/prelert/data/{job_id}/_close",
"paths": [ "/_xpack/prelert/data/{job_id}/_close" ],
"path": "/_xpack/prelert/jobs/{job_id}/_close",
"paths": [ "/_xpack/prelert/jobs/{job_id}/_close" ],
"parts": {
"job_id": {
"type": "string",

View File

@ -1,12 +1,12 @@
{
"xpack.prelert.flush_data": {
"xpack.prelert.flush_job": {
"methods": [
"POST"
],
"url": {
"path": "/_xpack/prelert/data/{job_id}/_flush",
"path": "/_xpack/prelert/jobs/{job_id}/_flush",
"paths": [
"/_xpack/prelert/data/{job_id}/_flush"
"/_xpack/prelert/jobs/{job_id}/_flush"
],
"parts": {
"job_id": {

View File

@ -4,9 +4,9 @@
"url": {
"path": "/_xpack/prelert/jobs/{job_id}",
"paths": [
"/_xpack/prelert/jobs",
"/_xpack/prelert/jobs/{job_id}",
"/_xpack/prelert/jobs/{job_id}/{metric}"
"/_xpack/prelert/jobs/_stats",
"/_xpack/prelert/jobs/{job_id}/_stats",
"/_xpack/prelert/jobs/{job_id}/{metric}/_stats"
],
"parts": {
"job_id": {

View File

@ -1,9 +1,9 @@
{
"xpack.prelert.post_data": {
"xpack.prelert.job_data": {
"methods": [ "POST" ],
"url": {
"path": "/_xpack/prelert/data/{job_id}",
"paths": [ "/_xpack/prelert/data/{job_id}" ],
"path": "/_xpack/prelert/jobs/{job_id}/data",
"paths": [ "/_xpack/prelert/jobs/{job_id}/data" ],
"parts": {
"job_id": {
"type": "string",

View File

@ -2,8 +2,8 @@
"xpack.prelert.open_job": {
"methods": [ "POST" ],
"url": {
"path": "/_xpack/prelert/data/{job_id}/_open",
"paths": [ "/_xpack/prelert/data/{job_id}/_open" ],
"path": "/_xpack/prelert/jobs/{job_id}/_open",
"paths": [ "/_xpack/prelert/jobs/{job_id}/_open" ],
"parts": {
"job_id": {
"type": "string",

View File

@ -70,14 +70,14 @@ setup:
- do:
xpack.prelert.post_data:
xpack.prelert.job_data:
job_id: job-stats-test
body: >
{"airline":"AAL","responsetime":"132.2046","time":"1403481600"}
{"airline":"JZA","responsetime":"990.4628","time":"1403481600"}
- do:
xpack.prelert.flush_data:
xpack.prelert.flush_job:
job_id: job-stats-test
- match: { acknowledged: true }

View File

@ -23,7 +23,7 @@ setup:
---
"Test POST data job api, flush, close and verify DataCounts doc":
- do:
xpack.prelert.post_data:
xpack.prelert.job_data:
job_id: farequote
body: >
{"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
@ -40,7 +40,7 @@ setup:
- match: { latest_record_timestamp: 1403481700000}
- do:
xpack.prelert.flush_data:
xpack.prelert.flush_job:
job_id: farequote
- match: { acknowledged: true }
@ -75,7 +75,7 @@ setup:
"Test POST data with invalid parameters":
- do:
catch: /parse_exception/
xpack.prelert.post_data:
xpack.prelert.job_data:
job_id: foo
reset_start: not_a_date
body: >
@ -84,7 +84,7 @@ setup:
- do:
catch: /parse_exception/
xpack.prelert.post_data:
xpack.prelert.job_data:
job_id: foo
reset_end: end_not_a_date
body: >
@ -95,18 +95,18 @@ setup:
"Test Flush data with invalid parameters":
- do:
catch: /parse_exception/
xpack.prelert.flush_data:
xpack.prelert.flush_job:
job_id: foo
start: not_a_date
- do:
catch: /parse_exception/
xpack.prelert.flush_data:
xpack.prelert.flush_job:
job_id: foo
end: end_not_a_date
- do:
catch: /parse_exception/
xpack.prelert.flush_data:
xpack.prelert.flush_job:
job_id: foo
advance_time: advance_time_not_a_date