Skip to content

Remove DeprecationLogger from route objects #52278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public TestDeprecationHeaderRestAction(Settings settings) {
@Override
public List<DeprecatedRoute> deprecatedRoutes() {
return singletonList(
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT, deprecationLogger));
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
}

@Override
Expand Down
17 changes: 7 additions & 10 deletions server/src/main/java/org/elasticsearch/rest/RestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
public class RestController implements HttpServerTransport.Dispatcher {

private static final Logger logger = LogManager.getLogger(RestController.class);
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, ship it.


private final PathTrie<MethodHandlers> handlers = new PathTrie<>(RestUtils.REST_DECODER);

Expand Down Expand Up @@ -94,13 +95,11 @@ public RestController(Set<RestHeaderDefinition> headersToCopy, UnaryOperator<Res
* @param path Path to handle (e.g., "/{index}/{type}/_bulk")
* @param handler The handler to actually execute
* @param deprecationMessage The message to log and send as a header in the response
* @param logger The existing deprecation logger to use
*/
protected void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler,
String deprecationMessage, DeprecationLogger logger) {
protected void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, String deprecationMessage) {
assert (handler instanceof DeprecationRestHandler) == false;

registerHandler(method, path, new DeprecationRestHandler(handler, deprecationMessage, logger));
registerHandler(method, path, new DeprecationRestHandler(handler, deprecationMessage, deprecationLogger));
}

/**
Expand All @@ -126,17 +125,15 @@ protected void registerAsDeprecatedHandler(RestRequest.Method method, String pat
* @param handler The handler to actually execute
* @param deprecatedMethod GET, POST, etc.
* @param deprecatedPath <em>Deprecated</em> path to handle (e.g., "/_optimize")
* @param logger The existing deprecation logger to use
*/
protected void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler,
RestRequest.Method deprecatedMethod, String deprecatedPath,
DeprecationLogger logger) {
RestRequest.Method deprecatedMethod, String deprecatedPath) {
// e.g., [POST /_optimize] is deprecated! Use [POST /_forcemerge] instead.
final String deprecationMessage =
"[" + deprecatedMethod.name() + " " + deprecatedPath + "] is deprecated! Use [" + method.name() + " " + path + "] instead.";

registerHandler(method, path, handler);
registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage, logger);
registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage);
}

