Search in sources :

Example 6 with DruidNodeDiscovery

use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.

the class K8sAnnouncerAndDiscoveryIntTest method testAnnouncementAndDiscoveryWorkflow.

@Test(timeout = 30000L)
public void testAnnouncementAndDiscoveryWorkflow() throws Exception {
    K8sApiClient k8sApiClient = new DefaultK8sApiClient(Config.defaultClient(), new DefaultObjectMapper());
    K8sDruidNodeDiscoveryProvider discoveryProvider = new K8sDruidNodeDiscoveryProvider(podInfo, discoveryConfig, k8sApiClient);
    discoveryProvider.start();
    BooleanSupplier nodeInquirer = discoveryProvider.getForNode(testNode.getDruidNode(), NodeRole.ROUTER);
    Assert.assertFalse(nodeInquirer.getAsBoolean());
    DruidNodeDiscovery discovery = discoveryProvider.getForNodeRole(NodeRole.ROUTER);
    CountDownLatch nodeViewInitialized = new CountDownLatch(1);
    CountDownLatch nodeAppeared = new CountDownLatch(1);
    CountDownLatch nodeDisappeared = new CountDownLatch(1);
    discovery.registerListener(new DruidNodeDiscovery.Listener() {

        @Override
        public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
            Iterator<DiscoveryDruidNode> iter = nodes.iterator();
            if (iter.hasNext() && testNode.getDruidNode().getHostAndPort().equals(iter.next().getDruidNode().getHostAndPort())) {
                nodeAppeared.countDown();
            }
        }

        @Override
        public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
            Iterator<DiscoveryDruidNode> iter = nodes.iterator();
            if (iter.hasNext() && testNode.getDruidNode().getHostAndPort().equals(iter.next().getDruidNode().getHostAndPort())) {
                nodeDisappeared.countDown();
            }
        }

        @Override
        public void nodeViewInitialized() {
            nodeViewInitialized.countDown();
        }
    });
    nodeViewInitialized.await();
    K8sDruidNodeAnnouncer announcer = new K8sDruidNodeAnnouncer(podInfo, discoveryConfig, k8sApiClient, jsonMapper);
    announcer.announce(testNode);
    nodeAppeared.await();
    Assert.assertTrue(nodeInquirer.getAsBoolean());
    announcer.unannounce(testNode);
    nodeDisappeared.await();
    Assert.assertFalse(nodeInquirer.getAsBoolean());
    discoveryProvider.stop();
}
Also used : DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) CountDownLatch(java.util.concurrent.CountDownLatch) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) Iterator(java.util.Iterator) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) BooleanSupplier(java.util.function.BooleanSupplier) Test(org.junit.Test)

Example 7 with DruidNodeDiscovery

use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.

the class ITHighAvailabilityTest method testDiscoveryAndSelfDiscovery.

@Test
public void testDiscoveryAndSelfDiscovery() {
    ITRetryUtil.retryUntil(() -> {
        try {
            List<DruidNodeDiscovery> disco = ImmutableList.of(druidNodeDiscovery.getForNodeRole(NodeRole.COORDINATOR), druidNodeDiscovery.getForNodeRole(NodeRole.OVERLORD), druidNodeDiscovery.getForNodeRole(NodeRole.HISTORICAL), druidNodeDiscovery.getForNodeRole(NodeRole.MIDDLE_MANAGER), druidNodeDiscovery.getForNodeRole(NodeRole.INDEXER), druidNodeDiscovery.getForNodeRole(NodeRole.BROKER), druidNodeDiscovery.getForNodeRole(NodeRole.ROUTER));
            int servicesDiscovered = 0;
            for (DruidNodeDiscovery nodeRole : disco) {
                Collection<DiscoveryDruidNode> nodes = nodeRole.getAllNodes();
                servicesDiscovered += testSelfDiscovery(nodes);
            }
            return servicesDiscovered > 5;
        } catch (Throwable t) {
            return false;
        }
    }, true, RETRY_DELAY, NUM_RETRIES, "Standard services discovered");
}
Also used : DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) Test(org.testng.annotations.Test) AbstractIndexerTest(org.apache.druid.tests.indexer.AbstractIndexerTest)

Example 8 with DruidNodeDiscovery

use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.

