.mapToObj( partitionIndex -> { String partitionName = TopicName.get(topicName).getPartition(partitionIndex).toString(); CompletableFuture<Consumer<T>> subFuture = new CompletableFuture<>(); ConsumerImpl<T> newConsumer = new ConsumerImpl<>(client, partitionName, configurationData, .filter(consumer1 -> { String consumerTopicName = consumer1.getTopic(); if (TopicName.get(consumerTopicName).getPartitionedTopicName().equals( TopicName.get(topicName).getPartitionedTopicName().toString())) { return true; } else { topic, subscription, topicName, numPartitions, allTopicPartitionsNumber.get()); if (this.namespaceName == null) { this.namespaceName = TopicName.get(topicName).getNamespaceObject();
/** * Returns the name of the persistence resource associated with the completeTopicName. * * @return the relative path to be used in persistence */ public String getPersistenceNamingEncoding() { // The convention is: domain://tenant/namespace/topic // We want to persist in the order: tenant/namespace/domain/topic // For legacy naming scheme, the convention is: domain://tenant/cluster/namespace/topic // We want to persist in the order: tenant/cluster/namespace/domain/topic if (isV2()) { return String.format("%s/%s/%s/%s", tenant, namespacePortion, domain, getEncodedLocalName()); } else { return String.format("%s/%s/%s/%s/%s", tenant, cluster, namespacePortion, domain, getEncodedLocalName()); } }
public String getSchemaName() { return getTenant() + "/" + getNamespacePortion() + "/" + getEncodedLocalName(); }
public static NamespaceName getNameSpaceFromPattern(Pattern pattern) { return TopicName.get(pattern.pattern()).getNamespaceObject(); }
/** * * @return Backlog quota for topic */ @Override public BacklogQuota getBacklogQuota() { TopicName topicName = TopicName.get(this.getName()); String namespace = topicName.getNamespace(); String policyPath = AdminResource.path(POLICIES, namespace); BacklogQuota backlogQuota = brokerService.getBacklogQuotaManager().getBacklogQuota(namespace, policyPath); return backlogQuota; }
public static boolean isValid(String topic) { try { get(topic); return true; } catch (Exception e) { return false; } }
} catch (RestException e) { try { validateAdminAccessForTenant(pulsar, clientAppId, originalPrincipal, topicName.getTenant()); } catch (RestException authException) { log.warn("Failed to authorize {} on cluster {}", clientAppId, topicName.toString()); throw new PulsarClientException(String.format("Authorization failed %s on topic %s with error %s", clientAppId, topicName.toString(), authException.getMessage())); topicName.toString(), ex.getMessage(), ex); throw ex; String path = path(PARTITIONED_TOPIC_PATH_ZNODE, topicName.getNamespace(), topicName.getDomain().toString(), topicName.getEncodedLocalName()); checkLocalOrGetPeerReplicationCluster(pulsar, topicName.getNamespaceObject()) .thenCompose(res -> fetchPartitionedTopicMetadataAsync(pulsar, path)).thenAccept(metadata -> { if (log.isDebugEnabled()) {
static String validateNonPersistentTopic(List<String> params) { String topic = checkArgument(params); TopicName topicName = TopicName.get(topic); if (topicName.getDomain() != TopicDomain.non_persistent) { throw new ParameterException("Need to provide a non-persistent topic name"); } return topicName.toString(); }
@Override public CompletableFuture<List<String>> getPartitionsForTopic(String topic) { return getPartitionedTopicMetadata(topic).thenApply(metadata -> { if (metadata.partitions > 1) { TopicName topicName = TopicName.get(topic); List<String> partitions = new ArrayList<>(metadata.partitions); for (int i = 0; i < metadata.partitions; i++) { partitions.add(topicName.getPartition(i).toString()); } return partitions; } else { return Collections.singletonList(topic); } }); }
private boolean topicNameValid(String topicName) { checkArgument(TopicName.isValid(topicName), "Invalid topic name:" + topicName); checkArgument(!topics.containsKey(topicName), "Topics already contains topic:" + topicName); if (this.namespaceName != null) { checkArgument(TopicName.get(topicName).getNamespace().toString().equals(this.namespaceName.toString()), "Topic " + topicName + " not in same namespace with Topics"); } return true; }
private CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(InetSocketAddress socketAddress, TopicName topicName) { CompletableFuture<PartitionedTopicMetadata> partitionFuture = new CompletableFuture<PartitionedTopicMetadata>(); client.getCnxPool().getConnection(socketAddress).thenAccept(clientCnx -> { long requestId = client.newRequestId(); ByteBuf request = Commands.newPartitionMetadataRequest(topicName.toString(), requestId); clientCnx.newLookup(request, requestId).thenAccept(lookupDataResult -> { try { partitionFuture.complete(new PartitionedTopicMetadata(lookupDataResult.partitions)); } catch (Exception e) { partitionFuture.completeExceptionally(new PulsarClientException.LookupException( format("Failed to parse partition-response redirect=%s , partitions with %s", lookupDataResult.redirect, lookupDataResult.partitions, e.getMessage()))); } }).exceptionally((e) -> { log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(), e.getCause().getMessage(), e); partitionFuture.completeExceptionally(e); return null; }); }).exceptionally(connectionException -> { partitionFuture.completeExceptionally(connectionException); return null; }); return partitionFuture; }
@Override public String lookupTopic(String topic) throws PulsarAdminException { TopicName topicName = TopicName.get(topic); String prefix = topicName.isV2() ? "/topic" : "/destination"; WebTarget target = v2lookup.path(prefix).path(topicName.getLookupName()); try { return doTopicLookup(target); } catch (Exception e) { throw getApiException(e); } }
TopicName topicName = TopicName.get(topic); String partitionedTopicPath = path(AdminResource.PARTITIONED_TOPIC_PATH_ZNODE, topicName.getNamespace().toString(), topicName.getDomain().toString(), topicName.getEncodedLocalName()); boolean isPartitionedTopic = false; try {
protected void internalDeletePartitionedTopic(boolean authoritative, boolean force) { validateAdminAccessForTenant(topicName.getTenant()); PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative); int numPartitions = partitionMetadata.partitions; try { for (int i = 0; i < numPartitions; i++) { TopicName topicNamePartition = topicName.getPartition(i); pulsar().getAdminClient().persistentTopics().deleteAsync(topicNamePartition.toString(), force) .whenComplete((r, ex) -> { if (ex != null) { topicName.getEncodedLocalName()); try { globalZk().delete(path, -1);
@Override public CompletableFuture<List<String>> getTopicsUnderNamespace(NamespaceName namespace, Mode mode) { CompletableFuture<List<String>> future = new CompletableFuture<>(); String format = namespace.isV2() ? "admin/v2/namespaces/%s/topics?mode=%s" : "admin/namespaces/%s/destinations?mode=%s"; httpClient .get(String.format(format, namespace, mode.toString()), String[].class) .thenAccept(topics -> { List<String> result = Lists.newArrayList(); // do not keep partition part of topic name Arrays.asList(topics).forEach(topic -> { String filtered = TopicName.get(topic).getPartitionedTopicName(); if (!result.contains(filtered)) { result.add(filtered); } }); future.complete(result);}) .exceptionally(ex -> { log.warn("Failed to getTopicsUnderNamespace namespace: {}.", namespace, ex.getMessage()); future.completeExceptionally(ex); return null; }); return future; }
private void put(TopicName topicName, PendingBookieOpsStats bookieOpsStats) { String namespace = topicName.getNamespace(); if (!nsBookieClientStatsMap.containsKey(namespace)) { Map<String, PendingBookieOpsStats> destBookieClientStatsMap = Maps.newTreeMap(); destBookieClientStatsMap.put(topicName.toString(), bookieOpsStats); nsBookieClientStatsMap.put(namespace, destBookieClientStatsMap); } else { nsBookieClientStatsMap.get(namespace).put(topicName.toString(), bookieOpsStats); } } }
public NamespaceBundle findBundle(TopicName topicName) { checkArgument(this.nsname.equals(topicName.getNamespaceObject())); long hashCode = factory.getLongHashCode(topicName.toString()); NamespaceBundle bundle = getBundle(hashCode); if (topicName.getDomain().equals(TopicDomain.non_persistent)) { bundle.setHasNonPersistentTopic(true); } return bundle; }
protected PartitionedTopicMetadata getPartitionedTopicMetadata(TopicName topicName, boolean authoritative) { validateClusterOwnership(topicName.getCluster()); // validates global-namespace contains local/peer cluster: if peer/local cluster present then lookup can // serve/redirect request else fail partitioned-metadata-request so, client fails while creating // producer/consumer validateGlobalNamespaceOwnership(topicName.getNamespaceObject()); try { checkConnect(topicName); } catch (WebApplicationException e) { validateAdminAccessForTenant(topicName.getTenant()); } catch (Exception e) { // unknown error marked as internal server error log.warn("Unexpected error while authorizing lookup. topic={}, role={}. Error: {}", topicName, clientAppId(), e.getMessage(), e); throw new RestException(e); } String path = path(PARTITIONED_TOPIC_PATH_ZNODE, namespaceName.toString(), domain(), topicName.getEncodedLocalName()); PartitionedTopicMetadata partitionMetadata = fetchPartitionedTopicMetadata(pulsar(), path); if (log.isDebugEnabled()) { log.debug("[{}] Total number of partitions for topic {} is {}", clientAppId(), topicName, partitionMetadata.partitions); } return partitionMetadata; }