Merge pull request elastic/elasticsearch#2786 from rjernst/deguice1

Remove guice from watcher http client and related classes.

Original commit: elastic/x-pack-elasticsearch@3b321c20f5
This commit is contained in:
Ryan Ernst 2016-07-12 15:07:23 -07:00 committed by GitHub
commit 16793ad260
11 changed files with 39 additions and 69 deletions

View File

@ -19,6 +19,8 @@ import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.license.plugin.core.LicensesMetaData;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction;
@ -47,7 +49,6 @@ public class Licensing implements ActionPlugin {
MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO);
}
@Inject
public Licensing(Settings settings) {
isTransportClient = transportClientMode(settings);
isTribeNode = isTribeNode(settings);
@ -82,7 +83,11 @@ public class Licensing implements ActionPlugin {
public Collection<Module> nodeModules() {
if (isTransportClient == false && isTribeNode == false) {
return Collections.<Module>singletonList(new LicensingModule());
return Collections.singletonList(b -> {
b.bind(LicensesService.class).asEagerSingleton();
b.bind(LicenseeRegistry.class).to(LicensesService.class);
b.bind(LicensesManagerService.class).to(LicensesService.class);
});
}
return Collections.emptyList();
}

View File

@ -1,24 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.license.core.LicenseVerifier;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.license.plugin.core.LicensesService;
public class LicensingModule extends AbstractModule {
@Override
protected void configure() {
bind(LicenseVerifier.class).asEagerSingleton();
bind(LicensesService.class).asEagerSingleton();
bind(LicenseeRegistry.class).to(LicensesService.class);
bind(LicensesManagerService.class).to(LicensesService.class);
}
}

View File

@ -133,6 +133,10 @@ public class Security implements ActionPlugin {
}
}
public CryptoService getCryptoService() {
return cryptoService;
}
public Collection<Module> nodeModules() {
List<Module> modules = new ArrayList<>();

View File

@ -12,7 +12,9 @@ import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.action.ActionRequest;
@ -20,6 +22,7 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Module;
@ -36,12 +39,18 @@ import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.action.TransportXPackInfoAction;
import org.elasticsearch.xpack.action.TransportXPackUsageAction;
import org.elasticsearch.xpack.action.XPackInfoAction;
import org.elasticsearch.xpack.action.XPackUsageAction;
import org.elasticsearch.xpack.common.ScriptServiceProxy;
import org.elasticsearch.xpack.common.http.HttpClientModule;
import org.elasticsearch.xpack.common.http.HttpClient;
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
import org.elasticsearch.xpack.common.http.auth.HttpAuthFactory;
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.xpack.common.text.TextTemplateModule;
import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.extensions.XPackExtensionsService;
@ -100,6 +109,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
}
protected final Settings settings;
private final Environment env;
protected boolean transportClientMode;
protected final XPackExtensionsService extensionsService;
@ -113,7 +123,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
public XPackPlugin(Settings settings) throws IOException {
this.settings = settings;
this.transportClientMode = transportClientMode(settings);
final Environment env = transportClientMode ? null : new Environment(settings);
this.env = transportClientMode ? null : new Environment(settings);
this.licensing = new Licensing(settings);
this.security = new Security(settings, env);
@ -151,7 +161,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
modules.addAll(graph.createGuiceModules());
if (transportClientMode == false) {
modules.add(new HttpClientModule());
modules.add(new TextTemplateModule());
}
return modules;
@ -169,6 +178,22 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
return services;
}
@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool) {
List<Object> components = new ArrayList<>();
if (transportClientMode == false) {
// watcher http stuff
Map<String, HttpAuthFactory> httpAuthFactories = new HashMap<>();
httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService()));
// TODO: add more auth types, or remove this indirection
HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories);
components.add(new HttpRequestTemplate.Parser(httpAuthRegistry));
components.add(new HttpClient(settings, httpAuthRegistry, env));
}
return components;
}
@Override
public Settings additionalSettings() {
Settings.Builder builder = Settings.builder();

View File

@ -79,7 +79,6 @@ public class HttpClient extends AbstractLifecycleComponent {
private SSLSocketFactory sslSocketFactory;
private HttpProxy proxy = HttpProxy.NO_PROXY;
@Inject
public HttpClient(Settings settings, HttpAuthRegistry httpAuthRegistry, Environment env) {
super(settings);
this.httpAuthRegistry = httpAuthRegistry;

View File

@ -1,34 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.common.http;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.xpack.common.http.auth.HttpAuthFactory;
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
/**
*/
public class HttpClientModule extends AbstractModule {
@Override
protected void configure() {
bind(HttpRequestTemplate.Parser.class).asEagerSingleton();
bind(HttpRequest.Parser.class).asEagerSingleton();
bind(HttpClient.class).asEagerSingleton();
MapBinder<String, HttpAuthFactory> parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class);
bind(BasicAuthFactory.class).asEagerSingleton();
parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class);
bind(HttpAuthRegistry.class).asEagerSingleton();
}
}

View File

@ -250,7 +250,6 @@ public class HttpRequest implements ToXContent {
private final HttpAuthRegistry httpAuthRegistry;
@Inject
public Parser(HttpAuthRegistry httpAuthRegistry) {
this.httpAuthRegistry = httpAuthRegistry;
}

View File

@ -255,7 +255,6 @@ public class HttpRequestTemplate implements ToXContent {
private final HttpAuthRegistry httpAuthRegistry;
@Inject
public Parser(HttpAuthRegistry httpAuthRegistry) {
this.httpAuthRegistry = httpAuthRegistry;
}

View File

@ -21,7 +21,6 @@ public class HttpAuthRegistry {
private final Map<String, HttpAuthFactory> factories;
@Inject
public HttpAuthRegistry(Map<String, HttpAuthFactory> factories) {
this.factories = factories;
}

View File

@ -20,7 +20,6 @@ public class BasicAuthFactory extends HttpAuthFactory<BasicAuth, ApplicableBasic
private final CryptoService cryptoService;
@Inject
public BasicAuthFactory(@Nullable CryptoService cryptoService) {
this.cryptoService = cryptoService;
}

View File

@ -59,7 +59,6 @@ public class Notification {
return Collections.emptyList();
}
return Arrays.<Class<? extends LifecycleComponent>>asList(
HttpClient.class,
EmailService.class,
HipChatService.class,
SlackService.class,