the class HttpRemoteTaskRunnerTest method testFreshStartAndStop.

/*
  Simulates startup of Overlord. Overlord is then stopped and is expected to close down certain things.
   */
@Test(timeout = 60_000L)
public void testFreshStartAndStop() {
    TestDruidNodeDiscovery druidNodeDiscovery = new TestDruidNodeDiscovery();
    DruidNodeDiscoveryProvider druidNodeDiscoveryProvider = EasyMock.createMock(DruidNodeDiscoveryProvider.class);
    EasyMock.expect(druidNodeDiscoveryProvider.getForService(WorkerNodeService.DISCOVERY_SERVICE_KEY)).andReturn(druidNodeDiscovery).times(2);
    ProvisioningStrategy provisioningStrategy = EasyMock.createMock(ProvisioningStrategy.class);
    ProvisioningService provisioningService = EasyMock.createNiceMock(ProvisioningService.class);
    EasyMock.expect(provisioningStrategy.makeProvisioningService(isA(HttpRemoteTaskRunner.class))).andReturn(provisioningService);
    provisioningService.close();
    EasyMock.expectLastCall();
    EasyMock.replay(druidNodeDiscoveryProvider, provisioningStrategy, provisioningService);
    DiscoveryDruidNode druidNode1 = new DiscoveryDruidNode(new DruidNode("service", "host1", false, 8080, null, true, false), NodeRole.MIDDLE_MANAGER, ImmutableMap.of(WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0", WorkerConfig.DEFAULT_CATEGORY)));
    DiscoveryDruidNode druidNode2 = new DiscoveryDruidNode(new DruidNode("service", "host2", false, 8080, null, true, false), NodeRole.MIDDLE_MANAGER, ImmutableMap.of(WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip2", 2, "0", WorkerConfig.DEFAULT_CATEGORY)));
    HttpRemoteTaskRunner taskRunner = newHttpTaskRunnerInstance(druidNodeDiscoveryProvider, provisioningStrategy);
    taskRunner.start();
    druidNodeDiscovery.getListeners().get(0).nodesAdded(ImmutableList.of(druidNode1, druidNode2));
    ConcurrentMap<String, WorkerHolder> workers = taskRunner.getWorkersForTestingReadOnly();
    Assert.assertEquals(2, workers.size());
    Assert.assertTrue(workers.values().stream().noneMatch(w -> w.getUnderlyingSyncer().isExecutorShutdown()));
    workers.values().iterator().next().stop();
    taskRunner.stop();
    Assert.assertTrue(druidNodeDiscovery.getListeners().isEmpty());
    Assert.assertEquals(2, workers.size());
    Assert.assertTrue(workers.values().stream().allMatch(w -> w.getUnderlyingSyncer().isExecutorShutdown()));
    EasyMock.verify(druidNodeDiscoveryProvider, provisioningStrategy, provisioningService);
}
Also used : DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) EasyMock.isA(org.easymock.EasyMock.isA) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(com.google.common.base.Optional) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) NoopProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.NoopProvisioningStrategy) TaskAnnouncement(org.apache.druid.indexing.worker.TaskAnnouncement) IAE(org.apache.druid.java.util.common.IAE) ImmutableSet(com.google.common.collect.ImmutableSet) Execs(org.apache.druid.java.util.common.concurrent.Execs) ImmutableMap(com.google.common.collect.ImmutableMap) DSuppliers(org.apache.druid.common.guava.DSuppliers) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) TaskState(org.apache.druid.indexer.TaskState) NoopTask(org.apache.druid.indexing.common.task.NoopTask) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) NodeRole(org.apache.druid.discovery.NodeRole) WorkerNodeService(org.apache.druid.discovery.WorkerNodeService) TaskStorage(org.apache.druid.indexing.overlord.TaskStorage) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) Iterables(com.google.common.collect.Iterables) HttpClient(org.apache.druid.java.util.http.client.HttpClient) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) HttpRemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.HttpRemoteTaskRunnerConfig) AtomicReference(java.util.concurrent.atomic.AtomicReference) TaskStatus(org.apache.druid.indexer.TaskStatus) Worker(org.apache.druid.indexing.worker.Worker) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ImmutableList(com.google.common.collect.ImmutableList) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Predicates(com.google.common.base.Predicates) DefaultWorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.DefaultWorkerBehaviorConfig) TaskRunnerListener(org.apache.druid.indexing.overlord.TaskRunnerListener) ProvisioningService(org.apache.druid.indexing.overlord.autoscaling.ProvisioningService) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Before(org.junit.Before) Period(org.joda.time.Period) WorkerConfig(org.apache.druid.indexing.worker.config.WorkerConfig) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) IndexerZkConfig(org.apache.druid.server.initialization.IndexerZkConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskLocation(org.apache.druid.indexer.TaskLocation) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) ProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.ProvisioningStrategy) TestHelper(org.apache.druid.segment.TestHelper) LifecycleLock(org.apache.druid.concurrent.LifecycleLock) DruidNode(org.apache.druid.server.DruidNode) TaskRunnerWorkItem(org.apache.druid.indexing.overlord.TaskRunnerWorkItem) Assert(org.junit.Assert) WorkerNodeService(org.apache.druid.discovery.WorkerNodeService) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) ProvisioningService(org.apache.druid.indexing.overlord.autoscaling.ProvisioningService) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) NoopProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.NoopProvisioningStrategy) ProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.ProvisioningStrategy) Test(org.junit.Test)

