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 sendLookupResponse(long requestId) { try { LoadManagerReport availableBroker = service.getDiscoveryProvider().nextBroker(); ctx.writeAndFlush(Commands.newLookupResponse(availableBroker.getPulsarServiceUrl(), availableBroker.getPulsarServiceUrlTls(), false, Redirect, requestId, false)); } catch (PulsarServerException e) { LOG.warn("[{}] Failed to get next active broker {}", remoteAddress, e.getMessage(), e); ctx.writeAndFlush( Commands.newLookupErrorResponse(ServerError.ServiceNotReady, e.getMessage(), requestId)); } }
private void performLookup(long clientRequestId, String topic, String brokerServiceUrl, boolean authoritative, int numberOfRetries) { if (numberOfRetries == 0) { proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady, "Reached max number of redirections", clientRequestId)); return; } catch (URISyntaxException e) { proxyConnection.ctx().writeAndFlush( Commands.newLookupErrorResponse(ServerError.MetadataError, e.getMessage(), clientRequestId)); return; log.warn("[{}] Failed to lookup topic {}: {}", clientAddress, topic, ex.getMessage()); proxyConnection.ctx().writeAndFlush( Commands.newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId)); return null; }); Commands.newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId)); return null; });
log.warn("[{}] {} with role {} and proxyClientAuthRole {} on topic {}", remoteAddress, msg, authRole, originalPrincipal, topicName); ctx.writeAndFlush(newLookupErrorResponse(ServerError.AuthorizationError, msg, requestId)); lookupSemaphore.release(); return; ctx.writeAndFlush(newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), requestId)); final String msg = "Proxy Client is not authorized to Lookup"; log.warn("[{}] {} with role {} on topic {}", remoteAddress, msg, authRole, topicName); ctx.writeAndFlush(newLookupErrorResponse(ServerError.AuthorizationError, msg, requestId)); lookupSemaphore.release(); final String msg = "Exception occured while trying to authorize lookup"; log.warn("[{}] {} with role {} on topic {}", remoteAddress, msg, authRole, topicName, ex); ctx.writeAndFlush(newLookupErrorResponse(ServerError.AuthorizationError, msg, requestId)); lookupSemaphore.release(); return null; log.debug("[{}] Failed lookup due to too many lookup-requests {}", remoteAddress, topicName); ctx.writeAndFlush(newLookupErrorResponse(ServerError.TooManyRequests, "Failed due to too many pending lookup requests", requestId));
} catch (Exception e) { log.warn("[{}] Failed to get next active broker {}", clientAddress, e.getMessage(), e); proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady, e.getMessage(), clientRequestId)); return; throttlingErrorMessage); proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady, throttlingErrorMessage, clientRequestId));
log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(), ex.getCause().getMessage(), ex); proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId)); return null;
} catch (RestException authException) { log.warn("Failed to authorized {} on cluster {}", clientAppId, topicName.toString()); validationFuture.complete(newLookupErrorResponse(ServerError.AuthorizationError, authException.getMessage(), requestId)); return; validationFuture.complete(newLookupErrorResponse(ServerError.MetadataError, "Redirected cluster's brokerService url is not configured", requestId)); return; newLookupErrorResponse(ServerError.MetadataError, ex.getMessage(), requestId)); return null; }); lookupfuture.complete(newLookupErrorResponse(ServerError.ServiceNotReady, "No broker was available to own " + topicName, requestId)); return; newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), requestId)); return null; }); lookupfuture.complete(newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), requestId)); return null; });