Search in sources :

Example 1 with TopicName

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

the class NamespaceBundlesTest method testSplitBundleInTwo.

@Test
public void testSplitBundleInTwo() throws Exception {
    final int NO_BUNDLES = 2;
    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);
    // (1) split : [0x00000000,0xffffffff] => [0x00000000_0x7fffffff,0x7fffffff_0xffffffff]
    Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = factory.splitBundles(bundle, NO_BUNDLES);
    assertNotNull(splitBundles);
    assertBundleDivideInTwo(bundle, splitBundles.getRight(), NO_BUNDLES);
    // (2) split: [0x00000000,0x7fffffff] => [0x00000000_0x3fffffff,0x3fffffff_0x7fffffff],
    // [0x7fffffff,0xffffffff] => [0x7fffffff_0xbfffffff,0xbfffffff_0xffffffff]
    NamespaceBundleFactory utilityFactory = getNamespaceBundleFactory();
    assertBundles(utilityFactory, nsname, bundle, splitBundles, NO_BUNDLES);
    // (3) split: [0x00000000,0x3fffffff] => [0x00000000_0x1fffffff,0x1fffffff_0x3fffffff],
    // [0x3fffffff,0x7fffffff] => [0x3fffffff_0x5fffffff,0x5fffffff_0x7fffffff]
    Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, splitBundles.getLeft(), splitBundles.getRight().get(0), NO_BUNDLES);
    assertBundles(utilityFactory, nsname, splitBundles.getRight().get(0), splitChildBundles, NO_BUNDLES);
    // (4) split: [0x7fffffff,0xbfffffff] => [0x7fffffff_0x9fffffff,0x9fffffff_0xbfffffff],
    // [0xbfffffff,0xffffffff] => [0xbfffffff_0xdfffffff,0xdfffffff_0xffffffff]
    splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, splitBundles.getLeft(), splitBundles.getRight().get(1), NO_BUNDLES);
    assertBundles(utilityFactory, nsname, splitBundles.getRight().get(1), splitChildBundles, NO_BUNDLES);
}
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)

Example 2 with TopicName

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

the class CliCommand method validateNonPersistentTopic.

String validateNonPersistentTopic(List<String> params) {
    String topic = checkArgument(params);
    TopicName topicName = TopicName.get(topic);
    if (topicName.getDomain() != TopicDomain.non_persistent) {
        throw new ParameterException("Need to provide a non-persistent topic name");
    }
    return topicName.toString();
}
Also used : ParameterException(com.beust.jcommander.ParameterException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 3 with TopicName

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

the class NonPersistentTopicsImpl method getPartitionedTopicMetadataAsync.

@Override
public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadataAsync(String topic) {
    TopicName topicName = validateTopic(topic);
    final CompletableFuture<PartitionedTopicMetadata> future = new CompletableFuture<>();
    WebTarget path = topicPath(topicName, "partitions");
    asyncGetRequest(path, 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) WebTarget(javax.ws.rs.client.WebTarget) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 4 with TopicName

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

the class NonPersistentTopicsImpl method createPartitionedTopicAsync.

@Override
public CompletableFuture<Void> createPartitionedTopicAsync(String topic, int numPartitions) {
    checkArgument(numPartitions > 1, "Number of partitions should be more than 1");
    TopicName topicName = validateTopic(topic);
    WebTarget path = topicPath(topicName, "partitions");
    return asyncPutRequest(path, Entity.entity(numPartitions, MediaType.APPLICATION_JSON));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 5 with TopicName

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

the class NonPersistentTopicsImpl method unloadAsync.

@Override
public CompletableFuture<Void> unloadAsync(String topic) {
    TopicName topicName = validateTopic(topic);
    WebTarget path = topicPath(topicName, "unload");
    return asyncPutRequest(path, Entity.entity("", MediaType.APPLICATION_JSON));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Aggregations

TopicName (org.apache.pulsar.common.naming.TopicName)127 Test (org.testng.annotations.Test)54 CompletableFuture (java.util.concurrent.CompletableFuture)43 WebTarget (javax.ws.rs.client.WebTarget)32 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)23 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)23 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 List (java.util.List)22 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)22 Map (java.util.Map)20 ExecutionException (java.util.concurrent.ExecutionException)20 TimeUnit (java.util.concurrent.TimeUnit)20 NamingException (org.apache.pulsar.broker.service.BrokerServiceException.NamingException)18 Field (java.lang.reflect.Field)17 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)17 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)17 ByteBuf (io.netty.buffer.ByteBuf)15 Set (java.util.Set)15 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)14