use of com.yahoo.pulsar.broker.web.RestException in project pulsar by yahoo.
the class BrokerStats method getBrokerResourceAvailability.
@GET
@Path("/broker-resource-availability/{property}/{cluster}/{namespace}")
@ApiOperation(value = "Broker availability report", notes = "This API gives the current broker availability in percent, each resource percentage usage is calculated and then" + "sum of all of the resource usage percent is called broker-resource-availability" + "<br/><br/>THIS API IS ONLY FOR USE BY TESTING FOR CONFIRMING NAMESPACE ALLOCATION ALGORITHM", response = ResourceUnit.class, responseContainer = "Map")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public Map<Long, Collection<ResourceUnit>> getBrokerResourceAvailability(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) throws Exception {
try {
NamespaceName ns = new NamespaceName(property, cluster, namespace);
SimpleLoadManagerImpl lm = (SimpleLoadManagerImpl) (pulsar().getLoadManager());
return lm.getResourceAvailabilityFor(ns).asMap();
} catch (Exception e) {
log.error("Unable to get Resource Availability - [{}]", e);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.broker.web.RestException in project pulsar by yahoo.
the class Brokers method getActiveBrokers.
@GET
@Path("/{cluster}")
@ApiOperation(value = "Get the list of active brokers (web service addresses) in the cluster.", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist") })
public Set<String> getActiveBrokers(@PathParam("cluster") String cluster) throws Exception {
validateSuperUserAccess();
validateClusterOwnership(cluster);
try {
// Add Native brokers
return pulsar().getLocalZkCache().getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT);
} catch (Exception e) {
LOG.error(String.format("[%s] Failed to get active broker list: cluster=%s", clientAppId(), cluster), e);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.broker.web.RestException in project pulsar by yahoo.
the class Brokers method getOwnedNamespaes.
@GET
@Path("/{cluster}/{broker}/ownedNamespaces")
@ApiOperation(value = "Get the list of namespaces served by the specific broker", response = NamespaceOwnershipStatus.class, responseContainer = "Map")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist") })
public Map<String, NamespaceOwnershipStatus> getOwnedNamespaes(@PathParam("cluster") String cluster, @PathParam("broker") String broker) throws Exception {
validateSuperUserAccess();
validateClusterOwnership(cluster);
validateBrokerName(broker);
try {
// now we validated that this is the broker specified in the request
return pulsar().getNamespaceService().getOwnedNameSpacesStatus();
} catch (Exception e) {
LOG.error("[{}] Failed to get the namespace ownership status. cluster={}, broker={}", clientAppId(), cluster, broker);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.broker.web.RestException in project pulsar by yahoo.
the class Namespaces method unsubscribeNamespace.
@POST
@Path("/{property}/{cluster}/{namespace}/unsubscribe/{subscription}")
@ApiOperation(value = "Unsubscribes the given subscription on all destinations on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void unsubscribeNamespace(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("subscription") String subscription, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
try {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName);
Exception exception = null;
for (NamespaceBundle nsBundle : bundles.getBundles()) {
try {
// check if the bundle is owned by any broker, if not then there are no subscriptions
if (pulsar().getNamespaceService().getOwner(nsBundle).isPresent()) {
// TODO: make this admin call asynchronous
pulsar().getAdminClient().namespaces().unsubscribeNamespaceBundle(nsName.toString(), nsBundle.getBundleRange(), subscription);
}
} catch (Exception e) {
if (exception == null) {
exception = e;
}
}
}
if (exception != null) {
if (exception instanceof PulsarAdminException) {
throw new RestException((PulsarAdminException) exception);
} else {
throw new RestException(exception.getCause());
}
}
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
throw new RestException(e);
}
log.info("[{}] Successfully unsubscribed {} on all the bundles for namespace {}", clientAppId(), subscription, nsName.toString());
}
use of com.yahoo.pulsar.broker.web.RestException in project pulsar by yahoo.
the class Namespaces method setRetention.
@POST
@Path("/{property}/{cluster}/{namespace}/retention")
@ApiOperation(value = " Set retention configuration on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist"), @ApiResponse(code = 409, message = "Concurrent modification"), @ApiResponse(code = 412, message = "Retention Quota must exceed backlog quota") })
public void setRetention(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, RetentionPolicies retention) {
validatePoliciesReadOnlyAccess();
try {
Stat nodeStat = new Stat();
final String path = path("policies", property, cluster, namespace);
byte[] content = globalZk().getData(path, null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
if (!checkQuotas(policies, retention)) {
log.warn("[{}] Failed to update retention configuration for namespace {}/{}/{}: conflicts with backlog quota", clientAppId(), property, cluster, namespace);
throw new RestException(Status.PRECONDITION_FAILED, "Retention Quota must exceed configured backlog quota for namespace.");
}
policies.retention_policies = retention;
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path("policies", property, cluster, namespace));
log.info("[{}] Successfully updated retention configuration: namespace={}/{}/{}, map={}", clientAppId(), property, cluster, namespace, jsonMapper().writeValueAsString(policies.retention_policies));
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update retention configuration for namespace {}/{}/{}: does not exist", clientAppId(), property, cluster, namespace);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to update retention configuration for namespace {}/{}/{}: concurrent modification", clientAppId(), property, cluster, namespace);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (RestException pfe) {
throw pfe;
} catch (Exception e) {
log.error("[{}] Failed to update retention configuration for namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
}
Aggregations