Search in sources :

Example 1 with Announcer

use of org.apache.druid.curator.announcement.Announcer 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 2 with Announcer

use of org.apache.druid.curator.announcement.Announcer in project druid by druid-io.

the class BatchServerInventoryViewTest method setUp.

@Before
public void setUp() throws Exception {
    testingCluster = new TestingCluster(1);
    testingCluster.start();
    cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(true)).build();
    cf.start();
    cf.blockUntilConnected();
    cf.create().creatingParentsIfNeeded().forPath(TEST_BASE_PATH);
    jsonMapper = TestHelper.makeJsonMapper();
    announcer = new Announcer(cf, Execs.directExecutor());
    announcer.start();
    DruidServerMetadata serverMetadata = new DruidServerMetadata("id", "host", null, Long.MAX_VALUE, ServerType.HISTORICAL, "tier", 0);
    ZkPathsConfig zkPathsConfig = new ZkPathsConfig() {

        @Override
        public String getBase() {
            return TEST_BASE_PATH;
        }
    };
    serverAnnouncer = new CuratorDataSegmentServerAnnouncer(serverMetadata, zkPathsConfig, announcer, jsonMapper);
    serverAnnouncer.announce();
    segmentAnnouncer = new BatchDataSegmentAnnouncer(serverMetadata, new BatchDataSegmentAnnouncerConfig() {

        @Override
        public int getSegmentsPerNode() {
            return 50;
        }
    }, zkPathsConfig, announcer, jsonMapper);
    testSegments = Sets.newConcurrentHashSet();
    for (int i = 0; i < INITIAL_SEGMENTS; i++) {
        testSegments.add(makeSegment(i));
    }
    batchServerInventoryView = new BatchServerInventoryView(new ZkPathsConfig() {

        @Override
        public String getBase() {
            return TEST_BASE_PATH;
        }
    }, cf, jsonMapper, Predicates.alwaysTrue(), "test");
    batchServerInventoryView.start();
    inventoryUpdateCounter.set(0);
    filteredBatchServerInventoryView = new BatchServerInventoryView(new ZkPathsConfig() {

        @Override
        public String getBase() {
            return TEST_BASE_PATH;
        }
    }, cf, jsonMapper, new Predicate<Pair<DruidServerMetadata, DataSegment>>() {

        @Override
        public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input) {
            return input.rhs.getInterval().getStart().isBefore(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS));
        }
    }, "test") {

        @Override
        protected DruidServer addInnerInventory(DruidServer container, String inventoryKey, Set<DataSegment> inventory) {
            DruidServer server = super.addInnerInventory(container, inventoryKey, inventory);
            inventoryUpdateCounter.incrementAndGet();
            return server;
        }
    };
    filteredBatchServerInventoryView.start();
}
Also used : BatchServerInventoryView(org.apache.druid.client.BatchServerInventoryView) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BatchDataSegmentAnnouncerConfig(org.apache.druid.server.initialization.BatchDataSegmentAnnouncerConfig) DruidServer(org.apache.druid.client.DruidServer) DruidServerMetadata(org.apache.druid.server.coordination.DruidServerMetadata) PotentiallyGzippedCompressionProvider(org.apache.druid.curator.PotentiallyGzippedCompressionProvider) DataSegment(org.apache.druid.timeline.DataSegment) CuratorDataSegmentServerAnnouncer(org.apache.druid.server.coordination.CuratorDataSegmentServerAnnouncer) Predicate(com.google.common.base.Predicate) TestingCluster(org.apache.curator.test.TestingCluster) Announcer(org.apache.druid.curator.announcement.Announcer) CuratorDataSegmentServerAnnouncer(org.apache.druid.server.coordination.CuratorDataSegmentServerAnnouncer) DataSegmentServerAnnouncer(org.apache.druid.server.coordination.DataSegmentServerAnnouncer) BatchDataSegmentAnnouncer(org.apache.druid.server.coordination.BatchDataSegmentAnnouncer) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) BatchDataSegmentAnnouncer(org.apache.druid.server.coordination.BatchDataSegmentAnnouncer) Nullable(javax.annotation.Nullable) Pair(org.apache.druid.java.util.common.Pair) Before(org.junit.Before)

Aggregations

Announcer (org.apache.druid.curator.announcement.Announcer)2 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)2 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Predicate (com.google.common.base.Predicate)1 HashSet (java.util.HashSet)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Nullable (javax.annotation.Nullable)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1 TestingCluster (org.apache.curator.test.TestingCluster)1 BatchServerInventoryView (org.apache.druid.client.BatchServerInventoryView)1 DruidServer (org.apache.druid.client.DruidServer)1 PotentiallyGzippedCompressionProvider (org.apache.druid.curator.PotentiallyGzippedCompressionProvider)1 DiscoveryDruidNode (org.apache.druid.discovery.DiscoveryDruidNode)1 DruidNodeDiscovery (org.apache.druid.discovery.DruidNodeDiscovery)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 Pair (org.apache.druid.java.util.common.Pair)1 DruidNode (org.apache.druid.server.DruidNode)1 BatchDataSegmentAnnouncer (org.apache.druid.server.coordination.BatchDataSegmentAnnouncer)1 CuratorDataSegmentServerAnnouncer (org.apache.druid.server.coordination.CuratorDataSegmentServerAnnouncer)1