Search in sources :

Example 6 with TopicName

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

the class PersistentTopicsImpl method getPartitionedStatsAsync.

@Override
public CompletableFuture<PartitionedTopicStats> getPartitionedStatsAsync(String topic, boolean perPartition) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "partitioned-stats");
    final CompletableFuture<PartitionedTopicStats> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<PartitionedTopicStats>() {

        @Override
        public void completed(PartitionedTopicStats response) {
            if (!perPartition) {
                response.partitions.clear();
            }
            future.complete(response);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PartitionedTopicStats(org.apache.pulsar.common.policies.data.PartitionedTopicStats) WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 7 with TopicName

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

the class PersistentTopicsImpl method getStatsAsync.

@Override
public CompletableFuture<PersistentTopicStats> getStatsAsync(String topic) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "stats");
    final CompletableFuture<PersistentTopicStats> future = new CompletableFuture<>();
    asyncGetRequest(path, 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) WebTarget(javax.ws.rs.client.WebTarget) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 8 with TopicName

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

the class PersistentTopicsImpl method terminateTopicAsync.

@Override
public CompletableFuture<MessageId> terminateTopicAsync(String topic) {
    TopicName tn = validateTopic(topic);
    final CompletableFuture<MessageId> future = new CompletableFuture<>();
    try {
        final WebTarget path = topicPath(tn, "terminate");
        request(path).async().post(Entity.entity("", MediaType.APPLICATION_JSON), new InvocationCallback<MessageIdImpl>() {

            @Override
            public void completed(MessageIdImpl messageId) {
                future.complete(messageId);
            }

            @Override
            public void failed(Throwable throwable) {
                log.warn("[{}] Failed to perform http post request: {}", path.getUri(), throwable.getMessage());
                future.completeExceptionally(getApiException(throwable.getCause()));
            }
        });
    } catch (PulsarAdminException cae) {
        future.completeExceptionally(cae);
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) TopicName(org.apache.pulsar.common.naming.TopicName) MessageId(org.apache.pulsar.client.api.MessageId)

Example 9 with TopicName

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

the class PersistentTopicsImpl method resetCursor.

@Override
public void resetCursor(String topic, String subName, MessageId messageId) throws PulsarAdminException {
    try {
        TopicName tn = validateTopic(topic);
        String encodedSubName = Codec.encode(subName);
        WebTarget path = topicPath(tn, "subscription", encodedSubName, "resetcursor");
        request(path).post(Entity.entity(messageId, MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) ServerErrorException(javax.ws.rs.ServerErrorException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 10 with TopicName

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

the class PersistentTopicsImpl method createSubscriptionAsync.

@Override
public CompletableFuture<Void> createSubscriptionAsync(String topic, String subscriptionName, MessageId messageId) {
    TopicName tn = validateTopic(topic);
    String encodedSubName = Codec.encode(subscriptionName);
    WebTarget path = topicPath(tn, "subscription", encodedSubName);
    return asyncPutRequest(path, Entity.entity(messageId, 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