Simplify rest handler constructors

This is the xplugins side of moving the client dependency for rest
handlers to the handleRequest method

Original commit: elastic/x-pack-elasticsearch@ce66e35e7b
This commit is contained in:
Ryan Ernst 2016-06-29 16:30:55 -07:00
parent b06249279e
commit 7822f28d7b
33 changed files with 147 additions and 147 deletions

View File

@ -16,7 +16,7 @@ import java.util.Map;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
@ -66,8 +66,8 @@ public class RestGraphAction extends BaseRestHandler {
public static final ParseField TERM_FIELD = new ParseField("term");
@Inject
public RestGraphAction(Settings settings, RestController controller, Client client, IndicesQueriesRegistry indicesQueriesRegistry) {
super(settings, client);
public RestGraphAction(Settings settings, RestController controller, IndicesQueriesRegistry indicesQueriesRegistry) {
super(settings);
// @deprecated TODO need to add deprecation support as per https://github.com/elastic/x-plugins/issues/1760#issuecomment-217507517
controller.registerHandler(GET, "/{index}/_graph/explore", this);
controller.registerHandler(POST, "/{index}/_graph/explore", this);
@ -82,7 +82,7 @@ public class RestGraphAction extends BaseRestHandler {
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws IOException {
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) throws IOException {
GraphExploreRequest graphRequest = new GraphExploreRequest(Strings.splitStringByCommaToArray(request.param("index")));
graphRequest.indicesOptions(IndicesOptions.fromRequest(request, graphRequest.indicesOptions()));
graphRequest.routing(request.param("routing"));

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.license.plugin.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
@ -21,13 +21,13 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE;
public class RestDeleteLicenseAction extends BaseRestHandler {
@Inject
public RestDeleteLicenseAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestDeleteLicenseAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, "/_xpack/license", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest(), new AcknowledgedRestListener<>(channel));
}
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.license.plugin.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
@ -32,8 +32,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestGetLicenseAction extends BaseRestHandler {
@Inject
public RestGetLicenseAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestGetLicenseAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_xpack/license", this);
}
@ -44,7 +44,7 @@ public class RestGetLicenseAction extends BaseRestHandler {
* The licenses are sorted by latest issue_date
*/
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
final Map<String, String> overrideParams = new HashMap<>(2);
overrideParams.put(License.REST_VIEW_MODE, "true");
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.license.plugin.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
@ -28,14 +28,14 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
public class RestPutLicenseAction extends BaseRestHandler {
@Inject
public RestPutLicenseAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestPutLicenseAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(PUT, "/_xpack/license", this);
controller.registerHandler(POST, "/_xpack/license", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
putLicenseRequest.license(request.content().toUtf8());
putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false));

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.monitoring.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.rest.XPackRestHandler;
@ -13,7 +12,7 @@ public abstract class MonitoringRestHandler extends XPackRestHandler {
protected static String URI_BASE = XPackRestHandler.URI_BASE + "/monitoring";
public MonitoringRestHandler(Settings settings, Client client) {
super(settings, client);
public MonitoringRestHandler(Settings settings) {
super(settings);
}
}

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.monitoring.rest.action;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -32,8 +32,8 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
public static final String MONITORING_VERSION = "system_version";
@Inject
public RestMonitoringBulkAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestMonitoringBulkAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, URI_BASE + "/_bulk", this);
controller.registerHandler(PUT, URI_BASE + "/_bulk", this);
controller.registerHandler(POST, URI_BASE + "/{type}/_bulk", this);
@ -41,7 +41,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, XPackClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, XPackClient client) throws Exception {
String defaultType = request.param("type");
String id = request.param(MONITORING_ID);

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
@ -56,7 +57,7 @@ public class SecurityRestFilter extends RestFilter {
}
@Override
public void process(RestRequest request, RestChannel channel, RestFilterChain filterChain) throws Exception {
public void process(RestRequest request, RestChannel channel, NodeClient client, RestFilterChain filterChain) throws Exception {
if (licenseState.authenticationAndAuthorizationEnabled()) {
// CORS - allow for preflight unauthenticated OPTIONS request
@ -70,7 +71,7 @@ public class SecurityRestFilter extends RestFilter {
RemoteHostHeader.process(request, threadContext);
}
filterChain.continueProcessing(request, channel);
filterChain.continueProcessing(request, channel, client);
}
static void putClientCertificateInContext(RestRequest request, ThreadContext threadContext, ESLogger logger) throws Exception {

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
@ -31,14 +31,14 @@ public class RestAuthenticateAction extends BaseRestHandler {
private final SecurityContext securityContext;
@Inject
public RestAuthenticateAction(Settings settings, RestController controller, Client client, SecurityContext securityContext) {
super(settings, client);
public RestAuthenticateAction(Settings settings, RestController controller, SecurityContext securityContext) {
super(settings);
this.securityContext = securityContext;
controller.registerHandler(GET, "/_xpack/security/_authenticate", this);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
final User user = securityContext.getUser();
assert user != null;
final String username = user.runAs() == null ? user.principal() : user.runAs().principal();

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.realm;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
@ -21,14 +21,14 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestClearRealmCacheAction extends BaseRestHandler {
@Inject
public RestClearRealmCacheAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestClearRealmCacheAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_cache/clear", this); // deprecated
controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_clear_cache", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
String[] realms = request.paramAsStringArrayOrEmptyIfAll("realms");
String[] usernames = request.paramAsStringArrayOrEmptyIfAll("usernames");

View File

@ -5,7 +5,8 @@
*/
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
@ -24,13 +25,13 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestClearRolesCacheAction extends BaseRestHandler {
@Inject
public RestClearRolesCacheAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestClearRolesCacheAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/role/{name}/_clear_cache", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
String[] roles = request.paramAsStringArrayOrEmptyIfAll("name");

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,13 +27,13 @@ import org.elasticsearch.xpack.security.client.SecurityClient;
public class RestDeleteRoleAction extends BaseRestHandler {
@Inject
public RestDeleteRoleAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestDeleteRoleAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.DELETE, "/_xpack/security/role/{name}", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
DeleteRoleRequestBuilder requestBuilder = new SecurityClient(client).prepareDeleteRole(request.param("name"));
if (request.hasParam("refresh")) {
requestBuilder.refresh(request.paramAsBoolean("refresh", true));

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -28,14 +28,14 @@ import org.elasticsearch.xpack.security.authz.RoleDescriptor;
public class RestGetRolesAction extends BaseRestHandler {
@Inject
public RestGetRolesAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestGetRolesAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/role/", this);
controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/role/{name}", this);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
final String[] roles = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
new SecurityClient(client).prepareGetRoles(roles).execute(new RestBuilderListener<GetRolesResponse>(channel) {
@Override

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,14 +27,14 @@ import org.elasticsearch.xpack.security.client.SecurityClient;
public class RestPutRoleAction extends BaseRestHandler {
@Inject
public RestPutRoleAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestPutRoleAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/role/{name}", this);
controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/role/{name}", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content());
requestBuilder.setRefreshPolicy(request.param("refresh"));
requestBuilder.execute(new RestBuilderListener<PutRoleResponse>(channel) {

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -29,8 +29,8 @@ public class RestChangePasswordAction extends BaseRestHandler {
private final SecurityContext securityContext;
@Inject
public RestChangePasswordAction(Settings settings, Client client, RestController controller, SecurityContext securityContext) {
super(settings, client);
public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext) {
super(settings);
this.securityContext = securityContext;
controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/user/{username}/_password", this);
controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/user/{username}/_password", this);
@ -39,7 +39,7 @@ public class RestChangePasswordAction extends BaseRestHandler {
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
final User user = securityContext.getUser();
String username = request.param("username");
if (username == null) {

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -28,13 +28,13 @@ import org.elasticsearch.xpack.security.client.SecurityClient;
public class RestDeleteUserAction extends BaseRestHandler {
@Inject
public RestDeleteUserAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestDeleteUserAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.DELETE, "/_xpack/security/user/{username}", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
String username = request.param("username");
DeleteUserRequestBuilder requestBuilder = new SecurityClient(client).prepareDeleteUser(username);

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -29,14 +29,14 @@ import org.elasticsearch.xpack.security.client.SecurityClient;
public class RestGetUsersAction extends BaseRestHandler {
@Inject
public RestGetUsersAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestGetUsersAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/user/", this);
controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/user/{username}", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
String[] usernames = request.paramAsStringArray("username", Strings.EMPTY_ARRAY);
new SecurityClient(client).prepareGetUsers(usernames).execute(new RestBuilderListener<GetUsersResponse>(channel) {

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,14 +27,14 @@ import org.elasticsearch.xpack.security.client.SecurityClient;
public class RestPutUserAction extends BaseRestHandler {
@Inject
public RestPutUserAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestPutUserAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/user/{username}", this);
controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/user/{username}", this);
}
@Override
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content());
if (request.hasParam("refresh")) {
requestBuilder.setRefreshPolicy(request.param("refresh"));

View File

@ -54,16 +54,16 @@ public class SecurityRestFilterTests extends ESTestCase {
RestRequest request = mock(RestRequest.class);
Authentication authentication = mock(Authentication.class);
when(authcService.authenticate(request)).thenReturn(authentication);
filter.process(request, channel, chain);
verify(chain).continueProcessing(request, channel);
filter.process(request, channel, null, chain);
verify(chain).continueProcessing(request, channel, null);
verifyZeroInteractions(channel);
}
public void testProcessBasicLicense() throws Exception {
RestRequest request = mock(RestRequest.class);
when(licenseState.authenticationAndAuthorizationEnabled()).thenReturn(false);
filter.process(request, channel, chain);
verify(chain).continueProcessing(request, channel);
filter.process(request, channel, null, chain);
verify(chain).continueProcessing(request, channel, null);
verifyZeroInteractions(channel, authcService);
}
@ -71,7 +71,7 @@ public class SecurityRestFilterTests extends ESTestCase {
RestRequest request = mock(RestRequest.class);
when(authcService.authenticate(request)).thenThrow(authenticationError("failed authc"));
try {
filter.process(request, channel, chain);
filter.process(request, channel, null, chain);
fail("expected rest filter process to throw an authentication exception when authentication fails");
} catch (ElasticsearchSecurityException e) {
assertThat(e.getMessage(), equalTo("failed authc"));
@ -83,8 +83,8 @@ public class SecurityRestFilterTests extends ESTestCase {
public void testProcessOptionsMethod() throws Exception {
RestRequest request = mock(RestRequest.class);
when(request.method()).thenReturn(RestRequest.Method.OPTIONS);
filter.process(request, channel, chain);
verify(chain).continueProcessing(request, channel);
filter.process(request, channel, null, chain);
verify(chain).continueProcessing(request, channel, null);
verifyZeroInteractions(channel);
verifyZeroInteractions(authcService);
}

View File

@ -5,6 +5,14 @@
*/
package org.elasticsearch.xpack;
import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
@ -21,8 +29,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.license.plugin.Licensing;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.ScriptPlugin;
@ -39,6 +45,8 @@ import org.elasticsearch.xpack.common.text.TextTemplateModule;
import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.extensions.XPackExtensionsService;
import org.elasticsearch.xpack.graph.Graph;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.notification.Notification;
import org.elasticsearch.xpack.notification.email.Account;
import org.elasticsearch.xpack.notification.email.support.BodyPartSource;
@ -49,14 +57,6 @@ import org.elasticsearch.xpack.security.authc.AuthenticationModule;
import org.elasticsearch.xpack.support.clock.ClockModule;
import org.elasticsearch.xpack.watcher.Watcher;
import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
public static final String NAME = "x-pack";

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
@ -19,12 +19,12 @@ public abstract class XPackRestHandler extends BaseRestHandler {
protected static String URI_BASE = "/_xpack";
public XPackRestHandler(Settings settings, Client client) {
super(settings, client);
public XPackRestHandler(Settings settings) {
super(settings);
}
@Override
protected final void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
handleRequest(request, channel, new XPackClient(client));
}

View File

@ -5,7 +5,8 @@
*/
package org.elasticsearch.xpack.rest.action;
import org.elasticsearch.client.Client;
import java.util.EnumSet;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -20,8 +21,6 @@ import org.elasticsearch.xpack.action.XPackInfoRequest;
import org.elasticsearch.xpack.action.XPackInfoResponse;
import org.elasticsearch.xpack.rest.XPackRestHandler;
import java.util.EnumSet;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
import static org.elasticsearch.rest.RestStatus.OK;
@ -29,14 +28,14 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestXPackInfoAction extends XPackRestHandler {
@Inject
public RestXPackInfoAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestXPackInfoAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(HEAD, URI_BASE, this);
controller.registerHandler(GET, URI_BASE, this);
}
@Override
protected void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
// we piggyback verbosity on "human" output
boolean verbose = request.paramAsBoolean("human", true);

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,13 +26,13 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestXPackUsageAction extends XPackRestHandler {
@Inject
public RestXPackUsageAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestXPackUsageAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/usage", this);
}
@Override
protected void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
new XPackUsageRequestBuilder(client.es()).execute(new RestBuilderListener<XPackUsageResponse>(restChannel) {
@Override
public RestResponse buildResponse(XPackUsageResponse response, XContentBuilder builder) throws Exception {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher.rest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
@ -19,12 +20,12 @@ public abstract class WatcherRestHandler extends BaseRestHandler {
protected static String URI_BASE = "_xpack/watcher";
public WatcherRestHandler(Settings settings, Client client) {
super(settings, client);
public WatcherRestHandler(Settings settings) {
super(settings);
}
@Override
protected final void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
handleRequest(request, channel, new WatcherClient(client));
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -29,8 +29,8 @@ import org.elasticsearch.xpack.watcher.watch.Watch;
public class RestAckWatchAction extends WatcherRestHandler {
@Inject
public RestAckWatchAction(Settings settings, RestController controller, Client client) {
super(settings, client);
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);
@ -41,7 +41,7 @@ public class RestAckWatchAction extends WatcherRestHandler {
}
@Override
protected void handleRequest(RestRequest request, RestChannel restChannel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel restChannel, WatcherClient client) throws Exception {
AckWatchRequest ackWatchRequest = new AckWatchRequest(request.param("id"));
String[] actions = request.paramAsStringArray("actions", null);
if (actions != null) {

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -29,17 +29,17 @@ import org.elasticsearch.xpack.watcher.watch.Watch;
public class RestActivateWatchAction extends WatcherRestHandler {
@Inject
public RestActivateWatchAction(Settings settings, RestController controller, Client client) {
super(settings, client);
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, client);
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);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
String watchId = request.param("id");
client.activateWatch(new ActivateWatchRequest(watchId, true), new RestBuilderListener<ActivateWatchResponse>(channel) {
@Override
@ -53,12 +53,12 @@ public class RestActivateWatchAction extends WatcherRestHandler {
static class DeactivateRestHandler extends WatcherRestHandler {
public DeactivateRestHandler(Settings settings, Client client) {
super(settings, client);
public DeactivateRestHandler(Settings settings) {
super(settings);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
String watchId = request.param("id");
client.activateWatch(new ActivateWatchRequest(watchId, false), new RestBuilderListener<ActivateWatchResponse>(channel) {
@Override

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -30,8 +30,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestDeleteWatchAction extends WatcherRestHandler {
@Inject
public RestDeleteWatchAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestDeleteWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, URI_BASE + "/watch/{id}", this);
}

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.inject.Inject;
@ -42,8 +42,8 @@ public class RestExecuteWatchAction extends WatcherRestHandler {
final TriggerService triggerService;
@Inject
public RestExecuteWatchAction(Settings settings, RestController controller, Client client, TriggerService triggerService) {
super(settings, client);
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);

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -30,8 +30,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestGetWatchAction extends WatcherRestHandler {
@Inject
public RestGetWatchAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestGetWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/watch/{id}", this);
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -26,10 +26,10 @@ public class RestHijackOperationAction extends WatcherRestHandler {
@Inject
public RestHijackOperationAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestHijackOperationAction(Settings settings, RestController controller) {
super(settings);
if (!settings.getAsBoolean(ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING, false)) {
WatcherRestHandler unsupportedHandler = new UnsupportedHandler(settings, client);
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);
@ -46,7 +46,7 @@ public class RestHijackOperationAction extends WatcherRestHandler {
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
jsonBuilder.startObject().field("error","This endpoint is not supported for " +
request.method().name() + " on " + WatchStore.INDEX + " index. Please use " +
@ -58,12 +58,12 @@ public class RestHijackOperationAction extends WatcherRestHandler {
public static class UnsupportedHandler extends WatcherRestHandler {
public UnsupportedHandler(Settings settings, Client client) {
super(settings, client);
public UnsupportedHandler(Settings settings) {
super(settings);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
request.path();
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
jsonBuilder.startObject().field("error","This endpoint is not supported for " +

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -31,8 +31,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestPutWatchAction extends WatcherRestHandler {
@Inject
public RestPutWatchAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestPutWatchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, URI_BASE + "/watch/{id}", this);
controller.registerHandler(PUT, URI_BASE + "/watch/{id}", this);
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestChannel;
@ -22,38 +22,38 @@ import org.elasticsearch.xpack.watcher.transport.actions.service.WatcherServiceR
public class RestWatchServiceAction extends WatcherRestHandler {
@Inject
public RestWatchServiceAction(Settings settings, RestController controller, Client client) {
super(settings, client);
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, client));
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_stop", new StopRestHandler(settings, client));
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_start", new StartRestHandler(settings));
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_stop", new StopRestHandler(settings));
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
client.watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
}
static class StartRestHandler extends WatcherRestHandler {
public StartRestHandler(Settings settings, Client client) {
super(settings, client);
public StartRestHandler(Settings settings) {
super(settings);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
client.watcherService(new WatcherServiceRequest().start(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
}
}
static class StopRestHandler extends WatcherRestHandler {
public StopRestHandler(Settings settings, Client client) {
super(settings, client);
public StopRestHandler(Settings settings) {
super(settings);
}
@Override
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
client.watcherService(new WatcherServiceRequest().stop(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
}
}

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -29,8 +29,8 @@ import static org.elasticsearch.rest.RestStatus.OK;
public class RestWatcherStatsAction extends WatcherRestHandler {
@Inject
public RestWatcherStatsAction(Settings settings, RestController controller, Client client) {
super(settings, client);
public RestWatcherStatsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/stats", this);
controller.registerHandler(GET, URI_BASE + "/stats/{metric}", this);
}

View File

@ -39,7 +39,7 @@ public class RestExecuteWatchActionTests extends ESTestCase {
ExecuteWatchRequestBuilder builder = new ExecuteWatchRequestBuilder(client);
when(watcherClient.prepareExecuteWatch()).thenReturn(builder);
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController, client,
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController,
triggerService);
restExecuteWatchAction.handleRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition,
debugCondition), restChannel, watcherClient);