private boolean checkCluster(DestinationName destination) { if (destination.isGlobal() || conf.getClusterName().equals(destination.getCluster())) { return true; } else { if (log.isDebugEnabled()) { log.debug("Destination [{}] does not belong to local cluster [{}]", destination.toString(), conf.getClusterName()); } return false; } }
CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(DiscoveryService service, DestinationName destination, String role) { CompletableFuture<PartitionedTopicMetadata> metadataFuture = new CompletableFuture<>(); try { checkAuthorization(service, destination, role); final String path = path(PARTITIONED_TOPIC_PATH_ZNODE, destination.getProperty(), destination.getCluster(), destination.getNamespacePortion(), "persistent", destination.getEncodedLocalName()); // gets the number of partitions from the zk cache globalZkCache .getDataAsync(path, (key, content) -> getThreadLocal().readValue(content, PartitionedTopicMetadata.class)) .thenAccept(metadata -> { // if the partitioned topic is not found in zk, then the topic // is not partitioned if (metadata.isPresent()) { metadataFuture.complete(metadata.get()); } else { metadataFuture.complete(new PartitionedTopicMetadata()); } }).exceptionally(ex -> { metadataFuture.completeExceptionally(ex); return null; }); } catch (Exception e) { metadataFuture.completeExceptionally(e); } return metadataFuture; }
throw ex; String path = path(PARTITIONED_TOPIC_PATH_ZNODE, dn.getProperty(), dn.getCluster(), dn.getNamespacePortion(), "persistent", dn.getEncodedLocalName()); fetchPartitionedTopicMetadataAsync(pulsar, path).thenAccept(metadata -> {
private CompletableFuture<Void> updatePartitionedTopic(DestinationName dn, int numPartitions) { String path = path(PARTITIONED_TOPIC_PATH_ZNODE, dn.getProperty(), dn.getCluster(), dn.getNamespacePortion(), domain(), dn.getEncodedLocalName()); CompletableFuture<Void> updatePartition = new CompletableFuture<>(); createSubscriptions(dn, numPartitions).thenAccept(res -> { try { byte[] data = jsonMapper().writeValueAsBytes(new PartitionedTopicMetadata(numPartitions)); globalZk().setData(path, data, -1, (rc, path1, ctx, stat) -> { if (rc == KeeperException.Code.OK.intValue()) { updatePartition.complete(null); } else { updatePartition.completeExceptionally(KeeperException.create(KeeperException.Code.get(rc), "failed to create update partitions")); } }, null); } catch (Exception e) { updatePartition.completeExceptionally(e); } }).exceptionally(ex -> { updatePartition.completeExceptionally(ex); return null; }); return updatePartition; }
final String cluster = fqdn.getCluster();
validateClusterOwnership(topic.getCluster()); checkConnect(topic); validateReplicationSettingsOnNamespace(pulsar(), topic.getNamespaceObject());
public PartitionedTopicMetadata getPartitionedTopicMetadata(String property, String cluster, String namespace, String destination, boolean authoritative) { DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination); validateClusterOwnership(dn.getCluster()); try { checkConnect(dn); } catch (WebApplicationException e) { validateAdminAccessOnProperty(dn.getProperty()); } catch (Exception e) { // unknown error marked as internal server error log.warn("Unexpected error while authorizing lookup. destination={}, role={}. Error: {}", destination, clientAppId(), e.getMessage(), e); throw new RestException(e); } String path = path(PARTITIONED_TOPIC_PATH_ZNODE, property, cluster, namespace, domain(), dn.getEncodedLocalName()); PartitionedTopicMetadata partitionMetadata = fetchPartitionedTopicMetadata(pulsar(), path); if (log.isDebugEnabled()) { log.debug("[{}] Total number of partitions for topic {} is {}", clientAppId(), dn, partitionMetadata.partitions); } return partitionMetadata; }
String path = path(PARTITIONED_TOPIC_PATH_ZNODE, dn.getProperty(), dn.getCluster(), dn.getNamespacePortion(), domain(), dn.getEncodedLocalName()); CompletableFuture<Void> result = new CompletableFuture<>();