[Watcher] Log Deprecation Warnings for old API usage

This makes use of the registerAsDeprecatedHandler method to automatically warn users when they're using deprecated functionality.

This will also automatically provide a Warning header for anyone using HTTP clients (though they have to be looking for it...).

- This also changes from PUT _start, _restart, _stop (Watcher endpoints) to POST _start, _restart, _stop
    - The deprecated variant still honors PUT
- Nothing about the hijack endpoints was deprecated because they did not change from 2.x

Watcher portion only

Original commit: elastic/x-pack-elasticsearch@36f87a6526
This commit is contained in:
Chris Earle 2016-07-07 13:29:59 -04:00
parent 63add2c959
commit 641caabdae
12 changed files with 103 additions and 49 deletions

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -23,6 +22,9 @@ import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchRequest;
import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchResponse;
import org.elasticsearch.xpack.watcher.watch.Watch;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
/**
* The rest action to ack a watch
*/
@ -31,13 +33,26 @@ public class RestAckWatchAction extends WatcherRestHandler {
@Inject
public RestAckWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/_ack", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/_ack", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/_ack/{actions}", this);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/_ack/{actions}", this);
// these are going to be removed in 6.0
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/{actions}/_ack", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/{actions}/_ack", this);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_ack", this,
POST, "/_watcher/watch/{id}/_ack", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}/_ack", this,
PUT, "/_watcher/watch/{id}/_ack", deprecationLogger);
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_ack/{actions}", this,
POST, "/_watcher/watch/{id}/{actions}/_ack", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}/_ack/{actions}", this,
PUT, "/_watcher/watch/{id}/{actions}/_ack", deprecationLogger);
// @deprecated The following can be totally dropped in 6.0
// Note: we deprecated "/{actions}/_ack" totally; so we don't replace it with a matching _xpack variant
controller.registerAsDeprecatedHandler(POST, "/_watcher/watch/{id}/{actions}/_ack", this,
"[POST /_watcher/watch/{id}/{actions}/_ack] is deprecated! Use " +
"[POST /_xpack/watcher/watch/{id}/_ack/{actions}] instead.",
deprecationLogger);
controller.registerAsDeprecatedHandler(PUT, "/_watcher/watch/{id}/{actions}/_ack", this,
"[PUT /_watcher/watch/{id}/{actions}/_ack] is deprecated! Use " +
"[PUT /_xpack/watcher/watch/{id}/_ack/{actions}] instead.",
deprecationLogger);
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -23,6 +22,9 @@ import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchR
import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchResponse;
import org.elasticsearch.xpack.watcher.watch.Watch;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
/**
* The rest action to de/activate a watch
*/
@ -31,11 +33,18 @@ public class RestActivateWatchAction extends WatcherRestHandler {
@Inject
public RestActivateWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/_activate", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/_activate", this);
DeactivateRestHandler deactivateRestHandler = new DeactivateRestHandler(settings);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/_deactivate", deactivateRestHandler);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/_deactivate", deactivateRestHandler);
final DeactivateRestHandler deactivateRestHandler = new DeactivateRestHandler(settings);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_activate", this,
POST, "/_watcher/watch/{id}/_activate", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}/_activate", this,
PUT, "/_watcher/watch/{id}/_activate", deprecationLogger);
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_deactivate", deactivateRestHandler,
POST, "/_watcher/watch/{id}/_deactivate", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}/_deactivate", deactivateRestHandler,
PUT, "/_watcher/watch/{id}/_deactivate", deprecationLogger);
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -32,7 +31,9 @@ public class RestDeleteWatchAction extends WatcherRestHandler {
@Inject
public RestDeleteWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, URI_BASE + "/watch/{id}", this);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(DELETE, URI_BASE + "/watch/{id}", this,
DELETE, "/_watcher/watch/{id}", deprecationLogger);
}
@Override

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.inject.Inject;
@ -32,6 +31,8 @@ import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.IGNORE_CONDITION;
import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.RECORD_EXECUTION;
@ -44,11 +45,17 @@ public class RestExecuteWatchAction extends WatcherRestHandler {
@Inject
public RestExecuteWatchAction(Settings settings, RestController controller, TriggerService triggerService) {
super(settings);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{id}/_execute", this);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{id}/_execute", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/_execute", this);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/_execute", this);
this.triggerService = triggerService;
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_execute", this,
POST, "/_watcher/watch/{id}/_execute", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}/_execute", this,
PUT, "/_watcher/watch/{id}/_execute", deprecationLogger);
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/_execute", this,
POST, "/_watcher/watch/_execute", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/_execute", this,
PUT, "/_watcher/watch/_execute", deprecationLogger);
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -32,7 +31,10 @@ public class RestGetWatchAction extends WatcherRestHandler {
@Inject
public RestGetWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/watch/{id}", this);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(GET, URI_BASE + "/watch/{id}", this,
GET, "/_watcher/watch/{id}", deprecationLogger);
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -19,29 +18,34 @@ import org.elasticsearch.xpack.watcher.client.WatcherClient;
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
import org.elasticsearch.xpack.watcher.watch.WatchStore;
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
/**
*/
public class RestHijackOperationAction extends WatcherRestHandler {
private static String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access";
private static final String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access";
@Inject
public RestHijackOperationAction(Settings settings, RestController controller) {
super(settings);
if (!settings.getAsBoolean(ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING, false)) {
WatcherRestHandler unsupportedHandler = new UnsupportedHandler(settings);
controller.registerHandler(RestRequest.Method.POST, WatchStore.INDEX + "/watch", this);
controller.registerHandler(RestRequest.Method.POST, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(RestRequest.Method.POST, WatchStore.INDEX + "/watch/{id}/_update", this);
controller.registerHandler(RestRequest.Method.DELETE, WatchStore.INDEX + "/watch/_query", this);
controller.registerHandler(RestRequest.Method.DELETE, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(RestRequest.Method.GET, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(RestRequest.Method.POST, WatchStore.INDEX + "/watch/_bulk", unsupportedHandler);
controller.registerHandler(RestRequest.Method.POST, WatchStore.INDEX + "/_bulk", unsupportedHandler);
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/watch/_bulk", unsupportedHandler);
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_bulk", unsupportedHandler);
controller.registerHandler(RestRequest.Method.DELETE, WatchStore.INDEX, unsupportedHandler);
controller.registerHandler(POST, WatchStore.INDEX + "/watch", this);
controller.registerHandler(POST, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(PUT, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(POST, WatchStore.INDEX + "/watch/{id}/_update", this);
controller.registerHandler(DELETE, WatchStore.INDEX + "/watch/_query", this);
controller.registerHandler(DELETE, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(GET, WatchStore.INDEX + "/watch/{id}", this);
controller.registerHandler(POST, WatchStore.INDEX + "/watch/_bulk", unsupportedHandler);
controller.registerHandler(POST, WatchStore.INDEX + "/_bulk", unsupportedHandler);
controller.registerHandler(PUT, WatchStore.INDEX + "/watch/_bulk", unsupportedHandler);
controller.registerHandler(PUT, WatchStore.INDEX + "/_bulk", unsupportedHandler);
controller.registerHandler(DELETE, WatchStore.INDEX, unsupportedHandler);
}
}
@ -73,4 +77,5 @@ public class RestHijackOperationAction extends WatcherRestHandler {
channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, jsonBuilder));
}
}
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -33,8 +32,12 @@ public class RestPutWatchAction extends WatcherRestHandler {
@Inject
public RestPutWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, URI_BASE + "/watch/{id}", this);
controller.registerHandler(PUT, URI_BASE + "/watch/{id}", this);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}", this,
POST, "/_watcher/watch/{id}", deprecationLogger);
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/watch/{id}", this,
PUT, "/_watcher/watch/{id}", deprecationLogger);
}
@Override

