Skip to content

Commit b9e2d16

Browse files
authored
Remove DeprecationLogger from route objects (#52278)
This commit removes the need for DeprecatedRoute and ReplacedRoute to have an instance of a DeprecationLogger. Instead the RestController now has a DeprecationLogger that will be used for all deprecated and replaced route messages. Relates #51950
1 parent b38c04f commit b9e2d16

File tree

85 files changed

+138
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+138
-524
lines changed

qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public TestDeprecationHeaderRestAction(Settings settings) {
7676
@Override
7777
public List<DeprecatedRoute> deprecatedRoutes() {
7878
return singletonList(
79-
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT, deprecationLogger));
79+
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
8080
}
8181

8282
@Override

server/src/main/java/org/elasticsearch/rest/RestController.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
public class RestController implements HttpServerTransport.Dispatcher {
6363

6464
private static final Logger logger = LogManager.getLogger(RestController.class);
65+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
6566

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

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

103-
registerHandler(method, path, new DeprecationRestHandler(handler, deprecationMessage, logger));
102+
registerHandler(method, path, new DeprecationRestHandler(handler, deprecationMessage, deprecationLogger));
104103
}
105104

106105
/**
@@ -126,17 +125,15 @@ protected void registerAsDeprecatedHandler(RestRequest.Method method, String pat
126125
* @param handler The handler to actually execute
127126
* @param deprecatedMethod GET, POST, etc.
128127
* @param deprecatedPath <em>Deprecated</em> path to handle (e.g., "/_optimize")
129-
* @param logger The existing deprecation logger to use
130128
*/
131129
protected void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler,
132-
RestRequest.Method deprecatedMethod, String deprecatedPath,
133-
DeprecationLogger logger) {
130+
RestRequest.Method deprecatedMethod, String deprecatedPath) {
134131
// e.g., [POST /_optimize] is deprecated! Use [POST /_forcemerge] instead.
135132
final String deprecationMessage =
136133
"[" + deprecatedMethod.name() + " " + deprecatedPath + "] is deprecated! Use [" + method.name() + " " + path + "] instead.";
137134

138135
registerHandler(method, path, handler);
139-
registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage, logger);
136+
registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage);
140137
}
141138

