use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PersistentTopicsImpl method deletePartitionedTopicAsync.
@Override
public CompletableFuture<Void> deletePartitionedTopicAsync(String topic) {
TopicName tn = validateTopic(topic);
WebTarget path = topicPath(tn, "partitions");
return asyncDeleteRequest(path);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class LookupProxyHandler method handlePartitionMetadataResponse.
private void handlePartitionMetadataResponse(CommandPartitionedTopicMetadata partitionMetadata, long clientRequestId) {
TopicName topicName = TopicName.get(partitionMetadata.getTopic());
if (isBlank(brokerServiceURL)) {
service.getDiscoveryProvider().getPartitionedTopicMetadata(service, topicName, proxyConnection.clientAuthRole, proxyConnection.authenticationData).thenAccept(metadata -> {
if (log.isDebugEnabled()) {
log.debug("[{}] Total number of partitions for topic {} is {}", proxyConnection.clientAuthRole, topicName, metadata.partitions);
}
proxyConnection.ctx().writeAndFlush(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;
});
} else {
URI brokerURI;
try {
brokerURI = new URI(brokerServiceURL);
} catch (URISyntaxException e) {
proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.MetadataError, e.getMessage(), clientRequestId));
return;
}
InetSocketAddress addr = new InetSocketAddress(brokerURI.getHost(), brokerURI.getPort());
if (log.isDebugEnabled()) {
log.debug("Getting connections to '{}' for Looking up topic '{}' with clientReq Id '{}'", addr, topicName.getPartitionedTopicName(), clientRequestId);
}
service.getConnectionPool().getConnection(addr).thenAccept(clientCnx -> {
// Connected to backend broker
long requestId = service.newRequestId();
ByteBuf command;
if (service.getConfiguration().isAuthenticationEnabled()) {
command = Commands.newPartitionMetadataRequest(topicName.toString(), requestId, proxyConnection.clientAuthRole, proxyConnection.clientAuthData, proxyConnection.clientAuthMethod);
} else {
command = Commands.newPartitionMetadataRequest(topicName.toString(), requestId);
}
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(), ex.getCause().getMessage(), ex);
proxyConnection.ctx().writeAndFlush(Commands.newLookupErrorResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId));
return null;
});
}).exceptionally(ex -> {
// Failed to connect to backend broker
proxyConnection.ctx().writeAndFlush(Commands.newPartitionMetadataResponse(ServerError.ServiceNotReady, ex.getMessage(), clientRequestId));
return null;
});
}
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class BacklogQuotaManager method handleExceededBacklogQuota.
/**
* Handle exceeded backlog by using policies set in the zookeeper for given topic
*
* @param persistentTopic
* Topic on which backlog has been exceeded
*/
public void handleExceededBacklogQuota(PersistentTopic persistentTopic) {
TopicName topicName = TopicName.get(persistentTopic.getName());
String namespace = topicName.getNamespace();
String policyPath = AdminResource.path(POLICIES, namespace);
BacklogQuota quota = getBacklogQuota(namespace, policyPath);
log.info("Backlog quota exceeded for topic [{}]. Applying [{}] policy", persistentTopic.getName(), quota.getPolicy());
switch(quota.getPolicy()) {
case consumer_backlog_eviction:
dropBacklog(persistentTopic, quota);
break;
case producer_exception:
case producer_request_hold:
disconnectProducers(persistentTopic);
break;
default:
break;
}
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class BrokerService method addTopicToStatsMaps.
private void addTopicToStatsMaps(TopicName topicName, Topic topic) {
try {
NamespaceBundle namespaceBundle = pulsar.getNamespaceService().getBundle(topicName);
if (namespaceBundle != null) {
synchronized (multiLayerTopicsMap) {
String serviceUnit = namespaceBundle.toString();
//
multiLayerTopicsMap.computeIfAbsent(topicName.getNamespace(), //
k -> new ConcurrentOpenHashMap<>()).computeIfAbsent(serviceUnit, //
k -> new ConcurrentOpenHashMap<>()).put(topicName.toString(), topic);
}
}
invalidateOfflineTopicStatCache(topicName);
} catch (Exception e) {
log.warn("Got exception when retrieving bundle name during create persistent topic", e);
}
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class BrokerService method checkTopicNsOwnership.
void checkTopicNsOwnership(final String topic) throws RuntimeException {
TopicName topicName = TopicName.get(topic);
boolean ownedByThisInstance;
try {
ownedByThisInstance = pulsar.getNamespaceService().isServiceUnitOwned(topicName);
} catch (Exception e) {
log.debug(String.format("Failed to check the ownership of the topic: %s", topicName), e);
throw new RuntimeException(new ServerMetadataException(e));
}
if (!ownedByThisInstance) {
String msg = String.format("Namespace not served by this instance. Please redo the lookup. " + "Request is denied: namespace=%s", topicName.getNamespace());
log.warn(msg);
throw new RuntimeException(new ServiceUnitNotReadyException(msg));
}
}
Aggregations