use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class NamespacesImpl method setBacklogQuota.
@Override
public void setBacklogQuota(String namespace, BacklogQuota backlogQuota) throws PulsarAdminException {
try {
NamespaceName ns = new NamespaceName(namespace);
request(namespaces.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path("backlogQuota")).post(Entity.entity(backlogQuota, MediaType.APPLICATION_JSON), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class NamespacesImpl method unload.
@Override
public void unload(String namespace) throws PulsarAdminException {
try {
NamespaceName ns = new NamespaceName(namespace);
request(namespaces.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path("unload")).put(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class NamespacesImpl method setRetention.
@Override
public void setRetention(String namespace, RetentionPolicies retention) throws PulsarAdminException {
try {
NamespaceName ns = new NamespaceName(namespace);
request(namespaces.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path("retention")).post(Entity.entity(retention, MediaType.APPLICATION_JSON), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class Namespaces method deleteNamespaceBundle.
@DELETE
@Path("/{property}/{cluster}/{namespace}/{bundle}")
@ApiOperation(value = "Delete a namespace bundle and all the destinations under it.")
@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 = 409, message = "Namespace bundle is not empty") })
public void deleteNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
// ensure that non-global namespace is directed to the correct cluster
validateClusterOwnership(cluster);
Policies policies = getNamespacePolicies(property, cluster, namespace);
// ensure the local cluster is the only cluster for the global namespace configuration
try {
if (cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
if (policies.replication_clusters.size() > 1) {
// There are still more than one clusters configured for the global namespace
throw new RestException(Status.PRECONDITION_FAILED, "Cannot delete the global namespace " + nsName + ". There are still more than one replication clusters configured.");
}
if (policies.replication_clusters.size() == 1 && !policies.replication_clusters.contains(config().getClusterName())) {
// the only replication cluster is other cluster, redirect
String replCluster = policies.replication_clusters.get(0);
ClusterData replClusterData = clustersCache().get(AdminResource.path("clusters", replCluster)).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Cluser " + replCluster + " does not exist"));
URL replClusterUrl;
if (!config().isTlsEnabled()) {
replClusterUrl = new URL(replClusterData.getServiceUrl());
} else if (!replClusterData.getServiceUrlTls().isEmpty()) {
replClusterUrl = new URL(replClusterData.getServiceUrlTls());
} else {
throw new RestException(Status.PRECONDITION_FAILED, "The replication cluster does not provide TLS encrypted service");
}
URI redirect = UriBuilder.fromUri(uri.getRequestUri()).host(replClusterUrl.getHost()).port(replClusterUrl.getPort()).replaceQueryParam("authoritative", false).build();
log.debug("[{}] Redirecting the rest call to {}: cluster={}", clientAppId(), redirect, cluster);
throw new WebApplicationException(Response.temporaryRedirect(redirect).build());
}
}
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
throw new RestException(e);
}
NamespaceBundle bundle = validateNamespaceBundleOwnership(nsName, policies.bundles, bundleRange, authoritative, true);
try {
List<String> destinations = getDestinations(property, cluster, namespace);
for (String destination : destinations) {
NamespaceBundle destinationBundle = (NamespaceBundle) pulsar().getNamespaceService().getBundle(DestinationName.get(destination));
if (bundle.equals(destinationBundle)) {
throw new RestException(Status.CONFLICT, "Cannot delete non empty bundle");
}
}
// remove from owned namespace map and ephemeral node from ZK
pulsar().getNamespaceService().removeOwnedServiceUnit(bundle);
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
log.error("[{}] Failed to remove namespace bundle {}/{}", clientAppId(), nsName.toString(), bundleRange, e);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.
the class ResourceQuotas method getNamespaceBundleResourceQuota.
@GET
@Path("/{property}/{cluster}/{namespace}/{bundle}")
@ApiOperation(value = "Get resource quota of a namespace bundle.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public ResourceQuota getNamespaceBundleResourceQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange) {
validateSuperUserAccess();
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 {
return pulsar().getLocalZkCacheService().getResourceQuotaCache().getQuota(nsBundle);
} catch (Exception e) {
log.error("[{}] Failed to get resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
throw new RestException(e);
}
}
Aggregations