/**
Expand All @@ -162,9 +159,9 @@ protected void registerHandler(RestRequest.Method method, String path, RestHandl
public void registerHandler(final RestHandler restHandler) {
restHandler.routes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler));
restHandler.deprecatedRoutes().forEach(route ->
registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage(), route.getLogger()));
registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage()));
restHandler.replacedRoutes().forEach(route -> registerWithDeprecatedHandler(route.getMethod(), route.getPath(),
restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath(), route.getLogger()));
restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath()));
}

@Override
Expand Down
17 changes: 2 additions & 15 deletions server/src/main/java/org/elasticsearch/rest/RestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.rest;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.rest.RestRequest.Method;

Expand Down Expand Up @@ -115,21 +114,15 @@ public Method getMethod() {
class DeprecatedRoute extends Route {

private final String deprecationMessage;
private final DeprecationLogger logger;

public DeprecatedRoute(Method method, String path, String deprecationMessage, DeprecationLogger logger) {
public DeprecatedRoute(Method method, String path, String deprecationMessage) {
super(method, path);
this.deprecationMessage = deprecationMessage;
this.logger = logger;
}

public String getDeprecationMessage() {
return deprecationMessage;
}

public DeprecationLogger getLogger() {
return logger;
}
}

/**
Expand All @@ -140,13 +133,11 @@ class ReplacedRoute extends Route {

private final String deprecatedPath;
private final Method deprecatedMethod;
private final DeprecationLogger logger;

public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) {
public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath) {
super(method, path);
this.deprecatedMethod = deprecatedMethod;
this.deprecatedPath = deprecatedPath;
this.logger = logger;
}

public String getDeprecatedPath() {
Expand All @@ -156,9 +147,5 @@ public String getDeprecatedPath() {
public Method getDeprecatedMethod() {
return deprecatedMethod;
}

public DeprecationLogger getLogger() {
return logger;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class RestUpgradeActionDeprecated extends BaseRestHandler {
@Override
public List<DeprecatedRoute> deprecatedRoutes() {
return unmodifiableList(asList(
new DeprecatedRoute(POST, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger),
new DeprecatedRoute(POST, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger)));
new DeprecatedRoute(POST, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE),
new DeprecatedRoute(POST, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class RestUpgradeStatusActionDeprecated extends BaseRestHandler {
@Override
public List<DeprecatedRoute> deprecatedRoutes() {
return unmodifiableList(asList(
new DeprecatedRoute(GET, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger),
new DeprecatedRoute(GET, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger)));
new DeprecatedRoute(GET, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE),
new DeprecatedRoute(GET, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
Expand Down Expand Up @@ -180,12 +179,11 @@ public void testRegisterAsDeprecatedHandler() {
String path = "/_" + randomAlphaOfLengthBetween(1, 6);
RestHandler handler = mock(RestHandler.class);
String deprecationMessage = randomAlphaOfLengthBetween(1, 10);
DeprecationLogger logger = mock(DeprecationLogger.class);

// don't want to test everything -- just that it actually wraps the handler
doCallRealMethod().when(controller).registerAsDeprecatedHandler(method, path, handler, deprecationMessage, logger);
doCallRealMethod().when(controller).registerAsDeprecatedHandler(method, path, handler, deprecationMessage);

controller.registerAsDeprecatedHandler(method, path, handler, deprecationMessage, logger);
controller.registerAsDeprecatedHandler(method, path, handler, deprecationMessage);

verify(controller).registerHandler(eq(method), eq(path), any(DeprecationRestHandler.class));
}
Expand All @@ -198,18 +196,17 @@ public void testRegisterWithDeprecatedHandler() {
final RestHandler handler = mock(RestHandler.class);
final RestRequest.Method deprecatedMethod = randomFrom(RestRequest.Method.values());
final String deprecatedPath = "/_" + randomAlphaOfLengthBetween(1, 6);
final DeprecationLogger logger = mock(DeprecationLogger.class);

final String deprecationMessage = "[" + deprecatedMethod.name() + " " + deprecatedPath + "] is deprecated! Use [" +
method.name() + " " + path + "] instead.";

// don't want to test everything -- just that it actually wraps the handlers
doCallRealMethod().when(controller).registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath, logger);
doCallRealMethod().when(controller).registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath);

controller.registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath, logger);
controller.registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath);

verify(controller).registerHandler(method, path, handler);
verify(controller).registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage, logger);
verify(controller).registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage);
}

public void testRegisterSecondMethodWithDifferentNamedWildcard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
package org.elasticsearch.xpack.ml.rest;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -22,9 +20,6 @@

public class RestDeleteExpiredDataAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestDeleteExpiredDataAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
// TODO: remove deprecated endpoint in 8.0.0
return Collections.singletonList(
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "_delete_expired_data",
DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data",
deprecationLogger)
DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/
package org.elasticsearch.xpack.ml.rest;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
Expand All @@ -30,9 +28,6 @@ public class RestFindFileStructureAction extends BaseRestHandler {

private static final TimeValue DEFAULT_TIMEOUT = new TimeValue(25, TimeUnit.SECONDS);

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestFindFileStructureAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -43,8 +38,7 @@ public List<ReplacedRoute> replacedRoutes() {
// TODO: remove deprecated endpoint in 8.0.0
return Collections.singletonList(
new ReplacedRoute(POST, MachineLearning.BASE_PATH + "find_file_structure",
POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure",
deprecationLogger)
POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure")
);
}

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -22,9 +20,6 @@

public class RestMlInfoAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestMlInfoAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
// TODO: remove deprecated endpoint in 8.0.0
return Collections.singletonList(
new ReplacedRoute(GET, MachineLearning.BASE_PATH + "info",
GET, MachineLearning.PRE_V7_BASE_PATH + "info",
deprecationLogger)
GET, MachineLearning.PRE_V7_BASE_PATH + "info")
);
}

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -22,9 +20,6 @@

public class RestSetUpgradeModeAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestSetUpgradeModeAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
// TODO: remove deprecated endpoint in 8.0.0
return Collections.singletonList(
new ReplacedRoute(POST, MachineLearning.BASE_PATH + "set_upgrade_mode",
POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode",
deprecationLogger)
POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode")
);
}

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -23,9 +21,6 @@

public class RestDeleteCalendarAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -36,7 +31,7 @@ public List<ReplacedRoute> replacedRoutes() {
// TODO: remove deprecated endpoint in 8.0.0
return Collections.singletonList(
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}",
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger)
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}")
);
}

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -24,9 +22,6 @@

public class RestDeleteCalendarEventAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarEventAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -39,7 +34,7 @@ public List<ReplacedRoute> replacedRoutes() {
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" +
ScheduledEvent.EVENT_ID.getPreferredName() + "}",
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" +
ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger)
ScheduledEvent.EVENT_ID.getPreferredName() + "}")
);
}

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -24,9 +22,6 @@

public class RestDeleteCalendarJobAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarJobAction.class));

@Override
public List<Route> routes() {
return Collections.emptyList();
Expand All @@ -39,7 +34,7 @@ public List<ReplacedRoute> replacedRoutes() {
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" +
Job.ID.getPreferredName() + "}",
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" +
Job.ID.getPreferredName() + "}", deprecationLogger)
Job.ID.getPreferredName() + "}")
);
}

Expand Down
Loading