Search in sources :

Example 21 with Topic

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();
}
Also used : Topic(org.apache.pulsar.broker.service.Topic) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic)

Example 22 with Topic

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;
    });
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Topic(org.apache.pulsar.broker.service.Topic) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 23 with Topic

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");
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) Topic(org.apache.pulsar.broker.service.Topic) NonPersistentTopic(org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic) RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException)

Example 24 with Topic

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");
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) Topic(org.apache.pulsar.broker.service.Topic) NonPersistentTopic(org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic) RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException)

Example 25 with Topic

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();
}
Also used : Topic(org.apache.pulsar.broker.service.Topic) NonPersistentTopic(org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Topic (org.apache.pulsar.broker.service.Topic)28 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)15 KeeperException (org.apache.zookeeper.KeeperException)15 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)13 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)11 TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)11 CompletableFuture (java.util.concurrent.CompletableFuture)10 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)10 RestException (org.apache.pulsar.broker.web.RestException)10 ExecutionException (java.util.concurrent.ExecutionException)9 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)9 WebApplicationException (javax.ws.rs.WebApplicationException)8 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)8 IOException (java.io.IOException)6 Subscription (org.apache.pulsar.broker.service.Subscription)6 ObjectObjectHashMap (com.carrotsearch.hppc.ObjectObjectHashMap)5 MoreObjects (com.google.common.base.MoreObjects)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 Lists (com.google.common.collect.Lists)5 Maps (com.google.common.collect.Maps)5