mirror of https://github.com/apache/druid.git
fix lifecycle startup/stop ordering problem with discovery module and make druid able to load local extensions
This commit is contained in:
parent
15843c3978
commit
be5bb7f2eb
|
@ -59,7 +59,7 @@ import java.util.concurrent.ThreadFactory;
|
|||
/**
|
||||
* The DiscoveryModule allows for the registration of Keys of DruidNode objects, which it intends to be
|
||||
* automatically announced at the end of the lifecycle start.
|
||||
*
|
||||
* <p/>
|
||||
* In order for this to work a ServiceAnnouncer instance *must* be injected and instantiated first.
|
||||
* This can often be achieved by registering ServiceAnnouncer.class with the LifecycleModule.
|
||||
*/
|
||||
|
@ -69,19 +69,25 @@ public class DiscoveryModule implements Module
|
|||
|
||||
/**
|
||||
* Requests that the un-annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
* <p/>
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class)) automatically.
|
||||
* Announcement will happen in the LAST stage of the Lifecycle
|
||||
*/
|
||||
public static void registerDefault(Binder binder)
|
||||
{
|
||||
registerKey(binder, Key.get(new TypeLiteral<DruidNode>(){}));
|
||||
registerKey(
|
||||
binder, Key.get(
|
||||
new TypeLiteral<DruidNode>()
|
||||
{
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
* <p/>
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the LAST stage of the Lifecycle
|
||||
|
@ -90,12 +96,18 @@ public class DiscoveryModule implements Module
|
|||
*/
|
||||
public static void register(Binder binder, Annotation annotation)
|
||||
{
|
||||
registerKey(binder, Key.get(new TypeLiteral<DruidNode>(){}, annotation));
|
||||
registerKey(
|
||||
binder, Key.get(
|
||||
new TypeLiteral<DruidNode>()
|
||||
{
|
||||
}, annotation
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
* <p/>
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the LAST stage of the Lifecycle
|
||||
|
@ -104,12 +116,18 @@ public class DiscoveryModule implements Module
|
|||
*/
|
||||
public static void register(Binder binder, Class<? extends Annotation> annotation)
|
||||
{
|
||||
registerKey(binder, Key.get(new TypeLiteral<DruidNode>(){}, annotation));
|
||||
registerKey(
|
||||
binder, Key.get(
|
||||
new TypeLiteral<DruidNode>()
|
||||
{
|
||||
}, annotation
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the keyed DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
* <p/>
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the LAST stage of the Lifecycle
|
||||
|
@ -137,7 +155,9 @@ public class DiscoveryModule implements Module
|
|||
.asEagerSingleton();
|
||||
}
|
||||
|
||||
@Provides @LazySingleton @Named(NAME)
|
||||
@Provides
|
||||
@LazySingleton
|
||||
@Named(NAME)
|
||||
public CuratorServiceAnnouncer getServiceAnnouncer(
|
||||
final CuratorServiceAnnouncer announcer,
|
||||
final Injector injector,
|
||||
|
@ -181,7 +201,8 @@ public class DiscoveryModule implements Module
|
|||
return announcer;
|
||||
}
|
||||
|
||||
@Provides @LazySingleton
|
||||
@Provides
|
||||
@LazySingleton
|
||||
public ServiceDiscovery<Void> getServiceDiscovery(
|
||||
CuratorFramework curator,
|
||||
CuratorDiscoveryConfig config,
|
||||
|
@ -217,14 +238,14 @@ public class DiscoveryModule implements Module
|
|||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
Lifecycle.Stage.LAST
|
||||
}
|
||||
);
|
||||
|
||||
return serviceDiscovery;
|
||||
}
|
||||
|
||||
@Provides @LazySingleton
|
||||
@Provides
|
||||
@LazySingleton
|
||||
public ServerDiscoveryFactory getServerDiscoveryFactory(
|
||||
ServiceDiscovery<Void> serviceDiscovery
|
||||
)
|
||||
|
|
|
@ -29,6 +29,10 @@ import java.util.List;
|
|||
*/
|
||||
public class ExtensionsConfig
|
||||
{
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
private boolean searchCurrentClassloader = true;
|
||||
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
private List<String> coordinates = ImmutableList.of();
|
||||
|
@ -44,6 +48,11 @@ public class ExtensionsConfig
|
|||
"https://metamx.artifactoryonline.com/metamx/pub-libs-releases-local"
|
||||
);
|
||||
|
||||
public boolean searchCurrentClassloader()
|
||||
{
|
||||
return searchCurrentClassloader;
|
||||
}
|
||||
|
||||
public List<String> getCoordinates()
|
||||
{
|
||||
return coordinates;
|
||||
|
|
|
@ -139,14 +139,13 @@ public class
|
|||
for (Artifact artifact : artifacts) {
|
||||
if (!exclusions.contains(artifact.getGroupId())) {
|
||||
urls.add(artifact.getFile().toURI().toURL());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log.error("Skipped Artifact[%s]", artifact);
|
||||
}
|
||||
}
|
||||
|
||||
for (URL url : urls) {
|
||||
log.error("Added URL[%s]", url);
|
||||
log.info("Added URL[%s]", url);
|
||||
}
|
||||
|
||||
loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Initialization.class.getClassLoader());
|
||||
|
@ -165,6 +164,13 @@ public class
|
|||
}
|
||||
}
|
||||
|
||||
if (config.searchCurrentClassloader()) {
|
||||
for (T module : ServiceLoader.load(clazz, Initialization.class.getClassLoader())) {
|
||||
log.info("Adding local module[%s]", module.getClass());
|
||||
retVal.add(module);
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -243,7 +249,8 @@ public class
|
|||
private final ObjectMapper smileMapper;
|
||||
private final List<Module> modules;
|
||||
|
||||
public ModuleList(Injector baseInjector) {
|
||||
public ModuleList(Injector baseInjector)
|
||||
{
|
||||
this.baseInjector = baseInjector;
|
||||
this.jsonMapper = baseInjector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
||||
this.smileMapper = baseInjector.getInstance(Key.get(ObjectMapper.class, Smile.class));
|
||||
|
@ -260,24 +267,19 @@ public class
|
|||
if (input instanceof DruidModule) {
|
||||
baseInjector.injectMembers(input);
|
||||
modules.add(registerJacksonModules(((DruidModule) input)));
|
||||
}
|
||||
else if (input instanceof Module) {
|
||||
} else if (input instanceof Module) {
|
||||
baseInjector.injectMembers(input);
|
||||
modules.add((Module) input);
|
||||
}
|
||||
else if (input instanceof Class) {
|
||||
} else if (input instanceof Class) {
|
||||
if (DruidModule.class.isAssignableFrom((Class) input)) {
|
||||
modules.add(registerJacksonModules(baseInjector.getInstance((Class<? extends DruidModule>) input)));
|
||||
}
|
||||
else if (Module.class.isAssignableFrom((Class) input)) {
|
||||
} else if (Module.class.isAssignableFrom((Class) input)) {
|
||||
modules.add(baseInjector.getInstance((Class<? extends Module>) input));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new ISE("Class[%s] does not implement %s", input.getClass(), Module.class);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new ISE("Unknown module type[%s]", input.getClass());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue