use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class ResourceQuotas method setNamespaceBundleResourceQuota.
@POST
@Path("/{property}/{cluster}/{namespace}/{bundle}")
@ApiOperation(value = "Set resource quota on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 409, message = "Concurrent modification") })
public void setNamespaceBundleResourceQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, ResourceQuota quota) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
NamespaceBundle nsBundle = validateNamespaceBundleRange(fqnn, policies.bundles, bundleRange);
try {
pulsar().getLocalZkCacheService().getResourceQuotaCache().setQuota(nsBundle, quota);
log.info("[{}] Successfully set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to set resource quota for namespace bundle {}: concurrent modification", clientAppId(), nsBundle.toString());
throw new RestException(Status.CONFLICT, "Cuncurrent modification on namespace bundle quota");
} catch (Exception e) {
log.error("[{}] Failed to set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
throw new RestException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class Namespaces method setNamespaceMessageTTL.
@POST
@Path("/{property}/{cluster}/{namespace}/messageTTL")
@ApiOperation(value = "Set message TTL in seconds for namespace")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), @ApiResponse(code = 412, message = "Invalid TTL") })
public void setNamespaceMessageTTL(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, int messageTTL) {
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
if (messageTTL < 0) {
throw new RestException(Status.PRECONDITION_FAILED, "Invalid value for message TTL");
}
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
Entry<Policies, Stat> policiesNode = null;
try {
// Force to read the data s.t. the watch to the cache content is setup.
policiesNode = policiesCache().getWithStat(path("policies", property, cluster, namespace)).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace " + nsName + " does not exist"));
policiesNode.getKey().message_ttl_in_seconds = messageTTL;
// Write back the new policies into zookeeper
globalZk().setData(path("policies", property, cluster, namespace), jsonMapper().writeValueAsBytes(policiesNode.getKey()), policiesNode.getValue().getVersion());
policiesCache().invalidate(path("policies", property, cluster, namespace));
log.info("[{}] Successfully updated the message TTL on namespace {}/{}/{}", clientAppId(), property, cluster, namespace);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update the message TTL 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 the message TTL on namespace {}/{}/{} expected policy node version={} : concurrent modification", clientAppId(), property, cluster, namespace, policiesNode.getValue().getVersion());
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (Exception e) {
log.error("[{}] Failed to update the message TTL on namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class Namespaces method clearNamespaceBundleBacklog.
@POST
@Path("/{property}/{cluster}/{namespace}/{bundle}/clearBacklog")
@ApiOperation(value = "Clear backlog for all destinations on a namespace bundle.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void clearNamespaceBundleBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
validateNamespaceBundleOwnership(nsName, policies.bundles, bundleRange, authoritative, true);
clearBacklog(nsName, bundleRange, null);
log.info("[{}] Successfully cleared backlog on namespace bundle {}/{}", clientAppId(), nsName.toString(), bundleRange);
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class Namespaces method clearNamespaceBundleBacklogForSubscription.
@POST
@Path("/{property}/{cluster}/{namespace}/{bundle}/clearBacklog/{subscription}")
@ApiOperation(value = "Clear backlog for a given subscription on all destinations on a namespace bundle.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void clearNamespaceBundleBacklogForSubscription(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("subscription") String subscription, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
validateNamespaceBundleOwnership(nsName, policies.bundles, bundleRange, authoritative, true);
clearBacklog(nsName, bundleRange, subscription);
log.info("[{}] Successfully cleared backlog for subscription {} on namespace bundle {}/{}", clientAppId(), subscription, nsName.toString(), bundleRange);
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class ServiceUnitZkUtils method suBundleFromPath.
public static final NamespaceBundle suBundleFromPath(String path, NamespaceBundleFactory factory) {
String[] parts = path.split("/");
checkArgument(parts.length > 2);
checkArgument(parts[1].equals("namespace"));
checkArgument(parts.length > 5);
Range<Long> range = getHashRange(parts[5]);
return factory.getBundle(new NamespaceName(parts[2], parts[3], parts[4]), range);
}
Aggregations