Search in sources :

Example 16 with TopicName

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

the class PersistentTopicsImpl method getInternalInfoAsync.

@Override
public CompletableFuture<JsonObject> getInternalInfoAsync(String topic) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "internal-info");
    final CompletableFuture<JsonObject> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<String>() {

        @Override
        public void completed(String response) {
            JsonObject json = new Gson().fromJson(response, JsonObject.class);
            future.complete(json);
        }

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

Example 17 with TopicName

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

the class PersistentTopicsImpl method grantPermission.

@Override
public void grantPermission(String topic, String role, Set<AuthAction> actions) throws PulsarAdminException {
    try {
        TopicName tn = TopicName.get(topic);
        WebTarget path = topicPath(tn, "permissions", role);
        request(path).post(Entity.entity(actions, 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 18 with TopicName

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

the class PersistentTopicsImpl method skipMessagesAsync.

@Override
public CompletableFuture<Void> skipMessagesAsync(String topic, String subName, long numMessages) {
    TopicName tn = validateTopic(topic);
    String encodedSubName = Codec.encode(subName);
    WebTarget path = topicPath(tn, "subscription", encodedSubName, "skip", String.valueOf(numMessages));
    return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 19 with TopicName

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

the class PersistentTopicsImpl method createSubscription.

@Override
public void createSubscription(String topic, String subscriptionName, MessageId messageId) throws PulsarAdminException {
    try {
        TopicName tn = validateTopic(topic);
        String encodedSubName = Codec.encode(subscriptionName);
        WebTarget path = topicPath(tn, "subscription", encodedSubName);
        request(path).put(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 20 with TopicName

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

the class PersistentTopicsImpl method getPermissions.

@Override
public Map<String, Set<AuthAction>> getPermissions(String topic) throws PulsarAdminException {
    try {
        TopicName tn = TopicName.get(topic);
        WebTarget path = topicPath(tn, "permissions");
        return request(path).get(new GenericType<Map<String, Set<AuthAction>>>() {
        });
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) 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) AuthAction(org.apache.pulsar.common.policies.data.AuthAction)

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