More endpoint adjustments (elastic/elasticsearch#750)

This commit contains some more of the endpoint changes Sophie and Steve
agreed with Clint:

1. get_jobs_stats renamed to get_job_stats

2. Revert snapshot must now be done using an ID - other options removed

3. Renamed "categorydefinitions" to "categories" in endpoints

4. get_jobs now has an implicit _all if no job ID/wildcard is specified

5. There is an option to retrieve a specific model snapshot by ID in
   get_model_snapshots

Relates elastic/elasticsearch#630

Original commit: elastic/x-pack-elasticsearch@9dd71c64a8
This commit is contained in:
David Roberts 2017-01-19 11:41:35 +00:00 committed by GitHub
parent e826a56212
commit 10441a3e38
30 changed files with 231 additions and 299 deletions

View File

@ -34,7 +34,7 @@ import org.elasticsearch.xpack.ml.action.DeleteModelSnapshotAction;
import org.elasticsearch.xpack.ml.action.DeleteSchedulerAction;
import org.elasticsearch.xpack.ml.action.FlushJobAction;
import org.elasticsearch.xpack.ml.action.GetBucketsAction;
import org.elasticsearch.xpack.ml.action.GetCategoriesDefinitionAction;
import org.elasticsearch.xpack.ml.action.GetCategoriesAction;
import org.elasticsearch.xpack.ml.action.GetInfluencersAction;
import org.elasticsearch.xpack.ml.action.GetJobsAction;
import org.elasticsearch.xpack.ml.action.GetJobsStatsAction;
@ -86,7 +86,7 @@ import org.elasticsearch.xpack.ml.rest.job.RestCloseJobAction;
import org.elasticsearch.xpack.ml.rest.job.RestDeleteJobAction;
import org.elasticsearch.xpack.ml.rest.job.RestFlushJobAction;
import org.elasticsearch.xpack.ml.rest.job.RestGetJobsAction;
import org.elasticsearch.xpack.ml.rest.job.RestGetJobsStatsAction;
import org.elasticsearch.xpack.ml.rest.job.RestGetJobStatsAction;
import org.elasticsearch.xpack.ml.rest.job.RestOpenJobAction;
import org.elasticsearch.xpack.ml.rest.job.RestPostDataAction;
import org.elasticsearch.xpack.ml.rest.job.RestPutJobAction;
@ -233,7 +233,7 @@ public class MlPlugin extends Plugin implements ActionPlugin {
public List<Class<? extends RestHandler>> getRestHandlers() {
return Arrays.asList(
RestGetJobsAction.class,
RestGetJobsStatsAction.class,
RestGetJobStatsAction.class,
RestPutJobAction.class,
RestDeleteJobAction.class,
RestOpenJobAction.class,
@ -285,7 +285,7 @@ public class MlPlugin extends Plugin implements ActionPlugin {
new ActionHandler<>(ValidateDetectorAction.INSTANCE, ValidateDetectorAction.TransportAction.class),
new ActionHandler<>(ValidateTransformAction.INSTANCE, ValidateTransformAction.TransportAction.class),
new ActionHandler<>(ValidateTransformsAction.INSTANCE, ValidateTransformsAction.TransportAction.class),
new ActionHandler<>(GetCategoriesDefinitionAction.INSTANCE, GetCategoriesDefinitionAction.TransportAction.class),
new ActionHandler<>(GetCategoriesAction.INSTANCE, GetCategoriesAction.TransportAction.class),
new ActionHandler<>(GetModelSnapshotsAction.INSTANCE, GetModelSnapshotsAction.TransportAction.class),
new ActionHandler<>(RevertModelSnapshotAction.INSTANCE, RevertModelSnapshotAction.TransportAction.class),
new ActionHandler<>(UpdateModelSnapshotAction.INSTANCE, UpdateModelSnapshotAction.TransportAction.class),

View File

@ -39,13 +39,13 @@ import java.util.Objects;
import static org.elasticsearch.action.ValidateActions.addValidationError;
public class GetCategoriesDefinitionAction extends
Action<GetCategoriesDefinitionAction.Request, GetCategoriesDefinitionAction.Response, GetCategoriesDefinitionAction.RequestBuilder> {
public class GetCategoriesAction extends
Action<GetCategoriesAction.Request, GetCategoriesAction.Response, GetCategoriesAction.RequestBuilder> {
public static final GetCategoriesDefinitionAction INSTANCE = new GetCategoriesDefinitionAction();
private static final String NAME = "cluster:admin/ml/categorydefinitions/get";
public static final GetCategoriesAction INSTANCE = new GetCategoriesAction();
private static final String NAME = "cluster:admin/ml/categories/get";
private GetCategoriesDefinitionAction() {
private GetCategoriesAction() {
super(NAME);
}
@ -177,7 +177,7 @@ Action<GetCategoriesDefinitionAction.Request, GetCategoriesDefinitionAction.Resp
public static class RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder> {
public RequestBuilder(ElasticsearchClient client, GetCategoriesDefinitionAction action) {
public RequestBuilder(ElasticsearchClient client, GetCategoriesAction action) {
super(client, action, new Request());
}
}

View File

@ -62,6 +62,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
public static class Request extends ActionRequest implements ToXContent {
public static final ParseField SNAPSHOT_ID = new ParseField("snapshot_id");
public static final ParseField SORT = new ParseField("sort");
public static final ParseField DESCRIPTION = new ParseField("description");
public static final ParseField START = new ParseField("start");
@ -72,6 +73,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
static {
PARSER.declareString((request, jobId) -> request.jobId = jobId, Job.ID);
PARSER.declareString((request, snapshotId) -> request.snapshotId = snapshotId, SNAPSHOT_ID);
PARSER.declareString(Request::setDescriptionString, DESCRIPTION);
PARSER.declareString(Request::setStart, START);
PARSER.declareString(Request::setEnd, END);
@ -80,15 +82,19 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
PARSER.declareObject(Request::setPageParams, PageParams.PARSER, PageParams.PAGE);
}
public static Request parseRequest(String jobId, XContentParser parser) {
public static Request parseRequest(String jobId, String snapshotId, XContentParser parser) {
Request request = PARSER.apply(parser, null);
if (jobId != null) {
request.jobId = jobId;
}
if (snapshotId != null) {
request.snapshotId = snapshotId;
}
return request;
}
private String jobId;
private String snapshotId;
private String sort;
private String description;
private String start;
@ -99,14 +105,20 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
Request() {
}
public Request(String jobId) {
public Request(String jobId, String snapshotId) {
this.jobId = ExceptionsHelper.requireNonNull(jobId, Job.ID.getPreferredName());
this.snapshotId = snapshotId;
}
public String getJobId() {
return jobId;
}
@Nullable
public String getSnapshotId() {
return snapshotId;
}
@Nullable
public String getSort() {
return sort;
@ -168,6 +180,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
jobId = in.readString();
snapshotId = in.readOptionalString();
sort = in.readOptionalString();
description = in.readOptionalString();
start = in.readOptionalString();
@ -180,6 +193,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(jobId);
out.writeOptionalString(snapshotId);
out.writeOptionalString(sort);
out.writeOptionalString(description);
out.writeOptionalString(start);
@ -192,6 +206,9 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Job.ID.getPreferredName(), jobId);
if (snapshotId != null) {
builder.field(SNAPSHOT_ID.getPreferredName(), snapshotId);
}
if (description != null) {
builder.field(DESCRIPTION.getPreferredName(), description);
}
@ -212,7 +229,7 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
@Override
public int hashCode() {
return Objects.hash(jobId, description, start, end, sort, desc);
return Objects.hash(jobId, snapshotId, description, start, end, sort, desc);
}
@Override
@ -224,9 +241,9 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
return false;
}
Request other = (Request) obj;
return Objects.equals(jobId, other.jobId) && Objects.equals(description, other.description)
&& Objects.equals(start, other.start) && Objects.equals(end, other.end) && Objects.equals(sort, other.sort)
&& Objects.equals(desc, other.desc);
return Objects.equals(jobId, other.jobId) && Objects.equals(snapshotId, other.snapshotId)
&& Objects.equals(description, other.description) && Objects.equals(start, other.start)
&& Objects.equals(end, other.end) && Objects.equals(sort, other.sort) && Objects.equals(desc, other.desc);
}
}
@ -319,14 +336,14 @@ extends Action<GetModelSnapshotsAction.Request, GetModelSnapshotsAction.Response
@Override
protected void doExecute(Request request, ActionListener<Response> listener) {
logger.debug(String.format(Locale.ROOT,
"Get model snapshots for job %s. from = %d, size = %d"
+ " start = '%s', end='%s', sort=%s descending=%b, description filter=%s",
request.getJobId(), request.pageParams.getFrom(), request.pageParams.getSize(), request.getStart(), request.getEnd(),
request.getSort(), request.getDescOrder(), request.getDescriptionString()));
logger.debug("Get model snapshots for job {} snapshot ID {}. from = {}, size = {}"
+ " start = '{}', end='{}', sort={} descending={}, description filter={}",
request.getJobId(), request.getSnapshotId(), request.pageParams.getFrom(), request.pageParams.getSize(),
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getDescriptionString());
jobProvider.modelSnapshots(request.getJobId(), request.pageParams.getFrom(), request.pageParams.getSize(),
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), null, request.getDescriptionString(),
request.getStart(), request.getEnd(), request.getSort(), request.getDescOrder(), request.getSnapshotId(),
request.getDescriptionString(),
page -> {
clearQuantiles(page);
listener.onResponse(new Response(page));

View File

@ -54,8 +54,6 @@ import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import static org.elasticsearch.action.ValidateActions.addValidationError;
public class RevertModelSnapshotAction
extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Response, RevertModelSnapshotAction.RequestBuilder> {
@ -78,71 +76,48 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
public static class Request extends AcknowledgedRequest<Request> implements ToXContent {
public static final ParseField TIME = new ParseField("time");
public static final ParseField SNAPSHOT_ID = new ParseField("snapshot_id");
public static final ParseField DESCRIPTION = new ParseField("description");
public static final ParseField DELETE_INTERVENING = new ParseField("delete_intervening_results");
private static ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
static {
PARSER.declareString((request, jobId) -> request.jobId = jobId, Job.ID);
PARSER.declareString(Request::setTime, TIME);
PARSER.declareString(Request::setSnapshotId, SNAPSHOT_ID);
PARSER.declareString(Request::setDescription, DESCRIPTION);
PARSER.declareString((request, snapshotId) -> request.snapshotId = snapshotId, SNAPSHOT_ID);
PARSER.declareBoolean(Request::setDeleteInterveningResults, DELETE_INTERVENING);
}
public static Request parseRequest(String jobId, XContentParser parser) {
public static Request parseRequest(String jobId, String snapshotId, XContentParser parser) {
Request request = PARSER.apply(parser, null);
if (jobId != null) {
request.jobId = jobId;
}
if (snapshotId != null) {
request.snapshotId = snapshotId;
}
return request;
}
private String jobId;
private String time;
private String snapshotId;
private String description;
private boolean deleteInterveningResults;
Request() {
}
public Request(String jobId) {
public Request(String jobId, String snapshotId) {
this.jobId = ExceptionsHelper.requireNonNull(jobId, Job.ID.getPreferredName());
this.snapshotId = ExceptionsHelper.requireNonNull(snapshotId, SNAPSHOT_ID.getPreferredName());
}
public String getJobId() {
return jobId;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getSnapshotId() {
return snapshotId;
}
public void setSnapshotId(String snapshotId) {
this.snapshotId = snapshotId;
}
@Override
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getDeleteInterveningResults() {
return deleteInterveningResults;
}
@ -153,20 +128,14 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (time == null && snapshotId == null && description == null) {
validationException = addValidationError(Messages.getMessage(Messages.REST_INVALID_REVERT_PARAMS), validationException);
}
return validationException;
return null;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
jobId = in.readString();
time = in.readOptionalString();
snapshotId = in.readOptionalString();
description = in.readOptionalString();
snapshotId = in.readString();
deleteInterveningResults = in.readBoolean();
}
@ -174,9 +143,7 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(jobId);
out.writeOptionalString(time);
out.writeOptionalString(snapshotId);
out.writeOptionalString(description);
out.writeString(snapshotId);
out.writeBoolean(deleteInterveningResults);
}
@ -184,15 +151,7 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Job.ID.getPreferredName(), jobId);
if (time != null) {
builder.field(TIME.getPreferredName(), time);
}
if (snapshotId != null) {
builder.field(SNAPSHOT_ID.getPreferredName(), snapshotId);
}
if (description != null) {
builder.field(DESCRIPTION.getPreferredName(), description);
}
builder.field(SNAPSHOT_ID.getPreferredName(), snapshotId);
builder.field(DELETE_INTERVENING.getPreferredName(), deleteInterveningResults);
builder.endObject();
return builder;
@ -200,7 +159,7 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
@Override
public int hashCode() {
return Objects.hash(jobId, time, snapshotId, description, deleteInterveningResults);
return Objects.hash(jobId, snapshotId, deleteInterveningResults);
}
@Override
@ -212,8 +171,7 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
return false;
}
Request other = (Request) obj;
return Objects.equals(jobId, other.jobId) && Objects.equals(time, other.time) && Objects.equals(snapshotId, other.snapshotId)
&& Objects.equals(description, other.description)
return Objects.equals(jobId, other.jobId) && Objects.equals(snapshotId, other.snapshotId)
&& Objects.equals(deleteInterveningResults, other.deleteInterveningResults);
}
}
@ -338,14 +296,8 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
@Override
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> listener) throws Exception {
logger.debug("Received request to revert to time '{}' description '{}' snapshot id '{}' for job '{}', deleting intervening " +
"results: {}",
request.getTime(), request.getDescription(), request.getSnapshotId(), request.getJobId(),
request.getDeleteInterveningResults());
if (request.getTime() == null && request.getSnapshotId() == null && request.getDescription() == null) {
throw new IllegalStateException(Messages.getMessage(Messages.REST_INVALID_REVERT_PARAMS));
}
logger.debug("Received request to revert to snapshot id '{}' for job '{}', deleting intervening results: {}",
request.getSnapshotId(), request.getJobId(), request.getDeleteInterveningResults());
QueryPage<Job> job = jobManager.getJob(request.getJobId(), clusterService.state());
Allocation allocation = jobManager.getJobAllocation(request.getJobId());
@ -365,9 +317,9 @@ extends Action<RevertModelSnapshotAction.Request, RevertModelSnapshotAction.Resp
private void getModelSnapshot(Request request, JobProvider provider, Consumer<ModelSnapshot> handler,
Consumer<Exception> errorHandler) {
logger.info("Reverting to snapshot '" + request.getSnapshotId() + "' for time '" + request.getTime() + "'");
logger.info("Reverting to snapshot '" + request.getSnapshotId() + "'");
provider.modelSnapshots(request.getJobId(), 0, 1, null, request.getTime(),
provider.modelSnapshots(request.getJobId(), 0, 1, null, null,
ModelSnapshot.TIMESTAMP.getPreferredName(), true, request.getSnapshotId(), request.getDescription(),
page -> {
List<ModelSnapshot> revertCandidates = page.results();

View File

@ -36,12 +36,6 @@ public final class Messages {
public static final String LICENSE_LIMIT_JOBS_REACTIVATE = "license.limit.jobs.reactivate";
public static final String LICENSE_LIMIT_PARTITIONS = "license.limit.partitions";
public static final String LOGFILE_INVALID_CHARS_IN_PATH = "logfile.invalid.chars.path";
public static final String LOGFILE_INVALID_PATH = "logfile.invalid.path";
public static final String LOGFILE_MISSING = "logfile.missing";
public static final String LOGFILE_MISSING_DIRECTORY = "logfile.missing.directory";
public static final String JOB_AUDIT_CREATED = "job.audit.created";
public static final String JOB_AUDIT_DELETED = "job.audit.deleted";
public static final String JOB_AUDIT_PAUSED = "job.audit.paused";
@ -219,8 +213,6 @@ public final class Messages {
public static final String JSON_TRANSFORM_CONFIG_MAPPING = "json.transform.config.mapping.error";
public static final String JSON_TRANSFORM_CONFIG_PARSE = "json.transform.config.parse.error";
public static final String ON_HOST = "on.host";
public static final String REST_ACTION_NOT_ALLOWED_FOR_SCHEDULED_JOB = "rest.action.not.allowed.for.scheduled.job";
public static final String REST_INVALID_DATETIME_PARAMS = "rest.invalid.datetime.params";
@ -230,22 +222,13 @@ public final class Messages {
public static final String REST_INVALID_FROM = "rest.invalid.from";
public static final String REST_INVALID_SIZE = "rest.invalid.size";
public static final String REST_INVALID_FROM_SIZE_SUM = "rest.invalid.from.size.sum";
public static final String REST_GZIP_ERROR = "rest.gzip.error";
public static final String REST_START_AFTER_END = "rest.start.after.end";
public static final String REST_RESET_BUCKET_NO_LATENCY = "rest.reset.bucket.no.latency";
public static final String REST_INVALID_REVERT_PARAMS = "rest.invalid.revert.params";
public static final String REST_JOB_NOT_CLOSED_REVERT = "rest.job.not.closed.revert";
public static final String REST_NO_SUCH_MODEL_SNAPSHOT = "rest.no.such.model.snapshot";
public static final String REST_INVALID_DESCRIPTION_PARAMS = "rest.invalid.description.params";
public static final String REST_DESCRIPTION_ALREADY_USED = "rest.description.already.used";
public static final String REST_CANNOT_DELETE_HIGHEST_PRIORITY = "rest.cannot.delete.highest.priority";
public static final String REST_ALERT_MISSING_ARGUMENT = "rest.alert.missing.argument";
public static final String REST_ALERT_INVALID_TIMEOUT = "rest.alert.invalid.timeout";
public static final String REST_ALERT_INVALID_THRESHOLD = "rest.alert.invalid.threshold";
public static final String REST_ALERT_CANT_USE_PROB = "rest.alert.cant.use.prob";
public static final String REST_ALERT_INVALID_TYPE = "rest.alert.invalid.type";
public static final String PROCESS_ACTION_SLEEPING_JOB = "process.action.sleeping.job";
public static final String PROCESS_ACTION_CLOSED_JOB = "process.action.closed.job";
public static final String PROCESS_ACTION_CLOSING_JOB = "process.action.closing.job";
@ -257,8 +240,6 @@ public final class Messages {
public static final String PROCESS_ACTION_UPDATING_JOB = "process.action.updating.job";
public static final String PROCESS_ACTION_WRITING_JOB = "process.action.writing.job";
public static final String SUPPORT_BUNDLE_SCRIPT_ERROR = "support.bundle.script.error";
private Messages() {
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.ml.rest.job;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
@ -18,18 +19,24 @@ import org.elasticsearch.xpack.ml.job.Job;
import java.io.IOException;
public class RestGetJobsStatsAction extends BaseRestHandler {
public class RestGetJobStatsAction extends BaseRestHandler {
@Inject
public RestGetJobsStatsAction(Settings settings, RestController controller) {
public RestGetJobStatsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", this);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "anomaly_detectors/_stats", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
GetJobsStatsAction.Request request = new GetJobsStatsAction.Request(restRequest.param(Job.ID.getPreferredName()));
String jobId = restRequest.param(Job.ID.getPreferredName());
if (Strings.isNullOrEmpty(jobId)) {
jobId = Job.ALL;
}
GetJobsStatsAction.Request request = new GetJobsStatsAction.Request(jobId);
return channel -> client.execute(GetJobsStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.ml.rest.job;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
@ -26,11 +27,17 @@ public class RestGetJobsAction extends BaseRestHandler {
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "anomaly_detectors", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
GetJobsAction.Request request = new GetJobsAction.Request(restRequest.param(Job.ID.getPreferredName()));
String jobId = restRequest.param(Job.ID.getPreferredName());
if (Strings.isNullOrEmpty(jobId)) {
jobId = Job.ALL;
}
GetJobsAction.Request request = new GetJobsAction.Request(jobId);
return channel -> client.execute(GetJobsAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.ml.rest.modelsnapshots;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
@ -23,6 +24,9 @@ import java.io.IOException;
public class RestGetModelSnapshotsAction extends BaseRestHandler {
private final String ALL = "_all";
private final String ALL_SNAPSHOT_IDS = null;
// Even though these are null, setting up the defaults in case
// we want to change them later
private final String DEFAULT_SORT = null;
@ -35,21 +39,31 @@ public class RestGetModelSnapshotsAction extends BaseRestHandler {
public RestGetModelSnapshotsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "anomaly_detectors/{"
+ Job.ID.getPreferredName() + "}/model_snapshots/", this);
+ Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this);
// endpoints that support body parameters must also accept POST
controller.registerHandler(RestRequest.Method.POST, MlPlugin.BASE_PATH + "anomaly_detectors/{"
+ Job.ID.getPreferredName() + "}/model_snapshots/", this);
+ Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "anomaly_detectors/{"
+ Job.ID.getPreferredName() + "}/model_snapshots", this);
// endpoints that support body parameters must also accept POST
controller.registerHandler(RestRequest.Method.POST, MlPlugin.BASE_PATH + "anomaly_detectors/{"
+ Job.ID.getPreferredName() + "}/model_snapshots", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String jobId = restRequest.param(Job.ID.getPreferredName());
String snapshotId = restRequest.param(Request.SNAPSHOT_ID.getPreferredName());
if (ALL.equals(snapshotId)) {
snapshotId = ALL_SNAPSHOT_IDS;
}
Request getModelSnapshots;
if (restRequest.hasContentOrSourceParam()) {
XContentParser parser = restRequest.contentOrSourceParamParser();
getModelSnapshots = Request.parseRequest(jobId, parser);
getModelSnapshots = Request.parseRequest(jobId, snapshotId, parser);
} else {
getModelSnapshots = new Request(jobId);
getModelSnapshots = new Request(jobId, snapshotId);
getModelSnapshots.setSort(restRequest.param(Request.SORT.getPreferredName(), DEFAULT_SORT));
if (restRequest.hasParam(Request.START.getPreferredName())) {
getModelSnapshots.setStart(restRequest.param(Request.START.getPreferredName(), DEFAULT_START));

View File

@ -21,32 +21,26 @@ import java.io.IOException;
public class RestRevertModelSnapshotAction extends BaseRestHandler {
private final String TIME_DEFAULT = null;
private final String SNAPSHOT_ID_DEFAULT = null;
private final String DESCRIPTION_DEFAULT = null;
private final boolean DELETE_INTERVENING_DEFAULT = false;
@Inject
public RestRevertModelSnapshotAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST,
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/_revert",
this);
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" +
RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
String jobId = restRequest.param(Job.ID.getPreferredName());
String snapshotId = restRequest.param(RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName());
RevertModelSnapshotAction.Request request;
if (restRequest.hasContentOrSourceParam()) {
XContentParser parser = restRequest.contentOrSourceParamParser();
request = RevertModelSnapshotAction.Request.parseRequest(jobId, parser);
request = RevertModelSnapshotAction.Request.parseRequest(jobId, snapshotId, parser);
} else {
request = new RevertModelSnapshotAction.Request(jobId);
request.setTime(restRequest.param(RevertModelSnapshotAction.Request.TIME.getPreferredName(), TIME_DEFAULT));
request.setSnapshotId(restRequest.param(RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName(), SNAPSHOT_ID_DEFAULT));
request.setDescription(
restRequest.param(RevertModelSnapshotAction.Request.DESCRIPTION.getPreferredName(), DESCRIPTION_DEFAULT));
request = new RevertModelSnapshotAction.Request(jobId, snapshotId);
request.setDeleteInterveningResults(restRequest
.paramAsBoolean(RevertModelSnapshotAction.Request.DELETE_INTERVENING.getPreferredName(), DELETE_INTERVENING_DEFAULT));
}

View File

@ -16,8 +16,8 @@ import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.ml.MlPlugin;
import org.elasticsearch.xpack.ml.action.GetCategoriesDefinitionAction;
import org.elasticsearch.xpack.ml.action.GetCategoriesDefinitionAction.Request;
import org.elasticsearch.xpack.ml.action.GetCategoriesAction;
import org.elasticsearch.xpack.ml.action.GetCategoriesAction.Request;
import org.elasticsearch.xpack.ml.job.Job;
import org.elasticsearch.xpack.ml.job.results.PageParams;
@ -29,16 +29,16 @@ public class RestGetCategoriesAction extends BaseRestHandler {
public RestGetCategoriesAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET,
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categorydefinitions/{"
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{"
+ Request.CATEGORY_ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.GET,
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categorydefinitions", this);
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", this);
controller.registerHandler(RestRequest.Method.POST,
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categorydefinitions/{"
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{"
+ Request.CATEGORY_ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.POST,
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categorydefinitions", this);
MlPlugin.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", this);
}
@Override
@ -50,7 +50,7 @@ public class RestGetCategoriesAction extends BaseRestHandler {
if (bodyBytes != null && bodyBytes.length() > 0) {
XContentParser parser = restRequest.contentParser();
request = GetCategoriesDefinitionAction.Request.parseRequest(jobId, parser);
request = GetCategoriesAction.Request.parseRequest(jobId, parser);
request.setCategoryId(categoryId);
} else {
@ -69,7 +69,7 @@ public class RestGetCategoriesAction extends BaseRestHandler {
}
}
return channel -> client.execute(GetCategoriesDefinitionAction.INSTANCE, request, new RestToXContentListener<>(channel));
return channel -> client.execute(GetCategoriesAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

@ -1,5 +1,5 @@
# Ml Engine API messages
# Machine Learning API messages
autodetect.flush.timeout =[{0}] Timed out flushing job.
autodetect.flush.failed.unexpected.death =[{0}] Flush failed: Unexpected death of the Autodetect process flushing job.
@ -19,11 +19,6 @@ license.limit.jobs = Cannot create new job - your license limits you to {0,numbe
license.limit.jobs.reactivate = Cannot reactivate job with id ''{0}'' - your license limits you to {1,number,integer} concurrently running jobs. You must close a job before you can reactivate another.
license.limit.partitions = Cannot create new job - your license disallows partition fields, but you have configured one.
logfile.invalid.chars.path = Invalid log file path. ''{0}''. Log file names cannot contain ''\\'' or ''/''
logfile.invalid.path = Invalid log file path. ''{0}'' is outside the base logs directory
logfile.missing = Cannot read log file ''{0}''
logfile.missing.directory = Cannot open log file directory ''{0}''
job.audit.created = Job created
job.audit.deleted = Job deleted
job.audit.paused = Job paused
@ -175,16 +170,8 @@ json.list.document.parse.error = JSON parse error reading the list
json.transform.config.mapping.error = JSON mapping error reading the transform configuration
json.transform.config.parse.error = JSON parse error reading the transform configuration
on.host = on host {0}
rest.action.not.allowed.for.scheduled.job = This action is not allowed for a scheduled job
rest.alert.invalid.timeout = Invalid timeout parameter. Timeout must be > 0
rest.alert.invalid.threshold = Invalid alert parameters. {0} must be in the range 0-100
rest.alert.missing.argument = Missing argument: either 'score' or 'probability' must be specified
rest.alert.invalid.type = The alert type argument ''{0}'' isn''t a recognised type
rest.alert.cant.use.prob = Influencer alerts require an anomaly score argument
rest.invalid.datetime.params = Query param ''{0}'' with value ''{1}'' cannot be parsed as a date or converted to a number (epoch).
rest.invalid.flush.params.missing.argument = Invalid flush parameters: ''{0}'' has not been specified.
rest.invalid.flush.params.unexpected = Invalid flush parameters: unexpected ''{0}''.
@ -192,13 +179,10 @@ rest.invalid.reset.params = Invalid reset range parameters: ''{0}'' has not been
rest.invalid.from = Parameter 'from' cannot be < 0
rest.invalid.size = Parameter 'size' cannot be < 0
rest.invalid.from.size.sum = The sum of parameters ''from'' and ''size'' cannot be higher than {0}. Please use filters to reduce the number of results.
rest.gzip.error = Content-Encoding = gzip but the data is not in gzip format
rest.start.after.end = Invalid time range: end time ''{0}'' is earlier than start time ''{1}''.
rest.reset.bucket.no.latency = Bucket resetting is not supported when no latency is configured.
rest.invalid.revert.params = Cannot revert to a model snapshot as no parameters were specified.
rest.job.not.closed.revert = Can only revert to a model snapshot when the job is closed.
rest.no.such.model.snapshot = No matching model snapshot exists for job ''{0}''
rest.invalid.description.params = Both snapshot ID and new description must be provided when changing a model snapshot description.
rest.description.already.used = Model snapshot description ''{0}'' has already been used for job ''{1}''
rest.cannot.delete.highest.priority = Model snapshot ''{0}'' is the active snapshot for job ''{1}'', so cannot be deleted
@ -213,5 +197,3 @@ process.action.sleeping.job = holding
process.action.updating.job = updating
process.action.writing.job = writing to
support.bundle.script.error = Error executing the support bundle script ''{0}''

View File

@ -9,12 +9,12 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.ml.job.results.PageParams;
import org.elasticsearch.xpack.ml.support.AbstractStreamableXContentTestCase;
public class GetCategoryDefinitionRequestTests extends AbstractStreamableXContentTestCase<GetCategoriesDefinitionAction.Request> {
public class GetCategoriesRequestTests extends AbstractStreamableXContentTestCase<GetCategoriesAction.Request> {
@Override
protected GetCategoriesDefinitionAction.Request createTestInstance() {
protected GetCategoriesAction.Request createTestInstance() {
String jobId = randomAsciiOfLength(10);
GetCategoriesDefinitionAction.Request request = new GetCategoriesDefinitionAction.Request(jobId);
GetCategoriesAction.Request request = new GetCategoriesAction.Request(jobId);
if (randomBoolean()) {
request.setCategoryId(randomAsciiOfLength(10));
} else {
@ -27,12 +27,12 @@ public class GetCategoryDefinitionRequestTests extends AbstractStreamableXConten
}
@Override
protected GetCategoriesDefinitionAction.Request createBlankInstance() {
return new GetCategoriesDefinitionAction.Request();
protected GetCategoriesAction.Request createBlankInstance() {
return new GetCategoriesAction.Request();
}
@Override
protected GetCategoriesDefinitionAction.Request parseInstance(XContentParser parser) {
return GetCategoriesDefinitionAction.Request.parseRequest(null, parser);
protected GetCategoriesAction.Request parseInstance(XContentParser parser) {
return GetCategoriesAction.Request.parseRequest(null, parser);
}
}

View File

@ -11,18 +11,18 @@ import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase;
import java.util.Collections;
public class GetCategoryDefinitionResponseTests extends AbstractStreamableTestCase<GetCategoriesDefinitionAction.Response> {
public class GetCategoriesResponseTests extends AbstractStreamableTestCase<GetCategoriesAction.Response> {
@Override
protected GetCategoriesDefinitionAction.Response createTestInstance() {
protected GetCategoriesAction.Response createTestInstance() {
CategoryDefinition definition = new CategoryDefinition(randomAsciiOfLength(10));
QueryPage<CategoryDefinition> queryPage =
new QueryPage<>(Collections.singletonList(definition), 1L, CategoryDefinition.RESULTS_FIELD);
return new GetCategoriesDefinitionAction.Response(queryPage);
return new GetCategoriesAction.Response(queryPage);
}
@Override
protected GetCategoriesDefinitionAction.Response createBlankInstance() {
return new GetCategoriesDefinitionAction.Response();
protected GetCategoriesAction.Response createBlankInstance() {
return new GetCategoriesAction.Response();
}
}

View File

@ -9,7 +9,7 @@ import org.elasticsearch.xpack.ml.action.GetJobsStatsAction.Request;
import org.elasticsearch.xpack.ml.job.Job;
import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase;
public class GetJobsStatsActionRequestTests extends AbstractStreamableTestCase<Request> {
public class GetJobStatsActionRequestTests extends AbstractStreamableTestCase<Request> {
@Override
protected Request createTestInstance() {

View File

@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
public class GetJobsStatsActionResponseTests extends AbstractStreamableTestCase<Response> {
public class GetJobStatsActionResponseTests extends AbstractStreamableTestCase<Response> {
@Override
protected Response createTestInstance() {

View File

@ -14,12 +14,12 @@ public class GetModelSnapshotsActionRequestTests extends AbstractStreamableXCont
@Override
protected Request parseInstance(XContentParser parser) {
return GetModelSnapshotsAction.Request.parseRequest(null, parser);
return GetModelSnapshotsAction.Request.parseRequest(null, null, parser);
}
@Override
protected Request createTestInstance() {
Request request = new Request(randomAsciiOfLengthBetween(1, 20));
Request request = new Request(randomAsciiOfLengthBetween(1, 20), randomBoolean() ? null : randomAsciiOfLengthBetween(1, 20));
if (randomBoolean()) {
request.setDescriptionString(randomAsciiOfLengthBetween(1, 20));
}

View File

@ -13,16 +13,8 @@ public class RevertModelSnapshotActionRequestTests extends AbstractStreamableXCo
@Override
protected Request createTestInstance() {
RevertModelSnapshotAction.Request request = new RevertModelSnapshotAction.Request(randomAsciiOfLengthBetween(1, 20));
if (randomBoolean()) {
request.setDescription(randomAsciiOfLengthBetween(1, 20));
}
if (randomBoolean()) {
request.setTime(randomAsciiOfLengthBetween(1, 20));
}
if (randomBoolean()) {
request.setSnapshotId(randomAsciiOfLengthBetween(1, 20));
}
RevertModelSnapshotAction.Request request =
new RevertModelSnapshotAction.Request(randomAsciiOfLengthBetween(1, 20), randomAsciiOfLengthBetween(1, 20));
if (randomBoolean()) {
request.setDeleteInterveningResults(randomBoolean());
}
@ -36,7 +28,6 @@ public class RevertModelSnapshotActionRequestTests extends AbstractStreamableXCo
@Override
protected Request parseInstance(XContentParser parser) {
return RevertModelSnapshotAction.Request.parseRequest(null, parser);
return RevertModelSnapshotAction.Request.parseRequest(null, null, parser);
}
}

View File

@ -72,12 +72,21 @@ public class MlJobIT extends ESRestTestCase {
public void testGetJobs_GivenSingleJob() throws Exception {
createFarequoteJob();
// Explicit _all
Response response = client().performRequest("get", MlPlugin.BASE_PATH + "anomaly_detectors/_all");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
String responseAsString = responseEntityToString(response);
assertThat(responseAsString, containsString("\"count\":1"));
assertThat(responseAsString, containsString("\"job_id\":\"farequote\""));
// Implicit _all
response = client().performRequest("get", MlPlugin.BASE_PATH + "anomaly_detectors");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
responseAsString = responseEntityToString(response);
assertThat(responseAsString, containsString("\"count\":1"));
assertThat(responseAsString, containsString("\"job_id\":\"farequote\""));
}
public void testGetJobs_GivenMultipleJobs() throws Exception {
@ -85,6 +94,7 @@ public class MlJobIT extends ESRestTestCase {
createFarequoteJob("farequote_2");
createFarequoteJob("farequote_3");
// Explicit _all
Response response = client().performRequest("get", MlPlugin.BASE_PATH + "anomaly_detectors/_all");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
@ -93,6 +103,16 @@ public class MlJobIT extends ESRestTestCase {
assertThat(responseAsString, containsString("\"job_id\":\"farequote_1\""));
assertThat(responseAsString, containsString("\"job_id\":\"farequote_2\""));
assertThat(responseAsString, containsString("\"job_id\":\"farequote_3\""));
// Implicit _all
response = client().performRequest("get", MlPlugin.BASE_PATH + "anomaly_detectors");
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
responseAsString = responseEntityToString(response);
assertThat(responseAsString, containsString("\"count\":3"));
assertThat(responseAsString, containsString("\"job_id\":\"farequote_1\""));
assertThat(responseAsString, containsString("\"job_id\":\"farequote_2\""));
assertThat(responseAsString, containsString("\"job_id\":\"farequote_3\""));
}
private Response createFarequoteJob() throws Exception {

View File

@ -20,13 +20,13 @@ public class GetModelSnapshotsTests extends ESTestCase {
public void testModelSnapshots_GivenNegativeFrom() {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> new GetModelSnapshotsAction.Request("foo").setPageParams(new PageParams(-5, 10)));
() -> new GetModelSnapshotsAction.Request("foo", null).setPageParams(new PageParams(-5, 10)));
assertEquals("Parameter [from] cannot be < 0", e.getMessage());
}
public void testModelSnapshots_GivenNegativeSize() {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> new GetModelSnapshotsAction.Request("foo").setPageParams(new PageParams(10, -5)));
() -> new GetModelSnapshotsAction.Request("foo", null).setPageParams(new PageParams(10, -5)));
assertEquals("Parameter [size] cannot be < 0", e.getMessage());
}

View File

@ -2,10 +2,10 @@
"xpack.ml.get_categories": {
"methods": [ "GET", "POST" ],
"url": {
"path": "/_xpack/ml/anomaly_detectors/{job_id}/results/categorydefinitions/{category_id}",
"path": "/_xpack/ml/anomaly_detectors/{job_id}/results/categories/{category_id}",
"paths": [
"/_xpack/ml/anomaly_detectors/{job_id}/results/categorydefinitions/{category_id}",
"/_xpack/ml/anomaly_detectors/{job_id}/results/categorydefinitions/"
"/_xpack/ml/anomaly_detectors/{job_id}/results/categories/{category_id}",
"/_xpack/ml/anomaly_detectors/{job_id}/results/categories/"
],
"parts": {
"job_id": {

View File

@ -1,15 +1,15 @@
{
"xpack.ml.get_jobs_stats": {
"xpack.ml.get_job_stats": {
"methods": [ "GET"],
"url": {
"path": "/_xpack/ml/anomaly_detectors/{job_id}/_stats",
"paths": [
"/_xpack/ml/anomaly_detectors/_stats",
"/_xpack/ml/anomaly_detectors/{job_id}/_stats"
],
"parts": {
"job_id": {
"type": "string",
"required": true,
"description": "The ID of the jobs stats to fetch"
}
}

View File

@ -4,12 +4,12 @@
"url": {
"path": "/_xpack/ml/anomaly_detectors/{job_id}",
"paths": [
"/_xpack/ml/anomaly_detectors/{job_id}"
"/_xpack/ml/anomaly_detectors/{job_id}",
"/_xpack/ml/anomaly_detectors/"
],
"parts": {
"job_id": {
"type": "string",
"required": true,
"description": "The ID of the jobs to fetch"
}
}

View File

@ -2,13 +2,20 @@
"xpack.ml.get_model_snapshots": {
"methods": [ "GET", "POST" ],
"url": {
"path": "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots",
"paths": [ "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots" ],
"path": "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}",
"paths": [
"/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}",
"/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots"
],
"parts": {
"job_id": {
"type": "string",
"required": true,
"description": "The ID of the job to fetch"
},
"snapshot_id": {
"type": "string",
"description": "The ID of the snapshot to fetch"
}
},
"params": {

View File

@ -2,36 +2,28 @@
"xpack.ml.revert_model_snapshot": {
"methods": [ "POST" ],
"url": {
"path": "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/_revert",
"paths": [ "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/_revert" ],
"path": "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}/_revert",
"paths": [ "/_xpack/ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}/_revert" ],
"parts": {
"job_id": {
"type": "string",
"required": true,
"description": "The ID of the job to fetch"
}
},
"params": {
"time": {
"type": "date",
"description": "revert to a snapshot with a timestamp no later than this time"
},
"snapshot_id": {
"type": "string",
"description": "the snapshot ID of the snapshot to revert to"
},
"description": {
"type": "string",
"description": "the description of the snapshot to revert to"
},
"description": "The ID of the snapshot to revert to"
}
},
"params": {
"delete_intervening_results": {
"type": "boolean",
"description": "should we reset the results back to the time of the snapshot?"
"description": "Should we reset the results back to the time of the snapshot?"
}
}
},
"body": {
"description": "Model snapshot selection criteria"
"description": "Reversion options"
}
}
}

View File

@ -15,15 +15,15 @@ setup:
index:
index: .ml-anomalies-foo
type: model_snapshot
id: "1"
body: { "job_id": "foo", "timestamp": "2016-06-02T00:00:00Z", "restore_priority": "1" }
id: "foo-1"
body: { "job_id": "foo", "snapshot_id": "1", "timestamp": "2016-06-02T00:00:00Z", "restore_priority": "1" }
- do:
index:
index: .ml-anomalies-foo
type: model_snapshot
id: "2"
body: { "job_id": "foo", "timestamp": "2016-06-01T00:00:00Z", "restore_priority": "2" }
id: "foo-2"
body: { "job_id": "foo", "snapshot_id": "2", "timestamp": "2016-06-01T00:00:00Z", "restore_priority": "2" }
- do:
indices.refresh:
@ -35,11 +35,32 @@ setup:
xpack.ml.get_model_snapshots:
job_id: "foo"
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
---
"Test get model snapshots API with _all":
- do:
xpack.ml.get_model_snapshots:
job_id: "foo"
snapshot_id: "_all"
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
---
"Test get specific model snapshot":
- do:
xpack.ml.get_model_snapshots:
job_id: "foo"
snapshot_id: "2"
- match: { count: 1 }
- match: { model_snapshots.0.restore_priority: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
---
"Test get model snapshots API with start/end":
- do:
@ -48,7 +69,6 @@ setup:
start: "2016-05-01T00:00:00Z"
end: "2016-07-01T00:00:00Z"
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
@ -60,7 +80,6 @@ setup:
job_id: "foo"
desc: false
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 1 }
- match: { model_snapshots.0.timestamp: 1464825600000 }
@ -72,7 +91,6 @@ setup:
job_id: "foo"
size: 1
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 2 }
- match: { model_snapshots.0.timestamp: 1464739200000 }
@ -85,7 +103,6 @@ setup:
job_id: "foo"
from: 1
- match: { count: 2 }
- match: { model_snapshots.0.restore_priority: 1 }
- match: { model_snapshots.0.timestamp: 1464825600000 }

View File

@ -8,7 +8,7 @@
- match: { jobs: [] }
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: "_all"
- match: { count: 0 }
- match: { jobs: [] }

View File

@ -59,7 +59,7 @@ setup:
- match: { jobs.0.description: "Job 2"}
---
"Test get all jobs":
"Test explicit get all jobs":
- do:
xpack.ml.get_jobs:
@ -69,3 +69,14 @@ setup:
- match: { jobs.0.description: "Job 1"}
- match: { jobs.1.job_id: "job-2"}
- match: { jobs.1.description: "Job 2"}
---
"Test implicit get all jobs":
- do:
xpack.ml.get_jobs: {}
- match: { count: 2 }
- match: { jobs.0.job_id: "job-1"}
- match: { jobs.0.description: "Job 1"}
- match: { jobs.1.job_id: "job-2"}
- match: { jobs.1.description: "Job 2"}

View File

@ -83,7 +83,7 @@ setup:
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: job-stats-test
- match: { jobs.0.job_id : job-stats-test }
- match: { jobs.0.data_counts.processed_record_count: 2 }
@ -96,17 +96,32 @@ setup:
"Test get job stats of scheduled job that has not received and data":
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: scheduled-job
- match: { jobs.0.job_id : scheduled-job }
- match: { jobs.0.data_counts.processed_record_count: 0 }
- is_false: jobs.0.model_size_stats
- match: { jobs.0.status: OPENED }
---
"Test get all job stats explicitly":
- do:
xpack.ml.get_job_stats:
job_id: _all
- match: { count: 2 }
---
"Test get all job stats implicitly":
- do:
xpack.ml.get_job_stats: {}
- match: { count: 2 }
---
"Test get job stats given missing job":
- do:
catch: missing
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: unknown-job

View File

@ -66,7 +66,7 @@ setup:
- match: { acknowledged: true }
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: farequote
- match: { jobs.0.status: "CLOSED" }
@ -99,7 +99,7 @@ setup:
- match: { acknowledged: true }
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: farequote
- match: { jobs.0.status: "CLOSED" }

View File

@ -132,20 +132,6 @@ setup:
- do:
indices.refresh:
index: .ml-state
---
"Test revert model with only job_id":
- do:
catch: request
xpack.ml.revert_model_snapshot:
job_id: "foo"
---
"Test revert model with invalid time":
- do:
catch: request
xpack.ml.revert_model_snapshot:
job_id: "foo"
time: "foo"
---
"Test revert model with invalid snapshotId":
@ -155,14 +141,6 @@ setup:
job_id: "foo"
snapshot_id: "not_exist"
---
"Test revert model with invalid description":
- do:
catch: /resource_not_found_exception/
xpack.ml.revert_model_snapshot:
job_id: "foo"
description: "foo"
---
"Test revert model with valid snapshotId":
- do:
@ -190,59 +168,7 @@ setup:
- match: { model.snapshot_doc_count: 0 }
---
"Test revert model with valid time":
- do:
xpack.ml.revert_model_snapshot:
job_id: "foo"
time: "2016-06-02T01:00:00Z"
- match: { acknowledged: true }
- match: { model.job_id: "foo" }
- match: { model.timestamp: 1464825600000 }
- match: { model.restore_priority: 1 }
- match: { model.snapshot_id: "foo1" }
- match: { model.snapshot_doc_count: 0 }
- do:
xpack.ml.revert_model_snapshot:
job_id: "foo"
time: "2016-06-01T01:00:00Z"
- match: { acknowledged: true }
- match: { model.job_id: "foo" }
- match: { model.timestamp: 1464739200000 }
- match: { model.restore_priority: 2 }
- match: { model.snapshot_id: "foo2" }
- match: { model.snapshot_doc_count: 0 }
---
"Test revert model with valid description":
- do:
xpack.ml.revert_model_snapshot:
job_id: "foo"
description: "first"
- match: { acknowledged: true }
- match: { model.job_id: "foo" }
- match: { model.timestamp: 1464825600000 }
- match: { model.restore_priority: 1 }
- match: { model.snapshot_id: "foo1" }
- match: { model.snapshot_doc_count: 0 }
- do:
xpack.ml.revert_model_snapshot:
job_id: "foo"
description: "second"
- match: { acknowledged: true }
- match: { model.job_id: "foo" }
- match: { model.timestamp: 1464739200000 }
- match: { model.restore_priority: 2 }
- match: { model.snapshot_id: "foo2" }
- match: { model.snapshot_doc_count: 0 }
---
"Test revert model with deleteInterveningResults":
"Test revert model with delete_intervening_results":
- do:
xpack.ml.get_buckets:
job_id: "foo"
@ -292,9 +218,8 @@ setup:
- match: { influencers.0.timestamp: 1462060800000 }
- do:
xpack.ml.get_jobs_stats:
xpack.ml.get_job_stats:
job_id: foo
- match: { jobs.0.data_counts.latest_record_timestamp: 1464739200000 }