Remove guice from watcher http client and related classes.
This is the first deguicing for xplugins to use the new createComponents(). The removal was very straightforward. One thing to note is HttpAuthFactory only has one implementation (basic auth), but I kept the registry and such for now. Also, HttpRequest.Parser is only used in 2 tests, not at all in main code, it should probably be removed. Original commit: elastic/x-pack-elasticsearch@839e7e4900
This commit is contained in:
parent
e92860f552
commit
dd89a7b061
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -133,6 +133,10 @@ public class Security implements ActionPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public CryptoService getCryptoService() {
|
||||
return cryptoService;
|
||||
}
|
||||
|
||||
public Collection<Module> nodeModules() {
|
||||
List<Module> modules = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -41,7 +43,12 @@ 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 +107,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 +121,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 +159,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 +176,22 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> createComponents() {
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -250,7 +250,6 @@ public class HttpRequest implements ToXContent {
|
|||
|
||||
private final HttpAuthRegistry httpAuthRegistry;
|
||||
|
||||
@Inject
|
||||
public Parser(HttpAuthRegistry httpAuthRegistry) {
|
||||
this.httpAuthRegistry = httpAuthRegistry;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,6 @@ public class HttpRequestTemplate implements ToXContent {
|
|||
|
||||
private final HttpAuthRegistry httpAuthRegistry;
|
||||
|
||||
@Inject
|
||||
public Parser(HttpAuthRegistry httpAuthRegistry) {
|
||||
this.httpAuthRegistry = httpAuthRegistry;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ public class HttpAuthRegistry {
|
|||
|
||||
private final Map<String, HttpAuthFactory> factories;
|
||||
|
||||
@Inject
|
||||
public HttpAuthRegistry(Map<String, HttpAuthFactory> factories) {
|
||||
this.factories = factories;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public class BasicAuthFactory extends HttpAuthFactory<BasicAuth, ApplicableBasic
|
|||
|
||||
private final CryptoService cryptoService;
|
||||
|
||||
@Inject
|
||||
public BasicAuthFactory(@Nullable CryptoService cryptoService) {
|
||||
this.cryptoService = cryptoService;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class Notification {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.<Class<? extends LifecycleComponent>>asList(
|
||||
HttpClient.class,
|
||||
EmailService.class,
|
||||
HipChatService.class,
|
||||
SlackService.class,
|
||||
|
|
Loading…
Reference in New Issue