diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java index c0e62c147ea..24e413eb05f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java @@ -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, diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetDatafeedsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetDatafeedsAction.java index 7279535ea5e..c53aefa814c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetDatafeedsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetDatafeedsAction.java @@ -46,7 +46,7 @@ public class GetDatafeedsAction extends Action client.execute(GetDatafeedsStatsAction.INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java index 57b7618878b..d961e05ebfe 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java @@ -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)); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java similarity index 88% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionRequestTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java index a26cc78ea0d..4539665d768 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java @@ -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 { +public class GetDatafeedStatsActionRequestTests extends AbstractStreamableTestCase { @Override protected Request createTestInstance() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionResponseTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java similarity index 93% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionResponseTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java index 4206374f66e..7711f45c086 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsStatsActionResponseTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase; import java.util.ArrayList; import java.util.List; -public class GetDatafeedsStatsActionResponseTests extends AbstractStreamableTestCase { +public class GetDatafeedStatsActionResponseTests extends AbstractStreamableTestCase { @Override protected Response createTestInstance() { diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds_stats.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeed_stats.json similarity index 71% rename from elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds_stats.json rename to elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeed_stats.json index f3d89a86ec2..2bb23b7eabe 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds_stats.json +++ b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeed_stats.json @@ -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" } } diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds.json index 0335b25d6c8..6773f984385 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds.json +++ b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_datafeeds.json @@ -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" } } diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/datafeeds_crud.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/datafeeds_crud.yaml index 11ecf3990de..6cc6ad059a9 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/datafeeds_crud.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/datafeeds_crud.yaml @@ -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: [] } diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds_stats.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml similarity index 79% rename from elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds_stats.yaml rename to elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml index 29b7e46f930..c053a1a8829 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds_stats.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml @@ -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"} diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds.yaml index 85a9f92de21..30feb209caf 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeeds.yaml @@ -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"} diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml index a1b1127ed21..dbc868cb956 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml @@ -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 } ---