Skip to content

Commit

Permalink
[ML] Resurrect _xpack/ml routes (#77367)
Browse files Browse the repository at this point in the history
Related to #51816 / #68905.

Adds back the _xpack/ml routes when using rest compatibility for a request.
  • Loading branch information
droberts195 authored Sep 14, 2021
1 parent 201a328 commit 9d9d897
Show file tree
Hide file tree
Showing 92 changed files with 2,599 additions and 73 deletions.
47 changes: 47 additions & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,53 @@ tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
task.replaceKeyInDo("rollup.stop_job", "xpack-rollup.stop_job")
task.addAllowedWarningRegex(".*_xpack/rollup.* is deprecated.*")

task.replaceKeyInDo("ml.close_job", "xpack-ml.close_job")
task.replaceKeyInDo("ml.delete_calendar", "xpack-ml.delete_calendar")
task.replaceKeyInDo("ml.delete_calendar_event", "xpack-ml.delete_calendar_event")
task.replaceKeyInDo("ml.delete_calendar_job", "xpack-ml.delete_calendar_job")
task.replaceKeyInDo("ml.delete_datafeed", "xpack-ml.delete_datafeed")
task.replaceKeyInDo("ml.delete_expired_data", "xpack-ml.delete_expired_data")
task.replaceKeyInDo("ml.delete_filter", "xpack-ml.delete_filter")
task.replaceKeyInDo("ml.delete_forecast", "xpack-ml.delete_forecast")
task.replaceKeyInDo("ml.delete_job", "xpack-ml.delete_job")
task.replaceKeyInDo("ml.delete_model_snapshot", "xpack-ml.delete_model_snapshot")
task.replaceKeyInDo("ml.flush_job", "xpack-ml.flush_job")
task.replaceKeyInDo("ml.forecast", "xpack-ml.forecast")
task.replaceKeyInDo("ml.get_buckets", "xpack-ml.get_buckets")
task.replaceKeyInDo("ml.get_calendar_events", "xpack-ml.get_calendar_events")
task.replaceKeyInDo("ml.get_calendars", "xpack-ml.get_calendars")
task.replaceKeyInDo("ml.get_categories", "xpack-ml.get_categories")
task.replaceKeyInDo("ml.get_datafeed_stats", "xpack-ml.get_datafeed_stats")
task.replaceKeyInDo("ml.get_datafeeds", "xpack-ml.get_datafeeds")
task.replaceKeyInDo("ml.get_filters", "xpack-ml.get_filters")
task.replaceKeyInDo("ml.get_influencers", "xpack-ml.get_influencers")
task.replaceKeyInDo("ml.get_job_stats", "xpack-ml.get_job_stats")
task.replaceKeyInDo("ml.get_jobs", "xpack-ml.get_jobs")
task.replaceKeyInDo("ml.get_model_snapshots", "xpack-ml.get_model_snapshots")
task.replaceKeyInDo("ml.get_overall_buckets", "xpack-ml.get_overall_buckets")
task.replaceKeyInDo("ml.get_records", "xpack-ml.get_records")
task.replaceKeyInDo("ml.info", "xpack-ml.info")
task.replaceKeyInDo("ml.open_job", "xpack-ml.open_job")
task.replaceKeyInDo("ml.post_calendar_events", "xpack-ml.post_calendar_events")
task.replaceKeyInDo("ml.post_data", "xpack-ml.post_data")
task.replaceKeyInDo("ml.preview_datafeed", "xpack-ml.preview_datafeed")
task.replaceKeyInDo("ml.put_calendar", "xpack-ml.put_calendar")
task.replaceKeyInDo("ml.put_calendar_job", "xpack-ml.put_calendar_job")
task.replaceKeyInDo("ml.put_datafeed", "xpack-ml.put_datafeed")
task.replaceKeyInDo("ml.put_filter", "xpack-ml.put_filter")
task.replaceKeyInDo("ml.put_job", "xpack-ml.put_job")
task.replaceKeyInDo("ml.revert_model_snapshot", "xpack-ml.revert_model_snapshot")
task.replaceKeyInDo("ml.set_upgrade_mode", "xpack-ml.set_upgrade_mode")
task.replaceKeyInDo("ml.start_datafeed", "xpack-ml.start_datafeed")
task.replaceKeyInDo("ml.stop_datafeed", "xpack-ml.stop_datafeed")
task.replaceKeyInDo("ml.update_datafeed", "xpack-ml.update_datafeed")
task.replaceKeyInDo("ml.update_filter", "xpack-ml.update_filter")
task.replaceKeyInDo("ml.update_job", "xpack-ml.update_job")
task.replaceKeyInDo("ml.update_model_snapshot", "xpack-ml.update_model_snapshot")
task.replaceKeyInDo("ml.validate", "xpack-ml.validate")
task.replaceKeyInDo("ml.validate_detector", "xpack-ml.validate_detector")
task.addAllowedWarningRegex(".*_xpack/ml.* is deprecated.*")

task.replaceKeyInDo("ssl.certificates", "xpack-ssl.certificates", "Test get SSL certificates")
task.addAllowedWarningRegexForTest(".*_xpack/ssl.* is deprecated.*", "Test get SSL certificates")
task.replaceValueInMatch("_type", "_doc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ public class MachineLearning extends Plugin implements SystemIndexPlugin,
ShutdownAwarePlugin {
public static final String NAME = "ml";
public static final String BASE_PATH = "/_ml/";
// Endpoints that were deprecated in 7.x can still be called in 8.x using the REST compatibility layer
public static final String PRE_V7_BASE_PATH = "/_xpack/ml/";
public static final String DATAFEED_THREAD_POOL_NAME = NAME + "_datafeed";
public static final String JOB_COMMS_THREAD_POOL_NAME = NAME + "_job_comms";
public static final String UTILITY_THREAD_POOL_NAME = NAME + "_utility";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -18,14 +19,17 @@

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestDeleteExpiredDataAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(DELETE, BASE_PATH + "_delete_expired_data/{" + Job.ID + "}"),
new Route(DELETE, BASE_PATH + "_delete_expired_data")
Route.builder(DELETE, BASE_PATH + "_delete_expired_data/{" + Job.ID + "}")
.replaces(DELETE, PRE_V7_BASE_PATH + "_delete_expired_data/{" + Job.ID + "}", RestApiVersion.V_7).build(),
Route.builder(DELETE, BASE_PATH + "_delete_expired_data")
.replaces(DELETE, PRE_V7_BASE_PATH + "_delete_expired_data", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -17,13 +18,15 @@

import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestMlInfoAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(GET, BASE_PATH + "info")
Route.builder(GET, BASE_PATH + "info")
.replaces(GET, PRE_V7_BASE_PATH + "info", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -17,13 +18,15 @@

import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestSetUpgradeModeAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(POST, BASE_PATH + "set_upgrade_mode")
Route.builder(POST, BASE_PATH + "set_upgrade_mode")
.replaces(POST, PRE_V7_BASE_PATH + "set_upgrade_mode", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest.calendar;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -18,12 +19,16 @@

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestDeleteCalendarAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(new Route(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}"));
return List.of(
Route.builder(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}")
.replaces(DELETE, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}", RestApiVersion.V_7).build()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest.calendar;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -19,14 +20,17 @@

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestDeleteCalendarEventAction extends BaseRestHandler {


@Override
public List<Route> routes() {
return List.of(
new Route(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}/events/{" + ScheduledEvent.EVENT_ID + "}")
Route.builder(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}/events/{" + ScheduledEvent.EVENT_ID + "}")
.replaces(DELETE, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}/events/{" + ScheduledEvent.EVENT_ID + "}",
RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest.calendar;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -19,13 +20,15 @@

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestDeleteCalendarJobAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}")
Route.builder(DELETE, BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}")
.replaces(DELETE, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -21,13 +22,15 @@

import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestGetCalendarEventsAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(GET, BASE_PATH + "calendars/{" + Calendar.ID + "}/events")
Route.builder(GET, BASE_PATH + "calendars/{" + Calendar.ID + "}/events")
.replaces(GET, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}/events", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
Expand All @@ -22,16 +23,21 @@
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestGetCalendarsAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(GET, BASE_PATH + "calendars/{" + Calendar.ID + "}"),
new Route(GET, BASE_PATH + "calendars/"),
new Route(POST, BASE_PATH + "calendars/{" + Calendar.ID + "}"),
new Route(POST, BASE_PATH + "calendars/")
Route.builder(GET, BASE_PATH + "calendars/{" + Calendar.ID + "}")
.replaces(GET, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}", RestApiVersion.V_7).build(),
Route.builder(GET, BASE_PATH + "calendars/")
.replaces(GET, PRE_V7_BASE_PATH + "calendars/", RestApiVersion.V_7).build(),
Route.builder(POST, BASE_PATH + "calendars/{" + Calendar.ID + "}")
.replaces(POST, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}", RestApiVersion.V_7).build(),
Route.builder(POST, BASE_PATH + "calendars/")
.replaces(POST, PRE_V7_BASE_PATH + "calendars/", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -19,12 +20,16 @@

import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestPostCalendarEventAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(new Route(POST, BASE_PATH + "calendars/{" + Calendar.ID + "}/events"));
return List.of(
Route.builder(POST, BASE_PATH + "calendars/{" + Calendar.ID + "}/events")
.replaces(POST, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}/events", RestApiVersion.V_7).build()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -20,12 +21,16 @@

import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestPutCalendarAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(new Route(PUT, BASE_PATH + "calendars/{" + Calendar.ID + "}"));
return List.of(
Route.builder(PUT, BASE_PATH + "calendars/{" + Calendar.ID + "}")
.replaces(PUT, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}", RestApiVersion.V_7).build()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest.calendar;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -19,13 +20,15 @@

import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestPutCalendarJobAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(PUT, BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}")
Route.builder(PUT, BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}")
.replaces(PUT, PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID + "}/jobs/{" + Job.ID + "}", RestApiVersion.V_7).build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.ml.rest.datafeeds;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -19,13 +20,15 @@

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestDeleteDatafeedAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(DELETE, BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}")
Route.builder(DELETE, BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}")
.replaces(DELETE, PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}", RestApiVersion.V_7).build()
);
}

Expand Down
Loading

0 comments on commit 9d9d897

Please sign in to comment.