Search in sources :

Example 16 with PulsarAdminException

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

the class FunctionsImpl method getFunction.

@Override
public FunctionConfig getFunction(String tenant, String namespace, String function) throws PulsarAdminException {
    try {
        Response response = request(functions.path(tenant).path(namespace).path(function)).get();
        if (!response.getStatusInfo().equals(Response.Status.OK)) {
            throw new ClientErrorException(response);
        }
        String jsonResponse = response.readEntity(String.class);
        FunctionConfig.Builder functionConfigBuilder = FunctionConfig.newBuilder();
        Utils.mergeJson(jsonResponse, functionConfigBuilder);
        return functionConfigBuilder.build();
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : Response(javax.ws.rs.core.Response) FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) ClientErrorException(javax.ws.rs.ClientErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ClientErrorException(javax.ws.rs.ClientErrorException)

Example 17 with PulsarAdminException

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

the class FunctionsImpl method getFunctionStatus.

@Override
public FunctionStatusList getFunctionStatus(String tenant, String namespace, String function) throws PulsarAdminException {
    try {
        Response response = request(functions.path(tenant).path(namespace).path(function).path("status")).get();
        if (!response.getStatusInfo().equals(Response.Status.OK)) {
            throw new ClientErrorException(response);
        }
        String jsonResponse = response.readEntity(String.class);
        FunctionStatusList.Builder functionStatusBuilder = FunctionStatusList.newBuilder();
        Utils.mergeJson(jsonResponse, functionStatusBuilder);
        return functionStatusBuilder.build();
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : Response(javax.ws.rs.core.Response) FunctionStatusList(org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatusList) ClientErrorException(javax.ws.rs.ClientErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ClientErrorException(javax.ws.rs.ClientErrorException)

Example 18 with PulsarAdminException

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

the class FunctionsImpl method triggerFunction.

@Override
public String triggerFunction(String tenant, String namespace, String functionName, String triggerValue, String triggerFile) throws PulsarAdminException {
    try {
        final FormDataMultiPart mp = new FormDataMultiPart();
        if (triggerFile != null) {
            mp.bodyPart(new FileDataBodyPart("dataStream", new File(triggerFile), MediaType.APPLICATION_OCTET_STREAM_TYPE));
        }
        if (triggerValue != null) {
            mp.bodyPart(new FormDataBodyPart("data", triggerValue, MediaType.TEXT_PLAIN_TYPE));
        }
        String response = request(functions.path(tenant).path(namespace).path(functionName).path("trigger")).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA), String.class);
        return response;
    } 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)

Example 19 with PulsarAdminException

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

the class BrokerStatsImpl method getBrokerResourceAvailability.

public JsonObject getBrokerResourceAvailability(String namespace) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget admin = ns.isV2() ? adminV2BrokerStats : adminBrokerStats;
        String json = request(admin.path("/broker-resource-availability").path(ns.toString())).get(String.class);
        return new Gson().fromJson(json, JsonObject.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Gson(com.google.gson.Gson) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 20 with PulsarAdminException

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

the class NamespacesImpl method setMaxProducersPerTopic.

@Override
public void setMaxProducersPerTopic(String namespace, int maxProducersPerTopic) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "maxProducersPerTopic");
        request(path).post(Entity.entity(maxProducersPerTopic, 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)

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