Search in sources :

Example 1 with PersistentTopicStats

use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.

the class PersistentTopicsImpl method getStatsAsync.

@Override
public CompletableFuture<PersistentTopicStats> getStatsAsync(String topic) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "stats");
    final CompletableFuture<PersistentTopicStats> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<PersistentTopicStats>() {

        @Override
        public void completed(PersistentTopicStats response) {
            future.complete(response);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WebTarget(javax.ws.rs.client.WebTarget) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 2 with PersistentTopicStats

use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.

the class MembershipManager method getCurrentMembership.

public List<WorkerInfo> getCurrentMembership() {
    List<WorkerInfo> workerIds = new LinkedList<>();
    PersistentTopicStats persistentTopicStats = null;
    PulsarAdmin pulsarAdmin = this.getPulsarAdminClient();
    try {
        persistentTopicStats = pulsarAdmin.persistentTopics().getStats(this.workerConfig.getClusterCoordinationTopic());
    } catch (PulsarAdminException e) {
        log.error("Failed to get status of coordinate topic {}", this.workerConfig.getClusterCoordinationTopic(), e);
        throw new RuntimeException(e);
    }
    for (ConsumerStats consumerStats : persistentTopicStats.subscriptions.get(COORDINATION_TOPIC_SUBSCRIPTION).consumers) {
        WorkerInfo workerInfo = WorkerInfo.parseFrom(consumerStats.metadata.get(WORKER_IDENTIFIER));
        workerIds.add(workerInfo);
    }
    return workerIds;
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ConsumerStats(org.apache.pulsar.common.policies.data.ConsumerStats) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) LinkedList(java.util.LinkedList)

Example 3 with PersistentTopicStats

use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.

the class BrokerService method getTopicStats.

public Map<String, PersistentTopicStats> getTopicStats() {
    HashMap<String, PersistentTopicStats> stats = new HashMap<>();
    topics.forEach((name, topicFuture) -> {
        Topic currentTopic = topicFuture.getNow(null);
        if (currentTopic != null) {
            stats.put(name, currentTopic.getStats());
        }
    });
    return stats;
}
Also used : ConcurrentOpenHashMap(org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap) HashMap(java.util.HashMap) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) NonPersistentTopic(org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic)

Example 4 with PersistentTopicStats

use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.

the class PulsarSpoutTest method testNoSharedConsumer.

@Test
public void testNoSharedConsumer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    pulsarSpoutConf.setSharedConsumerEnabled(false);
    PulsarSpout otherSpout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector otherMockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherSpout.open(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 2);
    otherSpout.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
}
Also used : SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 5 with PersistentTopicStats

use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.

the class PulsarSpoutTest method testSharedConsumer.

@Test
public void testSharedConsumer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    PulsarSpout otherSpout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector otherMockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherSpout.open(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    otherSpout.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
}
Also used : SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Aggregations

PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)27 Test (org.testng.annotations.Test)22 PulsarClient (org.apache.pulsar.client.api.PulsarClient)12 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)6 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)6 BacklogQuota (org.apache.pulsar.common.policies.data.BacklogQuota)6 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)6 URL (java.net.URL)5 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)5 PartitionedTopicStats (org.apache.pulsar.common.policies.data.PartitionedTopicStats)4 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)3 ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)3 TopologyContext (org.apache.storm.task.TopologyContext)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WebTarget (javax.ws.rs.client.WebTarget)2 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)2