use of org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace in project pulsar by apache.
the class ServerCnx method handleGetTopicsOfNamespace.
@Override
protected void handleGetTopicsOfNamespace(CommandGetTopicsOfNamespace commandGetTopicsOfNamespace) {
final long requestId = commandGetTopicsOfNamespace.getRequestId();
final String namespace = commandGetTopicsOfNamespace.getNamespace();
final CommandGetTopicsOfNamespace.Mode mode = commandGetTopicsOfNamespace.getMode();
final NamespaceName namespaceName = NamespaceName.get(namespace);
final Semaphore lookupSemaphore = service.getLookupRequestSemaphore();
if (lookupSemaphore.tryAcquire()) {
if (invalidOriginalPrincipal(originalPrincipal)) {
final String msg = "Valid Proxy Client role should be provided for getTopicsOfNamespaceRequest ";
log.warn("[{}] {} with role {} and proxyClientAuthRole {} on namespace {}", remoteAddress, msg, authRole, originalPrincipal, namespaceName);
commandSender.sendErrorResponse(requestId, ServerError.AuthorizationError, msg);
lookupSemaphore.release();
return;
}
isNamespaceOperationAllowed(namespaceName, NamespaceOperation.GET_TOPICS).thenApply(isAuthorized -> {
if (isAuthorized) {
getBrokerService().pulsar().getNamespaceService().getListOfTopics(namespaceName, mode).thenAccept(topics -> {
if (log.isDebugEnabled()) {
log.debug("[{}] Received CommandGetTopicsOfNamespace for namespace [//{}] by {}, size:{}", remoteAddress, namespace, requestId, topics.size());
}
commandSender.sendGetTopicsOfNamespaceResponse(topics, requestId);
lookupSemaphore.release();
}).exceptionally(ex -> {
log.warn("[{}] Error GetTopicsOfNamespace for namespace [//{}] by {}", remoteAddress, namespace, requestId);
commandSender.sendErrorResponse(requestId, BrokerServiceException.getClientErrorCode(new ServerMetadataException(ex)), ex.getMessage());
lookupSemaphore.release();
return null;
});
} else {
final String msg = "Proxy Client is not authorized to GetTopicsOfNamespace";
log.warn("[{}] {} with role {} on namespace {}", remoteAddress, msg, getPrincipal(), namespaceName);
commandSender.sendErrorResponse(requestId, ServerError.AuthorizationError, msg);
lookupSemaphore.release();
}
return null;
}).exceptionally(ex -> {
logNamespaceNameAuthException(remoteAddress, "GetTopicsOfNamespace", getPrincipal(), Optional.of(namespaceName), ex);
final String msg = "Exception occurred while trying to authorize GetTopicsOfNamespace";
commandSender.sendErrorResponse(requestId, ServerError.AuthorizationError, msg);
lookupSemaphore.release();
return null;
});
} else {
if (log.isDebugEnabled()) {
log.debug("[{}] Failed GetTopicsOfNamespace lookup due to too many lookup-requests {}", remoteAddress, namespaceName);
}
commandSender.sendErrorResponse(requestId, ServerError.TooManyRequests, "Failed due to too many pending lookup requests");
}
}
use of org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace in project pulsar by apache.
the class Commands method newGetTopicsOfNamespaceRequest.
public static ByteBuf newGetTopicsOfNamespaceRequest(String namespace, long requestId, Mode mode) {
BaseCommand cmd = localCmd(Type.GET_TOPICS_OF_NAMESPACE);
CommandGetTopicsOfNamespace topics = cmd.setGetTopicsOfNamespace();
topics.setNamespace(namespace);
topics.setRequestId(requestId);
topics.setMode(mode);
return serializeWithSize(cmd);
}
Aggregations