Search in sources :

Example 1 with DruidNodeDiscovery

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();
}
Also used : DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) LinkedHashMap(java.util.LinkedHashMap) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) Collection(java.util.Collection) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) Before(org.junit.Before)

Example 2 with DruidNodeDiscovery

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;
    }
}
Also used : DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) Iterables(com.google.common.collect.Iterables) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) LifecycleStart(org.apache.druid.java.util.common.lifecycle.LifecycleStart) Pair(org.apache.druid.java.util.common.Pair) Interval(org.joda.time.Interval) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(com.google.common.base.Optional) Map(java.util.Map) DateTimes(org.apache.druid.java.util.common.DateTimes) SqlQuery(org.apache.druid.sql.http.SqlQuery) Function(com.google.common.base.Function) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Rule(org.apache.druid.server.coordinator.rules.Rule) Maps(com.google.common.collect.Maps) QueryContexts(org.apache.druid.query.QueryContexts) List(java.util.List) NodeRole(org.apache.druid.discovery.NodeRole) LoadRule(org.apache.druid.server.coordinator.rules.LoadRule) Server(org.apache.druid.client.selector.Server) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LifecycleStart(org.apache.druid.java.util.common.lifecycle.LifecycleStart)

Example 3 with DruidNodeDiscovery

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);
    }
}
Also used : DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) ScheduledExecutors(org.apache.druid.java.util.common.concurrent.ScheduledExecutors) HttpClient(org.apache.druid.java.util.http.client.HttpClient) ChangeRequestHttpSyncer(org.apache.druid.server.coordination.ChangeRequestHttpSyncer) URL(java.net.URL) ChangeRequestsSnapshot(org.apache.druid.server.coordination.ChangeRequestsSnapshot) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Collections2(com.google.common.collect.Collections2) LifecycleStart(org.apache.druid.java.util.common.lifecycle.LifecycleStart) SegmentChangeRequestLoad(org.apache.druid.server.coordination.SegmentChangeRequestLoad) Pair(org.apache.druid.java.util.common.Pair) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop) DruidServerMetadata(org.apache.druid.server.coordination.DruidServerMetadata) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Predicates(com.google.common.base.Predicates) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IAE(org.apache.druid.java.util.common.IAE) Function(com.google.common.base.Function) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) Iterator(java.util.Iterator) RE(org.apache.druid.java.util.common.RE) MalformedURLException(java.net.MalformedURLException) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ISE(org.apache.druid.java.util.common.ISE) SegmentChangeRequestDrop(org.apache.druid.server.coordination.SegmentChangeRequestDrop) Maps(com.google.common.collect.Maps) HostAndPort(com.google.common.net.HostAndPort) TimeUnit(java.util.concurrent.TimeUnit) DataNodeService(org.apache.druid.discovery.DataNodeService) List(java.util.List) Predicate(com.google.common.base.Predicate) LifecycleLock(org.apache.druid.concurrent.LifecycleLock) DataSegment(org.apache.druid.timeline.DataSegment) Preconditions(com.google.common.base.Preconditions) SegmentId(org.apache.druid.timeline.SegmentId) DataSegmentChangeRequest(org.apache.druid.server.coordination.DataSegmentChangeRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ISE(org.apache.druid.java.util.common.ISE) DataNodeService(org.apache.druid.discovery.DataNodeService) LifecycleStart(org.apache.druid.java.util.common.lifecycle.LifecycleStart)

Example 4 with DruidNodeDiscovery

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();
}
Also used : DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ServerConfig(org.apache.druid.server.initialization.ServerConfig) Announcer(org.apache.druid.curator.announcement.Announcer) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) BooleanSupplier(java.util.function.BooleanSupplier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with DruidNodeDiscovery

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");
}
Also used : CliCustomNodeRole(org.apache.druid.cli.CliCustomNodeRole) NodeRole(org.apache.druid.discovery.NodeRole) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) Test(org.testng.annotations.Test) AbstractIndexerTest(org.apache.druid.tests.indexer.AbstractIndexerTest)

Aggregations

DruidNodeDiscovery (org.apache.druid.discovery.DruidNodeDiscovery)13 DiscoveryDruidNode (org.apache.druid.discovery.DiscoveryDruidNode)10 DruidNodeDiscoveryProvider (org.apache.druid.discovery.DruidNodeDiscoveryProvider)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 List (java.util.List)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 NodeRole (org.apache.druid.discovery.NodeRole)4 LifecycleStop (org.apache.druid.java.util.common.lifecycle.LifecycleStop)4 Optional (com.google.common.base.Optional)3 ImmutableList (com.google.common.collect.ImmutableList)3 URL (java.net.URL)3 HashSet (java.util.HashSet)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ISE (org.apache.druid.java.util.common.ISE)3 Function (com.google.common.base.Function)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps (com.google.common.collect.Maps)2