Example 9 with DruidNodeDiscovery

use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.

the class CommonCacheNotifier method sendUpdate.

private List<ListenableFuture<StatusResponseHolder>> sendUpdate(String updatedAuthenticatorPrefix, byte[] serializedEntity) {
    List<ListenableFuture<StatusResponseHolder>> futures = new ArrayList<>();
    for (NodeRole nodeRole : NODE_TYPES) {
        DruidNodeDiscovery nodeDiscovery = discoveryProvider.getForNodeRole(nodeRole);
        Collection<DiscoveryDruidNode> nodes = nodeDiscovery.getAllNodes();
        for (DiscoveryDruidNode node : nodes) {
            URL listenerURL = getListenerURL(node.getDruidNode(), StringUtils.format(baseUrl, StringUtils.urlEncode(updatedAuthenticatorPrefix)));
            // best effort, if this fails, remote node will poll and pick up the update eventually
            Request req = new Request(HttpMethod.POST, listenerURL);
            req.setContent(MediaType.APPLICATION_JSON, serializedEntity);
            BasicAuthDBConfig itemConfig = itemConfigMap.get(updatedAuthenticatorPrefix);
            ListenableFuture<StatusResponseHolder> future = httpClient.go(req, new ResponseHandler(), Duration.millis(itemConfig.getCacheNotificationTimeout()));
            futures.add(future);
        }
    }
    return futures;
}
Also used : HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ArrayList(java.util.ArrayList) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) NodeRole(org.apache.druid.discovery.NodeRole) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder)

Example 10 with DruidNodeDiscovery

use of org.apache.druid.discovery.DruidNodeDiscovery in project druid by druid-io.

the class HttpRemoteTaskRunner method startWorkersHandling.

