Search in sources :

Example 46 with DestinationName

use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.

the class PersistentTopicsImpl method getStatsAsync.

@Override
public CompletableFuture<PersistentTopicStats> getStatsAsync(String destination) {
    DestinationName ds = validateTopic(destination);
    final CompletableFuture<PersistentTopicStats> future = new CompletableFuture<>();
    asyncGetRequest(persistentTopics.path(ds.getNamespace()).path(ds.getEncodedLocalName()).path("stats"), 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) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) PersistentTopicStats(com.yahoo.pulsar.common.policies.data.PersistentTopicStats)

Example 47 with DestinationName

use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.

the class PersistentTopicsImpl method getPartitionedTopicMetadataAsync.

@Override
public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadataAsync(String destination) {
    DestinationName ds = validateTopic(destination);
    final CompletableFuture<PartitionedTopicMetadata> future = new CompletableFuture<>();
    asyncGetRequest(persistentTopics.path(ds.getNamespace()).path(ds.getEncodedLocalName()).path("partitions"), new InvocationCallback<PartitionedTopicMetadata>() {

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

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) PartitionedTopicMetadata(com.yahoo.pulsar.common.partition.PartitionedTopicMetadata)

Example 48 with DestinationName

use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.

the class PersistentTopicsImpl method resetCursorAsync.

@Override
public CompletableFuture<Void> resetCursorAsync(String destination, String subName, long timestamp) {
    DestinationName ds = validateTopic(destination);
    String encodedSubName = Codec.encode(subName);
    return asyncPostRequest(persistentTopics.path(ds.getNamespace()).path(ds.getEncodedLocalName()).path("subscription").path(encodedSubName).path("resetcursor").path(String.valueOf(timestamp)), Entity.entity("", MediaType.APPLICATION_JSON));
}
Also used : DestinationName(com.yahoo.pulsar.common.naming.DestinationName)

Example 49 with DestinationName

use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.

the class BacklogQuotaManager method handleExceededBacklogQuota.

/**
     * Handle exceeded backlog by using policies set in the zookeeper for given topic
     *
     * @param persistentTopic
     *            Topic on which backlog has been exceeded
     */
public void handleExceededBacklogQuota(PersistentTopic persistentTopic) {
    DestinationName destination = DestinationName.get(persistentTopic.getName());
    String namespace = destination.getNamespace();
    String policyPath = AdminResource.path("policies", namespace);
    BacklogQuota quota = getBacklogQuota(namespace, policyPath);
    log.info("Backlog quota exceeded for topic [{}]. Applying [{}] policy", persistentTopic.getName(), quota.getPolicy());
    switch(quota.getPolicy()) {
        case consumer_backlog_eviction:
            dropBacklog(persistentTopic, quota);
            break;
        case producer_exception:
        case producer_request_hold:
            disconnectProducers(persistentTopic);
            break;
        default:
            break;
    }
}
Also used : DestinationName(com.yahoo.pulsar.common.naming.DestinationName) BacklogQuota(com.yahoo.pulsar.common.policies.data.BacklogQuota)

Example 50 with DestinationName

use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.

the class BrokerService method removeTopicFromCache.

public void removeTopicFromCache(String topic) {
    try {
        DestinationName destination = DestinationName.get(topic);
        NamespaceBundle namespaceBundle = pulsar.getNamespaceService().getBundle(destination);
        checkArgument(namespaceBundle instanceof NamespaceBundle);
        String bundleName = namespaceBundle.toString();
        String namespaceName = destination.getNamespaceObject().toString();
        synchronized (multiLayerTopicsMap) {
            ConcurrentOpenHashMap<String, ConcurrentOpenHashMap<String, PersistentTopic>> namespaceMap = multiLayerTopicsMap.get(namespaceName);
            ConcurrentOpenHashMap<String, PersistentTopic> bundleMap = namespaceMap.get(bundleName);
            bundleMap.remove(topic);
            if (bundleMap.isEmpty()) {
                namespaceMap.remove(bundleName);
            }
            if (namespaceMap.isEmpty()) {
                multiLayerTopicsMap.remove(namespaceName);
                final ClusterReplicationMetrics clusterReplicationMetrics = pulsarStats.getClusterReplicationMetrics();
                replicationClients.forEach((cluster, client) -> {
                    clusterReplicationMetrics.remove(clusterReplicationMetrics.getKeyName(namespaceName, cluster));
                });
            }
        }
    } catch (Exception e) {
        log.warn("Got exception when retrieving bundle name during removeTopicFromCache", e);
    }
    topics.remove(topic);
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) ConcurrentOpenHashMap(com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashMap) ClusterReplicationMetrics(com.yahoo.pulsar.broker.stats.ClusterReplicationMetrics) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) PersistenceException(com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) KeeperException(org.apache.zookeeper.KeeperException) ServerMetadataException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException) IOException(java.io.IOException) ServiceUnitNotReadyException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)

Aggregations

DestinationName (com.yahoo.pulsar.common.naming.DestinationName)91 Test (org.testng.annotations.Test)36 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)33 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)26 CompletableFuture (java.util.concurrent.CompletableFuture)24 KeeperException (org.apache.zookeeper.KeeperException)23 PreconditionFailedException (com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)22 WebApplicationException (javax.ws.rs.WebApplicationException)21 IOException (java.io.IOException)20 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)19 RestException (com.yahoo.pulsar.broker.web.RestException)18 NotFoundException (com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException)18 PartitionedTopicMetadata (com.yahoo.pulsar.common.partition.PartitionedTopicMetadata)17 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)16 TopicBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException)16 Path (javax.ws.rs.Path)16 NotAllowedException (com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException)14 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)14 Field (java.lang.reflect.Field)14