Minor adjustments to datafeed endpoints (elastic/elasticsearch#761)

1. get_datafeeds_stats -> get_datafeed_stats

2. get_datafeeds now accepts implicit _all

Relates elastic/elasticsearch#630

Original commit: elastic/x-pack-elasticsearch@1fc0f69ee2
This commit is contained in:
David Roberts 2017-01-20 10:57:06 +00:00 committed by GitHub
parent 2eb0499454
commit bddfac59ed
13 changed files with 59 additions and 25 deletions

View File

@ -100,7 +100,7 @@ import org.elasticsearch.xpack.ml.rest.results.RestGetInfluencersAction;
import org.elasticsearch.xpack.ml.rest.results.RestGetRecordsAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestDeleteDatafeedAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestGetDatafeedsAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestGetDatafeedsStatsAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestGetDatafeedStatsAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestPutDatafeedAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestStartDatafeedAction;
import org.elasticsearch.xpack.ml.rest.datafeeds.RestStopDatafeedAction;
@ -238,7 +238,7 @@ public class MlPlugin extends Plugin implements ActionPlugin {
RestRevertModelSnapshotAction.class,
RestUpdateModelSnapshotAction.class,
RestGetDatafeedsAction.class,
RestGetDatafeedsStatsAction.class,
RestGetDatafeedStatsAction.class,
RestPutDatafeedAction.class,
RestDeleteDatafeedAction.class,
RestStartDatafeedAction.class,

View File

@ -46,7 +46,7 @@ public class GetDatafeedsAction extends Action<GetDatafeedsAction.Request, GetDa
public static final GetDatafeedsAction INSTANCE = new GetDatafeedsAction();
public static final String NAME = "cluster:admin/ml/datafeeds/get";
private static final String ALL = "_all";
public static final String ALL = "_all";
private GetDatafeedsAction() {
super(NAME);

View File

@ -49,7 +49,7 @@ public class GetDatafeedsStatsAction extends Action<GetDatafeedsStatsAction.Requ
public static final GetDatafeedsStatsAction INSTANCE = new GetDatafeedsStatsAction();
public static final String NAME = "cluster:admin/ml/datafeeds/stats/get";
private static final String ALL = "_all";
public static final String ALL = "_all";
private static final String STATUS = "status";
private GetDatafeedsStatsAction() {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.ml.rest.datafeeds;
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,19 +19,24 @@ import org.elasticsearch.xpack.ml.datafeed.DatafeedConfig;
import java.io.IOException;
public class RestGetDatafeedsStatsAction extends BaseRestHandler {
public class RestGetDatafeedStatsAction extends BaseRestHandler {
@Inject
public RestGetDatafeedsStatsAction(Settings settings, RestController controller) {
public RestGetDatafeedStatsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", this);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "datafeeds/_stats", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
GetDatafeedsStatsAction.Request request = new GetDatafeedsStatsAction.Request(
restRequest.param(DatafeedConfig.ID.getPreferredName()));
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
if (Strings.isNullOrEmpty(datafeedId)) {
datafeedId = GetDatafeedsStatsAction.ALL;
}
GetDatafeedsStatsAction.Request request = new GetDatafeedsStatsAction.Request(datafeedId);
return channel -> client.execute(GetDatafeedsStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

@ -25,11 +25,17 @@ public class RestGetDatafeedsAction extends BaseRestHandler {
super(settings);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this);
controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH
+ "datafeeds", this);
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
GetDatafeedsAction.Request request = new GetDatafeedsAction.Request(restRequest.param(DatafeedConfig.ID.getPreferredName()));
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
if (datafeedId == null) {
datafeedId = GetDatafeedsAction.ALL;
}
GetDatafeedsAction.Request request = new GetDatafeedsAction.Request(datafeedId);
return channel -> client.execute(GetDatafeedsAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

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

View File

@ -14,7 +14,7 @@ import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase;
import java.util.ArrayList;
import java.util.List;
public class GetDatafeedsStatsActionResponseTests extends AbstractStreamableTestCase<Response> {
public class GetDatafeedStatsActionResponseTests extends AbstractStreamableTestCase<Response> {
@Override
protected Response createTestInstance() {

View File

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

View File

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

View File

@ -40,7 +40,7 @@ setup:
- match: { datafeeds: [] }
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: "_all"
- match: { count: 0 }
- match: { datafeeds: [] }

View File

@ -56,32 +56,43 @@ setup:
- do:
catch: missing
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: missing-datafeed
---
"Test get single datafeed stats":
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: datafeed-1
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
- match: { datafeeds.0.status: "STOPPED"}
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: datafeed-2
- match: { datafeeds.0.datafeed_id: "datafeed-2"}
- match: { datafeeds.0.status: "STOPPED"}
---
"Test get all datafeeds stats":
"Test explicit get all datafeed stats":
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: _all
- match: { count: 2 }
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
- match: { datafeeds.0.status: "STOPPED"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.status: "STOPPED"}
---
"Test implicit get all datafeed stats":
- do:
xpack.ml.get_datafeed_stats: {}
- match: { count: 2 }
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
- match: { datafeeds.0.status: "STOPPED"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.status: "STOPPED"}

View File

@ -75,7 +75,7 @@ setup:
- match: { datafeeds.0.job_id: "job-2"}
---
"Test get all datafeeds":
"Test explicit get all datafeeds":
- do:
xpack.ml.get_datafeeds:
@ -85,3 +85,14 @@ setup:
- match: { datafeeds.0.job_id: "job-1"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.job_id: "job-2"}
---
"Test implicit get all datafeeds":
- do:
xpack.ml.get_datafeeds: {}
- match: { count: 2 }
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
- match: { datafeeds.0.job_id: "job-1"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.job_id: "job-2"}

View File

@ -45,14 +45,14 @@ setup:
"datafeed_id": "datafeed-1"
"start": 0
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: "datafeed-1"
- match: { datafeeds.0.status: STARTED }
- do:
xpack.ml.stop_datafeed:
"datafeed_id": "datafeed-1"
- do:
xpack.ml.get_datafeeds_stats:
xpack.ml.get_datafeed_stats:
datafeed_id: "datafeed-1"
- match: { datafeeds.0.status: STOPPED }
---