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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations