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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations