Skip to content

Commit

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

Adds back the _xpack/ml routes when using rest compatibility for a request.
  • Loading branch information
droberts195 committed Sep 7, 2021
1 parent ac86642 commit 1f01d46
Show file tree
Hide file tree
Showing 46 changed files with 254 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,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
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.LoggingDeprecationHandler;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -21,14 +22,17 @@

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 RestGetDatafeedStatsAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return List.of(
new Route(GET, BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}/_stats"),
new Route(GET, BASE_PATH + "datafeeds/_stats")
Route.builder(GET, BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}/_stats")
.replaces(GET, PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID + "}/_stats", RestApiVersion.V_7).build(),
Route.builder(GET, BASE_PATH + "datafeeds/_stats")
.replaces(GET, PRE_V7_BASE_PATH + "datafeeds/_stats", 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.LoggingDeprecationHandler;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -23,14 +24,17 @@
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.xpack.core.ml.utils.ToXContentParams.EXCLUDE_GENERATED;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
import static org.elasticsearch.xpack.ml.MachineLearning.PRE_V7_BASE_PATH;

public class RestGetDatafeedsAction extends BaseRestHandler {

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

Expand Down
Loading

0 comments on commit 1f01d46

Please sign in to comment.