Search in sources :

Example 11 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException 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 12 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException 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 13 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException 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)

Example 14 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.

the class ResourceQuotasImpl method getNamespaceBundleResourceQuota.

public ResourceQuota getNamespaceBundleResourceQuota(String namespace, String bundle) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, bundle);
        return request(path).get(ResourceQuota.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 15 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.

the class FunctionsImpl method updateFunction.

@Override
public void updateFunction(FunctionConfig functionConfig, String fileName) throws PulsarAdminException {
    try {
        final FormDataMultiPart mp = new FormDataMultiPart();
        if (fileName != null) {
            mp.bodyPart(new FileDataBodyPart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM_TYPE));
        }
        mp.bodyPart(new FormDataBodyPart("functionConfig", Utils.printJson(functionConfig), MediaType.APPLICATION_JSON_TYPE));
        request(functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName())).put(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) File(java.io.File) FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)89 WebTarget (javax.ws.rs.client.WebTarget)57 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)51 Test (org.testng.annotations.Test)18 ClientErrorException (javax.ws.rs.ClientErrorException)14 ExecutionException (java.util.concurrent.ExecutionException)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)12 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)10 ServerErrorException (javax.ws.rs.ServerErrorException)9 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)9 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)8 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)7 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)7 TopicName (org.apache.pulsar.common.naming.TopicName)6 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)6 RestException (org.apache.pulsar.broker.web.RestException)5 List (java.util.List)4 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)4 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)4