Search in sources :

Example 1 with ManagedLedgerOfflineBacklog

use of org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog in project pulsar by yahoo.

the class PersistentTopics method getBacklog.

@GET
@Path("{property}/{cluster}/{namespace}/{destination}/backlog")
@ApiOperation(value = "Get estimated backlog for offline topic.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public PersistentOfflineTopicStats getBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    destination = decode(destination);
    validateAdminAccessOnProperty(property);
    // note that we do not want to load the topic and hence skip validateAdminOperationOnDestination()
    try {
        policiesCache().get(path("policies", property, cluster, namespace));
    } catch (KeeperException.NoNodeException e) {
        log.warn("[{}] Failed to get topic backlog {}/{}/{}: Namespace does not exist", clientAppId(), property, cluster, namespace);
        throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to get topic backlog {}/{}/{}", clientAppId(), property, cluster, namespace, e);
        throw new RestException(e);
    }
    DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination);
    PersistentOfflineTopicStats offlineTopicStats = null;
    try {
        offlineTopicStats = pulsar().getBrokerService().getOfflineTopicStat(dn);
        if (offlineTopicStats != null) {
            // offline topic stat has a cost - so use cached value until TTL
            long elapsedMs = System.currentTimeMillis() - offlineTopicStats.statGeneratedAt.getTime();
            if (TimeUnit.MINUTES.convert(elapsedMs, TimeUnit.MILLISECONDS) < OFFLINE_TOPIC_STAT_TTL_MINS) {
                return offlineTopicStats;
            }
        }
        final ManagedLedgerConfig config = pulsar().getBrokerService().getManagedLedgerConfig(dn).get();
        ManagedLedgerOfflineBacklog offlineTopicBacklog = new ManagedLedgerOfflineBacklog(config.getDigestType(), config.getPassword(), pulsar().getAdvertisedAddress(), false);
        offlineTopicStats = offlineTopicBacklog.estimateUnloadedTopicBacklog((ManagedLedgerFactoryImpl) pulsar().getManagedLedgerFactory(), dn);
        pulsar().getBrokerService().cacheOfflineTopicStats(dn, offlineTopicStats);
    } catch (Exception exception) {
        throw new RestException(exception);
    }
    return offlineTopicStats;
}
Also used : ManagedLedgerOfflineBacklog(org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog) PersistentOfflineTopicStats(com.yahoo.pulsar.common.policies.data.PersistentOfflineTopicStats) RestException(com.yahoo.pulsar.broker.web.RestException) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) TopicBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) PreconditionFailedException(com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) NotFoundException(com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException) NotAllowedException(com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NotAllowedException (com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException)1 RestException (com.yahoo.pulsar.broker.web.RestException)1 NotFoundException (com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException)1 PreconditionFailedException (com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 PersistentOfflineTopicStats (com.yahoo.pulsar.common.policies.data.PersistentOfflineTopicStats)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)1 ManagedLedgerFactoryImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)1 ManagedLedgerOfflineBacklog (org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog)1 KeeperException (org.apache.zookeeper.KeeperException)1