use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.
the class TieredBrokerHostSelectorTest method setUp.
@Before
public void setUp() {
druidNodeDiscoveryProvider = EasyMock.createStrictMock(DruidNodeDiscoveryProvider.class);
node1 = new DiscoveryDruidNode(new DruidNode("hotBroker", "hotHost", false, 8080, null, true, false), NodeRole.BROKER, ImmutableMap.of());
node2 = new DiscoveryDruidNode(new DruidNode("coldBroker", "coldHost1", false, 8080, null, true, false), NodeRole.BROKER, ImmutableMap.of());
node3 = new DiscoveryDruidNode(new DruidNode("coldBroker", "coldHost2", false, 8080, null, true, false), NodeRole.BROKER, ImmutableMap.of());
druidNodeDiscovery = new DruidNodeDiscovery() {
@Override
public Collection<DiscoveryDruidNode> getAllNodes() {
return ImmutableSet.of(node1, node2, node3);
}
@Override
public void registerListener(Listener listener) {
listener.nodesAdded(ImmutableList.of(node1, node2, node3));
listener.nodeViewInitialized();
}
};
EasyMock.expect(druidNodeDiscoveryProvider.getForNodeRole(NodeRole.BROKER)).andReturn(druidNodeDiscovery);
EasyMock.replay(druidNodeDiscoveryProvider);
brokerSelector = new TieredBrokerHostSelector(new TestRuleManager(null, null), new TieredBrokerConfig() {
@Override
public LinkedHashMap<String, String> getTierToBrokerMap() {
return new LinkedHashMap<String, String>(ImmutableMap.of("hot", "hotBroker", "medium", "mediumBroker", DruidServer.DEFAULT_TIER, "coldBroker"));
}
@Override
public String getDefaultBrokerServiceName() {
return "hotBroker";
}
}, druidNodeDiscoveryProvider, Arrays.asList(new ManualTieredBrokerSelectorStrategy(null), new TimeBoundaryTieredBrokerSelectorStrategy(), new PriorityTieredBrokerSelectorStrategy(0, 1)));
brokerSelector.start();
}
use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.
the class TieredBrokerHostSelector method start.
@LifecycleStart
public void start() {
synchronized (lock) {
if (started) {
return;
}
for (Map.Entry<String, String> entry : tierConfig.getTierToBrokerMap().entrySet()) {
servers.put(entry.getValue(), new NodesHolder());
}
DruidNodeDiscovery druidNodeDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.BROKER);
druidNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {
@Override
public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach((node) -> {
NodesHolder nodesHolder = servers.get(node.getDruidNode().getServiceName());
if (nodesHolder != null) {
nodesHolder.add(node.getDruidNode().getHostAndPortToUse(), TO_SERVER.apply(node));
}
});
}
@Override
public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach((node) -> {
NodesHolder nodesHolder = servers.get(node.getDruidNode().getServiceName());
if (nodesHolder != null) {
nodesHolder.remove(node.getDruidNode().getHostAndPortToUse());
}
});
}
});
started = true;
}
}
use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.
the class HttpServerInventoryView method start.
@LifecycleStart
public void start() {
synchronized (lifecycleLock) {
if (!lifecycleLock.canStart()) {
throw new ISE("can't start.");
}
log.info("Starting %s.", execNamePrefix);
try {
executor = ScheduledExecutors.fixed(config.getNumThreads(), execNamePrefix + "-%s");
DruidNodeDiscovery druidNodeDiscovery = druidNodeDiscoveryProvider.getForService(DataNodeService.DISCOVERY_SERVICE_KEY);
druidNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {
private final AtomicBoolean initialized = new AtomicBoolean(false);
@Override
public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach(node -> serverAdded(toDruidServer(node)));
}
@Override
public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach(node -> serverRemoved(toDruidServer(node)));
}
@Override
public void nodeViewInitialized() {
if (!initialized.getAndSet(true)) {
executor.execute(HttpServerInventoryView.this::serverInventoryInitialized);
}
}
private DruidServer toDruidServer(DiscoveryDruidNode node) {
return new DruidServer(node.getDruidNode().getHostAndPortToUse(), node.getDruidNode().getHostAndPort(), node.getDruidNode().getHostAndTlsPort(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getMaxSize(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getServerType(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getTier(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getPriority());
}
});
scheduleSyncMonitoring();
lifecycleLock.started();
} finally {
lifecycleLock.exitStart();
}
log.info("Started %s.", execNamePrefix);
}
}
use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.
the class CuratorDruidNodeAnnouncerAndDiscoveryTest method testAnnouncementAndDiscovery.
@Test(timeout = 60_000L)
public void testAnnouncementAndDiscovery() throws Exception {
ObjectMapper objectMapper = new DefaultObjectMapper();
// additional setup to serde DruidNode
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ServerConfig.class, new ServerConfig()).addValue("java.lang.String", "dummy").addValue("java.lang.Integer", 1234).addValue(ObjectMapper.class, objectMapper));
curator.start();
curator.blockUntilConnected();
Announcer announcer = new Announcer(curator, Execs.directExecutor());
announcer.start();
CuratorDruidNodeAnnouncer druidNodeAnnouncer = new CuratorDruidNodeAnnouncer(announcer, new ZkPathsConfig(), objectMapper);
DiscoveryDruidNode coordinatorNode1 = new DiscoveryDruidNode(new DruidNode("s1", "h1", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
DiscoveryDruidNode coordinatorNode2 = new DiscoveryDruidNode(new DruidNode("s2", "h2", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
DiscoveryDruidNode overlordNode1 = new DiscoveryDruidNode(new DruidNode("s3", "h3", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
DiscoveryDruidNode overlordNode2 = new DiscoveryDruidNode(new DruidNode("s4", "h4", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
druidNodeAnnouncer.announce(coordinatorNode1);
druidNodeAnnouncer.announce(overlordNode1);
CuratorDruidNodeDiscoveryProvider druidNodeDiscoveryProvider = new CuratorDruidNodeDiscoveryProvider(curator, new ZkPathsConfig(), objectMapper);
druidNodeDiscoveryProvider.start();
DruidNodeDiscovery coordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.COORDINATOR);
BooleanSupplier coord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(coordinatorNode1.getDruidNode(), NodeRole.COORDINATOR);
DruidNodeDiscovery overlordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.OVERLORD);
BooleanSupplier overlord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(overlordNode1.getDruidNode(), NodeRole.OVERLORD);
while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordDiscovery.getAllNodes()) && !coord1NodeDiscovery.getAsBoolean()) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(overlordNode1), overlordDiscovery.getAllNodes()) && !overlord1NodeDiscovery.getAsBoolean()) {
Thread.sleep(100);
}
HashSet<DiscoveryDruidNode> coordNodes = new HashSet<>();
coordDiscovery.registerListener(createSetAggregatingListener(coordNodes));
HashSet<DiscoveryDruidNode> overlordNodes = new HashSet<>();
overlordDiscovery.registerListener(createSetAggregatingListener(overlordNodes));
while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordNodes)) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(overlordNode1), overlordNodes)) {
Thread.sleep(100);
}
druidNodeAnnouncer.announce(coordinatorNode2);
druidNodeAnnouncer.announce(overlordNode2);
while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordDiscovery.getAllNodes())) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordDiscovery.getAllNodes())) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordNodes)) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordNodes)) {
Thread.sleep(100);
}
druidNodeAnnouncer.unannounce(coordinatorNode1);
druidNodeAnnouncer.unannounce(coordinatorNode2);
druidNodeAnnouncer.unannounce(overlordNode1);
druidNodeAnnouncer.unannounce(overlordNode2);
while (!checkNodes(ImmutableSet.of(), coordDiscovery.getAllNodes())) {
Thread.sleep(100);
}
while (!checkNodes(ImmutableSet.of(), overlordDiscovery.getAllNodes())) {
Thread.sleep(100);
}
while (!coordNodes.isEmpty()) {
Thread.sleep(100);
}
while (!overlordNodes.isEmpty()) {
Thread.sleep(100);
}
druidNodeDiscoveryProvider.stop();
announcer.stop();
}
use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.
the class ITHighAvailabilityTest method testCustomDiscovery.
@Test
public void testCustomDiscovery() {
ITRetryUtil.retryUntil(() -> {
try {
DruidNodeDiscovery customDisco = druidNodeDiscovery.getForNodeRole(new NodeRole(CliCustomNodeRole.SERVICE_NAME));
int count = testSelfDiscovery(customDisco.getAllNodes());
return count > 0;
} catch (Throwable t) {
return false;
}
}, true, RETRY_DELAY, NUM_RETRIES, "Custom service discovered");
}
Aggregations