use of org.apache.pulsar.broker.service.Topic in project incubator-pulsar by apache.
the class PersistentTopicsBase method internalGetStats.
protected PersistentTopicStats internalGetStats(boolean authoritative) {
validateAdminAndClientPermission();
if (topicName.isGlobal()) {
validateGlobalNamespaceOwnership(namespaceName);
}
validateTopicOwnership(topicName, authoritative);
Topic topic = getTopicReference(topicName);
return topic.getStats();
}
use of org.apache.pulsar.broker.service.Topic in project incubator-pulsar by apache.
the class PulsarService method loadNamespaceTopics.
/**
* Load all the topics contained in a namespace
*
* @param bundle
* <code>NamespaceBundle</code> to identify the service unit
* @throws Exception
*/
public void loadNamespaceTopics(NamespaceBundle bundle) {
executor.submit(() -> {
LOG.info("Loading all topics on bundle: {}", bundle);
NamespaceName nsName = bundle.getNamespaceObject();
List<CompletableFuture<Topic>> persistentTopics = Lists.newArrayList();
long topicLoadStart = System.nanoTime();
for (String topic : getNamespaceService().getListOfTopics(nsName)) {
try {
TopicName topicName = TopicName.get(topic);
if (bundle.includes(topicName)) {
CompletableFuture<Topic> future = brokerService.getTopic(topic);
if (future != null) {
persistentTopics.add(future);
}
}
} catch (Throwable t) {
LOG.warn("Failed to preload topic {}", topic, t);
}
}
if (!persistentTopics.isEmpty()) {
FutureUtil.waitForAll(persistentTopics).thenRun(() -> {
double topicLoadTimeSeconds = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - topicLoadStart) / 1000.0;
LOG.info("Loaded {} topics on {} -- time taken: {} seconds", persistentTopics.size(), bundle, topicLoadTimeSeconds);
});
}
return null;
});
}
use of org.apache.pulsar.broker.service.Topic in project incubator-pulsar by apache.
the class NonPersistentTopics method getTopicReference.
private Topic getTopicReference(TopicName topicName) {
try {
Topic topic = pulsar().getBrokerService().getTopicReference(topicName.toString());
checkNotNull(topic);
return topic;
} catch (Exception e) {
throw new RestException(Status.NOT_FOUND, "Topic not found");
}
}
use of org.apache.pulsar.broker.service.Topic in project incubator-pulsar by apache.
the class NonPersistentTopics method getTopicReference.
private Topic getTopicReference(TopicName topicName) {
try {
Topic topic = pulsar().getBrokerService().getTopicReference(topicName.toString());
checkNotNull(topic);
return topic;
} catch (Exception e) {
throw new RestException(Status.NOT_FOUND, "Topic not found");
}
}
use of org.apache.pulsar.broker.service.Topic in project incubator-pulsar by apache.
the class NonPersistentTopics method getInternalStats.
@GET
@Path("{property}/{namespace}/{topic}/internalStats")
@ApiOperation(value = "Get the internal stats for the topic.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Topic does not exist") })
public PersistentTopicInternalStats getInternalStats(@PathParam("property") String property, @PathParam("namespace") String namespace, @PathParam("topic") @Encoded String encodedTopic, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateTopicName(property, namespace, encodedTopic);
validateAdminOperationOnTopic(topicName, authoritative);
Topic topic = getTopicReference(topicName);
return topic.getInternalStats();
}
Aggregations