142139
/**
@@ -162,9 +159,9 @@ protected void registerHandler(RestRequest.Method method, String path, RestHandl
162159
public void registerHandler(final RestHandler restHandler) {
163160
restHandler.routes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler));
164161
restHandler.deprecatedRoutes().forEach(route ->
165-
registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage(), route.getLogger()));
162+
registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage()));
166163
restHandler.replacedRoutes().forEach(route -> registerWithDeprecatedHandler(route.getMethod(), route.getPath(),
167-
restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath(), route.getLogger()));
164+
restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath()));
168165
}
169166

170167
@Override

server/src/main/java/org/elasticsearch/rest/RestHandler.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.rest;
2121

2222
import org.elasticsearch.client.node.NodeClient;
23-
import org.elasticsearch.common.logging.DeprecationLogger;
2423
import org.elasticsearch.common.xcontent.XContent;
2524
import org.elasticsearch.rest.RestRequest.Method;
2625

@@ -115,21 +114,15 @@ public Method getMethod() {
115114
class DeprecatedRoute extends Route {
116115

117116
private final String deprecationMessage;
118-
private final DeprecationLogger logger;
119117

120-
public DeprecatedRoute(Method method, String path, String deprecationMessage, DeprecationLogger logger) {
118+
public DeprecatedRoute(Method method, String path, String deprecationMessage) {
121119
super(method, path);
122120
this.deprecationMessage = deprecationMessage;
123-
this.logger = logger;
124121
}
125122

126123
public String getDeprecationMessage() {
127124
return deprecationMessage;
128125
}
129-
130-
public DeprecationLogger getLogger() {
131-
return logger;
132-
}
133126
}
134127

135128
/**
@@ -140,13 +133,11 @@ class ReplacedRoute extends Route {
140133

141134
private final String deprecatedPath;
142135
private final Method deprecatedMethod;
143-
private final DeprecationLogger logger;
144136

145-
public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) {
137+
public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath) {
146138
super(method, path);
147139
this.deprecatedMethod = deprecatedMethod;
148140
this.deprecatedPath = deprecatedPath;
149-
this.logger = logger;
150141
}
151142

152143
public String getDeprecatedPath() {
@@ -156,9 +147,5 @@ public String getDeprecatedPath() {
156147
public Method getDeprecatedMethod() {
157148
return deprecatedMethod;
158149
}
159-
160-
public DeprecationLogger getLogger() {
161-
return logger;
162-
}
163150
}
164151
}

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public class RestUpgradeActionDeprecated extends BaseRestHandler {
4848
@Override
4949
public List<DeprecatedRoute> deprecatedRoutes() {
5050
return unmodifiableList(asList(
51-
new DeprecatedRoute(POST, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger),
52-
new DeprecatedRoute(POST, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger)));
51+
new DeprecatedRoute(POST, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE),
52+
new DeprecatedRoute(POST, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE)));
5353
}
5454

5555
@Override

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusActionDeprecated.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public class RestUpgradeStatusActionDeprecated extends BaseRestHandler {
4646
@Override
4747
public List<DeprecatedRoute> deprecatedRoutes() {
4848
return unmodifiableList(asList(
49-
new DeprecatedRoute(GET, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger),
50-
new DeprecatedRoute(GET, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger)));
49+
new DeprecatedRoute(GET, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE),
50+
new DeprecatedRoute(GET, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE)));
5151
}
5252

5353
@Override

server/src/test/java/org/elasticsearch/rest/RestControllerTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.common.bytes.BytesArray;
2525
import org.elasticsearch.common.bytes.BytesReference;
2626
import org.elasticsearch.common.component.AbstractLifecycleComponent;
27-
import org.elasticsearch.common.logging.DeprecationLogger;
2827
import org.elasticsearch.common.settings.ClusterSettings;
2928
import org.elasticsearch.common.settings.Settings;
3029
import org.elasticsearch.common.transport.BoundTransportAddress;
@@ -180,12 +179,11 @@ public void testRegisterAsDeprecatedHandler() {
180179
String path = "/_" + randomAlphaOfLengthBetween(1, 6);
181180
RestHandler handler = mock(RestHandler.class);
182181
String deprecationMessage = randomAlphaOfLengthBetween(1, 10);
183-
DeprecationLogger logger = mock(DeprecationLogger.class);
184182

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

188-
controller.registerAsDeprecatedHandler(method, path, handler, deprecationMessage, logger);
186+
controller.registerAsDeprecatedHandler(method, path, handler, deprecationMessage);
189187

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

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

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

209-
controller.registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath, logger);
206+
controller.registerWithDeprecatedHandler(method, path, handler, deprecatedMethod, deprecatedPath);
210207

211208
verify(controller).registerHandler(method, path, handler);
212-
verify(controller).registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage, logger);
209+
verify(controller).registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage);
213210
}
214211

215212
public void testRegisterSecondMethodWithDifferentNamedWildcard() {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -22,9 +20,6 @@
2220

2321
public class RestDeleteExpiredDataAction extends BaseRestHandler {
2422

25-
private static final DeprecationLogger deprecationLogger =
26-
new DeprecationLogger(LogManager.getLogger(RestDeleteExpiredDataAction.class));
27-
2823
@Override
2924
public List<Route> routes() {
3025
return Collections.emptyList();
@@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
3530
// TODO: remove deprecated endpoint in 8.0.0
3631
return Collections.singletonList(
3732
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "_delete_expired_data",
38-
DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data",
39-
deprecationLogger)
33+
DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data")
4034
);
4135
}
4236

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.ElasticsearchParseException;
109
import org.elasticsearch.client.node.NodeClient;
11-
import org.elasticsearch.common.logging.DeprecationLogger;
1210
import org.elasticsearch.common.unit.TimeValue;
1311
import org.elasticsearch.rest.BaseRestHandler;
1412
import org.elasticsearch.rest.RestRequest;
@@ -30,9 +28,6 @@ public class RestFindFileStructureAction extends BaseRestHandler {
3028

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

33-
private static final DeprecationLogger deprecationLogger =
34-
new DeprecationLogger(LogManager.getLogger(RestFindFileStructureAction.class));
35-
3631
@Override
3732
public List<Route> routes() {
3833
return Collections.emptyList();
@@ -43,8 +38,7 @@ public List<ReplacedRoute> replacedRoutes() {
4338
// TODO: remove deprecated endpoint in 8.0.0
4439
return Collections.singletonList(
4540
new ReplacedRoute(POST, MachineLearning.BASE_PATH + "find_file_structure",
46-
POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure",
47-
deprecationLogger)
41+
POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure")
4842
);
4943
}
5044

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -22,9 +20,6 @@
2220

2321
public class RestMlInfoAction extends BaseRestHandler {
2422

25-
private static final DeprecationLogger deprecationLogger =
26-
new DeprecationLogger(LogManager.getLogger(RestMlInfoAction.class));
27-
2823
@Override
2924
public List<Route> routes() {
3025
return Collections.emptyList();
@@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
3530
// TODO: remove deprecated endpoint in 8.0.0
3631
return Collections.singletonList(
3732
new ReplacedRoute(GET, MachineLearning.BASE_PATH + "info",
38-
GET, MachineLearning.PRE_V7_BASE_PATH + "info",
39-
deprecationLogger)
33+
GET, MachineLearning.PRE_V7_BASE_PATH + "info")
4034
);
4135
}
4236

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -22,9 +20,6 @@
2220

2321
public class RestSetUpgradeModeAction extends BaseRestHandler {
2422

25-
private static final DeprecationLogger deprecationLogger =
26-
new DeprecationLogger(LogManager.getLogger(RestSetUpgradeModeAction.class));
27-
2823
@Override
2924
public List<Route> routes() {
3025
return Collections.emptyList();
@@ -35,8 +30,7 @@ public List<ReplacedRoute> replacedRoutes() {
3530
// TODO: remove deprecated endpoint in 8.0.0
3631
return Collections.singletonList(
3732
new ReplacedRoute(POST, MachineLearning.BASE_PATH + "set_upgrade_mode",
38-
POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode",
39-
deprecationLogger)
33+
POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode")
4034
);
4135
}
4236

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest.calendar;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -23,9 +21,6 @@
2321

2422
public class RestDeleteCalendarAction extends BaseRestHandler {
2523

26-
private static final DeprecationLogger deprecationLogger =
27-
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarAction.class));
28-
2924
@Override
3025
public List<Route> routes() {
3126
return Collections.emptyList();
@@ -36,7 +31,7 @@ public List<ReplacedRoute> replacedRoutes() {
3631
// TODO: remove deprecated endpoint in 8.0.0
3732
return Collections.singletonList(
3833
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}",
39-
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger)
34+
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}")
4035
);
4136
}
4237

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest.calendar;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -24,9 +22,6 @@
2422

2523
public class RestDeleteCalendarEventAction extends BaseRestHandler {
2624

27-
private static final DeprecationLogger deprecationLogger =
28-
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarEventAction.class));
29-
3025
@Override
3126
public List<Route> routes() {
3227
return Collections.emptyList();
@@ -39,7 +34,7 @@ public List<ReplacedRoute> replacedRoutes() {
3934
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" +
4035
ScheduledEvent.EVENT_ID.getPreferredName() + "}",
4136
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" +
42-
ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger)
37+
ScheduledEvent.EVENT_ID.getPreferredName() + "}")
4338
);
4439
}
4540

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.rest.calendar;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.client.node.NodeClient;
10-
import org.elasticsearch.common.logging.DeprecationLogger;
119
import org.elasticsearch.rest.BaseRestHandler;
1210
import org.elasticsearch.rest.RestRequest;
1311
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -24,9 +22,6 @@
2422

2523
public class RestDeleteCalendarJobAction extends BaseRestHandler {
2624

27-
private static final DeprecationLogger deprecationLogger =
28-
new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarJobAction.class));
29-
3025
@Override
3126
public List<Route> routes() {
3227
return Collections.emptyList();
@@ -39,7 +34,7 @@ public List<ReplacedRoute> replacedRoutes() {
3934
new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" +
4035
Job.ID.getPreferredName() + "}",
4136
DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" +
42-
Job.ID.getPreferredName() + "}", deprecationLogger)
37+
Job.ID.getPreferredName() + "}")
4338
);
4439
}
4540

0 commit comments

Comments
 (0)