private void startWorkersHandling() throws InterruptedException {
    final CountDownLatch workerViewInitialized = new CountDownLatch(1);
    DruidNodeDiscovery druidNodeDiscovery = druidNodeDiscoveryProvider.getForService(WorkerNodeService.DISCOVERY_SERVICE_KEY);
    this.nodeDiscoveryListener = new DruidNodeDiscovery.Listener() {

        @Override
        public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
            nodes.forEach(node -> addWorker(toWorker(node)));
        }

        @Override
        public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
            nodes.forEach(node -> removeWorker(toWorker(node)));
        }

        @Override
        public void nodeViewInitialized() {
            // CountDownLatch.countDown() does nothing when count has already reached 0.
            workerViewInitialized.countDown();
        }
    };
    druidNodeDiscovery.registerListener(nodeDiscoveryListener);
    long workerDiscoveryStartTime = System.currentTimeMillis();
    while (!workerViewInitialized.await(30, TimeUnit.SECONDS)) {
        if (System.currentTimeMillis() - workerDiscoveryStartTime > TimeUnit.MINUTES.toMillis(5)) {
            throw new ISE("Couldn't discover workers.");
        } else {
            log.info("Waiting for worker discovery...");
        }
    }
    log.info("[%s] Workers are discovered.", workers.size());
    // We would start assigning tasks which are pretty soon going to be reported by discovered workers.
    for (WorkerHolder worker : workers.values()) {
        log.info("Waiting for worker[%s] to sync state...", worker.getWorker().getHost());
        worker.waitForInitialization();
    }
    log.info("Workers have sync'd state successfully.");
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) ScheduledFuture(java.util.concurrent.ScheduledFuture) RemoteTaskRunnerWorkItem(org.apache.druid.indexing.overlord.RemoteTaskRunnerWorkItem) TaskLogStreamer(org.apache.druid.tasklogs.TaskLogStreamer) URL(java.net.URL) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) Collections2(com.google.common.collect.Collections2) LifecycleStart(org.apache.druid.java.util.common.lifecycle.LifecycleStart) Pair(org.apache.druid.java.util.common.Pair) Optional(com.google.common.base.Optional) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskAnnouncement(org.apache.druid.indexing.worker.TaskAnnouncement) WorkerBehaviorConfig(org.apache.druid.indexing.overlord.setup.WorkerBehaviorConfig) DateTimes(org.apache.druid.java.util.common.DateTimes) Execs(org.apache.druid.java.util.common.concurrent.Execs) ImmutableMap(com.google.common.collect.ImmutableMap) GuardedBy(com.google.errorprone.annotations.concurrent.GuardedBy) InputStreamResponseHandler(org.apache.druid.java.util.http.client.response.InputStreamResponseHandler) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Collectors(java.util.stream.Collectors) TaskState(org.apache.druid.indexer.TaskState) WorkerTaskRunnerConfig(org.apache.druid.indexing.overlord.config.WorkerTaskRunnerConfig) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Predicate(com.google.common.base.Predicate) WorkerNodeService(org.apache.druid.discovery.WorkerNodeService) TaskStorage(org.apache.druid.indexing.overlord.TaskStorage) WorkerSelectStrategy(org.apache.druid.indexing.overlord.setup.WorkerSelectStrategy) Joiner(com.google.common.base.Joiner) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ScheduledExecutors(org.apache.druid.java.util.common.concurrent.ScheduledExecutors) HttpClient(org.apache.druid.java.util.http.client.HttpClient) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Supplier(com.google.common.base.Supplier) HashMap(java.util.HashMap) HttpRemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.HttpRemoteTaskRunnerConfig) TaskStatus(org.apache.druid.indexer.TaskStatus) ScalingStats(org.apache.druid.indexing.overlord.autoscaling.ScalingStats) Worker(org.apache.druid.indexing.worker.Worker) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ImmutableList(com.google.common.collect.ImmutableList) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop) Request(org.apache.druid.java.util.http.client.Request) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskRunnerListener(org.apache.druid.indexing.overlord.TaskRunnerListener) ByteSource(com.google.common.io.ByteSource) ProvisioningService(org.apache.druid.indexing.overlord.autoscaling.ProvisioningService) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) Nullable(javax.annotation.Nullable) ExecutorService(java.util.concurrent.ExecutorService) ImmutableWorkerInfo(org.apache.druid.indexing.overlord.ImmutableWorkerInfo) Period(org.joda.time.Period) TaskRunnerUtils(org.apache.druid.indexing.overlord.TaskRunnerUtils) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) KeeperException(org.apache.zookeeper.KeeperException) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) IndexerZkConfig(org.apache.druid.server.initialization.IndexerZkConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Throwables(com.google.common.base.Throwables) TaskLocation(org.apache.druid.indexer.TaskLocation) WorkerTaskRunner(org.apache.druid.indexing.overlord.WorkerTaskRunner) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) FutureCallback(com.google.common.util.concurrent.FutureCallback) RunnerTaskState(org.apache.druid.indexer.RunnerTaskState) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ProvisioningStrategy(org.apache.druid.indexing.overlord.autoscaling.ProvisioningStrategy) Futures(com.google.common.util.concurrent.Futures) LifecycleLock(org.apache.druid.concurrent.LifecycleLock) ListenableScheduledFuture(com.google.common.util.concurrent.ListenableScheduledFuture) TaskRunnerWorkItem(org.apache.druid.indexing.overlord.TaskRunnerWorkItem) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ISE(org.apache.druid.java.util.common.ISE) CountDownLatch(java.util.concurrent.CountDownLatch)

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