View File

@ -15,6 +15,9 @@ import org.elasticsearch.xpack.watcher.client.WatcherClient;
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
import org.elasticsearch.xpack.watcher.transport.actions.service.WatcherServiceRequest;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
/**
*/
public class RestWatchServiceAction extends WatcherRestHandler {
@ -22,9 +25,15 @@ public class RestWatchServiceAction extends WatcherRestHandler {
@Inject
public RestWatchServiceAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_restart", this);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_start", new StartRestHandler(settings));
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_stop", new StopRestHandler(settings));
// @deprecated Remove in 6.0
// NOTE: we switched from PUT in 2.x to POST in 5.x
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/_restart", this,
PUT, "/_watcher/_restart", deprecationLogger);
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/_start", new StartRestHandler(settings),
PUT, "/_watcher/_start", deprecationLogger);
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/_stop", new StopRestHandler(settings),
PUT, "/_watcher/_stop", deprecationLogger);
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -31,8 +30,12 @@ public class RestWatcherStatsAction extends WatcherRestHandler {
@Inject
public RestWatcherStatsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/stats", this);
controller.registerHandler(GET, URI_BASE + "/stats/{metric}", this);
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(GET, URI_BASE + "/stats", this,
GET, "/_watcher/stats", deprecationLogger);
controller.registerWithDeprecatedHandler(GET, URI_BASE + "/stats/{metric}", this,
GET, "/_watcher/stats/{metric}", deprecationLogger);
}
@Override

View File

@ -1,7 +1,7 @@
{
"xpack.watcher.restart": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"methods": [ "POST" ],
"url": {
"path": "/_xpack/watcher/_restart",
"paths": [ "/_xpack/watcher/_restart" ],

View File

@ -1,7 +1,7 @@
{
"xpack.watcher.start": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"methods": [ "POST" ],
"url": {
"path": "/_xpack/watcher/_start",
"paths": [ "/_xpack/watcher/_start" ],

View File

@ -1,7 +1,7 @@
{
"xpack.watcher.stop": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"methods": [ "POST" ],
"url": {
"path": "/_xpack/watcher/_stop",
"paths": [ "/_xpack/watcher/_stop" ],