use of org.apache.pulsar.common.naming.NamespaceName 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;
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NonPersistentTopics method getListFromBundle.
@GET
@Path("/{property}/{cluster}/{namespace}/{bundle}")
@ApiOperation(value = "Get the list of non-persistent topics under a namespace bundle.", 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> getListFromBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange) {
log.info("[{}] list of topics on namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
validateAdminAccessOnProperty(property);
Policies policies = getNamespacePolicies(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(NamespaceName.get(property, cluster, namespace));
}
NamespaceName fqnn = NamespaceName.get(property, cluster, namespace);
if (!isBundleOwnedByAnyBroker(fqnn, policies.bundles, bundleRange)) {
log.info("[{}] Namespace bundle is not owned by any broker {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
return null;
}
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, true, true);
try {
final List<String> topicList = Lists.newArrayList();
pulsar().getBrokerService().getTopics().forEach((name, topicFuture) -> {
TopicName topicName = TopicName.get(name);
if (nsBundle.includes(topicName)) {
topicList.add(name);
}
});
return topicList;
} catch (Exception e) {
log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespacesImpl method deleteNamespaceBundle.
@Override
public void deleteNamespaceBundle(String namespace, String bundleRange) throws PulsarAdminException {
try {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, bundleRange);
request(path).delete(ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespacesImpl method getPermissions.
@Override
public Map<String, Set<AuthAction>> getPermissions(String namespace) throws PulsarAdminException {
try {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, "permissions");
return request(path).get(new GenericType<Map<String, Set<AuthAction>>>() {
});
} catch (Exception e) {
throw getApiException(e);
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespacesImpl method getNamespaceAntiAffinityGroup.
@Override
public String getNamespaceAntiAffinityGroup(String namespace) throws PulsarAdminException {
try {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, "antiAffinity");
return request(path).get(new GenericType<String>() {
});
} catch (Exception e) {
throw getApiException(e);
}
}
Aggregations