use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class Namespaces method getBundlesData.
@GET
@Path("/{property}/{cluster}/{namespace}/bundles")
@ApiOperation(hidden = true, value = "Get the bundles split data.")
@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 = "Namespace is not setup to split in bundles") })
public BundlesData getBundlesData(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
validateNamespaceName(property, cluster, namespace);
Policies policies = getNamespacePolicies(namespaceName);
return policies.bundles;
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class Namespaces method removeNamespaceAntiAffinityGroup.
@DELETE
@Path("/{property}/{cluster}/{namespace}/antiAffinity")
@ApiOperation(value = "Remove anti-affinity group of 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") })
public void removeNamespaceAntiAffinityGroup(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateAdminAccessOnProperty(property);
validatePoliciesReadOnlyAccess();
log.info("[{}] Deleting anti-affinity group for {}/{}/{}", clientAppId(), property, cluster, namespace);
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);
policies.antiAffinityGroup = null;
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path(POLICIES, property, cluster, namespace));
log.info("[{}] Successfully removed anti-affinity group for a namespace={}/{}/{}", clientAppId(), property, cluster, namespace);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to remove anti-affinity group 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 remove anti-affinity group for namespace {}/{}/{}: concurrent modification", clientAppId(), property, cluster, namespace);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (Exception e) {
log.error("[{}] Failed to remove anti-affinity group for namespace {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class Namespaces method createNamespace.
@SuppressWarnings("deprecation")
@PUT
@Path("/{property}/{cluster}/{namespace}")
@ApiOperation(hidden = true, value = "Creates a new empty namespace with no policies attached.")
@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 already exists"), @ApiResponse(code = 412, message = "Namespace name is not valid") })
public void createNamespace(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, BundlesData initialBundles) {
validateNamespaceName(property, cluster, namespace);
if (!namespaceName.isGlobal()) {
// If the namespace is non global, make sure property has the access on the cluster. For global namespace,
// same check is made at the time of setting replication.
validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
}
Policies policies = new Policies();
if (initialBundles != null && initialBundles.getNumBundles() > 0) {
if (initialBundles.getBoundaries() == null || initialBundles.getBoundaries().size() == 0) {
policies.bundles = getBundles(initialBundles.getNumBundles());
} else {
policies.bundles = validateBundlesData(initialBundles);
}
} else {
int defaultNumberOfBundles = config().getDefaultNumberOfNamespaceBundles();
policies.bundles = getBundles(defaultNumberOfBundles);
}
internalCreateNamespace(policies);
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class Namespaces method getBacklogQuotaMap.
@GET
@Path("/{property}/{cluster}/{namespace}/backlogQuotaMap")
@ApiOperation(hidden = true, value = "Get backlog quota map on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateAdminAccessOnProperty(property);
validateNamespaceName(property, cluster, namespace);
Policies policies = getNamespacePolicies(namespaceName);
return policies.backlog_quota_map;
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class NonPersistentTopics method getList.
@GET
@Path("/{property}/{cluster}/{namespace}")
@ApiOperation(value = "Get the list of non-persistent topics under a namespace.", response = String.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace doesn't exist") })
public List<String> getList(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
log.info("[{}] list of topics on namespace {}/{}/{}/{}", clientAppId(), property, cluster, namespace);
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(property, cluster, namespace);
NamespaceName nsName = NamespaceName.get(property, cluster, namespace);
if (!cluster.equals(Constants.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
} else {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(nsName);
}
final List<CompletableFuture<List<String>>> futures = Lists.newArrayList();
final List<String> boundaries = policies.bundles.getBoundaries();
for (int i = 0; i < boundaries.size() - 1; i++) {
final String bundle = String.format("%s_%s", boundaries.get(i), boundaries.get(i + 1));
try {
futures.add(pulsar().getAdminClient().nonPersistentTopics().getListInBundleAsync(nsName.toString(), bundle));
} catch (PulsarServerException e) {
log.error(String.format("[%s] Failed to get list of topics under namespace %s/%s/%s/%s", clientAppId(), property, cluster, namespace, bundle), e);
throw new RestException(e);
}
}
final List<String> topics = Lists.newArrayList();
try {
FutureUtil.waitForAll(futures).get();
futures.forEach(topicListFuture -> {
try {
if (topicListFuture.isDone() && topicListFuture.get() != null) {
topics.addAll(topicListFuture.get());
}
} catch (InterruptedException | ExecutionException e) {
log.error(String.format("[%s] Failed to get list of topics under namespace %s/%s/%s", clientAppId(), property, cluster, namespace), e);
}
});
} catch (InterruptedException | ExecutionException e) {
log.error(String.format("[%s] Failed to get list of topics under namespace %s/%s/%s", clientAppId(), property, cluster, namespace), e);
throw new RestException(e instanceof ExecutionException ? e.getCause() : e);
}
return topics;
}
Aggregations