mirror of https://github.com/apache/druid.git
stuff
This commit is contained in:
parent
73011267af
commit
d4b052a579
|
@ -24,15 +24,22 @@ import com.google.common.base.Supplier;
|
|||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.util.Modules;
|
||||
import org.apache.calcite.avatica.server.AbstractAvaticaHandler;
|
||||
import org.apache.druid.cli.CliBroker;
|
||||
import org.apache.druid.discovery.DiscoveryDruidNode;
|
||||
import org.apache.druid.discovery.DruidNodeDiscovery;
|
||||
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
|
||||
import org.apache.druid.discovery.NodeRole;
|
||||
import org.apache.druid.guice.DruidInjectorBuilder;
|
||||
import org.apache.druid.guice.LazySingleton;
|
||||
import org.apache.druid.guice.StartupInjectorBuilder;
|
||||
|
@ -90,10 +97,14 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
public class Launcher
|
||||
{
|
||||
|
@ -389,18 +400,125 @@ public class Launcher
|
|||
Launcher.main1(null);
|
||||
}
|
||||
|
||||
private static Module propOverrideModuel()
|
||||
{
|
||||
Properties localProps = new Properties();
|
||||
localProps.put("druid.enableTlsPort", "false");
|
||||
localProps.put("druid.zk.service.enabled", "false");
|
||||
localProps.put("druid.plaintextPort","12345");
|
||||
|
||||
|
||||
Module m = binder -> binder.bind(Properties.class).toInstance(localProps);
|
||||
return m;
|
||||
}
|
||||
|
||||
public static class DiscovertModule extends AbstractModule {
|
||||
|
||||
DiscovertModule() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
}
|
||||
|
||||
@Provides
|
||||
DruidNodeDiscoveryProvider getProvider() {
|
||||
final DruidNode coordinatorNode = new DruidNode("test-coordinator", "dummy", false, 8081, null, true, false);
|
||||
FakeDruidNodeDiscoveryProvider provider = new FakeDruidNodeDiscoveryProvider(
|
||||
ImmutableMap.of(
|
||||
NodeRole.COORDINATOR, new FakeDruidNodeDiscovery(ImmutableMap.of(NodeRole.COORDINATOR, coordinatorNode))
|
||||
)
|
||||
);
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* A fake {@link DruidNodeDiscoveryProvider} for {@link #createMockSystemSchema}.
|
||||
*/
|
||||
private static class FakeDruidNodeDiscoveryProvider extends DruidNodeDiscoveryProvider
|
||||
{
|
||||
private final Map<NodeRole, FakeDruidNodeDiscovery> nodeDiscoveries;
|
||||
|
||||
public FakeDruidNodeDiscoveryProvider(Map<NodeRole, FakeDruidNodeDiscovery> nodeDiscoveries)
|
||||
{
|
||||
this.nodeDiscoveries = nodeDiscoveries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanSupplier getForNode(DruidNode node, NodeRole nodeRole)
|
||||
{
|
||||
boolean get = nodeDiscoveries.getOrDefault(nodeRole, new FakeDruidNodeDiscovery())
|
||||
.getAllNodes()
|
||||
.stream()
|
||||
.anyMatch(x -> x.getDruidNode().equals(node));
|
||||
return () -> get;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DruidNodeDiscovery getForNodeRole(NodeRole nodeRole)
|
||||
{
|
||||
return nodeDiscoveries.getOrDefault(nodeRole, new FakeDruidNodeDiscovery());
|
||||
}
|
||||
}
|
||||
|
||||
private static class FakeDruidNodeDiscovery implements DruidNodeDiscovery
|
||||
{
|
||||
private final Set<DiscoveryDruidNode> nodes;
|
||||
|
||||
FakeDruidNodeDiscovery()
|
||||
{
|
||||
this.nodes = new HashSet<>();
|
||||
}
|
||||
|
||||
FakeDruidNodeDiscovery(Map<NodeRole, DruidNode> nodes)
|
||||
{
|
||||
this.nodes = Sets.newHashSetWithExpectedSize(nodes.size());
|
||||
nodes.forEach((k, v) -> {
|
||||
addNode(v, k);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DiscoveryDruidNode> getAllNodes()
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void addNode(DruidNode node, NodeRole role)
|
||||
{
|
||||
final DiscoveryDruidNode discoveryNode = new DiscoveryDruidNode(node, role, ImmutableMap.of());
|
||||
this.nodes.add(discoveryNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(Listener listener)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static Module discoverModule()
|
||||
{
|
||||
|
||||
// DruidNodeDiscoveryProvider instance = ;
|
||||
// Module m = binder -> binder.bind(DruidNodeDiscoveryProvider.class).toInstance(instance);
|
||||
return new DiscovertModule();
|
||||
|
||||
}
|
||||
|
||||
static class CustomStartupInjectorBuilder extends StartupInjectorBuilder {
|
||||
|
||||
private List<com.google.inject.Module> overrideModules =new ArrayList<>();
|
||||
|
||||
public CustomStartupInjectorBuilder()
|
||||
{
|
||||
Properties localProps = new Properties();
|
||||
localProps.put("druid.enableTlsPort", "false");
|
||||
localProps.put("druid.plaintextPort","12345");
|
||||
|
||||
|
||||
addOverride(binder -> binder.bind(Properties.class).toInstance(localProps));
|
||||
Module m = propOverrideModuel();
|
||||
addOverride(m);
|
||||
// addOverride(binder -> {
|
||||
// binder.bind(SSLClientConfig.class).toProvider(Providers.of(null));
|
||||
// binder.bind(SSLClientConfig.class).annotatedWith(Global.class).toProvider(Providers.of(null));
|
||||
|
@ -431,19 +549,27 @@ public class Launcher
|
|||
|
||||
}
|
||||
|
||||
private static void main1(Object object)
|
||||
private static void main1(Object object) throws Exception
|
||||
{
|
||||
final Injector injector = new CustomStartupInjectorBuilder()
|
||||
.forTests()
|
||||
.build();
|
||||
|
||||
|
||||
SqlTestFramework framework = getCI().extracted(
|
||||
propOverrideModuel(),
|
||||
discoverModule()
|
||||
)
|
||||
|
||||
;
|
||||
|
||||
// SSLContextProvider u = injector.getInstance(SSLContextProvider.class);
|
||||
// System.out.println(u);
|
||||
|
||||
|
||||
|
||||
CliBroker c = new CliBroker();
|
||||
injector.injectMembers(c);
|
||||
framework.injector().injectMembers(c);
|
||||
// c.configure(new Properties());
|
||||
c.run();
|
||||
|
||||
|
|
|
@ -77,12 +77,15 @@ import java.util.function.Function;
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
public class DiscoveryModule implements Module
|
||||
{
|
||||
public DiscoveryModule(){
|
||||
super();
|
||||
}
|
||||
private static final String NAME = "DiscoveryModule:internal";
|
||||
|
||||
private static final String INTERNAL_DISCOVERY_PROP = "druid.discovery.type";
|
||||
|
@ -98,7 +101,7 @@ public class DiscoveryModule implements Module
|
|||
|
||||
/**
|
||||
* Requests that the un-annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
*
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class)) automatically.
|
||||
* Announcement will happen in the ANNOUNCEMENTS stage of the Lifecycle
|
||||
|
@ -112,7 +115,7 @@ public class DiscoveryModule implements Module
|
|||
|
||||
/**
|
||||
* Requests that the annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
*
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the ANNOUNCEMENTS stage of the Lifecycle
|
||||
|
@ -126,7 +129,7 @@ public class DiscoveryModule implements Module
|
|||
|
||||
/**
|
||||
* Requests that the annotated DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
*
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the ANNOUNCEMENTS stage of the Lifecycle
|
||||
|
@ -141,7 +144,7 @@ public class DiscoveryModule implements Module
|
|||
|
||||
/**
|
||||
* Requests that the keyed DruidNode instance be injected and published as part of the lifecycle.
|
||||
*
|
||||
*
|
||||
* That is, this module will announce the DruidNode instance returned by
|
||||
* injector.getInstance(Key.get(DruidNode.class, annotation)) automatically.
|
||||
* Announcement will happen in the ANNOUNCEMENTS stage of the Lifecycle
|
||||
|
|
|
@ -20,11 +20,7 @@
|
|||
package org.apache.druid.initialization;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import org.apache.druid.curator.CuratorModule;
|
||||
import org.apache.druid.curator.discovery.DiscoveryModule;
|
||||
import org.apache.druid.discovery.NodeRole;
|
||||
import org.apache.druid.guice.AnnouncerModule;
|
||||
import org.apache.druid.guice.CoordinatorDiscoveryModule;
|
||||
import org.apache.druid.guice.DruidInjectorBuilder;
|
||||
import org.apache.druid.guice.DruidSecondaryModule;
|
||||
import org.apache.druid.guice.ExpressionModule;
|
||||
|
@ -106,8 +102,8 @@ public class CoreInjectorBuilder extends DruidInjectorBuilder
|
|||
HttpClientModule.escalatedGlobal(),
|
||||
new HttpClientModule("druid.broker.http", Client.class, true),
|
||||
new HttpClientModule("druid.broker.http", EscalatedClient.class, true),
|
||||
new CuratorModule(),
|
||||
new AnnouncerModule(),
|
||||
// new CuratorModule(),
|
||||
// new AnnouncerModule(),
|
||||
new MetricsModule(),
|
||||
new SegmentWriteOutMediumModule(),
|
||||
new ServerModule(),
|
||||
|
@ -115,12 +111,12 @@ public class CoreInjectorBuilder extends DruidInjectorBuilder
|
|||
new JettyServerModule(),
|
||||
new ExpressionModule(),
|
||||
new NestedDataModule(),
|
||||
new DiscoveryModule(),
|
||||
// new DiscoveryModule(),
|
||||
new ServerViewModule(),
|
||||
new MetadataConfigModule(),
|
||||
new DerbyMetadataStorageDruidModule(),
|
||||
new JacksonConfigManagerModule(),
|
||||
new CoordinatorDiscoveryModule(),
|
||||
// new CoordinatorDiscoveryModule(),
|
||||
new LocalDataStorageDruidModule(),
|
||||
new TombstoneDataStorageModule(),
|
||||
new FirehoseModule(),
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.apache.druid.guice.JsonConfigProvider;
|
|||
import org.apache.druid.guice.LazySingleton;
|
||||
import org.apache.druid.guice.LegacyBrokerParallelMergeConfigModule;
|
||||
import org.apache.druid.guice.LifecycleModule;
|
||||
import org.apache.druid.guice.ManageLifecycle;
|
||||
import org.apache.druid.guice.QueryRunnerFactoryModule;
|
||||
import org.apache.druid.guice.QueryableModule;
|
||||
import org.apache.druid.guice.SegmentWranglerModule;
|
||||
|
@ -164,7 +163,7 @@ public class CliBroker extends ServerRunnable
|
|||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
binder.bind(SegmentManager.class).in(LazySingleton.class);
|
||||
binder.bind(ZkCoordinator.class).in(ManageLifecycle.class);
|
||||
// binder.bind(ZkCoordinator.class).in(ManageLifecycle.class);
|
||||
binder.bind(ServerTypeConfig.class).toInstance(new ServerTypeConfig(ServerType.BROKER));
|
||||
Jerseys.addResource(binder, HistoricalResource.class);
|
||||
Jerseys.addResource(binder, SegmentListerResource.class);
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Module;
|
||||
import org.apache.druid.java.util.common.IAE;
|
||||
import org.apache.druid.java.util.common.StringUtils;
|
||||
import org.apache.druid.query.topn.TopNQueryConfig;
|
||||
|
@ -335,8 +336,19 @@ public class SqlTestFrameworkConfig
|
|||
public static class ConfigurationInstance
|
||||
{
|
||||
public SqlTestFramework framework;
|
||||
private SqlTestFrameworkConfig config;
|
||||
private QueryComponentSupplier testHost;
|
||||
|
||||
ConfigurationInstance(SqlTestFrameworkConfig config, QueryComponentSupplier testHost)
|
||||
{
|
||||
this.config = config;
|
||||
this.testHost = testHost;
|
||||
SqlTestFramework framework1 = extracted();
|
||||
framework=framework1;
|
||||
}
|
||||
|
||||
//FIXME remove
|
||||
public SqlTestFramework extracted(Module ...modules)
|
||||
{
|
||||
SqlTestFramework.Builder builder = new SqlTestFramework.Builder(testHost)
|
||||
.withConfig(config)
|
||||
|
@ -344,7 +356,12 @@ public class SqlTestFrameworkConfig
|
|||
.minTopNThreshold(config.minTopNThreshold)
|
||||
.mergeBufferCount(config.numMergeBuffers)
|
||||
.withOverrideModule(config.resultCache.makeModule());
|
||||
framework = builder.build();
|
||||
for (Module m : modules) {
|
||||
builder.withOverrideModule(m);
|
||||
}
|
||||
|
||||
SqlTestFramework framework1 = builder.build();
|
||||
return framework1;
|
||||
}
|
||||
|
||||
public ConfigurationInstance(
|
||||
|
|
Loading…
Reference in New Issue