Search in sources :

Example 76 with NamespaceName

use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.

the class NamespacesImpl method clearNamespaceBacklogForSubscription.

@Override
public void clearNamespaceBacklogForSubscription(String namespace, String subscription) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "clearBacklog", subscription);
        request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 77 with NamespaceName

use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.

the class NamespacesImpl method clearNamespaceBacklog.

@Override
public void clearNamespaceBacklog(String namespace) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "clearBacklog");
        request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 78 with NamespaceName

use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.

the class NamespacesImpl method clearNamespaceBundleBacklogForSubscription.

@Override
public void clearNamespaceBundleBacklogForSubscription(String namespace, String bundle, String subscription) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, bundle, "clearBacklog", subscription);
        request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 79 with NamespaceName

use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.

the class PulsarClientImpl method patternTopicSubscribeAsync.

private <T> CompletableFuture<Consumer<T>> patternTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema) {
    String regex = conf.getTopicsPattern().pattern();
    TopicName destination = TopicName.get(regex);
    NamespaceName namespaceName = destination.getNamespaceObject();
    CompletableFuture<Consumer<T>> consumerSubscribedFuture = new CompletableFuture<>();
    lookup.getTopicsUnderNamespace(namespaceName).thenAccept(topics -> {
        if (log.isDebugEnabled()) {
            log.debug("Get topics under namespace {}, topics.size: {}", namespaceName.toString(), topics.size());
            topics.forEach(topicName -> log.debug("Get topics under namespace {}, topic: {}", namespaceName.toString(), topicName));
        }
        List<String> topicsList = topicsPatternFilter(topics, conf.getTopicsPattern());
        conf.getTopicNames().addAll(topicsList);
        ConsumerBase<T> consumer = new PatternTopicsConsumerImpl<>(conf.getTopicsPattern(), PulsarClientImpl.this, conf, externalExecutorProvider.getExecutor(), consumerSubscribedFuture, schema);
        synchronized (consumers) {
            consumers.put(consumer, Boolean.TRUE);
        }
    }).exceptionally(ex -> {
        log.warn("[{}] Failed to get topics under namespace", namespaceName);
        consumerSubscribedFuture.completeExceptionally(ex);
        return null;
    });
    return consumerSubscribedFuture;
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) TopicName(org.apache.pulsar.common.naming.TopicName) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ReaderConfigurationData(org.apache.pulsar.client.impl.conf.ReaderConfigurationData) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ConsumerBuilder(org.apache.pulsar.client.api.ConsumerBuilder) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProducerBuilder(org.apache.pulsar.client.api.ProducerBuilder) Lists(com.google.common.collect.Lists) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) ThreadFactory(java.util.concurrent.ThreadFactory) PulsarClient(org.apache.pulsar.client.api.PulsarClient) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ExecutorService(java.util.concurrent.ExecutorService) EventLoopGroup(io.netty.channel.EventLoopGroup) IdentityHashMap(java.util.IdentityHashMap) EventLoopUtil(org.apache.pulsar.common.util.netty.EventLoopUtil) Logger(org.slf4j.Logger) ReaderConfiguration(org.apache.pulsar.client.api.ReaderConfiguration) Reader(org.apache.pulsar.client.api.Reader) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) ProducerConfiguration(org.apache.pulsar.client.api.ProducerConfiguration) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) MessageId(org.apache.pulsar.client.api.MessageId) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) Pattern(java.util.regex.Pattern) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 80 with NamespaceName

use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.

the class NamespaceBundlesTest method testsplitBundles.

@Test
public void testsplitBundles() throws Exception {
    NamespaceName nsname = NamespaceName.get("pulsar/global/ns1");
    TopicName topicName = TopicName.get("persistent://pulsar/global/ns1/topic-1");
    NamespaceBundles bundles = factory.getBundles(nsname);
    NamespaceBundle bundle = bundles.findBundle(topicName);
    final int numberSplitBundles = 4;
    // (1) split in 4
    Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = factory.splitBundles(bundle, numberSplitBundles);
    // existing_no_bundles(1) +
    // additional_new_split_bundle(4) -
    // parent_target_bundle(1)
    int totalExpectedSplitBundles = bundles.getBundles().size() + numberSplitBundles - 1;
    validateSplitBundlesRange(bundles.getFullBundle(), splitBundles.getRight());
    assertEquals(totalExpectedSplitBundles, splitBundles.getLeft().getBundles().size());
    // (2) split in 4: first bundle from above split bundles
    NamespaceBundleFactory utilityFactory = getNamespaceBundleFactory();
    NamespaceBundles bundles2 = splitBundles.getLeft();
    NamespaceBundle testChildBundle = bundles2.getBundles().get(0);
    Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, bundles2, testChildBundle, numberSplitBundles);
    // existing_no_bundles(4) +
    // additional_new_split_bundle(4) -
    // parent_target_bundle(1)
    totalExpectedSplitBundles = bundles2.getBundles().size() + numberSplitBundles - 1;
    validateSplitBundlesRange(testChildBundle, splitChildBundles.getRight());
    assertEquals(totalExpectedSplitBundles, splitChildBundles.getLeft().getBundles().size());
    // (3) split in 3: second bundle from above split bundles
    NamespaceBundle testChildBundl2 = bundles2.getBundles().get(1);
    Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles2 = splitBundlesUtilFactory(utilityFactory, nsname, bundles2, testChildBundl2, 3);
    // existing_no_bundles(4) +
    // additional_new_split_bundle(3) -
    // parent_target_bundle(1)
    totalExpectedSplitBundles = bundles2.getBundles().size() + 3 - 1;
    validateSplitBundlesRange(testChildBundl2, splitChildBundles2.getRight());
    assertEquals(totalExpectedSplitBundles, splitChildBundles2.getLeft().getBundles().size());
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) ArrayList(java.util.ArrayList) List(java.util.List) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Aggregations

NamespaceName (org.apache.pulsar.common.naming.NamespaceName)99 WebTarget (javax.ws.rs.client.WebTarget)52 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)52 Test (org.testng.annotations.Test)27 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)26 List (java.util.List)15 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)13 RestException (org.apache.pulsar.broker.web.RestException)13 TopicName (org.apache.pulsar.common.naming.TopicName)13 Field (java.lang.reflect.Field)12 URL (java.net.URL)11 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)11 Policies (org.apache.pulsar.common.policies.data.Policies)10 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)8 BundlesData (org.apache.pulsar.common.policies.data.BundlesData)8 KeeperException (org.apache.zookeeper.KeeperException)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 HashSet (java.util.HashSet)6 CompletableFuture (java.util.concurrent.CompletableFuture)6