private TopicName validateTopicName(String topic, long requestId, GeneratedMessageLite requestCommand) { try { return TopicName.get(topic); } catch (Throwable t) { if (log.isDebugEnabled()) { log.debug("[{}] Failed to parse topic name '{}'", remoteAddress, topic, t); } if (requestCommand instanceof CommandLookupTopic) { ctx.writeAndFlush(Commands.newLookupErrorResponse(ServerError.InvalidTopicName, "Invalid topic name: " + t.getMessage(), requestId)); } else if (requestCommand instanceof CommandPartitionedTopicMetadata) { ctx.writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.InvalidTopicName, "Invalid topic name: " + t.getMessage(), requestId)); } else { ctx.writeAndFlush(Commands.newError(requestId, ServerError.InvalidTopicName, "Invalid topic name: " + t.getMessage())); } return null; } }
private void sendPartitionMetadataResponse(CommandPartitionedTopicMetadata partitionMetadata) { final long requestId = partitionMetadata.getRequestId(); TopicName topicName = TopicName.get(partitionMetadata.getTopic()); service.getDiscoveryProvider() .getPartitionedTopicMetadata(service, topicName, authRole, authenticationData) .thenAccept(metadata -> { if (LOG.isDebugEnabled()) { LOG.debug("[{}] Total number of partitions for topic {} is {}", authRole, topicName, metadata.partitions); } ctx.writeAndFlush(Commands.newPartitionMetadataResponse(metadata.partitions, requestId)); }).exceptionally(ex -> { LOG.warn("[{}] Failed to get partitioned metadata for topic {} {}", remoteAddress, topicName, ex.getMessage(), ex); ctx.writeAndFlush( Commands.newPartitionMetadataResponse(ServerError.ServiceNotReady, ex.getMessage(), requestId)); return null; }); }
public void handlePartitionMetadataResponse(CommandPartitionedTopicMetadata partitionMetadata) { partitionsMetadataRequests.inc(); if (log.isDebugEnabled()) { log.debug("[{}] Received PartitionMetadataLookup", clientAddress); } final long clientRequestId = partitionMetadata.getRequestId(); if (this.service.getLookupRequestSemaphore().tryAcquire()) { handlePartitionMetadataResponse(partitionMetadata, clientRequestId); this.service.getLookupRequestSemaphore().release(); } else { rejectedPartitionsMetadataRequests.inc(); if (log.isDebugEnabled()) { log.debug("PartitionMetaData Request ID {} from {} rejected - {}.", clientRequestId, clientAddress, throttlingErrorMessage); } proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.ServiceNotReady, throttlingErrorMessage, clientRequestId)); } }
log.warn("[{}] {} with role {} and proxyClientAuthRole {} on topic {}", remoteAddress, msg, authRole, originalPrincipal, topicName); ctx.writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.AuthorizationError, msg, requestId)); lookupSemaphore.release(); if (ex == null) { int partitions = metadata.partitions; ctx.writeAndFlush(Commands.newPartitionMetadataResponse(partitions, requestId)); } else { if (ex instanceof PulsarClientException) { log.warn("Failed to authorize {} at [{}] on topic {} : {}", getRole(), remoteAddress, topicName, ex.getMessage()); ctx.writeAndFlush(Commands.newPartitionMetadataResponse( ServerError.AuthorizationError, ex.getMessage(), requestId)); } else { && ((RestException) ex).getResponse().getStatus() < 500 ? ServerError.MetadataError : ServerError.ServiceNotReady; ctx.writeAndFlush(Commands.newPartitionMetadataResponse(error, ex.getMessage(), requestId)); log.warn("[{}] {} with role {} on topic {}", remoteAddress, msg, authRole, topicName); ctx.writeAndFlush( Commands.newPartitionMetadataResponse(ServerError.AuthorizationError, msg, requestId)); lookupSemaphore.release(); final String msg = "Exception occured while trying to authorize get Partition Metadata"; log.warn("[{}] {} with role {} on topic {}", remoteAddress, msg, authRole, topicName);
Commands.newPartitionMetadataResponse(metadata.partitions, clientRequestId)); }).exceptionally(ex -> { log.warn("[{}] Failed to get partitioned metadata for topic {} {}", clientAddress, topicName, ex.getMessage(), ex); proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse( ServerError.ServiceNotReady, ex.getMessage(), clientRequestId)); return null; brokerURI = new URI(brokerServiceURL); } catch (URISyntaxException e) { proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.MetadataError, e.getMessage(), clientRequestId)); return; clientCnx.newLookup(command, requestId).thenAccept(lookupDataResult -> { proxyConnection.ctx().writeAndFlush( Commands.newPartitionMetadataResponse(lookupDataResult.partitions, clientRequestId)); }).exceptionally((ex) -> { log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(), }).exceptionally(ex -> { proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId)); return null;